IMP  2.4.0
The Integrative Modeling Platform
movement.py
1 """@namespace IMP.EMageFit.imp_general.movement
2  Utility functions to handle movement.
3 """
4 
5 import IMP
6 import IMP.algebra as alg
7 import IMP.atom as atom
8 import IMP.core as core
9 import logging
10 import random
11 
12 
13 def apply_random_transform(rb, max_trans=100):
14  """
15  Apply a random transformation to the rigid body and change the reference
16  frame
17  """
18  bb = alg.BoundingBox3D(alg.Vector3D(-max_trans, -max_trans, -max_trans),
19  alg.Vector3D(max_trans, max_trans, max_trans))
20  Trand = alg.Transformation3D(alg.get_random_rotation_3d(),
21  alg.get_random_vector_in(bb))
22  ref = rb.get_reference_frame()
23  Tr = ref.get_transformation_to()
24  T = alg.compose(Trand, Tr)
25  rb.set_reference_frame(alg.ReferenceFrame3D(T))
26  return Trand
27 
28 
29 def apply_transformation_to_hierarchy(prot, T, fn_write=False):
30  """
31  If fn_write is different from False, write to file
32  """
33  R = T.get_rotation()
34  t = T.get_translation()
35  xyz1 = [core.XYZ(l) for l in atom.get_leaves(prot)]
36  coords = [p.get_coordinates() for p in xyz1]
37  newvs = [R.get_rotated(v) + t for v in coords]
38  for i in range(len(newvs)):
39  xyz1[i].set_coordinates(newvs[i])
40  if(fn_write):
41  atom.write_pdb(prot, fn_write)
42 
43 
44 def get_random_transformation(max_distance, max_angle, seed=-1):
45  """
46  Return a random transformation
47  @param distance Maximum translation allowed
48  @param max_angle Maximum rotation angle allowed
49  """
50 
51  if seed == -1:
52  random.seed()
53  else:
54  random.seed(seed)
55 
56  phi = random.uniform(-max_angle, max_angle)
57  theta = random.uniform(-max_angle, max_angle)
58  psi = random.uniform(-max_angle, max_angle)
59  trans_x = random.uniform(-max_distance, max_distance)
60  trans_y = random.uniform(-max_distance, max_distance)
61  trans_z = random.uniform(-max_distance, max_distance)
62  trns = alg.Vector3D(trans_x, trans_y, trans_z)
63  rot = alg.get_rotation_from_fixed_zyz(phi, theta, psi)
64  transformation = alg.Transformation3D(rot, trns)
65  return transformation
def apply_random_transform
Apply a random transformation to the rigid body and change the reference frame.
Definition: movement.py:13
def apply_transformation_to_hierarchy
If fn_write is different from False, write to file.
Definition: movement.py:29
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
def get_random_transformation
Return a random transformation.
Definition: movement.py:44
Functionality for loading, creating, manipulating and scoring atomic structures.