
Hi Tom, Thank you very much for the quick response. I did not know about the clip, and it is a very clean solution for what I want to do. However, I am interested in knowing this dynamic selection because it will be very helpful for me to make a video of other trajectories. I tried your suggestion. Three things to note: - I did not need "wait" to render a video. - Adding "wait" just increased the time of the last frame. - I still see that the selection is not dynamically updated when clicking a play button (▶️) or typing "coordset #1". However, interestingly, if I move a frame with a slider, after "perframe 'open ~/selet_atoms.py'", I can see that the selection is updated in each frame. If it does not make sense too much, I can record my screen and send it to you. I am using ChimeraX 1.5. Thanks. Best, Siyoung On Tue, Oct 24, 2023 at 9:20 PM Tom Goddard <goddard@sonic.net> wrote:
By the way, did you know ChimeraX can hide everything with x > 0 using a clip plane. See the clip command
clip front 0 position 0,0,0 axis -1,0,0
documented here
https://www.cgl.ucsf.edu/chimerax/docs/user/commands/clip.html
Tom
On Oct 24, 2023, at 6:15 PM, Tom Goddard via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Hi Siyoung,
The movie recording needs a "wait" command to actually render frames. If you have 300 frames in your coordinate set it would be
perframe "open select_atoms.py" movie record coordset #1 wait 300 movie encode test.mp4
Also I would suggest that your python code not use "atom.hide". That is an obscure attribute for hiding backbone atoms with ribbon display. Instead use
atom.display = True atom.display = False
It might be possible to record the movie entirely in Python, but I've never tried it. I would not suggest trying that approach unless you want to waste a lot of time since the movie recording code was not designed to work in a Python script.
Tom
On Oct 24, 2023, at 6:01 PM, Siyoung Kim <kkssy141@gmail.com> wrote:
Thank you very much for the helpful information. I think I am very close to what I want to do.
I would like to make a video of a molecular dynamics trajectory and want to show only the atoms whose x coordinates are smaller than 0. Here is what I tried.
a) I made a python script that can be applied to each frame and named it "select_atoms.py" --------------------------------- from chimerax.atomic import all_atoms atoms = all_atoms(session) for atom in atoms: if atom.scene_coord[0] < 0: atom.hide = 0 else: atom.hide = 1 ----------------------------------
b) I opened up a trajectory in ChimeraX.
c) In ChimeraX, I executed --------------------------------------------- perframe "open select_atoms.py" movie record coordset #1 movie encode test.mp4 ----------------------------------------------
*Interestingly, if I just move a frame by myself using a slider, perframe is applied well. i.e., only the atoms whose x coordinates < 0 are shown in EACH frame* *However, if I record a video like the above or click a play button, perframe is not successfully applied. Only the atoms whose x coordinates < 0 in the last frame are shown in all frames. Updating a selection in each frame does not work with this approach.* I have attached the video. Would you please help me with this? Thank you.
I would be also curious if it could be done inside a python script. In the above, I made a script that should be applied to each frame and then called this script using perframe in ChimeraX. Would there be something like RED in the below? Thank you very much!
RECORDING A MOVIE 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 atoms[atoms.selecteds].hide = 0 atoms[~atoms.selecteds].hide = 1 SAVE THIS IMAGE ENCODING A MOVIE
On Mon, Oct 23, 2023 at 11:52 AM Siyoung Kim <kkssy141@gmail.com> wrote:
Hi Eric,
Thank you very much for the very helpful information! I learned a lot.
Best, Siyoung
On Fri, Oct 20, 2023 at 8:58 PM Eric Pettersen <pett@cgl.ucsf.edu> wrote:
On Oct 17, 2023, at 1:53 PM, Siyoung Kim via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
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?
There is automatically generated documentation, but I don't recommend it because it is poorly formatted and littered with rarely used constants and functions from base classes (*e.g.* Structure inherits from Model and Drawing and therefore documentation for first_intercept_children() [from Drawing] is included). Instead, I'd browse through the code for atomic class definitions themselves. The Cython class definitions for Atom, Element, and Bond are here: https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/atomic/atomic_cpp/... . The definitions for the other classes are here: https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/atomic/src/molobje... . The latter only has the base class definitions for Structure and PseudobondGroup (StructureData and PseudobondGroupData respectively). The final definitions are in structure.py <https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/atomic/src/structu...> and pbgroup.py <https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/atomic/src/pbgroup...> .
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 <https://github.com/RBVI/ChimeraX/blob/develop/src/bundles/atomic/src/molarra...>) 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
Thank you. Best, Siyoung
On Tue, Oct 17, 2023 at 4:06 PM Tom Goddard <goddard@sonic.net> wrote:
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.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/
<test.mp4>
_______________________________________________ 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/