Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@author: JH Prinz
"""
import numpy as np
import mdtraj as md
import simtk.unit as u
from openpathsampling.netcdfplus import StorableObject
# =============================================================================================
# SIMULATION TRAJECTORY
# =============================================================================================
class Trajectory(list, StorableObject):
"""
Simulation trajectory. Essentially a python list of snapshots
"""
engine = None
def __init__(self, trajectory=None):
"""
Create a simulation trajectory object
Parameters
----------
trajectory : :class:`openpathsampling.trajectory.Trajectory` or list of :class:`openpathsampling.snapshot.BaseSnapshot`
if specified, make a deep copy of specified trajectory
"""
def __init__(self, subchanges=None, samples=None, mover=None,
details=None, input_samples=None):
StorableObject.__init__(self)
self._lazy = {}
self._len = None
self._collapsed = None
self._results = None
self._trials = None
self._accepted = None
self.mover = mover
if subchanges is None:
self.subchanges = []
else:
self.subchanges = subchanges
if samples is None:
self.samples = []
import numpy as np
from openpathsampling.netcdfplus import StorableObject
# The decorator @restores_ allows us to restore the object from a JSON
# string completely and can thus be stored automatically
class PES(StorableObject):
"""Abstract base class for toy potential energy surfaces.
"""
# For now, we only support additive combinations; maybe someday that can
# include multiplication, too
def __init__(self):
super(PES, self).__init__()
def __add__(self, other):
return PES_Add(self, other)
def __sub__(self, other):
return PES_Sub(self, other)
def kinetic_energy(self, sys):
"""Default kinetic energy implementation.
store a clean set of samples
"""
return SampleSet(
[Sample(
replica=s.replica,
trajectory=s.trajectory,
ensemble=s.ensemble,
bias=s.bias,
# details=s.details,
mover=s.mover
) for s in self]
)
# @lazy_loading_attributes('parent', 'mover')
class Sample(StorableObject):
"""
A Sample represents a given "draw" from its ensemble, and is the return
object from a PathMover. It and contains all information about the move,
initial trajectories, new trajectories (both as references).
Since each Sample is a single representative of a single ensemble, each
Sample consists of one replica ID, one trajectory, and one ensemble.
This means that movers which generate more than one "draw" (often from
different ensembles, e.g. replica exchange) will generate more than one
Sample object.
Attributes
----------
replica : int
The replica ID to which this Sample applies. The replica ID can also
be negative.
import copy
import numpy as np
import mdtraj as md
import simtk.unit as u
from openpathsampling.netcdfplus import StorableObject, lazy_loading_attributes
# =============================================================================
# SIMULATION CONFIGURATION
# =============================================================================
class Configuration(StorableObject):
"""
Simulation configuration. Only Coordinates, the associated boxvectors
and the potential_energy
"""
# Class variables to store the global storage and the system context
# describing the system to be safed as configuration_indices
def __init__(self, coordinates=None, box_vectors=None,
potential_energy=None):
"""
Create a simulation configuration from either an OpenMM context or
individually-specified components.
Parameters
----------
__author__ = 'Jan-Hendrik Prinz'
import logging
import openpathsampling as paths
from openpathsampling.netcdfplus import StorableObject, lazy_loading_attributes
from openpathsampling.netcdfplus import DelayedLoader
from .treelogic import TreeMixin
logger = logging.getLogger(__name__)
# @lazy_loading_attributes('details')
class MoveChange(TreeMixin, StorableObject):
'''
A class that described the concrete realization of a PathMove.
Attributes
----------
mover : PathMover
The mover that generated this MoveChange
samples : list of Sample
A list of newly generated samples by this particular move.
Only used by node movers like RepEx or Shooters
subchanges : list of MoveChanges
the MoveChanges created by submovers
details : Details
an object that contains MoveType specific attributes and information.
E.g. for a RandomChoiceMover which Mover was selected.
'''
if type(base_class) is not tuple:
base_class = (base_class,)
cls = type(name, base_class, {})
if description is not None:
cls.__doc__ = description
cls = feats.attach_features(
features,
use_lazy_reversed=use_lazy_reversed)(cls)
return cls
class SnapshotDescriptor(frozenset, StorableObject):
"""Container for information about snapshots generated by an engine.
Snapshot descriptors are used to define the dimensions of the features
used in a snapshot, in order to set correct sizes in storage. For
example, the arrays of atomic positions and velocities will each be of
shape ``(n_atoms, n_spatial)``. The snapshot descriptor stores the
values of ``n_atoms`` and ``n_spatial``. It also knows the class of
snapshot to be created by the engine. This is usually created upon
initialization of the engine, using information from the engine's
initialization parameters.
In practice, it is probably easiest to create snapshot descriptors using
their :meth:`.construct` method.
Parameters
----------
Configuration()
the reduced deep copy
"""
# TODO: Keep old potential_energy? Is not correct but might be useful. Boxvectors are fine!
return Configuration(coordinates=self.coordinates,
box_vectors=self.box_vectors,
potential_energy=self.potential_energy
)
# =============================================================================
# SIMULATION MOMENTUM / VELOCITY
# =============================================================================
class Momentum(StorableObject):
"""
Simulation momentum. Contains only velocities of all atoms and
associated kinetic energies
"""
# Class variables to store the global storage and the system context
# describing the system to be safed as momentums
def __init__(self, velocities=None, kinetic_energy=None):
"""
Create a simulation momentum from either an OpenMM context or
individually-specified components.
Parameters
----------
velocities : simtk.unit.Quantity wrapping Nx3 np array of dimension length
@author: JD Chodera
@author: JH Prinz
"""
import abc
from openpathsampling.netcdfplus import StorableObject
from . import features as feats
# =============================================================================
# ABSTRACT SNAPSHOT (IMPLEMENTS ONLY REVERSED SNAPSHOTS)
# =============================================================================
class BaseSnapshot(StorableObject):
"""
Simulation snapshot. Contains references to a configuration and momentum
"""
__metaclass__ = abc.ABCMeta
def __init__(self, topology=None):
"""
Attributes
----------
topology : openpathsamping.Topology, default: None
The corresponding topology used with this Snapshot. Can also be None
and means no topology is specified.
"""
super(BaseSnapshot, self).__init__()
import numpy as np
from openpathsampling.integration_tools import (
error_if_no_mdtraj, is_simtk_quantity_type, md
)
from openpathsampling.netcdfplus import StorableObject, LoaderProxy
import openpathsampling as paths
# ==============================================================================
# TRAJECTORY
# ==============================================================================
class Trajectory(list, StorableObject):
"""
Simulation trajectory. Essentially a python list of snapshots
"""
engine = None
def __init__(self, trajectory=None):
"""
Create a simulation trajectory object
Parameters
----------
trajectory : :obj:`Trajectory` or list of :obj:`openpathsampling.engines.BaseSnapshot`
if specified, make a deep copy of specified trajectory
"""