I recently started working with MDanalysis. I am working with a system of a crown ether, strontium and chlorides in water. The thing is that i have been working with plumed + amber to get the distance along all the production of strontium and the center of masses of the crown ether.
Now i was trying to get the same information but using MDanalysis but the values i get are so different from those i got previously and even do not really have sense.
import MDAnalysis as mda
import numpy as np
import pandas as pd
import MDAnalysis.analysis.distances as dist
topol='18c6_Sr_2Cl_12_6_4.prmtop'
traj='
nvt500.nc'
# Create a Universe object to load the topology and trajectory
u=mda.Universe(topol,traj)
comcw=u.select_atoms('resid 1 to 42')
sr_metal=u.select_atoms('resid 43')
distances = []
# Iterate through frames in the trajectory
for ts in u.trajectory:
# Calculate the COM of the selected group of atoms
com = comcw.center_of_mass()
# Calculate the position of the metal atom
metal = sr_metal.positions[0]
# Calculate the distance between the COM and the metal atom
dista =dist.distance_array(com,metal,box=u.dimensions)
# Append the distance to the list
distances.append(dista)
with open('distances.txt','w') as f:
for dist in distances:
f.write(f'{dist}\n')
~