schrodinger.trajectory.atomselection module

A group of classes to help select atoms from trajectory frames.

The selection of atoms can be done by atom index (FrameIndexSelection), Atom Selection Language (FrameAslSelection), and slice specification (FrameSliceSelection). In addition, the select_component function can be used to create a selection based on component names.

Although there is not currently a parent class, all AtomSelection classes implement a common interface that consists of the following methods:

  • getOffsets()
  • getAtomIndices()
  • getArraySelection()
  • isDynamic().

The getArraySelection() method is provided since numpy arrays allow non-index based methods (e.g. slices).

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.trajectory.atomselection.FrameAslSelection(asl_expr, is_dynamic=None)

Bases: object

A class for selecting atoms from frames in a given simulation using ASL.

Note that there is no control over the order of indices retrieved in an ASL selection - they will always be returned in numerical order. As such, FrameAslSelection objects are not appropriate for analyses with more than one selection.

createIndexSelection(frame, cmp=None, key=None)

Create a FrameIndexSelection from this instance.

Because FrameAslSelections do not imply an ordering of atoms, two methods of ordering the new selection are available. The first is to provide a cmp method. This method should expect two _StructureAtom instances as arguments and should behave like the cmp argument to the sort method of the built-in list. The second ordering method is to specify a _StructureAtom attribute on which to sort.

If neither of these is specified, the selection will be returned in order of atom indices. In this case, the frame instance is not needed and can be specified as None.

Raises a ValueError if the FrameAslSelection is dynamic.

Parameters:
  • cmp (callable) – A comparison function expecting two _StructureAtom instances.
  • key (str) – A _StructureAtom attribute on which to order the selection.
Return type:

FrameIndexSelection

Returns:

A FrameIndexSelection with the same atom selection as the current instance.

getArraySelection(frame)
Returns:A selection as a sequence of integers, using zero based indexing so it can be used with a numpy array.
getAtomIndices(frame)
Returns:A selection as a sequence of integers, using one based indexing so it can be used with a Structure.
getOffsets(frame)
Returns:A selection as a sequence of integers, using zero based indexing so it can be used with a numpy array.
isDynamic()
Returns:A bool indicating whether this selection changes from frame

to frame.

class schrodinger.trajectory.atomselection.FrameIndexSelection(indices)

Bases: object

A class that defines a static set of indices to be selected from all frames.

getArraySelection(frame)
Returns:A selection as a sequence of integers, using zero based indexing so it can be used with a numpy array.
getAtomIndices(frame)
Returns:A selection as a sequence of integers, using one based indexing so it can be used with a Structure.
getOffsets(frame)
Returns:A selection as a sequence of integers, using zero based indexing so it can be used with a numpy array.
isDynamic()
Returns:A bool indicating whether this selection changes from frame

to frame.

class schrodinger.trajectory.atomselection.FrameSliceSelection(slice_)

Bases: object

A class for efficiently selecting a range of atoms.

getArraySelection(frame)
Returns:An object that can be used as an index in a numpy array.
getAtomIndices(frame)
Returns:A selection as a sequence of integers, using one based indexing so it can be used with a Structure.
getOffsets(frame)
Returns:A selection as a sequence of integers, using zero based indexing so it can be used with a numpy array.
isDynamic()
Returns:A bool indicating whether this selection changes from frame

to frame.

schrodinger.trajectory.atomselection.combine_slice(slice_list)

Return a new slice object if the provided slice objects can be concatenated. Otherwise, return a sequence of integers representing a combination of slice ranges. Note that any duplicated indices are removed from the sequence.

schrodinger.trajectory.atomselection.select_component(cms_struct, comp_list)

Return a selection based on the component names. If selected indices can be converted to a slice, a FrameSliceSelection instance will be returned. Otherwise, return FrameIndexSelection.