
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@yale.edu | | New Haven, CT 06520-8107 | | -----------------------------------------------------------------

Hi Julian, Thanks for the kind words! Someone will be responding in more detail about Chimera. In the meanwhile, thought I should mention that in ChimeraX, we just added an option to the "open" command that allows running the same command script on each of a list of inputs (typically atomic structures or maps) without resorting to python. If you get a new daily build of ChimeraX, then you could use a command something like open my-command-file.cxc forEachFile ~/Desktop/data/*.pdb and it would open the first pdb file, run the command file, close everything, open the next data file, run the command file, [...] as explained here: <https://rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile> I didn't know if using ChimeraX was a possibility for you at this point, but may be useful down the line. ChimeraX has "hbonds" "clashes" and "contacts" commands which work much the same as in Chimera, except with improvements (at least in my opinion) on how the sets of atoms are specified. <https://rbvi.ucsf.edu/chimerax/docs/user/commands/hbonds.html> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/clashes.html> The main impediments to using forEachFile out of the box for the ligand-receptor case is that the ligands would need to be in separate files and the command script would have to open the receptor since it would get closed between script executions. So python might still be better in ChimeraX than trying to use that option. Best, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On May 3, 2021, at 5:10 AM, Julian Tirado-Rives <julian.tirado-rives@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@yale.edu | | New Haven, CT 06520-8107 | | -----------------------------------------------------------------

Hi Elaine, I did consider the "forEachFile" option, but the drawbacks you mentioned yourself did not make it an attractive alternative. Also, we do mostly visual inspection at the end of the process, so we need them open to be able to check each one and "cherry-pick" (or something like that). Thanks, anyway! - Julian - On 5/3/2021 12:04 PM, Elaine Meng wrote:
Hi Julian, Thanks for the kind words!
Someone will be responding in more detail about Chimera.
In the meanwhile, thought I should mention that in ChimeraX, we just added an option to the "open" command that allows running the same command script on each of a list of inputs (typically atomic structures or maps) without resorting to python. If you get a new daily build of ChimeraX, then you could use a command something like
open my-command-file.cxc forEachFile ~/Desktop/data/*.pdb
and it would open the first pdb file, run the command file, close everything, open the next data file, run the command file, [...] as explained here: <https://rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile>
I didn't know if using ChimeraX was a possibility for you at this point, but may be useful down the line. ChimeraX has "hbonds" "clashes" and "contacts" commands which work much the same as in Chimera, except with improvements (at least in my opinion) on how the sets of atoms are specified. <https://rbvi.ucsf.edu/chimerax/docs/user/commands/hbonds.html> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/clashes.html>
The main impediments to using forEachFile out of the box for the ligand-receptor case is that the ligands would need to be in separate files and the command script would have to open the receptor since it would get closed between script executions. So python might still be better in ChimeraX than trying to use that option.
Best, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On May 3, 2021, at 5:10 AM, Julian Tirado-Rives <julian.tirado-rives@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@yale.edu | | New Haven, CT 06520-8107 | | -----------------------------------------------------------------
-- ------------------------------------------------------------------------------------------- | Julian Tirado-Rives | | | Department of Chemistry | Phone: (203)432-3356 | | Yale University | Fax: (203)432-6144 | | P. O. Box 208107 | email: Julian.Tirado-Rives@yale.edu | | New Haven, CT 06520-8107 | | -------------------------------------------------------------------------------------------

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@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@yale.edu | | New Haven, CT 06520-8107 | | -----------------------------------------------------------------
_______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu Manage subscription: https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users

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@yale.edu <mailto:julian.tirado-rives@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@yale.edu <mailto:Julian.Tirado-Rives@yale.edu> | | New Haven, CT 06520-8107 | | -----------------------------------------------------------------
_______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu <mailto:Chimera-users@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@yale.edu | | New Haven, CT 06520-8107 | | -------------------------------------------------------------------------------------------

Dear Professor Tirado-Rives, I have a simple python script with different coloring I picked up few months. As Dr. Meng pointed out hbond is extremely useful after loading the PDB data. Sincerely, David
On May 3, 2021, at 5:10 AM, Julian Tirado-Rives <julian.tirado-rives@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@yale.edu | | New Haven, CT 06520-8107 | | -----------------------------------------------------------------
_______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu Manage subscription: https://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
participants (4)
-
David Gae
-
Elaine Meng
-
Eric Pettersen
-
Julian Tirado-Rives