Creating an AtomicStructure object (along with other atomic objects) from scratch using Python API
Hi there, I am new to ChimeraX and its python API. As I was looking through the documentation, I noticed there were some atomic data classes (AtomicStructure, Atom, Atoms, Residue). Say I have a PDB file with information about all the atoms in the model, am I able to simply create Atom objects from reading the PDB file and, consequently, add these Atom objects to an AtomicStructure object? The reason I want to do this is because I want to use the fitmap function while limiting any disk IO. So, opening the file in ChimeraX (even if using the no gui offscreen functionality) would not work. I thought of simply creating objects from scratch, but I am running into errors when instantiating them. Sorry if this is an obscure problem or if I was unclear. Thanks for your help! Best, Nikhil
Hi Nikhil, You absolutely can create structures completely in the Python layer, though the flow is kind of in the opposite direction: you create an AtomicStructure, use it's new_residue() method to create residues as needed and then add atoms to those residues. For creating atoms I recommend using the chimerax.atomic.struct_edit.add_atom() method, which handles a lot of bookkeeping that you might otherwise forget or not know about (rather than the low-level new_atom() method of AtomicStructure). Once you create a structure, you add it to the ChimeraX session with session.models.add([structure]). --Eric Eric Pettersen UCSF Computer Graphics Lab
On Aug 8, 2025, at 9:38 AM, nrajan53045--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi there,
I am new to ChimeraX and its python API. As I was looking through the documentation, I noticed there were some atomic data classes (AtomicStructure, Atom, Atoms, Residue). Say I have a PDB file with information about all the atoms in the model, am I able to simply create Atom objects from reading the PDB file and, consequently, add these Atom objects to an AtomicStructure object?
The reason I want to do this is because I want to use the fitmap function while limiting any disk IO. So, opening the file in ChimeraX (even if using the no gui offscreen functionality) would not work. I thought of simply creating objects from scratch, but I am running into errors when instantiating them.
Sorry if this is an obscure problem or if I was unclear. Thanks for your help!
Best, Nikhil _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
Hey Eric, The struct_edit.add_atom() method worked like a charm, thank you so much! Just to confirm, for maps, is there any method you'd recommend when creating its corresponding Volume object? Best, Nikhil On Fri, Aug 8, 2025 at 12:46 PM Eric Pettersen <pett@cgl.ucsf.edu> wrote:
Hi Nikhil, You absolutely can create structures completely in the Python layer, though the flow is kind of in the opposite direction: you create an AtomicStructure, use it's new_residue() method to create residues as needed and then add atoms to those residues. For creating atoms I recommend using the chimerax.atomic.struct_edit.add_atom() method, which handles a lot of bookkeeping that you might otherwise forget or not know about (rather than the low-level new_atom() method of AtomicStructure). Once you create a structure, you add it to the ChimeraX session with session.models.add([*structure*]).
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On Aug 8, 2025, at 9:38 AM, nrajan53045--- via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Hi there,
I am new to ChimeraX and its python API. As I was looking through the documentation, I noticed there were some atomic data classes (AtomicStructure, Atom, Atoms, Residue). Say I have a PDB file with information about all the atoms in the model, am I able to simply create Atom objects from reading the PDB file and, consequently, add these Atom objects to an AtomicStructure object?
The reason I want to do this is because I want to use the fitmap function while limiting any disk IO. So, opening the file in ChimeraX (even if using the no gui offscreen functionality) would not work. I thought of simply creating objects from scratch, but I am running into errors when instantiating them.
Sorry if this is an obscure problem or if I was unclear. Thanks for your help!
Best, Nikhil _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
If you mean you want to create a map using the atomic model the ChimeraX command to do it is "molmap" and the ChimeraX Programming Guide documents the equivalent Python function https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/core/commands/user_comm... To import that function in Python you would use from chimerax.map.molmap import molmap Tom
On Aug 10, 2025, at 5:54 PM, Nikhil Rajan via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hey Eric,
The struct_edit.add_atom() method worked like a charm, thank you so much!
Just to confirm, for maps, is there any method you'd recommend when creating its corresponding Volume object?
Best, Nikhil
On Fri, Aug 8, 2025 at 12:46 PM Eric Pettersen <pett@cgl.ucsf.edu <mailto:pett@cgl.ucsf.edu>> wrote:
Hi Nikhil, You absolutely can create structures completely in the Python layer, though the flow is kind of in the opposite direction: you create an AtomicStructure, use it's new_residue() method to create residues as needed and then add atoms to those residues. For creating atoms I recommend using the chimerax.atomic.struct_edit.add_atom() method, which handles a lot of bookkeeping that you might otherwise forget or not know about (rather than the low-level new_atom() method of AtomicStructure). Once you create a structure, you add it to the ChimeraX session with session.models.add([structure]).
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On Aug 8, 2025, at 9:38 AM, nrajan53045--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
Hi there,
I am new to ChimeraX and its python API. As I was looking through the documentation, I noticed there were some atomic data classes (AtomicStructure, Atom, Atoms, Residue). Say I have a PDB file with information about all the atoms in the model, am I able to simply create Atom objects from reading the PDB file and, consequently, add these Atom objects to an AtomicStructure object?
The reason I want to do this is because I want to use the fitmap function while limiting any disk IO. So, opening the file in ChimeraX (even if using the no gui offscreen functionality) would not work. I thought of simply creating objects from scratch, but I am running into errors when instantiating them.
Sorry if this is an obscure problem or if I was unclear. Thanks for your help!
Best, Nikhil _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
Hi, I was hoping to create a Volume object from a pre-existing map on emdb. Then I would fit my AtomicStructure into that Volume object via fitmap. I ended up figuring out how to create the Volume object (via the ArrayGridData class and volume_from_grid_data method). Thank you for your help though! Nikhil On Mon, Aug 11, 2025 at 1:30 PM Tom Goddard <goddard@sonic.net> wrote:
If you mean you want to create a map using the atomic model the ChimeraX command to do it is "molmap" and the ChimeraX Programming Guide documents the equivalent Python function
https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/core/commands/user_comm...
To import that function in Python you would use
from chimerax.map.molmap import molmap
Tom
On Aug 10, 2025, at 5:54 PM, Nikhil Rajan via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Hey Eric,
The struct_edit.add_atom() method worked like a charm, thank you so much!
Just to confirm, for maps, is there any method you'd recommend when creating its corresponding Volume object?
Best, Nikhil
On Fri, Aug 8, 2025 at 12:46 PM Eric Pettersen <pett@cgl.ucsf.edu> wrote:
Hi Nikhil, You absolutely can create structures completely in the Python layer, though the flow is kind of in the opposite direction: you create an AtomicStructure, use it's new_residue() method to create residues as needed and then add atoms to those residues. For creating atoms I recommend using the chimerax.atomic.struct_edit.add_atom() method, which handles a lot of bookkeeping that you might otherwise forget or not know about (rather than the low-level new_atom() method of AtomicStructure). Once you create a structure, you add it to the ChimeraX session with session.models.add([*structure*]).
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On Aug 8, 2025, at 9:38 AM, nrajan53045--- via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Hi there,
I am new to ChimeraX and its python API. As I was looking through the documentation, I noticed there were some atomic data classes (AtomicStructure, Atom, Atoms, Residue). Say I have a PDB file with information about all the atoms in the model, am I able to simply create Atom objects from reading the PDB file and, consequently, add these Atom objects to an AtomicStructure object?
The reason I want to do this is because I want to use the fitmap function while limiting any disk IO. So, opening the file in ChimeraX (even if using the no gui offscreen functionality) would not work. I thought of simply creating objects from scratch, but I am running into errors when instantiating them.
Sorry if this is an obscure problem or if I was unclear. Thanks for your help!
Best, Nikhil _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
Glad you figured out what you needed. The ChimeraX Recipes web page has many example Python scripts for working with atomic models and maps. https://rbvi.github.io/chimerax-recipes/ Tom
On Aug 11, 2025, at 3:18 PM, Nikhil Rajan <nrajan53045@utexas.edu> wrote:
Hi,
I was hoping to create a Volume object from a pre-existing map on emdb. Then I would fit my AtomicStructure into that Volume object via fitmap.
I ended up figuring out how to create the Volume object (via the ArrayGridData class and volume_from_grid_data method). Thank you for your help though!
Nikhil
On Mon, Aug 11, 2025 at 1:30 PM Tom Goddard <goddard@sonic.net <mailto:goddard@sonic.net>> wrote:
If you mean you want to create a map using the atomic model the ChimeraX command to do it is "molmap" and the ChimeraX Programming Guide documents the equivalent Python function
https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/core/commands/user_comm...
To import that function in Python you would use
from chimerax.map.molmap import molmap
Tom
On Aug 10, 2025, at 5:54 PM, Nikhil Rajan via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
Hey Eric,
The struct_edit.add_atom() method worked like a charm, thank you so much!
Just to confirm, for maps, is there any method you'd recommend when creating its corresponding Volume object?
Best, Nikhil
On Fri, Aug 8, 2025 at 12:46 PM Eric Pettersen <pett@cgl.ucsf.edu <mailto:pett@cgl.ucsf.edu>> wrote:
Hi Nikhil, You absolutely can create structures completely in the Python layer, though the flow is kind of in the opposite direction: you create an AtomicStructure, use it's new_residue() method to create residues as needed and then add atoms to those residues. For creating atoms I recommend using the chimerax.atomic.struct_edit.add_atom() method, which handles a lot of bookkeeping that you might otherwise forget or not know about (rather than the low-level new_atom() method of AtomicStructure). Once you create a structure, you add it to the ChimeraX session with session.models.add([structure]).
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On Aug 8, 2025, at 9:38 AM, nrajan53045--- via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
Hi there,
I am new to ChimeraX and its python API. As I was looking through the documentation, I noticed there were some atomic data classes (AtomicStructure, Atom, Atoms, Residue). Say I have a PDB file with information about all the atoms in the model, am I able to simply create Atom objects from reading the PDB file and, consequently, add these Atom objects to an AtomicStructure object?
The reason I want to do this is because I want to use the fitmap function while limiting any disk IO. So, opening the file in ChimeraX (even if using the no gui offscreen functionality) would not work. I thought of simply creating objects from scratch, but I am running into errors when instantiating them.
Sorry if this is an obscure problem or if I was unclear. Thanks for your help!
Best, Nikhil _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
participants (4)
-
Eric Pettersen -
Nikhil Rajan -
nrajan53045@utexas.edu -
Tom Goddard