1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for handling all types of structural statistics."""
24
25
26 from numpy import float64, mean, sqrt, std, zeros
27 from numpy.linalg import norm
28
29
31 """Determine the RMSD for the given atomic coordinates.
32
33 This is the per atom RMSD to the mean structure.
34
35
36 @keyword coord: The array of molecular coordinates. The first dimension corresponds to the model, the second the atom, the third the coordinate.
37 @type coord: rank-3 numpy array
38 @return: The RMSD value.
39 @rtype: float
40 """
41
42
43 M = len(coord)
44 N = len(coord[0])
45 model_rmsd = zeros(M, float64)
46 mean_str = zeros((N, 3), float64)
47
48
49 calc_mean_structure(coord, mean_str)
50
51
52 for i in range(M):
53
54 for j in range(N):
55
56 vect = mean_str[j] - coord[i][j]
57
58
59 model_rmsd[i] += norm(vect)**2
60
61
62 model_rmsd[i] = sqrt(model_rmsd[i] / N)
63
64
65 if verbosity:
66 print("Model %2s RMSD: %s" % (i, model_rmsd[i]))
67
68
69 rmsd_mean = mean(model_rmsd)
70
71
72 try:
73 rmsd_sd = std(model_rmsd, ddof=1)
74
75
76 except TypeError:
77 rmsd_sd = std(model_rmsd) * sqrt(M / (M - 1.0))
78
79
80 if verbosity:
81 print("\nGlobal RMSD: %s +/- %s" % (rmsd_mean, rmsd_sd))
82
83
84 return rmsd_mean
85
86
88 """Average the coordinates.
89
90 @keyword coord: The list of coordinates of all models to superimpose. The first index is the models, the second is the atomic positions, and the third is the xyz coordinates.
91 @type coord: list of numpy rank-2, Nx3 arrays
92 @keyword mean: The data storage for the mean structure.
93 @type mean: numpy rank-2, Nx3 array
94 """
95
96
97 N = len(coord[0])
98 M = len(coord)
99
100
101 for i in range(N):
102 mean[i] = [0.0, 0.0, 0.0]
103
104
105 for i in range(N):
106
107 for j in range(M):
108 mean[i] += coord[j][i]
109
110
111 mean[i] = mean[i] / M
112