[Chimera-users] python code to loop over molecules
Julian Tirado-Rives
julian.tirado-rives at yale.edu
Mon May 3 11:28:36 PDT 2021
Hi Eric,
it seems that is just what I needed. Thanks! I will give it a whirl
and yell
for help when (and if) I get into serious trouble ...
Best,
- Julian -
On 5/3/2021 12:57 PM, Eric Pettersen wrote:
> Hi Julian,
> 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:
>
> /import chimera/
> /models = chimera.openModels.list()/
> /
> /
> To extract the poses in order, the crucial information to know is that
> each model has an /id/ and /subid/ attribute, so each pose will have
> and /id/ of 1. To get a list of them in order then is:
>
> /poses = sorted([m for m in models if m.id <http://m.id> == 1],
> key=lambda m: m.subid)/
>
> Then the number of poses is obviously /len(poses)/. For most of the
> additional things you mentioned, the easiest thing to do is run the
> equivalent command, /e.g./:
>
> /from chimera import runCommand as run/
> /for pose in poses:/
> /run("color red %s" % pose)/
> /
> /
> This may be all you need. But the /run()/ call doesn't return any
> values, so for instance if you need to do different things in the
> Python code depending on /how many/ 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.
>
> --Eric
>
> Eric Pettersen
> UCSF Computer Graphics Lab
>
>
>> On May 3, 2021, at 5:10 AM, Julian Tirado-Rives
>> <julian.tirado-rives at yale.edu <mailto:julian.tirado-rives at yale.edu>>
>> wrote:
>>
>> Dear Chimera (and ChimeraX) team:
>>
>> I need to find some python example or code snippet capable of
>> looping over all the molecules in a particular model and do some actions
>> separately in each one.
>>
>> In our research we use several different docking programs and other
>> ways of generating poses of protein-ligand complexes, and using several
>> different programs to analyze them gets quite complicated. Instead,
>> we've found that the easiest way is to generate from each code, or using
>> conversion utilities such as babel, a pdb file of the host and a sdf or
>> mol2 file containing all the ligand poses and read them into chimera.
>> An excellent program, by the way. We use it all the time.
>>
>> I would love to automate the process even further by doing all the
>> coloring, rendering, Hydrogen Bond and contact analysis, etc. in Python
>> rather than manually. I have been trying to do this, but have not
>> found a way to do the following:
>>
>> If we have, for instance, the host in model #0, and the ligand poses
>> in model #1 (#1.1, #1.2, ..., #1.N):
>>
>> - Get from chimera the number of molecules in model #1 (e.g what is N)
>> - loop from the first #1.1 to the last #1.N molecule
>> - do some cations there (e.g select, color, find HB's, etc)
>>
>> I think this should be a problem other people have encountered and
>> solved before, but I have not been able to find an example in your
>> depository, the mailing lists, or even the book ... I would appreciate
>> your input.
>>
>> Thanks for your help, and for an excellent program!
>>
>> - Julian -
>>
>>
>> --
>>
>> -----------------------------------------------------------------
>> | Julian Tirado-Rives | |
>> | Department of Chemistry | Phone: (203)432-3356 |
>> | Yale University | Fax: (203)432-6144 |
>> | P. O. Box 208107 | email: Julian.Tirado-Rives at yale.edu
>> <mailto:Julian.Tirado-Rives at yale.edu> |
>> | New Haven, CT 06520-8107 | |
>> -----------------------------------------------------------------
>>
>> _______________________________________________
>> Chimera-users mailing list: Chimera-users at cgl.ucsf.edu
>> <mailto:Chimera-users at cgl.ucsf.edu>
>> Manage subscription:
>> https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
>> <https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users>
>
--
-------------------------------------------------------------------------------------------
| Julian Tirado-Rives | |
| Department of Chemistry | Phone: (203)432-3356 |
| Yale University | Fax: (203)432-6144 |
| P. O. Box 208107 | email: Julian.Tirado-Rives at yale.edu |
| New Haven, CT 06520-8107 | |
-------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20210503/320c8df9/attachment.html>
More information about the Chimera-users
mailing list