What are the atom names that form the dihedral? If they are A-B-C-D and you want the torsion around B-C, make selections for these groups
A = glucose.select_atoms(“name A”)
B = glucose.select_atoms(“name B”)
C = glucose.select_atoms(“name C”)
D = glucose.select_atoms(“name D”)
These are all atomgroups. The above only works correctly if the dihedral is INSIDE each residue. If it bridges residues you have to shift atoms around. Effectively, element i of each atomgroup has to form a dihedral: A[i] - B[i] - C[i] - D[i]. It’s up to you to line them up correctly.
Calculate all dihedrals
from MDAnalysis.lib.distances import calc_dihedrals
results = []
times = []
for ts in u.trajectory:
dihedrals = calc_dihedrals(A, B, C, D, box=u.dimensions)
results.append(dihedrals)
times.append(ts.time)
results = np.array(results)
times = np.array(times)
plt.plot(times, results.T) # should plot timeseries of all dihedrals
I didn’t try out the code above so it probably won’t exactly work that way. However, it should get you started and give you an idea where to look. Ultimately, you have to write your own code because there’s nothing in MDAnalysis specific for carbohydrates.
Best,
Oliver