[chimerax-users] ChimeraX Python Scripting for EM Maps
Eric Pettersen
pett at cgl.ucsf.edu
Mon Feb 22 14:05:21 PST 2021
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-tip>
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.html#save> 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 at 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 at cam.ac.uk
> Cambridge University
>
> _______________________________________________
> ChimeraX-users mailing list
> ChimeraX-users at cgl.ucsf.edu
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimerax-users/attachments/20210222/44981648/attachment.html>
More information about the ChimeraX-users
mailing list