Hi Tom,
Thank you for your help. I can confirm that making a text file, select.py, that contains the below and running "run select.py" in the ChimeraX command line works.
from chimerax.atomic import all_atoms
for a in all_atoms(session):
if a.scene_coord[0] < 0:
a.selected = True
I am quite interested in learning more about the chimerax.atomix library. Would there be any helpful resources about this?
Another approach is to find a bundle that does something similar to what you want to do and look at its code to see how it does it. All the ChimeraX source code is in the repository linked to above (and the Python code is included in every ChimeraX installation).
Would it be also possible to loop over a molecular dynamics trajectory and select wanted atoms in this way?
Yes. A structure that is a trajectory will have multiple "coordinate sets" (sets of coordinates for the atoms). Therefore you can loop through the trajectory like so:
from chimerax.atomic import all_atomic_structures:
for s in all_atomic_structures(session):
for cs_id in s.coordset_ids:
s.active_coordset_id = cs_id
for a in s.atoms:
a.selected = a.scene_coord[0] < 0
It may also be useful to know that the value returned by s.atoms is an "Atoms" instance (see
molarray.py) which in many ways can be treated as a vector for efficiency, which could definitely matter when processing a trajectory. So the above code could instead be:
from chimerax.atomic import all_atomic_structures:
for s in all_atomic_structures(session):
for cs_id in s.coordset_ids:
s.active_coordset_id = cs_id
atoms = s.atoms
atoms.selecteds = atoms.scene_coords[:,0] < 0
--Eric
Eric Pettersen
UCSF Computer Graphics Lab
Oops. If you put this code in a file it needs to have a ".py" suffix, so call it select.py. The ".cxc" suffix is for ChimeraX commands.
Tom
> On Oct 17, 2023, at 12:58 PM, Tom Goddard via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
>
> Hi Siyoung,
>
> Here is Python code to select all atoms with x < 0.
>
> from chimerax.atomic import all_atoms
> for a in all_atoms(session):
> if a.scene_coord[0] < 0:
> a.selected = True
>
> You can type this in the ChimeraX Python shell (menu Tools / General / Shell), or probably easier, put it in a text file "select.cxc" and open that in ChimeraX to run it.
>
> Tom
>
>> On Oct 17, 2023, at 9:04 AM, Elaine Meng via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
>>
>> Hello Siyoung,
>> Sorry no, I can't think of a way to do it with a ChimeraX command. Maybe you could do it by using the initial orientation of the structure (just opening and not rotating) and veerrryyy carefully using the mouse to select a rectangle (Ctrl-click drag) but that is probably too difficult. Also you would need to know where X=0 is from just looking at the structure.
>>
>> Certainly you could do it with Python, but somebody else would have to advise on that.
>>
>> Best,
>> Elaine
>> -----
>> Elaine C. Meng, Ph.D.
>> UCSF Chimera(X) team
>> Department of Pharmaceutical Chemistry
>> University of California, San Francisco
>>
>>> On Oct 17, 2023, at 5:33 AM, Siyoung Kim via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
>>>
>>> Hello,
>>>
>>> Would there be a selection keyword that selects atoms based on their coordinates? For instance, is there a way that I can select atoms whose x coordinates are below 0 (e.g., x < 0)?
>>>
>>> Thank you.
>>> Best,
>>> Siyoung
>>
>>
>> _______________________________________________
>> 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/
>
_______________________________________________
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/