IMP logo
IMP Reference Guide  2.6.0
The Integrative Modeling Platform
alignments.py
1 """@namespace IMP.EMageFit.imp_general.alignments
2  Utility functions to handle alignments.
3 """
4 
5 import IMP
6 import IMP.atom
7 import IMP.algebra
8 import sys
9 import logging
10 
11 log = logging.getLogger("alignments")
12 
13 
14 def get_reference_frames_from_chain_alignment(reference_rbs, reference_index,
15  rbs_to_align, index_to_align):
16  """
17  Align the rigid bodies rbs_to_align to the the reference frames of
18  reference_rbs. The rb with index_to_align is aligned to the reference rb
19  with reference_index. The function returns the reference frames to
20  apply to the rbs_to_align.
21  """
22  ref_coords = \
23  [m.get_coordinates()
24  for m in reference_rbs[reference_index].get_members()]
25  coords = [m.get_coordinates()
26  for m in rbs_to_align[index_to_align].get_members()]
27  if(len(coords) != len(ref_coords)):
28  raise ValueError(
29  "Mismatch in the number of members. Reference %d Aligned %d " % (
30  len(ref_coords), len(coords)))
32  ref_coords)
33  new_refs = []
34  for rb in rbs_to_align:
35 # log.debug("aligning ... %s",rb)
36  t = rb.get_reference_frame().get_transformation_to()
37  new_t = IMP.algebra.compose(T, t)
38  new_refs.append(IMP.algebra.ReferenceFrame3D(new_t))
39  return new_refs
40 
41 
42 def align_centroids_using_pca(ref_frames, ref_frames_reference):
43  """
44  Align the centroids of 2 sets of rigid bodies using PCA using their
45  reference frames. returns the best rmsd and the ref_frames to get it.
46  """
47  if(len(ref_frames) != len(ref_frames_reference)):
48  raise ValueError("The number of reference frames must be the same")
49  Ts1 = [r.get_transformation_to() for r in ref_frames]
50  vs1 = [T.get_translation() for T in Ts1]
51  Ts2 = [r.get_transformation_to() for r in ref_frames_reference]
52  vs2 = [T.get_translation() for T in Ts2]
53 
54  # align with PCA
58  best_refs = []
59  best_rmsd = 1e5
60  for j, pcT in enumerate(pcTs):
61  new_Ts1 = [IMP.algebra.compose(pcT, T) for T in Ts1]
62  new_vs1 = [T.get_translation() for T in new_Ts1]
63  r = IMP.atom.get_rmsd(new_vs1, vs2)
64  if(r < best_rmsd):
65  best_rmsd = r
66  best_refs = [IMP.algebra.ReferenceFrame3D(T) for T in new_Ts1]
67  return best_rmsd, best_refs
68 
69 
70 def get_reference_frames_aligning_rbs(rbs, reference_rbs):
71  """ rbs = rigid bodies """
72  refs = [rb.get_reference_frame() for rb in rbs]
73  ref_refs = [rb.get_reference_frame() for rb in reference_rbs]
74  best_rmsd, best_refs = align_centroids_using_pca(refs, ref_refs)
def get_reference_frames_from_chain_alignment
Align the rigid bodies rbs_to_align to the the reference frames of reference_rbs. ...
Definition: alignments.py:14
A reference frame in 3D.
double get_rmsd(const Selection &s0, const Selection &s1)
def get_reference_frames_aligning_rbs
rbs = rigid bodies
Definition: alignments.py:70
Transformation3Ds get_alignments_from_first_to_second(const PrincipalComponentAnalysisD< 3 > &pca1, const PrincipalComponentAnalysisD< 3 > &pca2)
PrincipalComponentAnalysisD< D > get_principal_components(const Vector< VectorD< D > > &ps)
Perform principal components analysis on a set of vectors.
Transformation3D compose(const Transformation3D &a, const Transformation3D &b)
Compose two transformations.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
def align_centroids_using_pca
Align the centroids of 2 sets of rigid bodies using PCA using their reference frames.
Definition: alignments.py:42
Transformation3D get_transformation_aligning_first_to_second(Vector3Ds a, Vector3Ds b)
Functionality for loading, creating, manipulating and scoring atomic structures.