openpathsampling.trajectory.Trajectory

class openpathsampling.trajectory.Trajectory(trajectory=None)[source]

Simulation trajectory. Essentially a python list of snapshots

__init__(trajectory=None)[source]

Create a simulation trajectory object

Parameters:trajectory (openpathsampling.trajectory.Trajectory or list of openpathsampling.snapshot.BaseSnapshot) – if specified, make a deep copy of specified trajectory

Methods

__init__([trajectory]) Create a simulation trajectory object
append L.append(object) – append object to end
args() Return a list of args of the __init__ function of a class
as_proxies() Returns all contains all actual elements
base() Return the most parent class that is actually derived from Storable(Named)Object
computeActivity([atom_indices]) Compute the (timeless!) activity of a given trajectory, defined in Ref.
configurations() Return a list of the snapshots in the trajectory
coordinates() Return all coordinates as a numpy array
count(...)
count_weaks() Return the counts of how many objects of storable type are still in memory
descendants() Return a list of all subclassed objects
extend(iterable)
from_dict(dct) Reconstruct an object from a dictionary representaiton
full() Return a view of the trajectory with all atoms
get_as_proxy(item) Get an actual contained element
idx(store) Return the index which is used for the object in the given store.
index((value, [start, ...) Raises ValueError if the value is not present.
insert L.insert(index, object) – insert object before index
is_correlated(other) Checks if two trajectories share a common snapshot
iter_proxies() Returns an iterator over all actual elements
logEquilibriumTrajectoryProbability() Compute the (temperatureless!) log equilibrium probability
map(fnc[, allow_fast]) This runs a function and tries to be fast.
md([topology]) Construct a mdtraj.Trajectory object from the Trajectory itself
momenta() Return a list of the Momentum objects in the trajectory
objects() Returns a dictionary of all storable objects
pathHamiltonian() Compute the generalized path Hamiltonian of the trajectory.
pop(...) Raises IndexError if list is empty or index is out of range.
prepend(snapshot) Prepend a snapshot
remove L.remove(value) – remove first occurrence of value.
reverse L.reverse() – reverse IN PLACE
save(store) Save the object in the given store (or storage)
set_observer(active) (De-)Activate observing creation of storable objects
shared_configurations(other) Returns a set of shared snapshots
shared_subtrajectory(other) Returns a subtrajectory which only contains frames present in other
sort L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE;
subset(atom_indices) Reduce the view of the trajectory to a subset of atoms specified.
summarize_by_volumes(label_dict) Summarize trajectory based on number of continuous frames in volumes.
summarize_by_volumes_str(label_dict[, delimiter]) Return string version of the volumes visited by this trajectory.
to_dict() Convert object into a dictionary representation
xyz()

Attributes

base_cls Return the base class
base_cls_name Return the name of the base class
cls Return the class name as a string
engine
n_atoms Return the number of atoms in the trajectory in the current view.
n_frames Return the number of frames in the trajectory.
n_snapshots Return the number of frames in the trajectory.
observe_objects
reversed Returns a reversed (shallow) copy of the trajectory itself.
solute Reduce the view of the trajectory to a subset of solute atoms
spatial
topology Return a Topology object representing the topology of the
__contains__

x.__contains__(y) <==> y in x

__delattr__

x.__delattr__(‘name’) <==> del x.name

__delitem__

x.__delitem__(y) <==> del x[y]

__delslice__

x.__delslice__(i, j) <==> del x[i:j]

Use of negative indices is not supported.

__eq__

x.__eq__(y) <==> x==y

__format__()

default object formatter

__ge__

x.__ge__(y) <==> x>=y

__getattribute__

x.__getattribute__(‘name’) <==> x.name

__gt__

x.__gt__(y) <==> x>y

__iadd__

x.__iadd__(y) <==> x+=y

__imul__

x.__imul__(y) <==> x*=y

__iter__(this)[source]

Return an iterator over all snapshots in the storage

This will always give real openpathsampling.snapshot.Snapshot objects and never proxies to snapshots. If you prefer proxies (if available) use .iteritems()

Parameters:iter_range (slice or None) – if this is not None it confines the iterator to objects specified in the slice
Returns:The iterator that iterates the objects in the store
Return type:Iterator()
__le__

x.__le__(y) <==> x<=y

__len__
__lt__

x.__lt__(y) <==> x<y

__mul__

x.__mul__(n) <==> x*n

__ne__

x.__ne__(y) <==> x!=y

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__rmul__

x.__rmul__(n) <==> n*x

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__setitem__

x.__setitem__(i, y) <==> x[i]=y

__setslice__

x.__setslice__(i, j, y) <==> x[i:j]=y

Use of negative indices is not supported.

__sizeof__()

L.__sizeof__() – size of L in memory, in bytes

append()

L.append(object) – append object to end

args()

Return a list of args of the __init__ function of a class

Returns:the list of argument names. No information about defaults is included.
Return type:list of str
as_proxies()[source]

Returns all contains all actual elements

This will also return lazy proxy objects and not the references ones as does __iter__, __reversed__ or __getitme__. Useful for faster access to the elements

Returns:
Return type:list of openpathsampling.snapshot.Snapshot or openpathsampling.netcdfplus.proxy.LoaderProxy
base()

Return the most parent class that is actually derived from Storable(Named)Object

Important to determine which store should be used for storage

Returns:the base class
Return type:type
base_cls

Return the base class

Returns:the base class
Return type:type

See also

base()

base_cls_name

Return the name of the base class

Returns:the string representation of the base class
Return type:str
cls

Return the class name as a string

Returns:the class name
Return type:str
computeActivity(atom_indices=None)[source]

Compute the (timeless!) activity of a given trajectory, defined in Ref. [1] as

\[K[x(t)] / delta_t = delta_t \sum_{t=0}^{t_obs} \sum_{j=1}^N [r_j(t+delta_t) - r_j(t)]^2 / delta_t\]
Returns:K – activity K[x(t)] for the specified trajectory
Return type:simtk.unit

Notes

Can we avoid dividing and multipying by nanometers to speed up?

configurations()[source]

Return a list of the snapshots in the trajectory

Returns:the list of Configuration objects
Return type:list of Configuration
coordinates()[source]

Return all coordinates as a numpy array

Returns:coordinates – numpy.array of coordinates of size number of frames ‘n_frames’ x number of atoms ‘n_atoms’ x 3 in x,y,z
Return type:numpy.ndarray((n_frames, n_atoms, 3))
count(value) → integer -- return number of occurrences of value
count_weaks()

Return the counts of how many objects of storable type are still in memory

This includes objects not yet recycled by the garbage collector.

Returns:dict of str – the dictionary which assigns the base class name of each references objects the integer number of objects still present
Return type:int
descendants()

Return a list of all subclassed objects

Returns:list of subclasses of a storable object
Return type:list of type
from_dict(dct)

Reconstruct an object from a dictionary representaiton

Parameters:dct (dict) – the dictionary containing a state representaion of the class.
Returns:the reconstructed storable object
Return type:openpathsampling.netcdfplus.StorableObject
full()[source]

Return a view of the trajectory with all atoms

Returns:the trajectory showing the subsets of solute atoms
Return type:openpathsampling.trajectory.Trajectory
get_as_proxy(item)[source]

Get an actual contained element

This will also return lazy proxy objects and not the referenced ones as does __iter__, __reversed__ or __getitem__. Useful for faster access to the elements

This is equal to use list.__getitem__(trajectory, item)

Returns:
Return type:openpathsampling.snapshot.Snapshot or openpathsampling.netcdfplus.proxy.LoaderProxy
idx(store)

Return the index which is used for the object in the given store.

Once you store a storable object in a store it gets assigned a unique number that can be used to retrieve the object back from the store. This function will ask the given store if the object is stored if so what the used index is.

Parameters:store (openpathsampling.netcdfplus.objects.ObjectStore) – the store in which to ask for the index
Returns:the integer index for the object of it exists or None else
Return type:int or None
index(value[, start[, stop]]) → integer -- return first index of value.

Raises ValueError if the value is not present.

insert()

L.insert(index, object) – insert object before index

is_correlated(other)[source]

Checks if two trajectories share a common snapshot

Parameters:other (openpathsampling.trajectory.Trajectory) – the second trajectory to check for common snapshots
Returns:returns True if at least one snapshot appears in both trajectories
Return type:bool
iter_proxies()[source]

Returns an iterator over all actual elements

This will also return lazy proxy objects and not the references ones as does __iter__, __reversed__ or __getitme__. Useful for faster access to the elements

Returns:
Return type:Iterator() over list of openpathsampling.snapshot.Snapshot or openpathsampling.netcdfplus.proxy.LoaderProxy
logEquilibriumTrajectoryProbability()[source]

Compute the (temperatureless!) log equilibrium probability

Up to an unknown additive constant of an unbiased trajectory evolved according to Verlet dynamics with Andersen thermostatting.

Parameters:trajectory (openpathsampling.Trajectory) – the trajectory
Returns:log_q – the log equilibrium probability of the trajectory divided by the inverse temperature beta
Return type:float

Notes

This might be better places into the trajectory class. The trajectory should know the system and ensemble? and so it is not necessarily TPS specific

map(fnc, allow_fast=True)[source]

This runs a function and tries to be fast.

Fast here means that functions that are purely based on CVs can be evaluated without actually loading the real Snapshot object. This functions tries to do that and if it fails it does it the usual way and creates the snapshot object. This bears the possibility that the function uses the fake snapshots and returns a non-sense value. It is up to the user to make sure this will not happen.

md(topology=None)[source]

Construct a mdtraj.Trajectory object from the Trajectory itself

Parameters:topology (mdtraj.Topology) – If not None this topology will be used to construct the mdtraj objects otherwise the topology object will be taken from the configurations in the trajectory snapshots.
Returns:the trajectory
Return type:mdtraj.Trajectory
momenta()[source]

Return a list of the Momentum objects in the trajectory

Returns:the list of Momentum objects
Return type:list of Momentum()
n_atoms

Return the number of atoms in the trajectory in the current view.

Returns:n_atoms – number of atoms
Return type:int

Notes

If a trajectory has been subsetted then this returns only the number of the view otherwise if equals the number of atoms in the snapshots stored

n_frames

Return the number of frames in the trajectory.

Returns:
Return type:length (int) - the number of frames in the trajectory

See also

n_snapshots, len

n_snapshots

Return the number of frames in the trajectory.

Returns:
Return type:length (int) - the number of frames in the trajectory

Notes

Might be removed in later versions for len(trajectory) is more pythonic

See also

n_frames, len

objects()

Returns a dictionary of all storable objects

Returns:dict of str – a dictionary of all subclassed objects from StorableObject. The name points to the class.
Return type:type
pathHamiltonian()[source]

Compute the generalized path Hamiltonian of the trajectory.

Returns:H – the generalized path Hamiltonian
Return type:simtk.unit.Quantity with units of energy

References

For a description of the path Hamiltonian, see [1]:

[1] Chodera JD, Swope WC, Noe F, Prinz JH, Shirts MR, and Pande VS. Dynamical reweighting: Improved estimates of dynamical properties from simulations at multiple temperatures.

pop([index]) → item -- remove and return item at index (default last).

Raises IndexError if list is empty or index is out of range.

prepend(snapshot)[source]

Prepend a snapshot

Just convenience method to replace insert(0, snapshot)

remove()

L.remove(value) – remove first occurrence of value. Raises ValueError if the value is not present.

reverse()

L.reverse() – reverse IN PLACE

reversed

Returns a reversed (shallow) copy of the trajectory itself. Effectively creates a new Trajectory object and then fills it with shallow reversed copies of the contained snapshots.

Returns:the reversed trajectory
Return type:openpathsampling.trajectory.Trajectory
save(store)

Save the object in the given store (or storage)

Parameters:store (openpathsampling.netcdfplus.objects.ObjectStore or openpathsampling.netcdfplus.netcdfplus.NetCDFStorage) – the store or storage to be saved in. if a storage is given then the default store for the given object base type is determined and the appropriate store is used.
Returns:the integer index used to save the object or None if the object has already been saved.
Return type:int or None
set_observer(active)

(De-)Activate observing creation of storable objects

This can be used to track which storable objects are still alive and hence look for memory leaks and inspect caching. Use openpathsampling.netcdfplus.base.StorableObject.count_weaks() to get the current summary of created objects

Parameters:active (bool) – if True then observing is enabled. False disables observing. Per default observing is disabled.
shared_configurations(other)[source]

Returns a set of shared snapshots

Parameters:other (openpathsampling.trajectory.Trajectory) – the second trajectory to use
Returns:the set of common snapshots
Return type:set of openpathsampling.snapshot.Snapshot
shared_subtrajectory(other)[source]

Returns a subtrajectory which only contains frames present in other

Parameters:other (openpathsampling.trajectory.Trajectory) – the second trajectory to use
Returns:the shared subtrajectory
Return type:openpathsampling.trajectory.Trajectory
solute

Reduce the view of the trajectory to a subset of solute atoms specified in the associated DynamicsEngine

Returns:the trajectory showing the subsets of solute atoms
Return type:openpathsampling.trajectory.Trajectory
sort()

L.sort(cmp=None, key=None, reverse=False) – stable sort IN PLACE; cmp(x, y) -> -1, 0, 1

subset(atom_indices)[source]

Reduce the view of the trajectory to a subset of atoms specified.

This is only a view, no data will be changed or copied.

Returns:the trajectory showing the subsets of atoms
Return type:openpathsampling.trajectory.Trajectory
summarize_by_volumes(label_dict)[source]

Summarize trajectory based on number of continuous frames in volumes.

This uses a dictionary of disjoint volumes: the volumes must be disjoint so that every frame can be mapped to one volume. If the frame maps to none of the given volumes, it returns the label None.

Parameters:label_dict (dict) – dictionary with labels for keys and volumes for values
Returns:format is (label, number_of_frames)
Return type:list of tuple
summarize_by_volumes_str(label_dict, delimiter='-')[source]

Return string version of the volumes visited by this trajectory.

See Trajectory.summarize_by_volumes for details.

Parameters:
  • label_dict (dict) – dictionary with labels for keys and volumes for values
  • delimiter (string (default "-")) – string used to separate volumes in output
Returns:

order in which this trajectory visits the volumes in label_dict, separated by the delimiter

Return type:

string

to_dict()

Convert object into a dictionary representation

Used to convert the dictionary into JSON string for serialization

Returns:the dictionary representing the (immutable) state of the object
Return type:dict
topology

Return a Topology object representing the topology of the current view of the trajectory

Returns:the topology object
Return type:openpathsampling.topology.Topology