distance calculation from an atom to the COM

24 views
Skip to first unread message

isaac gimenez

unread,
Oct 12, 2023, 7:39:25 AM10/12/23
to MDnalysis discussion
Hi everyone!

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. 
can anyone suggest how to do it properly? thank you so much in advance!

The MDanalysisi script i prepared is the following one:

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')
~                                   
Isaac

isaac gimenez

unread,
Oct 12, 2023, 7:48:58 AM10/12/23
to MDnalysis discussion
i have already solved!
Thank you so much for posting it =)
Isaac
El dia dijous, 12 d’octubre de 2023 a les 13:39:25 UTC+2, isaac gimenez va escriure:
Reply all
Reply to author
Forward
0 new messages