Distance between 2 helix

46 views
Skip to first unread message

Hocine

unread,
Jul 29, 2023, 8:41:49 AM7/29/23
to MDnalysis discussion
Hi,

I am trying to calculate the distance between 2 helices, using the  centre of mass:

protein = u.select_atoms('protein')
Helix1= u.select_atoms("backbone and resid 100-150")
Helix2= u.select_atoms("backbone and  resid 345-390")

distances = []

for ts in u.trajectory:
    Helix1 = Helix1.center_of_mass(compound='residues')
    Helix2 = Helix2.center_of_mass(compound='residues')

    distance = np.min(np.linalg.norm(Helix1[:, np.newaxis] - Helix2, axis=-1))

    distances.append(distance)

Is this the correct way? Is there any efficient way to compute the distance between the 2 segments, knowing that they don't have the same number of residues?

Thanks in advance!!

Fiona Naughton

unread,
Jul 31, 2023, 7:06:48 PM7/31/23
to MDnalysis discussion
Hey!

Just to clarify, are you trying to calculate the distance between the center of mass of each helix, or find their closest residue-residue distance? That code should give you the later. You can use the built-in distance tools instead of np.linalg.norm; this will avoid any issues with periodic boundary conditions:

from MDAnalysis.analysis.distances import distance_array
...
    distance = np.min(distance_array(Helix1, Helix2, box=u.dimensions))

(I also see you've given the atomselections and the center of masses the same variables names - you''ll want to change one of them).

Best,
 - Fiona

Hocine

unread,
Aug 3, 2023, 2:48:30 PM8/3/23
to MDnalysis discussion
Dear Fiona,

Thanks for your reply!
Im trying to calculate the distance between the center of mass of each helix.

Fiona Naughton

unread,
Aug 9, 2023, 9:51:08 PM8/9/23
to MDnalysis discussion
Hi,

In that case, you can just use helix.center_of_mass() rather than helix.center_of_mass(compound='residues') - the later gives you a list with the centers of mass of each residue in the helix, the former gives just the center of mass of the helix as a whole.

If you're concerned about isolating only the "perpendicular" part of the distance between the two helicies since the two helicies are different lengths or if they move parallel to each other, that gets a little trickier; there's not a direct way to do that in MDAnalysis, but you could use Helanal to get the axis of each helix and then do some vector maths to find the axis perpendicular to both. Personally, what I do instead is manually adjust the atom selections to include only equivalent-length parts of the helicies, or (when looking at transmembrane helicies in a membrane in the xy-plane) take only the xy component of the COM distance.

Hope that helps,
 - Fiona


trying to isolate only the  , that does get a little trickier - there's a not a way to directly do that in MDAnalysis, but you can , or alter my helix selections to use similar regions / only take a a
Reply all
Reply to author
Forward
0 new messages