LOOS  v2.3.2
What's new in PyLOOS

PyLOOS has undergone some substantial changes in LOOS 2.3.0. The top-level module/namespace remains "loos", and it includes everything imported from the core of LOOS. We have added a new "pyloos" module under "loos" that now holds Python-specific code, such as the new trajectories classes.

One of the biggest changes in PyLOOS is the introduction of three new trajectory classes. These classes ultimately wrap loos Trajectory objects but provide more python-like interfaces. The first class is loos.pyloos.Trajectory. You can specify a stride and the number of frames to skip from the start of the trajectory. The trajectory object can then be used like a python iterator,

1 model = loos.createSystem('foo.pdb')
2 traj = loos.pyloos.Trajectory('foo.dcd', model, skip=50)
3 
4 for frame in traj:
5  print frame.centroid()

You can also use the trajectory like an array,

1 first_frame = traj[0]
2 last_frame = traj[-1]

There is often a need to know what frame number a frame corresponds to. If you are using the trajectory as in iterator, then the realIndex() function will return the frame number,

1 for frame in traj:
2  print traj.realIndex(), frame.centroid()

Since you can specify a skip and a stride, an array index does not necessarily give you the real frame number. Instead, use the frameNumber() member function. For example,

1 frame = traj[0] # This is actually frame index 50 in the
2  # trajectory because of the skip
3 
4 print traj.frameNumber(0) # This prints out 50

Another thing to be careful of is the linkage between groups through the shared atoms. By default, the frame returned will share atoms with whatever group was used to instantiate the trajectory. If you need to decouple the trajectory from the model, pass a copy to the constructor,

1 traj = loos.pyloos.Trajectory('foo.dcd', model.copy())

The other two trajectory classes, VirtualTrajectory and AlignedVirtualTrajectory let you combine multiple pyloos trajectory objects to make one big "virtual" trajectory. The latter supports the LOOS iterative alignment method and will return the aligned frames. Note that this does require reading in the alignment subset and aligning it at the first access to a frame, so there may be memory and performance penalties. The cached frames are discarded after the alignment however. Also, the AlignedVirtualTrajectory can be used with a single loos.pyloos.Trajectory to align it.

All of these classes have rich support for accessing the underlying components and getting information about what frame is being used, among others. For more information, see the above links, use the search bar, or see the documentation for pyloos under the Namespace tab.

In addition to the new trajectories, pyloos now sports several utility functions related to ensembles: loos.pyloos.averageStructure(), loos.pyloos.extractCoords(), and loos.pyloos.svd(), all of which use the new Trajectory classes. We have also added loos.pyloos.subspaceOverlap(), and loos.pyloos.covarianceOverlap().

The iterative alignment functions have also changed. There is now a loos.pyloos.iterativeAlignment() function that will take a loos.pyloos.Trajectory and align it (or a list/vector of loos::AtomicGroup). The loos-style interface is now available through loos.pyloos.iterativeAlignTrajectory(). You can optionally pass a list of frame indices to use. Both functions now return a Python tuple containing the results.

Finally, AtomicGroup now has support for NumPy with the AtomicGroup::getCoords() and AtomicGroup::setCoords() functions, which will return (or set) the coordinates of all atoms in the group. For example, calculating an average set of coordinates can be implemented this way:

1 avg = numpy.zeros(len(traj.frame), 3)
2 for frame in traj:
3  coords = frame.getCoords()
4  avg += coords
5 avg /= len(traj)