ChimeraX Python Scripting for EM Maps

To whom it may concern, Hello! I was hoping to ask for some help in Python Scripting in ChimeraX. Specifically, I am trying to fit structure files (.PDB) to electron density maps (.MAP). Is there a way to do this in .PY scripts in ChimeraX? I can’t seem to find such a command like “fitmap” in the documentation here (https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html). Additionally, it seems like the “Read and Write PDB Files” page (https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html) of the documentation page hasn’t been updated. Is there another place that outlines how to save structures? Thank you, Steven Truong sdt45@cam.ac.uk Cambridge University

Hi Steven, Maybe this page in the programmer documentation (and links therein) would help... it includes "fitmap," at least: <https://www.cgl.ucsf.edu/chimerax/docs/devel/core/commands/user_commands.htm...> I don't create the programmer documentation, but since the page says version 1.2 I'm hoping it's reasonably up-to-date. The "save" link doesn't say much, however, so somebody else will have to give more information on writing files. Best, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On Feb 19, 2021, at 10:05 AM, Steven Truong <sdt45@cam.ac.uk> wrote:
To whom it may concern, Hello! I was hoping to ask for some help in Python Scripting in ChimeraX. Specifically, I am trying to fit structure files (.PDB) to electron density maps (.MAP). Is there a way to do this in .PY scripts in ChimeraX? I can’t seem to find such a command like “fitmap” in the documentation here (https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html). Additionally, it seems like the “Read and Write PDB Files” page (https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html) of the documentation page hasn’t been updated. Is there another place that outlines how to save structures?

Hi Steven, Elaine pointed to the right place for the fitmap Python documentation. I've also added it under the Python Modules page under Volume data to make it easier to find. The open_pdb() and save_pdb() functions are here and have strangely not been documented. https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/pdb/src/pdb.py <https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/pdb/src/pdb.py> We will try to get those documented in the Programmer's manual. ChimeraX fitting of atomic models in maps is intended for interactive fitting. Keep that in mind if you are going to try to script it in Python. It doesn't have good capabilities for doing global searches and is really intended to locally optimize a fit once you have atomic models close to their correct positions. Tom
On Feb 19, 2021, at 10:29 AM, Elaine Meng <meng@cgl.ucsf.edu> wrotey:
Hi Steven, Maybe this page in the programmer documentation (and links therein) would help... it includes "fitmap," at least:
<https://www.cgl.ucsf.edu/chimerax/docs/devel/core/commands/user_commands.htm...>
I don't create the programmer documentation, but since the page says version 1.2 I'm hoping it's reasonably up-to-date.
The "save" link doesn't say much, however, so somebody else will have to give more information on writing files. Best, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On Feb 19, 2021, at 10:05 AM, Steven Truong <sdt45@cam.ac.uk> wrote:
To whom it may concern, Hello! I was hoping to ask for some help in Python Scripting in ChimeraX. Specifically, I am trying to fit structure files (.PDB) to electron density maps (.MAP). Is there a way to do this in .PY scripts in ChimeraX? I can’t seem to find such a command like “fitmap” in the documentation here (https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html). Additionally, it seems like the “Read and Write PDB Files” page (https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html) of the documentation page hasn’t been updated. Is there another place that outlines how to save structures?
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Hi Tom and Elaine, Thank you for your help! These are all very helpful suggestions, and I appreciate you getting back to me so quickly. Regarding fitting atomic models to maps, what would you suggest as a starting point to globally fit? Is this something you'd suggest be done outside of ChimeraX? Is there perhaps a way to semi-automate the process where you can interactively start from rough inspection — and then loop from there? Our group is hoping to do this for a few hundred models/maps, so manually doing this would be a bit time-consuming. However, we have fitted one model to a map, and it does seem to work very well when done interactively. Many thanks, Steven On Feb 19, 2021, at 3:00 PM, Tom Goddard <goddard@sonic.net<mailto:goddard@sonic.net>> wrote: Hi Steven, Elaine pointed to the right place for the fitmap Python documentation. I've also added it under the Python Modules page under Volume data to make it easier to find. The open_pdb() and save_pdb() functions are here and have strangely not been documented. https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/pdb/src/pdb.py We will try to get those documented in the Programmer's manual. ChimeraX fitting of atomic models in maps is intended for interactive fitting. Keep that in mind if you are going to try to script it in Python. It doesn't have good capabilities for doing global searches and is really intended to locally optimize a fit once you have atomic models close to their correct positions. Tom On Feb 19, 2021, at 10:29 AM, Elaine Meng <meng@cgl.ucsf.edu<mailto:meng@cgl.ucsf.edu>> wrotey: Hi Steven, Maybe this page in the programmer documentation (and links therein) would help... it includes "fitmap," at least: <https://www.cgl.ucsf.edu/chimerax/docs/devel/core/commands/user_commands.htm...> I don't create the programmer documentation, but since the page says version 1.2 I'm hoping it's reasonably up-to-date. The "save" link doesn't say much, however, so somebody else will have to give more information on writing files. Best, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco On Feb 19, 2021, at 10:05 AM, Steven Truong <sdt45@cam.ac.uk<mailto:sdt45@cam.ac.uk>> wrote: To whom it may concern, Hello! I was hoping to ask for some help in Python Scripting in ChimeraX. Specifically, I am trying to fit structure files (.PDB) to electron density maps (.MAP). Is there a way to do this in .PY scripts in ChimeraX? I can’t seem to find such a command like “fitmap” in the documentation here (https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html). Additionally, it seems like the “Read and Write PDB Files” page (https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html) of the documentation page hasn’t been updated. Is there another place that outlines how to save structures? _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu<mailto:ChimeraX-users@cgl.ucsf.edu> Manage subscription: https://plato.cgl.ucsf.edu/mailman/listinfo/chimerax-users

Hi Steven, To fit atomic models into maps automatically is in general very hard -- for instance you spend a lifetime developing algorithms trying to reliably dock one protein in a 10 protein complex reliably. But maybe you have easy cases, or maybe you don't care if the result is very wrong 20% of the time -- then maybe you can write a script to do it. The only thing ChimeraX does to find a global fit is randomly place and orient a molecule in your map and then do local optimization, as many placements as you want, then cluster ones that have very similar final position and orientation. The problem is there are often wrong fits with very high scores, and it is time consuming to sample enough positions. If you thought that approach might work I would first suggest trying it on several cases you are interested interactively using the fitmap command with the search option fit #1 in #2 search 100 https://www.rbvi.ucsf.edu/chimerax/docs/user/commands/fitmap.html#global Currently ChimeraX does not have the user interface that lists all the fits, but you could try it in Chimera which does list them and uses the same algorithm. In a Python script you could get the different fits in ChimeraX. Tom
On Feb 19, 2021, at 1:12 PM, Steven Truong <sdt45@cam.ac.uk> wrote:
Hi Tom and Elaine,
Thank you for your help! These are all very helpful suggestions, and I appreciate you getting back to me so quickly.
Regarding fitting atomic models to maps, what would you suggest as a starting point to globally fit? Is this something you'd suggest be done outside of ChimeraX? Is there perhaps a way to semi-automate the process where you can interactively start from rough inspection — and then loop from there? Our group is hoping to do this for a few hundred models/maps, so manually doing this would be a bit time-consuming. However, we have fitted one model to a map, and it does seem to work very well when done interactively.
Many thanks, Steven
On Feb 19, 2021, at 3:00 PM, Tom Goddard <goddard@sonic.net <mailto:goddard@sonic.net>> wrote:
Hi Steven,
Elaine pointed to the right place for the fitmap Python documentation. I've also added it under the Python Modules page under Volume data to make it easier to find. The open_pdb() and save_pdb() functions are here and have strangely not been documented.
https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/pdb/src/pdb.py <https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/pdb/src/pdb.py>
We will try to get those documented in the Programmer's manual.
ChimeraX fitting of atomic models in maps is intended for interactive fitting. Keep that in mind if you are going to try to script it in Python. It doesn't have good capabilities for doing global searches and is really intended to locally optimize a fit once you have atomic models close to their correct positions.
Tom
On Feb 19, 2021, at 10:29 AM, Elaine Meng <meng@cgl.ucsf.edu <mailto:meng@cgl.ucsf.edu>> wrotey:
Hi Steven, Maybe this page in the programmer documentation (and links therein) would help... it includes "fitmap," at least:
<https://www.cgl.ucsf.edu/chimerax/docs/devel/core/commands/user_commands.htm... <https://www.cgl.ucsf.edu/chimerax/docs/devel/core/commands/user_commands.html>>
I don't create the programmer documentation, but since the page says version 1.2 I'm hoping it's reasonably up-to-date.
The "save" link doesn't say much, however, so somebody else will have to give more information on writing files. Best, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On Feb 19, 2021, at 10:05 AM, Steven Truong <sdt45@cam.ac.uk <mailto:sdt45@cam.ac.uk>> wrote:
To whom it may concern, Hello! I was hoping to ask for some help in Python Scripting in ChimeraX. Specifically, I am trying to fit structure files (.PDB) to electron density maps (.MAP). Is there a way to do this in .PY scripts in ChimeraX? I can’t seem to find such a command like “fitmap” in the documentation here (https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html <https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html>). Additionally, it seems like the “Read and Write PDB Files” page (https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html <https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html>) of the documentation page hasn’t been updated. Is there another place that outlines how to save structures?
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu <mailto:ChimeraX-users@cgl.ucsf.edu> Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users <https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users>
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Hi Steven, That module should be documented, and we will fix that, but nonetheless directly calling those routines would typically be about your third choice for saving PDB files. The first choice would be to execute the equivalent ChimeraX command directly with code like: from chimerax.core.commands import run run(session, "save /path/to/file.pdb #1") This approach has the advantage of not needing to find equivalent API calls to every command you want to execute, or figuring out what arguments are needed for those calls. This approach is discussed in the "Pro Tip" section near the top of the Developer Tutorial. <https://www.cgl.ucsf.edu/chimerax/docs/devel/tutorials/introduction.html#pro...> The second approach would be to use the "save command" manager. That manager knows which bundles provide support for saving various file formats, and provides a generic interface for saving files, e.g.: session.save_command.save_data("/path/to/file.pdb", models=[model1], [other Python format-specific keywords]) This second approach has the disadvantage that the values for the keywords may not be obvious in some cases (i.e. you would have to look at the underlying API). This approach is discussed in the Python Functions implementing User Commands <https://www.cgl.ucsf.edu/chimerax/docs/devel/core/commands/user_commands.htm...> documentation, under "save". And finally, the third approach would be to call the PDB-saving API directly. Something like: from chimerax.pdb import save_pdb save_pdb(session, "/path/to/file.pdb", models=[model1]) The only advantage of this third approach is in the rare case where you need to use an esoteric Python-only keyword argument that isn't supported in the equivalent "save" command. For instance, save_pdb() has a polymeric_res_names argument for when you need to output residues in ATOM records that would otherwise be output as HETATM records (this capability is used by the modeller bundle). --Eric Eric Pettersen UCSF Computer Graphics Lab
On Feb 19, 2021, at 10:05 AM, Steven Truong <sdt45@cam.ac.uk> wrote:
To whom it may concern,
Hello! I was hoping to ask for some help in Python Scripting in ChimeraX. Specifically, I am trying to fit structure files (.PDB) to electron density maps (.MAP). Is there a way to do this in .PY scripts in ChimeraX? I can’t seem to find such a command like “fitmap” in the documentation here (https://www.cgl.ucsf.edu/chimerax/docs/devel/modules.html). Additionally, it seems like the “Read and Write PDB Files” page (https://www.cgl.ucsf.edu/chimerax/docs/devel/bundles/atomic/src/pdbio.html) of the documentation page hasn’t been updated. Is there another place that outlines how to save structures?
Thank you, Steven Truong sdt45@cam.ac.uk Cambridge University
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
participants (4)
-
Elaine Meng
-
Eric Pettersen
-
Steven Truong
-
Tom Goddard