<p>It's a reference issue. The second term.</p>
<p>Your first block makes a list of numpy arrays which are the RMSD against frame  0 of each of the stacks, while in your second you make a concatenation of frames, so your reference frame 0 is common.</p>
<p>The first code block could be smartened by splitting (abstracting) the file valid name enumeration and the reading/analysis. Namely, generate a list of valid filenames and <em>then</em> analyse. This separation would allow you recycle more easily the code: in the seocnd code block you have the file list problem again, which is instead resolved by a copypaste job —very inflexible. A one liner list comprehension (or, less so, a <code>functools.reduce</code>) is a nice option.</p>

CC BY-SA 4.0
2022-04-19T08:46:52.277Z
2022-04-19T08:46:52.277Z
Matteo Ferla
<p>I want to analyze the RMSD of my trajectory files using MdTraj.</p>
<p>I used two different codes for this purpose:</p>
<p>the first code:</p>
<pre><code>rep = 1
traj_name = &quot;step7_%d.dcd&quot; %rep
rmsd_total = []

while (os.path.isfile(traj_name)):
    t = md.load(traj_name, top = 'step5_input.pdb')
    top = t.topology 
    protein_sel = top.select('backbone')
    protein_traj = t.atom_slice(protein_sel)
    rmsd = md.rmsd(protein_traj, protein_traj, 0)    
    rmsd_without_zero = [i for i in rmsd if i != 0.0]
    rmsd_total.extend(rmsd_without_zero)

    rep+=1
    traj_name = &quot;step7_%d.dcd&quot; %rep
</code></pre>
<p>and the second code:</p>
<pre><code>traj_1 = md.load('step7_1.dcd', top='step5_input.pdb')
traj_2 = md.load('step7_2.dcd', top='step5_input.pdb')
traj_3 = md.load('step7_3.dcd', top='step5_input.pdb')
traj_4 = md.load('step7_4.dcd', top='step5_input.pdb')
traj_5 = md.load('step7_5.dcd', top='step5_input.pdb')
traj_6 = md.load('step7_6.dcd', top='step5_input.pdb')
traj_7 = md.load('step7_7.dcd', top='step5_input.pdb')
traj_8 = md.load('step7_8.dcd', top='step5_input.pdb')
traj_9 = md.load('step7_9.dcd', top='step5_input.pdb')
traj_10 = md.load('step7_10.dcd', top='step5_input.pdb')
traj_11 = md.load('step7_11.dcd', top='step5_input.pdb')
traj_12 = md.load('step7_12.dcd', top='step5_input.pdb')
traj_13 = md.load('step7_13.dcd', top='step5_input.pdb')
traj_14 = md.load('step7_14.dcd', top='step5_input.pdb')
traj_15 = md.load('step7_15.dcd', top='step5_input.pdb')
traj_16 = md.load('step7_16.dcd', top='step5_input.pdb')
traj_17 = md.load('step7_17.dcd', top='step5_input.pdb')
traj_18 = md.load('step7_18.dcd', top = 'step5_input.pdb')
traj_19 = md.load('step7_19.dcd', top = 'step5_input.pdb')
traj_20 = md.load('step7_20.dcd', top = 'step5_input.pdb')

combine = traj_1 + traj_2 + traj_3 + traj_4 + traj_5 + traj_6 + traj_7 + traj_8 + traj_9 + traj_10 + traj_11 + traj_12 + traj_13 + traj_14 + traj_15 + traj_16 + traj_17 + traj_18 + traj_19 + traj_20

protein_sel = combine.topology.select('backbone')
protein_traj = combine.atom_slice(protein_sel)
rmsd = md.rmsd(protein_traj, protein_traj, 0)
</code></pre>
<p>I believe these two codes should result in the same RMSD. However, I get two different RMSD diagrams out of these two codes?</p>
<p>Can anyone help me what is the problems with my first code? (since I think the second code is more accurate while is more naive)</p>

CC BY-SA 4.0
2023-09-15T16:09:36.717Z
Hi @amirre this has been authoritatively answered please kindly consider accepting the post and helpful for the other site members.
M__
<python>
different results of RMSD for the same trajectory file
# different results of RMSD for the same trajectory file

(Asked by: username_0 on 2022-04-19)

I want to analyze the RMSD of my trajectory files using MdTraj.
I used two different codes for this purpose:
the first code:
rep = 1
traj_name = "step7_%d.dcd" %rep
rmsd_total = []

while (os.path.isfile(traj_name)):
    t = md.load(traj_name, top = 'step5_input.pdb')
    top = t.topology 
    protein_sel = top.select('backbone')
    protein_traj = t.atom_slice(protein_sel)
    rmsd = md.rmsd(protein_traj, protein_traj, 0)    
    rmsd_without_zero = [i for i in rmsd if i != 0.0]
    rmsd_total.extend(rmsd_without_zero)

    rep+=1
    traj_name = "step7_%d.dcd" %rep

and the second code:
traj_1 = md.load('step7_1.dcd', top='step5_input.pdb')
traj_2 = md.load('step7_2.dcd', top='step5_input.pdb')
traj_3 = md.load('step7_3.dcd', top='step5_input.pdb')
traj_4 = md.load('step7_4.dcd', top='step5_input.pdb')
traj_5 = md.load('step7_5.dcd', top='step5_input.pdb')
traj_6 = md.load('step7_6.dcd', top='step5_input.pdb')
traj_7 = md.load('step7_7.dcd', top='step5_input.pdb')
traj_8 = md.load('step7_8.dcd', top='step5_input.pdb')
traj_9 = md.load('step7_9.dcd', top='step5_input.pdb')
traj_10 = md.load('step7_10.dcd', top='step5_input.pdb')
traj_11 = md.load('step7_11.dcd', top='step5_input.pdb')
traj_12 = md.load('step7_12.dcd', top='step5_input.pdb')
traj_13 = md.load('step7_13.dcd', top='step5_input.pdb')
traj_14 = md.load('step7_14.dcd', top='step5_input.pdb')
traj_15 = md.load('step7_15.dcd', top='step5_input.pdb')
traj_16 = md.load('step7_16.dcd', top='step5_input.pdb')
traj_17 = md.load('step7_17.dcd', top='step5_input.pdb')
traj_18 = md.load('step7_18.dcd', top = 'step5_input.pdb')
traj_19 = md.load('step7_19.dcd', top = 'step5_input.pdb')
traj_20 = md.load('step7_20.dcd', top = 'step5_input.pdb')

combine = traj_1 + traj_2 + traj_3 + traj_4 + traj_5 + traj_6 + traj_7 + traj_8 + traj_9 + traj_10 + traj_11 + traj_12 + traj_13 + traj_14 + traj_15 + traj_16 + traj_17 + traj_18 + traj_19 + traj_20

protein_sel = combine.topology.select('backbone')
protein_traj = combine.atom_slice(protein_sel)
rmsd = md.rmsd(protein_traj, protein_traj, 0)

I believe these two codes should result in the same RMSD. However, I get two different RMSD diagrams out of these two codes?
Can anyone help me what is the problems with my first code? (since I think the second code is more accurate while is more naive)

**Tags:** python
> **Comments:**
> **username_1**: Hi @amirre this has been authoritatively answered please kindly consider accepting the post and helpful for the other site members.  

---

## 1 answers

### Answer by username_2 on 2022-04-19. Score: 1

It's a reference issue. The second term.

Your first block makes a list of numpy arrays which are the RMSD against frame 0 of each of the stacks, while in your second you make a concatenation of frames, so your reference frame 0 is common.

The first code block could be smartened by splitting (abstracting) the file valid name enumeration and the reading/analysis. Namely, generate a list of valid filenames and *then* analyse. This separation would allow you recycle more easily the code: in the seocnd code block you have the file list problem again, which is instead resolved by a copypaste job —very inflexible. A one liner list comprehension (or, less so, a `functools.reduce`) is a nice option.


---

