IMP logo
IMP Reference Guide  2.22.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 random
10 
11 
12 def apply_random_transform(rb, max_trans=100):
13  """Apply a random transformation to the rigid body and change
14  the reference frame"""
16  IMP.algebra.Vector3D(-max_trans, -max_trans, -max_trans),
17  IMP.algebra.Vector3D(max_trans, max_trans, max_trans))
20  ref = rb.get_reference_frame()
21  Tr = ref.get_transformation_to()
22  T = IMP.algebra.compose(Trand, Tr)
23  rb.set_reference_frame(IMP.algebra.ReferenceFrame3D(T))
24  return Trand
25 
26 
27 def apply_transformation_to_hierarchy(prot, T, fn_write=False):
28  """
29  If fn_write is different from False, write to file
30  """
31  R = T.get_rotation()
32  t = T.get_translation()
33  xyz1 = [IMP.core.XYZ(leaf) for leaf in IMP.atom.get_leaves(prot)]
34  coords = [p.get_coordinates() for p in xyz1]
35  newvs = [R.get_rotated(v) + t for v in coords]
36  for i in range(len(newvs)):
37  xyz1[i].set_coordinates(newvs[i])
38  if fn_write:
39  IMP.atom.write_pdb(prot, fn_write)
40 
41 
42 def get_random_transformation(max_distance, max_angle, seed=-1):
43  """
44  Return a random transformation
45  @param max_distance Maximum translation allowed
46  @param max_angle Maximum rotation angle allowed
47  @param seed If specified, seed for random number generator
48  """
49 
50  if seed == -1:
51  random.seed()
52  else:
53  random.seed(seed)
54 
55  phi = random.uniform(-max_angle, max_angle)
56  theta = random.uniform(-max_angle, max_angle)
57  psi = random.uniform(-max_angle, max_angle)
58  trans_x = random.uniform(-max_distance, max_distance)
59  trans_y = random.uniform(-max_distance, max_distance)
60  trans_z = random.uniform(-max_distance, max_distance)
61  trns = IMP.algebra.Vector3D(trans_x, trans_y, trans_z)
62  rot = IMP.algebra.get_rotation_from_fixed_zyz(phi, theta, psi)
63  transformation = IMP.algebra.Transformation3D(rot, trns)
64  return transformation
def apply_random_transform
Apply a random transformation to the rigid body and change the reference frame.
Definition: movement.py:12
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:27
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:408
def get_random_transformation
Return a random transformation.
Definition: movement.py:42
Functionality for loading, creating, manipulating and scoring atomic structures.
Hierarchies get_leaves(const Selection &h)