LOOS  v2.3.2
alignment.py
1 """
2 PyLOOS interface to the LOOS iterative alignment routines
3 """
4 
5 
6 import loos
7 
8 
9 
10 ## Iteratively align a loos.pyloos.Trajectory object (or a list of AtomicGroups)
11 
12 def iterativeAlignment(ensemble, threshold=1e-8, maxiter=1000):
13  """
14  Iteratively align a loos.pyloos.Trajectory object (or a list of AtomicGroups).
15  Returns the transformations needed to perform the alignment. Note that it does
16  not currently transform what's passed into it.
17 
18  Args
19 
20  ensemble: loos.pyloos.Trajectory, or list of AtomicGroups
21  threshold (opt): change in average less than this ends alignment
22  maxiter(opt): maximum number of iterations allowed
23 
24 
25  Returns
26 
27  (list-of-xforms, final-rmsd, number-of-iterations)
28 
29 
30  Examples
31 
32  model = loos.createSystem('foo.pdb')
33  traj = loos.pyloos.Trajectory('foo.dcd', model, subset = 'name == "CA"')
34  (xforms, rmsd, iters) = loos.pyloos.iterativeAlignment(traj)
35 
36  ensemble = [frame.copy() for frame in traj]
37  (xforms, rmsd, iters) = loos.pyloos.iterativeAlignment(ensemble)
38  """
39  enlist = loos.DoubleVectorMatrix()
40  for e in ensemble:
41  enlist.push_back(e.coordsAsVector())
42  result = loos.iterativeAlignmentPy(enlist, threshold, maxiter)
43  return(loos.xformVectorToList(result.transforms), result.rmsd, result.iterations)
44 
45 
46 
47 # Optional 'framelist' argument specifies indices of frames to use
48 def iterativeAlignTrajectory(model, traj, threshold=1e-8, maxiter=1000, **kwargs):
49  """
50  Interface to the standard LOOS iterative alignment routines.
51  Returns the transformations needed to perform the alignment. Note that it does
52  not currently transform what's passed into it.
53 
54  Args
55 
56  model: AtomicGroup (subset of trajectory model) to use for aligning
57  traj: trajectory to align
58  threshold (opt): change in avg less than this ends alignment
59  maxiter (opt): max number of iterations allowed
60  framelist (opt): a python list (or loos.UIntVector) of frame indices
61  from the trajectory to use
62 
63 
64  Returns
65 
66  (list-of-xforms, final-rmsd, number-of-iterations)
67 
68 
69  Examples
70 
71  model = loos.createSystem('foo.pdb')
72  traj = loos.createTrajectory('foo.dcd', model)
73  subset = loos.selectAtoms(model, 'backbone')
74 
75  (xforms, rmsd, iters) = loos.pyloos.iterativeAlignTrajectory(subset, traj)
76  """
77  # If traj is not a loos.Trajectory, assume it supports the trajectory()
78  # method to access the underlying loos one
79  if not isinstance(traj, loos.Trajectory):
80  traj = traj.trajectory()
81 
82  # Handle framelist request
83  if 'framelist' in kwargs:
84  framelist = kwargs['framelist']
85  # If it's not a vector<uint>, assume it's iterable
86  if not isinstance(framelist, loos.UIntVector):
87  flist = loos.UIntVector(kwargs['framelist'])
88  else:
89  flist = framelist
90  result = loos.iterativeAlignmentPy(model, traj, flist, threshold, maxiter)
91 
92  else:
93  result = loos.iterativeAlignmentPy(model, traj, threshold, maxiter)
94 
95  return(loos.xformVectorToList(result.transforms), result.rmsd, result.iterations)
96 
def iterativeAlignment(ensemble, threshold=1e-8, maxiter=1000)
Iteratively align a loos.pyloos.Trajectory object (or a list of AtomicGroups)
Definition: alignment.py:12
def iterativeAlignTrajectory(model, traj, threshold=1e-8, maxiter=1000, kwargs)
Definition: alignment.py:48
Base-class for polymorphic trajectories.
Definition: Trajectory.hpp:64