IMP logo
IMP Reference Guide  2.10.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
7 import IMP.atom
8 import IMP.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  """
19  IMP.algebra.Vector3D(-max_trans, -max_trans, -max_trans),
20  IMP.algebra.Vector3D(max_trans, max_trans, max_trans))
23  ref = rb.get_reference_frame()
24  Tr = ref.get_transformation_to()
25  T = IMP.algebra.compose(Trand, Tr)
26  rb.set_reference_frame(IMP.algebra.ReferenceFrame3D(T))
27  return Trand
28 
29 
30 def apply_transformation_to_hierarchy(prot, T, fn_write=False):
31  """
32  If fn_write is different from False, write to file
33  """
34  R = T.get_rotation()
35  t = T.get_translation()
36  xyz1 = [IMP.core.XYZ(l) for l in IMP.atom.get_leaves(prot)]
37  coords = [p.get_coordinates() for p in xyz1]
38  newvs = [R.get_rotated(v) + t for v in coords]
39  for i in range(len(newvs)):
40  xyz1[i].set_coordinates(newvs[i])
41  if(fn_write):
42  IMP.atom.write_pdb(prot, fn_write)
43 
44 
45 def get_random_transformation(max_distance, max_angle, seed=-1):
46  """
47  Return a random transformation
48  @param max_distance Maximum translation allowed
49  @param max_angle Maximum rotation angle allowed
50  @param seed If specified, seed for random number generator
51  """
52 
53  if seed == -1:
54  random.seed()
55  else:
56  random.seed(seed)
57 
58  phi = random.uniform(-max_angle, max_angle)
59  theta = random.uniform(-max_angle, max_angle)
60  psi = random.uniform(-max_angle, max_angle)
61  trans_x = random.uniform(-max_distance, max_distance)
62  trans_y = random.uniform(-max_distance, max_distance)
63  trans_z = random.uniform(-max_distance, max_distance)
64  trns = IMP.algebra.Vector3D(trans_x, trans_y, trans_z)
65  rot = IMP.algebra.get_rotation_from_fixed_zyz(phi, theta, psi)
66  transformation = IMP.algebra.Transformation3D(rot, trns)
67  return transformation
def apply_random_transform
Apply a random transformation to the rigid body and change the reference frame.
Definition: movement.py:13
Simple 3D transformation class.
Rotation3D get_random_rotation_3d(const Rotation3D &center, double distance)
Pick a rotation at random near the provided one.
void write_pdb(const Selection &mhd, TextOutput out, unsigned int model=1)
Vector3D get_random_vector_in(const Cylinder3D &c)
Generate a random vector in a cylinder with uniform density.
A reference frame in 3D.
def apply_transformation_to_hierarchy
If fn_write is different from False, write to file.
Definition: movement.py:30
Rotation3D get_rotation_from_fixed_zyz(double Rot, double Tilt, double Psi)
Generate a rotation object from Euler Angles.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Transformation3D compose(const Transformation3D &a, const Transformation3D &b)
Compose two transformations.
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...
VectorD< 3 > Vector3D
Definition: VectorD.h:395
def get_random_transformation
Return a random transformation.
Definition: movement.py:45
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)