from chimerax.atomic import all_atomic_structures, selected_atoms
for structure in selected_atoms(self.session): # or selected_atoms(self.session).unique_structures
print("GOT ONE!")
And it never prints anything to the console window that launched chimerax.
I can "open 2lgi" and then "select". It displays the protein and shows the green wireframe around it. But my button click after that never produces any print statement.
Any idea what the problem could be? I know self.session is valid because the next few lines of code use it successfully.
Thanks so much Eric! This will give me great starting points.
Hi Barry,
Are you envisioning an interface where the user indicates a particular structure to use and then clicks a button to get your tool to operate on that structure, or instead when the user starts your tool it just automatically runs on the open structures? If the former, you might want to look at the code for the add_charge tool interface, which has a widget for choosing structures and buttons to launch the calculation. The code can be browsed here:
https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/add_charge/src/tool.py and it is in the ChimeraX app download. If you know how to find the site-packages folder in the app, it is chimerax/add_charge/tool.py under that. For the second approach where you just immediately launch the calculation on all structures, you would have code like:
from chimerax.atomic import all_atomic_structures
for s in all_atom_structures(session):
function_for_calculation(s)
If you wanted just selected structures, then:
from chimerax.atomic import selected_atoms
for s in selected_atoms(session).unique_structures:
function_for_calculation(s)
ChimeraX maintains a lot of information about structures it opens. Each structure object in the code snippets above would have dozens of attributes (listed in exhaustive detail
here) but the most import of which would be ’atoms’, ‘bonds’, ‘residues’, and ‘chains’ which are “Collections” (effectively arrays) of those kind of objects. So for instance, s.atoms.bfactors would be a numpy array of the bfactor values for the atoms in the structure. So you can do fast vector operations on large structures despite coding in Python. Conversely, you can loop through those collections as needed, e.g.:
for a in s.atoms::
if a.bfactor > 5.0 and a.element.name == ‘H’:
# do something.
Structures also have a ‘metadata’ attribute, which is a dictionary containing info that varies depending on the type of file the structure was read from. For PDB files, the metadata dictionary is keyed on PDB header record types (i.e. not ATOM/HETATM records) with values that are lists of strings, each string being one record of that type. Many of the header records also get processed into more useable Python form (e.g. SEQRES records are used in the Chain class sequence information).
Probably the best way to make progress is to find a tool or
ChimeraX Recipe that does something similar to what you want to do and use it as a general guide. Also, do not be shy about asking questions!
--Eric
Eric Pettersen
UCSF Computer Graphics Lab
Hello,
I have been writing a plugin for ChimeraX. One feature it does now is read a PDB file, parse some info, and act on that data internally. I'd like to change it so that it can use information about a loaded PDB in ChimeraX. To this I have a couple questions:
- Are there some basic docs on how someone could access a protein that is memory resident that was loaded from a PDB (i.e. just what data structures can I access programmatically related to a protein loaded with open(<pdbname>)).
- How do I find the data structure(s) for the currently viewed or selected or ??? protein? I'd like someone to be viewing a protein and then launch my plugin which will use that protein and its data for the plugin's internal calculations.
I'm sorry if this is noise. If there are good developer docs for these topics please feel free to point me in the right direction. Thanks.
_______________________________________________ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.eduTo unsubscribe send an email to chimerax-users-leave@cgl.ucsf.eduArchives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/