Hi Eric,
Thanks for the reply. I will try to make the script.
But I am struggling with not knowing some basics.
For instance, now I would like to automatically read many (tens) of consecutive trajectory files into one trajectory which I would do manually as
cd path_name
open structure.gro
open traj_1.xtc start 2
open traj_2.xtc start 2 replace false
open traj_3.xtc start 2 replace false
….. etc
But I am not able to find out how to make a cycle from 2 to say 100 to repeat reading the trajectories consecutively.
Best
Sasha
From: Eric Pettersen [mailto:pett@cgl.ucsf.edu]
Sent: Friday, May 2, 2025 11:41 PM
To: Alexandra Zahradnikova
Cc: chimerax-users@cgl.ucsf.edu
Subject: Re: [chimerax-users] RMSD for all frames in a trajectory
Hi Sasha,
It would be tricky, since you have to accumulate values across the trajectory, but I think it's doable. Here's much more pseudocode-y approach:
# get ref/traj as per previous script; the RMSF will be measured against the ref position
for rchain, tchain in zip(ref.chains, traj,chains):
ratoms = rchain.residues.principal_atoms
tatoms = tchain.residues.principal_atoms
rmsf_sums = numpy.zeros(len(ratoms))
r_coords = ratoms.scene_coords
for cs_id in traj.coordset_ids:
run(session, f"coordset {traj.atomspec} {cs_id}")
run(session, f"align {traj.atomspec}/{tchain.chain_d} to {ref.atomspec}/{rchain.chain_id}")
t_coords = tatoms.scene_coords
# some numpy operations here to take the two Nx3 arrays (r_coords, t_coords) and:
# (1) compute corresponding squared distances
# (2) sum them into the rmsf_sums array
# at the end of the loop, divide the sums by the number of coordsets (traj.num_coordsets) and take the square root
# output the RMSFs, possibly using a "for res, rmsf in zip(tchain.residues, rmsfs_sums):" loop
--Eric
On May 1, 2025, at 6:26 AM, Alexandra Zahradnikova via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Thanks for help, the script works for me nicely.
Would it be possible to make a similar script to calculate RMSF along the chain for a trajectory? Currently I do it by saving the trajectory as a pdb with all submodes, reopening the pdb, and applying the commands
Sequence associate /L, where L is the name of the analyzed chain; Headers→Cα RMSD; Headers→Save. It would be more practical without the necessity to save this large file.
From: Eric Pettersen [mailto:pett@cgl.ucsf.edu]
Sent: Tuesday, April 29, 2025 10:42 PM
To: Alexandra Zahradnikova
Cc: chimerax-users@cgl.ucsf.edu
Subject: Re: [chimerax-users] RMSD for all frames in a trajectory
I think this will be slightly easier in ChimeraX. My approach would be to open a structure of just the first frame (for use in aligning) as model 1, and open the trajectory as model 2. There are commands for aligning the structures ("align"), changing to a specific frame ("coordset"), and finding the RMSD values ("rmsd"). The code/pseudocode for the script would be:
from chimerax.atomic import all_atomic_structures
for s in all_atomic_structures(session):
from chimerax.core.commands import run
for cs_id in traj.coordset_ids:
run(session, f"coordset {traj.atomspec} {cs_id}")
run(session, f"align {traj.atomspec}/A to {ref.atomspec}/A") # maybe further limited to backbone or CA atoms
rmsd = run(session, f"rmsd {traj.atomspec}/{chain.chain_id} to {ref.atomspec}/{chain.chain_id}") # again, perhaps limited further
# code to either output the RMSD to a file now, or save it and output them collectively later
If you don't want all the commands the script is running to show up in the Log, you can add "log=False" to the run() calls.
UCSF Computer Graphics Lab
On Apr 29, 2025, at 11:21 AM, Alexandra Zahradnikova via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
I am working with a trajectory of a tetramer.
I would like to align the A chains in all frame of the trajectory and then calculate the rmsd of all chains in all frames relative to the respective chain of the first frame (i.e., align only chains A but calculate for all chains), and write the results to a text file. Is that possible? I can do a similar calculation with a script in old Chimera but don’t know how to do it in ChimeraX.
I attach the zipped script for old Chimera.