-
Notifications
You must be signed in to change notification settings - Fork 1
/
distance_functions.py
executable file
·63 lines (42 loc) · 1.55 KB
/
distance_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/mnt/lustre_fs/users/mjmcc/apps/python2.7/bin/python
##!/Library/Frameworks/Python.framework/Versions/2.7/bin/python
# USAGE:
# from distance_functions import *
# PREAMBLE:
import numpy as np
sqrt = np.sqrt
sums = np.sum
square = np.square
zeros = np.zeros
# SUBROUTINES:
def RMSD(x,y,n):
""" Calculates the Root Mean Squared Distance between two arrays of the same size
Usage: rmsd = RMSD(x,y,n)
Arguments:
x, y: numpy arrays with the same shape (n X 3)
n: number of particles being summed over; ex: number of atoms in the atom selection being analyzed;
if n = 1, this function calculates the distance between x and y arrays
"""
return sqrt(sums(square(x-y))/n)
def MSD(x,y,n):
""" Calculates the Mean Squared Distance between two arrays of the same size
Usage: msd = MSD(x,y,n)
Arguments:
x, y: numpy arrays with the same shape
n: number of particles being summed over; ex: number of atoms in the atom selection being analyzed;
if n = 1, this function calculates the distance squared between x and y arrays
"""
return sums(square(x-y))/n
def wrapping(x,dim):
""" Calculates the translation matrix needed to wrap a particle back into the original periodic box
Usage: t = wrapping(x,dim)
Arguments:
x: a numpy array of size (3) that corresponds to the xyz coordinates of an ATOM/COM/COG of a residue
dim: a numpy array of size (3) that holds the xyz dimensions of the periodic box at that timestep
"""
t = zeros(3)
dim2 = dim/2.
for i in range(3):
if (x[i]<-dim2[i]) or (x[i]>dim2[i]):
t[i] = -dim[i]*round(x[i]/dim[i])
return t