How to use the openpathsampling.netcdfplus.ObjectStore function in openpathsampling

To help you get started, we’ve selected a few openpathsampling examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openpathsampling / openpathsampling / openpathsampling / storage / features.py View on Github external
chunksizes=(1,)
                           )

class Momenta(Feature):
    _variables = ['momentum']

    @staticmethod
    def _init(self):
        self.storage.create_store('momenta', MomentumStore())

        self.init_variable('momentum', 'lazyobj.momenta',
                           description="the snapshot index (0..n_momentum-1) 'frame' of snapshot '{idx}'.",
                           chunksizes=(1,)
                           )

class MomentumStore(ObjectStore):
    """
    An ObjectStore for Momenta. Allows to store Momentum() instances in a netcdf file.
    """

    def __init__(self):
        super(MomentumStore, self).__init__(Momentum, json=False)

    def _save(self, momentum, idx):
        self.vars['velocities'][idx, :, :] = momentum.velocities

        if momentum.kinetic_energy is not None:
            self.vars['kinetic_energy'][idx] = momentum.kinetic_energy

    def _load(self, idx):
        velocities = self.vars['velocities'][idx]
        kinetic_energy = self.vars['kinetic_energy'][idx]
github openpathsampling / openpathsampling / openpathsampling / storage / remote.py View on Github external
filename : string
            filename of the netcdf file to be used or created
        mode : string, default: None
            the mode of file creation, one of ``w`` (write), ``a`` (append) or
            None, which will append any existing files.
        template : :class:`openpathsampling.Snapshot`
            a Snapshot instance that contains a reference to a Topology, the
            number of atoms and used units
        """

        self.reference_by_uuid = True
        self.simplifier = UUIDObjectJSON(self)

        self._setup_class()

        self.register_store('stores', RemoteClientObject(ObjectStore))
        self.stores.set_caching(True)
github openpathsampling / openpathsampling / openpathsampling / storage / remote.py View on Github external
def _save(self, obj, idx):
        # No loading, only caching and what is left in memory
        pass

    def __len__(self):
        if len(self.index) == 0:
            return 0
        else:
            return max(self.index.values()) + 1

    def _set_uuid(self, idx, uuid):
        pass


class RemoteMasterObject(ObjectStore):

    length = 0L

    def __init__(self, content_class, no_store=False):
        super(RemoteMasterObject, self).__init__(content_class)
        self.no_store = no_store

    def __len__(self):
        return self.length

    def load(self, idx):
        """
        Returns an object from the storage.

        Parameters
        ----------
github openpathsampling / openpathsampling / openpathsampling / storage / features.py View on Github external
self.init_variable('velocities', 'numpy.float32',
                           dimensions=('atom', 'spatial'),
                           description="the velocity of atom 'atom' in dimension " +
                                       "'coordinate' of momentum 'momentum'.",
                           chunksizes=(1, n_atoms, n_spatial),
                           simtk_unit=units['velocity']
                           )

        self.init_variable('kinetic_energy', 'float',
                           chunksizes=(1,),
                           simtk_unit=units['energy']
                           )


class ConfigurationStore(ObjectStore):
    def __init__(self):
        super(ConfigurationStore, self).__init__(Configuration, json=False)

    def _save(self, configuration, idx):
        # Store configuration.
        self.vars['coordinates'][idx] = configuration.coordinates

        if configuration.potential_energy is not None:
            self.vars['potential_energy'][idx] = configuration.potential_energy

        if configuration.box_vectors is not None:
            self.vars['box_vectors'][idx] = configuration.box_vectors

    def get(self, indices):
        return [self.load(idx) for idx in indices]
github openpathsampling / openpathsampling / openpathsampling / storage / sample_store.py View on Github external
from openpathsampling.sample import SampleSet, Sample
from openpathsampling.netcdfplus import ObjectStore, LoaderProxy


class SampleStore(ObjectStore):
    def __init__(self):
        super(SampleStore, self).__init__(Sample, json=False)
        self._cached_all = False

    def to_dict(self):
        return {}

    def _save(self, sample, idx):
        self.vars['trajectory'][idx] = sample.trajectory
        self.vars['ensemble'][idx] = sample.ensemble
        self.vars['replica'][idx] = sample.replica
        self.write('parent', idx, sample)
        self.write('details', idx, sample)
        self.vars['bias'][idx] = sample.bias
        self.vars['mover'][idx] = sample.mover
github openpathsampling / openpathsampling / openpathsampling / storage / remote.py View on Github external
self.reference_by_uuid = True

        self.tell(
"""
import openpathsampling as paths
# paths.netcdfplus.base.StorableObject.set_observer(True)
_cache_ = paths.storage.remote.RemoteClientStorage()
"""
        )

        self.simplifier = UUIDObjectJSON(self)

        self._setup_class()

        self.register_store('stores', RemoteMasterObject(ObjectStore, True))
        self.stores.set_caching(True)

        self._create_storages()
        self._initialize()

        for uuid, idx in self.stores.index.iteritems():
            store = self.stores.cache[idx]
            self.tell("_cache_.register_store('%s', _cache_.stores[paths.storage.remote.UUID('%s')])" % (store.name, uuid))
            self.tell("_cache_.%s.name = '%s'" % (store.name, store.name))

        self.tell("_cache_.set_caching_mode('default')")
        self.tell("_cache_.simplifier.update_class_list()")
github openpathsampling / openpathsampling / openpathsampling / storage / storage.py View on Github external
# topologies might be needed fot CVs so put them here
        self.create_store('topologies', NamedObjectStore(peng.Topology))
        self.create_store('cvs', paths.storage.CVStore())

        self.create_store('snapshots', SnapshotWrapperStore())

        self.create_store('samples', paths.storage.SampleStore())
        self.create_store('samplesets', paths.storage.SampleSetStore())
        self.create_store(
            'movechanges',
            paths.storage.MoveChangeStore()
        )
        self.create_store('steps', paths.storage.MCStepStore())

        # normal objects
        self.create_store('details', ObjectStore(paths.Details))
        self.create_store('pathmovers', NamedObjectStore(paths.PathMover))
        self.create_store('shootingpointselectors',
                          NamedObjectStore(paths.ShootingPointSelector))
        self.create_store('engines', NamedObjectStore(peng.DynamicsEngine))
        self.create_store('pathsimulators',
                          paths.storage.PathSimulatorStore())
        self.create_store('transitions', NamedObjectStore(paths.Transition))
        self.create_store('networks',
                          NamedObjectStore(paths.TransitionNetwork))
        self.create_store('schemes',
                          NamedObjectStore(paths.MoveScheme))
        self.create_store('interfacesets',
                          NamedObjectStore(paths.InterfaceSet))
        self.create_store('msouters',
                          NamedObjectStore(paths.MSOuterTISInterface))
github openpathsampling / openpathsampling / openpathsampling / collectivevariable.py View on Github external
def __init__(
            self,
            name,
            cv_time_reversible=False
    ):
        super(CollectiveVariable, self).__init__(name, peng.BaseSnapshot)

        self.cv_time_reversible = cv_time_reversible
        self.diskcache_allow_incomplete = not self.cv_time_reversible

        self.diskcache_chunksize = ObjectStore.default_store_chunk_size
        self._cache_dict = cd.ReversibleCacheChainDict(
            WeakKeyCache(),
            reversible=cv_time_reversible
        )

        self._single_dict._post = self._cache_dict
github openpathsampling / openpathsampling / openpathsampling / storage / snapshot_store.py View on Github external
from openpathsampling.snapshot import Snapshot, AbstractSnapshot, ToySnapshot
from openpathsampling.trajectory import Trajectory
from openpathsampling.netcdfplus import ObjectStore, LoaderProxy

import features as ft
from features import ConfigurationStore, MomentumStore


# =============================================================================================
# ABSTRACT BASE CLASS FOR SNAPSHOTS
# =============================================================================================

class AbstractSnapshotStore(ObjectStore):
    """
    An ObjectStore for Snapshots in netCDF files.
    """

    def __init__(self, snapshot_class):
        super(AbstractSnapshotStore, self).__init__(AbstractSnapshot, json=False)
        self.snapshot_class = snapshot_class

    def to_dict(self):
        return {
            'snapshot_class': self.snapshot_class
        }

    def _get(self, idx, from_reversed=False):
        if from_reversed:
            obj = self.cache[idx ^ 1]
github openpathsampling / openpathsampling / openpathsampling / storage / stores / movechange.py View on Github external
from openpathsampling.movechange import MoveChange
from openpathsampling.netcdfplus import StorableObject, ObjectStore

from uuid import UUID


class MoveChangeStore(ObjectStore):
    def __init__(self):
        super(MoveChangeStore, self).__init__(
            MoveChange,
            json=False
        )

        self._cached_all = False
        self.class_list = StorableObject.objects()

    def to_dict(self):
        return {}

    def _save(self, movechange, idx):
        self.vars['samples'][idx] = movechange.samples
        self.vars['input_samples'][idx] = movechange.input_samples
        self.vars['subchanges'][idx] = movechange.subchanges