<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    <font face="Helvetica, Arial, sans-serif">Hi Eric,<br>
      <br>
         it seems that is just what I needed. Thanks!  I will give it a
      whirl and yell<br>
      for help when (and if) I get into serious trouble ...<br>
      <br>
      Best,<br>
      <br>
                                                                           
      - Julian -<br>
    </font><br>
    <div class="moz-cite-prefix">On 5/3/2021 12:57 PM, Eric Pettersen
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:E6610904-2295-4B2D-A41A-B942526F0AA9@cgl.ucsf.edu">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      Hi Julian,
      <div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>It
        would seem that the first thing to do would be to get a list of
        the poses in order.  This gets a list of the currently open
        models:</div>
      <div class=""><br class="">
      </div>
      <div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre"> </span>import
          chimera</i></div>
      <div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre"> </span>models
          = chimera.openModels.list()</i></div>
      <div class=""><i class=""><br class="">
        </i></div>
      <div class=""><span style="font-style: normal;" class="">To
          extract the poses in order, the crucial information to know is
          that each model has an </span><i class="">id</i><span
          style="font-style: normal;" class=""> and </span><i class="">subid</i><span
          style="font-style: normal;" class=""> attribute, so each pose
          will have and </span><i class="">id</i><span
          style="font-style: normal;" class=""> of 1.  To get a list of
          them in order then is:</span></div>
      <div class=""><span style="font-style: normal;" class=""><br
            class="">
        </span></div>
      <div class=""><span class="Apple-tab-span" style="font-style: normal; white-space: pre;">       </span><i
          class="">poses = sorted([m for m in models if <a
            href="http://m.id" class="" moz-do-not-send="true">m.id</a> ==
          1], key=lambda m: m.subid)</i></div>
      <div class=""><br class="">
      </div>
      <div class=""><span style="font-style: normal;" class="">Then the
          number of poses is obviously </span><i class="">len(poses)</i><span
          style="font-style: normal;" class="">.  For most of the
          additional things you mentioned, the easiest thing to do is
          run the </span>equivalent command, <i class="">e.g.</i><span
          style="font-style: normal;" class="">:</span></div>
      <div class=""><span style="font-style: normal;" class=""><br
            class="">
        </span></div>
      <div class=""><span class="Apple-tab-span" style="font-style: normal; white-space: pre;">       </span><i
          class="">from chimera import runCommand as run</i></div>
      <div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre"> </span>for
          pose in poses:</i></div>
      <div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre">         </span>run("color
          red %s" % pose)</i></div>
      <div class=""><i class=""><br class="">
        </i></div>
      <div class=""><span style="font-style: normal;" class="">This may
          be all you need.  But the </span><i class="">run()</i><span
          style="font-style: normal;" class=""> call doesn't return any
          values, so for instance if you need to do different things in
          the Python code depending on </span><i class="">how many</i><span
          style="font-style: normal;" class=""> hydrogen bonds a pose
          forms, then you would have to call the underlying Python
          routine, which does return values.  That particular call is
          FindHBond.findHBonds(models).  I can expand on that if you
          need that kind of info.</span></div>
      <div class=""><span style="font-style: normal;" class=""><br
            class="">
        </span></div>
      <div class="">
        <div class="">--Eric</div>
        <div class=""><br class="">
        </div>
        <div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>Eric
          Pettersen</div>
        <div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>UCSF
          Computer Graphics Lab</div>
      </div>
      <div class=""><br class="">
      </div>
      <div class="">
        <div><br class="">
          <blockquote type="cite" class="">
            <div class="">On May 3, 2021, at 5:10 AM, Julian
              Tirado-Rives <<a
                href="mailto:julian.tirado-rives@yale.edu" class=""
                moz-do-not-send="true">julian.tirado-rives@yale.edu</a>>
              wrote:</div>
            <br class="Apple-interchange-newline">
            <div class="">
              <div class="">Dear Chimera (and ChimeraX) team:<br
                  class="">
                <br class="">
                   I need to find some python example or code snippet
                capable of<br class="">
                looping over all the molecules in a particular model and
                do some actions<br class="">
                separately in each one.<br class="">
                <br class="">
                    In our research we use several different docking
                programs and other<br class="">
                ways of generating poses of protein-ligand complexes,
                and using several<br class="">
                different programs to analyze them gets quite
                complicated. Instead,<br class="">
                we've found that the easiest way is to generate from
                each code, or using<br class="">
                conversion utilities such as babel, a pdb file of the
                host and a sdf or<br class="">
                mol2 file containing all the ligand poses and read them
                into chimera.<br class="">
                An excellent program, by the way. We use it all the
                time.<br class="">
                <br class="">
                   I would love to automate the process even further by
                doing all the<br class="">
                coloring, rendering, Hydrogen Bond and contact analysis,
                etc. in Python<br class="">
                rather than manually. I have been trying to do this, but
                have not found a way to do the following:<br class="">
                <br class="">
                If we have, for instance, the host in model #0, and the
                ligand poses in model #1 (#1.1, #1.2, ..., #1.N):<br
                  class="">
                <br class="">
                - Get from chimera the number of molecules in model #1
                (e.g what is N)<br class="">
                - loop from the first #1.1 to the last #1.N molecule<br
                  class="">
                - do some cations there (e.g select, color, find HB's,
                etc)<br class="">
                <br class="">
                  I think this should be a problem other people have
                encountered and<br class="">
                solved  before, but I have not been able to find an
                example in your<br class="">
                depository, the mailing lists, or even the book ... I
                would appreciate<br class="">
                your input.<br class="">
                <br class="">
                Thanks for your help, and for an excellent program!<br
                  class="">
                <br class="">
                                                            - Julian -<br
                  class="">
                <br class="">
                <br class="">
                -- <br class="">
                <br class="">
 -----------------------------------------------------------------<br
                  class="">
                | Julian Tirado-Rives      |
                                                     |<br class="">
                | Department of Chemistry  | Phone: (203)432-3356
                                |<br class="">
                | Yale University          | Fax:   (203)432-6144
                                |<br class="">
                | P. O. Box 208107         | <a
                  href="mailto:Julian.Tirado-Rives@yale.edu" class=""
                  moz-do-not-send="true">email:
                   Julian.Tirado-Rives@yale.edu</a> |<br class="">
                | New Haven, CT 06520-8107 |
                                                     |<br class="">
 -----------------------------------------------------------------<br
                  class="">
                <br class="">
                _______________________________________________<br
                  class="">
                Chimera-users mailing list: <a
                  href="mailto:Chimera-users@cgl.ucsf.edu" class=""
                  moz-do-not-send="true">Chimera-users@cgl.ucsf.edu</a><br
                  class="">
                Manage subscription: <a
                  href="https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users"
                  class="" moz-do-not-send="true">https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users</a><br
                  class="">
              </div>
            </div>
          </blockquote>
        </div>
        <br class="">
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
-------------------------------------------------------------------------------------------
 | Julian Tirado-Rives                  |                                                                   |
 | Department of Chemistry     | Phone: (203)432-3356                          |
 | Yale University                         | Fax:   (203)432-6144                             |
 | P. O. Box 208107                     | email:  <a class="moz-txt-link-abbreviated" href="mailto:Julian.Tirado-Rives@yale.edu">Julian.Tirado-Rives@yale.edu</a> |
 | New Haven, CT 06520-8107 |                                                                    |
  -------------------------------------------------------------------------------------------</pre>
  </body>
</html>