packmol-memgen-minimal 1.1.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- packmol_memgen/__init__.py +2 -0
- packmol_memgen/__version__.py +34 -0
- packmol_memgen/data/LICENSE.Apache-2.0 +201 -0
- packmol_memgen/data/extra_solvents.lib +789 -0
- packmol_memgen/data/frcmod.lipid_ext +97 -0
- packmol_memgen/data/frcmod.solvents +129 -0
- packmol_memgen/data/insane_lipids.txt +138 -0
- packmol_memgen/data/insane_solvents.txt +45 -0
- packmol_memgen/data/leaprc.extra_solvents +42 -0
- packmol_memgen/data/leaprc.lipid_ext +48 -0
- packmol_memgen/data/lipid_ext.lib +12312 -0
- packmol_memgen/data/martini_v3.0.0.itp +356605 -0
- packmol_memgen/data/memgen.parm +4082 -0
- packmol_memgen/data/pdbs.tar.gz +0 -0
- packmol_memgen/data/solvent.parm +14 -0
- packmol_memgen/example/example.sh +31 -0
- packmol_memgen/lib/__init__.py +0 -0
- packmol_memgen/lib/amber.py +77 -0
- packmol_memgen/lib/charmmlipid2amber/__init__.py +0 -0
- packmol_memgen/lib/charmmlipid2amber/charmmlipid2amber.csv +7164 -0
- packmol_memgen/lib/charmmlipid2amber/charmmlipid2amber.py +225 -0
- packmol_memgen/lib/pdbremix/LICENSE +21 -0
- packmol_memgen/lib/pdbremix/__init__.py +0 -0
- packmol_memgen/lib/pdbremix/_version.py +1 -0
- packmol_memgen/lib/pdbremix/amber.py +1103 -0
- packmol_memgen/lib/pdbremix/asa.py +227 -0
- packmol_memgen/lib/pdbremix/data/aminoacid.pdb +334 -0
- packmol_memgen/lib/pdbremix/data/binaries.json +26 -0
- packmol_memgen/lib/pdbremix/data/charmm22.parameter +2250 -0
- packmol_memgen/lib/pdbremix/data/charmm22.topology +1635 -0
- packmol_memgen/lib/pdbremix/data/color_b.py +682 -0
- packmol_memgen/lib/pdbremix/data/hin.lib +130 -0
- packmol_memgen/lib/pdbremix/data/hydroxide.lib +88 -0
- packmol_memgen/lib/pdbremix/data/make_chi.py +92 -0
- packmol_memgen/lib/pdbremix/data/opls.parameter +1108 -0
- packmol_memgen/lib/pdbremix/data/opls.topology +1869 -0
- packmol_memgen/lib/pdbremix/data/phd.frcmod +82 -0
- packmol_memgen/lib/pdbremix/data/phd.leaprc +4 -0
- packmol_memgen/lib/pdbremix/data/phd.prepin +35 -0
- packmol_memgen/lib/pdbremix/data/template.pdb +334 -0
- packmol_memgen/lib/pdbremix/data/znb.frcmod +24 -0
- packmol_memgen/lib/pdbremix/data/znb.leaprc +7 -0
- packmol_memgen/lib/pdbremix/data/znb.lib +69 -0
- packmol_memgen/lib/pdbremix/data.py +264 -0
- packmol_memgen/lib/pdbremix/fetch.py +102 -0
- packmol_memgen/lib/pdbremix/force.py +627 -0
- packmol_memgen/lib/pdbremix/gromacs.py +978 -0
- packmol_memgen/lib/pdbremix/lib/__init__.py +0 -0
- packmol_memgen/lib/pdbremix/lib/docopt.py +579 -0
- packmol_memgen/lib/pdbremix/lib/pyqcprot.py +305 -0
- packmol_memgen/lib/pdbremix/namd.py +1078 -0
- packmol_memgen/lib/pdbremix/pdbatoms.py +543 -0
- packmol_memgen/lib/pdbremix/pdbtext.py +120 -0
- packmol_memgen/lib/pdbremix/protein.py +311 -0
- packmol_memgen/lib/pdbremix/pymol.py +480 -0
- packmol_memgen/lib/pdbremix/rmsd.py +203 -0
- packmol_memgen/lib/pdbremix/simulate.py +420 -0
- packmol_memgen/lib/pdbremix/spacehash.py +73 -0
- packmol_memgen/lib/pdbremix/trajectory.py +286 -0
- packmol_memgen/lib/pdbremix/util.py +273 -0
- packmol_memgen/lib/pdbremix/v3.py +16 -0
- packmol_memgen/lib/pdbremix/v3array.py +482 -0
- packmol_memgen/lib/pdbremix/v3numpy.py +350 -0
- packmol_memgen/lib/pdbremix/volume.py +155 -0
- packmol_memgen/lib/utils.py +1017 -0
- packmol_memgen/main.py +2827 -0
- packmol_memgen_minimal-1.1.16.dist-info/METADATA +664 -0
- packmol_memgen_minimal-1.1.16.dist-info/RECORD +71 -0
- packmol_memgen_minimal-1.1.16.dist-info/WHEEL +4 -0
- packmol_memgen_minimal-1.1.16.dist-info/entry_points.txt +2 -0
- packmol_memgen_minimal-1.1.16.dist-info/licenses/LICENSE +338 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
__doc__ = """
|
|
4
|
+
|
|
5
|
+
3D vector geometry library in pure Python.
|
|
6
|
+
|
|
7
|
+
The vectors and transform matrices are subclassd from array.array.
|
|
8
|
+
Most operations are accessed through functions, allowing easy
|
|
9
|
+
switching with other libraries, such as v3numpy.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import math
|
|
13
|
+
import random
|
|
14
|
+
from array import array
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Vec3(array):
|
|
18
|
+
"""
|
|
19
|
+
Represents a 3-dimensional vector/coordinate.
|
|
20
|
+
|
|
21
|
+
Arithmetic operators are overloaded for artihmetic vector
|
|
22
|
+
operations. Scaling and other non-arithmetic operators are
|
|
23
|
+
carried out with functions.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __new__(cls, x=0, y=0, z=0):
|
|
27
|
+
return array.__new__(cls, 'd', (x,y,z))
|
|
28
|
+
|
|
29
|
+
def __repr__(self):
|
|
30
|
+
return "Vec3(%f, %f, %f)" % (self[0], self[1], self[2])
|
|
31
|
+
|
|
32
|
+
def __add__(self, rhs):
|
|
33
|
+
return Vec3(self[0]+rhs[0], self[1]+rhs[1], self[2]+rhs[2])
|
|
34
|
+
|
|
35
|
+
def __iadd__(self, rhs):
|
|
36
|
+
self[0] += rhs[0]
|
|
37
|
+
self[1] += rhs[1]
|
|
38
|
+
self[2] += rhs[2]
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
def __isub__(self, rhs):
|
|
42
|
+
self[0] -= rhs[0]
|
|
43
|
+
self[1] -= rhs[1]
|
|
44
|
+
self[2] -= rhs[2]
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def __sub__(self, rhs):
|
|
48
|
+
return Vec3(self[0]-rhs[0], self[1]-rhs[1], self[2]-rhs[2])
|
|
49
|
+
|
|
50
|
+
def __neg__(self):
|
|
51
|
+
return Vec3(-self[0], -self[1], -self[2])
|
|
52
|
+
|
|
53
|
+
def __pos__(self):
|
|
54
|
+
return self
|
|
55
|
+
|
|
56
|
+
def __mul__(self, s):
|
|
57
|
+
return Vec3(self[0]*s, self[1]*s, self[2]*s)
|
|
58
|
+
|
|
59
|
+
def __rmul__(self, s):
|
|
60
|
+
return Vec3(self[0]*s, self[1]*s, self[2]*s)
|
|
61
|
+
|
|
62
|
+
def __deepcopy__(self, memo):
|
|
63
|
+
cls = self.__class__
|
|
64
|
+
return array.__new__(cls, 'd', (self[0],self[1],self[2]))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def vector(*args):
|
|
68
|
+
"""
|
|
69
|
+
Creates a new vector
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
None: returns zero vector
|
|
73
|
+
v (vector): returns copy of v
|
|
74
|
+
x, y, z: returns (x, y, z)
|
|
75
|
+
"""
|
|
76
|
+
if len(args) == 0:
|
|
77
|
+
return Vec3(0, 0, 0)
|
|
78
|
+
elif len(args) == 1:
|
|
79
|
+
v = args[0]
|
|
80
|
+
return Vec3(v[0], v[1], v[2])
|
|
81
|
+
elif len(args) == 3:
|
|
82
|
+
return Vec3(*args)
|
|
83
|
+
else:
|
|
84
|
+
raise TypeError('vector() can take 0, 1, 3 arguments only')
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def set_vector(*args):
|
|
88
|
+
"""
|
|
89
|
+
Changes components of vector in place
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
v (vector), w (vector): copies values of w into v
|
|
93
|
+
v (vector), x, y, z: copiex x, y, z into v
|
|
94
|
+
"""
|
|
95
|
+
v = args[0]
|
|
96
|
+
if len(args) == 2:
|
|
97
|
+
w = args[1]
|
|
98
|
+
v[:] = w
|
|
99
|
+
elif len(args) == 4:
|
|
100
|
+
v[0], v[1], v[2] = args[1:4]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def mag(v):
|
|
104
|
+
"""
|
|
105
|
+
Returns the magnitude of v.
|
|
106
|
+
"""
|
|
107
|
+
x, y, z = v
|
|
108
|
+
return math.sqrt(x*x + y*y + z*z)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def mag2(v):
|
|
112
|
+
"""
|
|
113
|
+
Returns square of the magnitude of v.
|
|
114
|
+
"""
|
|
115
|
+
x, y, z = v
|
|
116
|
+
return x*x + y*y + z*z
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def scale(v, s):
|
|
120
|
+
"""
|
|
121
|
+
Returns vector that is v scaled (multiplied) by s
|
|
122
|
+
"""
|
|
123
|
+
return vector(s*v[0], s*v[1], s*v[2])
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def dot(v1, v2):
|
|
127
|
+
"""
|
|
128
|
+
Returns the dot product of two vectors
|
|
129
|
+
"""
|
|
130
|
+
x1, y1, z1 = v1
|
|
131
|
+
x2, y2, z2 = v2
|
|
132
|
+
return x1*x2 + y1*y2 + z1*z2
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def norm(v):
|
|
136
|
+
"""
|
|
137
|
+
Returns scaled v, normalized to magnitude 1.0.
|
|
138
|
+
"""
|
|
139
|
+
return scale(v, 1.0/mag(v))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def cross(v1, v2):
|
|
143
|
+
"""
|
|
144
|
+
Returns the cross product of two vectors.
|
|
145
|
+
"""
|
|
146
|
+
x1, y1, z1 = v1
|
|
147
|
+
x2, y2, z2 = v2
|
|
148
|
+
return vector(
|
|
149
|
+
y1*z2 - z1*y2,
|
|
150
|
+
z1*x2 - x1*z2,
|
|
151
|
+
x1*y2 - y1*x2)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def radians(degrees):
|
|
155
|
+
"""
|
|
156
|
+
Converts degrees to radians, which is used in math functions.
|
|
157
|
+
"""
|
|
158
|
+
return math.pi / 180.0 * degrees
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def degrees(radians):
|
|
162
|
+
"""
|
|
163
|
+
Converts radians to degrees, better for reporting.
|
|
164
|
+
"""
|
|
165
|
+
return 180.0 / math.pi*degrees * radians
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class Matrix3d(array):
|
|
169
|
+
"""
|
|
170
|
+
Represents affine transforms in 3D space.
|
|
171
|
+
|
|
172
|
+
To be accessed by the auxilary function matrix_elem(). Matrix3d
|
|
173
|
+
subclasses an array of 12 floats. This is subclassed mainly to
|
|
174
|
+
provide a more informative __repr_function.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
def __new__(cls, matrix_array=(1,0,0,0,1,0,0,0,1,0,0,0)):
|
|
178
|
+
return array.__new__(cls, 'd', matrix_array)
|
|
179
|
+
|
|
180
|
+
def __repr__(self):
|
|
181
|
+
def str3(x, y, z):
|
|
182
|
+
return "% 10.5f, % 10.5f, % 10.5f" % (x, y, z)
|
|
183
|
+
s = "Matrix3d((" + str3(*self[:3]) + ",\n"
|
|
184
|
+
s += " " + str3(*self[3:6]) + ",\n"
|
|
185
|
+
s += " " + str3(*self[6:9]) + ",\n"
|
|
186
|
+
s += " #-----------------------------------\n"
|
|
187
|
+
s += " " + str3(*self[9:12]) + "))"
|
|
188
|
+
return s
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def identity():
|
|
193
|
+
"""
|
|
194
|
+
Returns the identity transform.
|
|
195
|
+
"""
|
|
196
|
+
return Matrix3d()
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def matrix_elem(matrix, i, j, val=None):
|
|
200
|
+
"""
|
|
201
|
+
Reads/writes the elements of an affine transform.
|
|
202
|
+
|
|
203
|
+
1. 3x3 rotational component;
|
|
204
|
+
matrix_elem(m, i, j) for i=0..3, j=0..3
|
|
205
|
+
2. 3x1 translational component:
|
|
206
|
+
matrix_elem(m, 3, i) for i=0..3)
|
|
207
|
+
"""
|
|
208
|
+
k = i*3 + j
|
|
209
|
+
if val is None:
|
|
210
|
+
return matrix[k]
|
|
211
|
+
else:
|
|
212
|
+
matrix[k] = val
|
|
213
|
+
return val
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def transform(matrix, v):
|
|
217
|
+
"""
|
|
218
|
+
Returns vector of applying the transform in matrix to v.
|
|
219
|
+
"""
|
|
220
|
+
v_x, v_y, v_z = v
|
|
221
|
+
x = matrix_elem(matrix, 0, 0) * v_x + \
|
|
222
|
+
matrix_elem(matrix, 1, 0) * v_y + \
|
|
223
|
+
matrix_elem(matrix, 2, 0) * v_z + \
|
|
224
|
+
matrix_elem(matrix, 3, 0)
|
|
225
|
+
y = matrix_elem(matrix, 0, 1) * v_x + \
|
|
226
|
+
matrix_elem(matrix, 1, 1) * v_y + \
|
|
227
|
+
matrix_elem(matrix, 2, 1) * v_z + \
|
|
228
|
+
matrix_elem(matrix, 3, 1)
|
|
229
|
+
z = matrix_elem(matrix, 0, 2) * v_x + \
|
|
230
|
+
matrix_elem(matrix, 1, 2) * v_y + \
|
|
231
|
+
matrix_elem(matrix, 2, 2) * v_z + \
|
|
232
|
+
matrix_elem(matrix, 3, 2)
|
|
233
|
+
return vector(x, y, z)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def left_inverse(m):
|
|
237
|
+
"""
|
|
238
|
+
Returns the left inverse of m.
|
|
239
|
+
|
|
240
|
+
Example:
|
|
241
|
+
combine(left_inverse(m), m) == identity().
|
|
242
|
+
"""
|
|
243
|
+
rot_t = identity()
|
|
244
|
+
for i in range(0, 3):
|
|
245
|
+
for j in range(0, 3):
|
|
246
|
+
val = matrix_elem(m,j,i)
|
|
247
|
+
matrix_elem(rot_t,i,j,val)
|
|
248
|
+
t = vector(matrix_elem(m,3,0), matrix_elem(m,3,1), matrix_elem(m,3,2))
|
|
249
|
+
t_inv = transform(rot_t, t)
|
|
250
|
+
for i in range(0, 3):
|
|
251
|
+
matrix_elem(rot_t, 3, i, -t_inv[i])
|
|
252
|
+
return rot_t
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def rotation(axis, theta):
|
|
256
|
+
"""
|
|
257
|
+
Returns transform that rotate a vector at the origin around axis.
|
|
258
|
+
"""
|
|
259
|
+
m = identity()
|
|
260
|
+
c = math.cos(theta)
|
|
261
|
+
s = math.sin(theta)
|
|
262
|
+
t = 1.0 - c
|
|
263
|
+
x, y, z = norm(axis)
|
|
264
|
+
matrix_elem(m, 0, 0, t*x*x + c)
|
|
265
|
+
matrix_elem(m, 0, 1, t*x*y + z*s )
|
|
266
|
+
matrix_elem(m, 0, 2, t*x*z - y*s )
|
|
267
|
+
matrix_elem(m, 1, 0, t*y*x - z*s )
|
|
268
|
+
matrix_elem(m, 1, 1, t*y*y + c)
|
|
269
|
+
matrix_elem(m, 1, 2, t*y*z + x*s )
|
|
270
|
+
matrix_elem(m, 2, 0, t*z*x + y*s )
|
|
271
|
+
matrix_elem(m, 2, 1, t*z*y - x*s )
|
|
272
|
+
matrix_elem(m, 2, 2, t*z*z + c)
|
|
273
|
+
return m
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def translation(displacement):
|
|
277
|
+
"""
|
|
278
|
+
Returns transform that translates by displacement.
|
|
279
|
+
"""
|
|
280
|
+
m = identity()
|
|
281
|
+
for i in range(3):
|
|
282
|
+
matrix_elem(m, 3, i, displacement[i])
|
|
283
|
+
return m
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def combine(a, b):
|
|
287
|
+
"""
|
|
288
|
+
Returns transform that combines two transforms.
|
|
289
|
+
"""
|
|
290
|
+
c = identity()
|
|
291
|
+
for i in range(3):
|
|
292
|
+
# combine the rotational part by matrix multiplication
|
|
293
|
+
for j in range(3):
|
|
294
|
+
val = 0.0
|
|
295
|
+
for k in range(3):
|
|
296
|
+
val += matrix_elem(a, k, i) * matrix_elem(b, j, k)
|
|
297
|
+
matrix_elem(c, j, i, val)
|
|
298
|
+
val = matrix_elem(a, 3, i)
|
|
299
|
+
# combine the translational part by vector rotation
|
|
300
|
+
for k in range(3):
|
|
301
|
+
val += matrix_elem(a, k, i) * matrix_elem(b, 3, k)
|
|
302
|
+
matrix_elem(c, 3, i, val)
|
|
303
|
+
return c
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def is_similar_mag(a, b, small=1E-4):
|
|
308
|
+
"""
|
|
309
|
+
Evaluates similar magnitudes to within small.
|
|
310
|
+
"""
|
|
311
|
+
return abs(a-b) <= small
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def is_similar_vector(a, b, small=1E-4):
|
|
315
|
+
"""
|
|
316
|
+
Evaluates similar matrixes through matrix components.
|
|
317
|
+
"""
|
|
318
|
+
for a_x, b_x in zip(a, b):
|
|
319
|
+
if not is_similar_mag(a_x, b_x, small):
|
|
320
|
+
return False
|
|
321
|
+
return True
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def is_similar_matrix(a, b, small=1E-4):
|
|
325
|
+
"""
|
|
326
|
+
Evaluates similar matrixes through matrix components.
|
|
327
|
+
"""
|
|
328
|
+
for i in range(0, 3):
|
|
329
|
+
for j in range(0, 3):
|
|
330
|
+
if not is_similar_mag(matrix_elem(a,i,j), matrix_elem(b,i,j), small):
|
|
331
|
+
return False
|
|
332
|
+
return True
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
# common to v3list and v3numpy
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def parallel(v, axis):
|
|
339
|
+
"""
|
|
340
|
+
Returns component of v parallel to axis.
|
|
341
|
+
"""
|
|
342
|
+
l = mag(axis)
|
|
343
|
+
if is_similar_mag(l, 0):
|
|
344
|
+
return v
|
|
345
|
+
else:
|
|
346
|
+
return scale(axis, dot(v, axis)/l/l)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def perpendicular(v, axis):
|
|
350
|
+
"""
|
|
351
|
+
Returns component of v perpendicular to axis.
|
|
352
|
+
"""
|
|
353
|
+
return v - parallel(v, axis)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def normalize_angle(angle):
|
|
357
|
+
"""
|
|
358
|
+
Returns angle in radians that is [-pi, pi]
|
|
359
|
+
"""
|
|
360
|
+
while abs(angle) > math.pi:
|
|
361
|
+
if angle > math.pi:
|
|
362
|
+
angle -= math.pi*2
|
|
363
|
+
if angle < -math.pi:
|
|
364
|
+
angle += 2*math.pi
|
|
365
|
+
if is_similar_mag(abs(angle + math.pi), 0):
|
|
366
|
+
angle = math.pi
|
|
367
|
+
return angle
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def vec_angle(a, b):
|
|
371
|
+
"""
|
|
372
|
+
Returns angle in radians between a and b.
|
|
373
|
+
"""
|
|
374
|
+
a_len = mag(a)
|
|
375
|
+
b_len = mag(b)
|
|
376
|
+
if is_similar_mag(a_len, 0) or is_similar_mag(b_len, 0):
|
|
377
|
+
return 0.0
|
|
378
|
+
c = dot(a, b) / a_len / b_len
|
|
379
|
+
if c >= 1.0:
|
|
380
|
+
return 0.0
|
|
381
|
+
elif c <= -1.0:
|
|
382
|
+
return math.pi
|
|
383
|
+
else:
|
|
384
|
+
return math.acos(c)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def vec_dihedral(a, axis, c):
|
|
388
|
+
"""
|
|
389
|
+
Returns dihedral angle between a and c, along the axis.
|
|
390
|
+
"""
|
|
391
|
+
ap = perpendicular(a, axis)
|
|
392
|
+
cp = perpendicular(c, axis)
|
|
393
|
+
angle = vec_angle(ap, cp)
|
|
394
|
+
if dot(cross(ap, cp), axis) > 0:
|
|
395
|
+
angle = -angle
|
|
396
|
+
return angle
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def dihedral(p1, p2, p3, p4):
|
|
400
|
+
"""
|
|
401
|
+
Returns dihedral angle defined by the four positions.
|
|
402
|
+
"""
|
|
403
|
+
return vec_dihedral(p1-p2, p2-p3, p4-p3)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def distance(p1, p2):
|
|
407
|
+
"""
|
|
408
|
+
Returns distance between two points
|
|
409
|
+
"""
|
|
410
|
+
return mag(p1 - p2)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def rotation_at_center(axis, theta, center):
|
|
414
|
+
"""
|
|
415
|
+
Returns a rotation around the center.
|
|
416
|
+
"""
|
|
417
|
+
t = translation(-center)
|
|
418
|
+
r = rotation(axis, theta)
|
|
419
|
+
t_inv = translation(center)
|
|
420
|
+
return combine(t_inv, combine(r, t))
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def get_center(crds):
|
|
424
|
+
"""
|
|
425
|
+
Returns the geometric center of a bunch of positions.
|
|
426
|
+
"""
|
|
427
|
+
center = vector()
|
|
428
|
+
for crd in crds:
|
|
429
|
+
center += crd
|
|
430
|
+
return scale(center, 1.0/float(len(crds)))
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def get_width(crds):
|
|
434
|
+
"""
|
|
435
|
+
Returns the maximum width between any two crds in the group.
|
|
436
|
+
"""
|
|
437
|
+
center = get_center(crds)
|
|
438
|
+
max_diff = 0
|
|
439
|
+
for crd in crds:
|
|
440
|
+
diff = v3.distance(crd, center)
|
|
441
|
+
if diff > max_diff:
|
|
442
|
+
max_diff = diff
|
|
443
|
+
return 2*max_diff
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
def random_mag():
|
|
447
|
+
"""
|
|
448
|
+
Returns a random positive number from [0, 90] for testing.
|
|
449
|
+
"""
|
|
450
|
+
return random.uniform(0, 90)
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def random_real():
|
|
454
|
+
"""
|
|
455
|
+
Returns a random real +/- from [-90, 90] for testing.
|
|
456
|
+
"""
|
|
457
|
+
return random.uniform(-90, 90)
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def random_vector():
|
|
461
|
+
"""
|
|
462
|
+
Returns a random vector for testing.
|
|
463
|
+
"""
|
|
464
|
+
return vector(random_real(), random_real(), random_real())
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def random_rotation():
|
|
468
|
+
"""
|
|
469
|
+
Returns a random rotational matrix for testing.
|
|
470
|
+
"""
|
|
471
|
+
return rotation(random_vector(), radians(random_real()))
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def random_matrix():
|
|
475
|
+
"""
|
|
476
|
+
Returns a random transformation matrix for testing.
|
|
477
|
+
"""
|
|
478
|
+
return combine(random_rotation(), translation(random_vector()))
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|