Using Simple atomic distance analysis for atom groups in two different trajectories #4594
-
Hello Everyone, I am not a very expert user of MDAnalysis, Here I have a question regarding 'simple atomic distance analysis' as explained in the documentation, it says " This module provides a class to efficiently compute distances between two groups of atoms with an equal number of atoms over a trajectory".Since this method is bound to calculate the distances over a trajectory if offer another bound that both gorups of atoms should belong same trajectory/frame. I tried to slice the trajectory following documentation, I accessed two different trajectories and tried to calculate the distance but result in just the zeros. I also tried to extract coordinated info as numpy array and process but it resulted in loss of periodic boundary condition(pbc) thus effecting eventual results. Can anyone suggest a smart way to select atom groups from first trajectory u.trajectory[0] and subtract distances from all over the trajetory ? does Time step class can help in this regard ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Can you show your code? Can you explain again what you want to calculate, e.g., by writing down equations? Do you want to calculate the displacement of atom i relative to frame 0 as a function of time
where
You'll probably do something like (for the first case) using calc_bonds() import numpy as np
import MDAnalysis as mda
from MDAnalysis.lib.distances import calc_bonds
u = mda.Universe(TOP, TRAJ)
ag = u.select_atoms("protein and name CA") # replace with your own selection
# frame 0
u.trajectory[0]
x_ref = ag.positions # makes a copy as a numpy array
d_i = np.zeros((u.trajectory.n_frames, ag.n_atoms), dtype=np.float64)
for iframe, ts in enumerate(u.trajectory):
# calculate distances with PBC taken into account (use ts.dimensions)
d_i[iframe] = calc_bonds(x_ref, ag, box=ts.dimensions) The array |
Beta Was this translation helpful? Give feedback.
I am glad this was helpful. If it answered your question please mark it as an answer as this helps everybody else who's looking at the forum. Otherwise please let us know what is still not working. Thanks.