
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: 1. 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>)). 1. 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.

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/too... 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 <https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/atomic/atomic.html>) 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 <https://rbvi.github.io/chimerax-recipes/> 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
On Aug 18, 2023, at 2:50 PM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
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.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/

Thanks so much Eric! This will give me great starting points. ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: Monday, August 21, 2023 8:14 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu> Cc: chimerax-users@cgl.ucsf.edu <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] General developer questions 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/too... 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<https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/atomic/atomic.html>) 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<https://rbvi.github.io/chimerax-recipes/> 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 On Aug 18, 2023, at 2:50 PM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote: 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: 1. 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>)). 1. 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.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/

Eric, I am trying your code: I have this code at the top of my plugin: from chimerax.atomic import all_atomic_structures, selected_atoms I have this code that runs when I press a button: 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. ________________________________ From: BARRY E DEZONIA <barry.dezonia@wisc.edu> Sent: Tuesday, August 22, 2023 12:47 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] General developer questions Thanks so much Eric! This will give me great starting points. ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: Monday, August 21, 2023 8:14 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu> Cc: chimerax-users@cgl.ucsf.edu <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] General developer questions 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/too... 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<https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/atomic/atomic.html>) 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<https://rbvi.github.io/chimerax-recipes/> 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 On Aug 18, 2023, at 2:50 PM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote: 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: 1. 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>)). 1. 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.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/

Hi Barry, If I start ChimeraX and open 2lgi and select it, then open the Python shell (Tools→General_>Shell) and input: for structure in selected_atoms(session).unique_structures: print(structure) The output is: 2lgi #1.1 2lgi #1.2 2lgi #1.3 2lgi #1.4 2lgi #1.5 2lgi #1.6 2lgi #1.7 2lgi #1.8 2lgi #1.9 2lgi #1.10 Is that what happens for you if you do the same with the Python shell tool? --Eric
On Aug 25, 2023, at 11:18 AM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Eric,
I am trying your code:
I have this code at the top of my plugin:
from chimerax.atomic import all_atomic_structures, selected_atoms
I have this code that runs when I press a button:
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.
From: BARRY E DEZONIA <barry.dezonia@wisc.edu <mailto:barry.dezonia@wisc.edu>> Sent: Tuesday, August 22, 2023 12:47 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] General developer questions
Thanks so much Eric! This will give me great starting points. From: Eric Pettersen <pett@cgl.ucsf.edu <mailto:pett@cgl.ucsf.edu>> Sent: Monday, August 21, 2023 8:14 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu <mailto:barry.dezonia@wisc.edu>> Cc: chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] General developer questions
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/too... <https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/add_charge/src/too...> 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 <https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/atomic/atomic.html>) 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 <https://rbvi.github.io/chimerax-recipes/> 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
On Aug 18, 2023, at 2:50 PM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
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.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/ <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/ <https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/>

Basically, yes, that is what it does ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: Friday, August 25, 2023 1:38 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu> Cc: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] General developer questions Hi Barry, If I start ChimeraX and open 2lgi and select it, then open the Python shell (Tools→General_>Shell) and input: for structure in selected_atoms(session).unique_structures: print(structure) The output is: 2lgi #1.1 2lgi #1.2 2lgi #1.3 2lgi #1.4 2lgi #1.5 2lgi #1.6 2lgi #1.7 2lgi #1.8 2lgi #1.9 2lgi #1.10 Is that what happens for you if you do the same with the Python shell tool? --Eric On Aug 25, 2023, at 11:18 AM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> wrote: Eric, I am trying your code: I have this code at the top of my plugin: from chimerax.atomic import all_atomic_structures, selected_atoms I have this code that runs when I press a button: 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. ________________________________ From: BARRY E DEZONIA <barry.dezonia@wisc.edu<mailto:barry.dezonia@wisc.edu>> Sent: Tuesday, August 22, 2023 12:47 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] General developer questions Thanks so much Eric! This will give me great starting points. ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu<mailto:pett@cgl.ucsf.edu>> Sent: Monday, August 21, 2023 8:14 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu<mailto:barry.dezonia@wisc.edu>> Cc: chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu> <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] General developer questions 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/too... 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<https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/atomic/atomic.html>) 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<https://rbvi.github.io/chimerax-recipes/> 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 On Aug 18, 2023, at 2:50 PM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> wrote: 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: 1. 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>)). 1. 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.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/

Weird. It's now working in my plugin. Never mind I guess. ________________________________ From: BARRY E DEZONIA <barry.dezonia@wisc.edu> Sent: Friday, August 25, 2023 1:41 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] General developer questions Basically, yes, that is what it does ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: Friday, August 25, 2023 1:38 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu> Cc: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] General developer questions Hi Barry, If I start ChimeraX and open 2lgi and select it, then open the Python shell (Tools→General_>Shell) and input: for structure in selected_atoms(session).unique_structures: print(structure) The output is: 2lgi #1.1 2lgi #1.2 2lgi #1.3 2lgi #1.4 2lgi #1.5 2lgi #1.6 2lgi #1.7 2lgi #1.8 2lgi #1.9 2lgi #1.10 Is that what happens for you if you do the same with the Python shell tool? --Eric On Aug 25, 2023, at 11:18 AM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> wrote: Eric, I am trying your code: I have this code at the top of my plugin: from chimerax.atomic import all_atomic_structures, selected_atoms I have this code that runs when I press a button: 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. ________________________________ From: BARRY E DEZONIA <barry.dezonia@wisc.edu<mailto:barry.dezonia@wisc.edu>> Sent: Tuesday, August 22, 2023 12:47 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] General developer questions Thanks so much Eric! This will give me great starting points. ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu<mailto:pett@cgl.ucsf.edu>> Sent: Monday, August 21, 2023 8:14 PM To: BARRY E DEZONIA <barry.dezonia@wisc.edu<mailto:barry.dezonia@wisc.edu>> Cc: chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu> <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] General developer questions 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/too... 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<https://www.cgl.ucsf.edu/chimerax/docs/devel/modules/atomic/atomic.html>) 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<https://rbvi.github.io/chimerax-recipes/> 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 On Aug 18, 2023, at 2:50 PM, BARRY E DEZONIA via ChimeraX-users <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> wrote: 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: 1. 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>)). 1. 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.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 (2)
-
BARRY E DEZONIA
-
Eric Pettersen