How to use the openpathsampling.netcdfplus.StorableNamedObject 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 / high_level / network.py View on Github external
import pandas as pd

import openpathsampling as paths
from openpathsampling.netcdfplus import StorableNamedObject

from functools import reduce  # not built-in for py3

logger = logging.getLogger(__name__)

def index_to_string(index):
    n_underscore = index // 26
    letter_value = index % 26
    mystr = "_"*n_underscore + chr(65 + letter_value)
    return mystr

class TransitionNetwork(StorableNamedObject):
    """
    Subclasses of TransitionNetwork are the main way to set up calculations

    Attributes
    ----------
    sampling_ensembles
    all_ensembles
    sampling_transitions
    """
    def __init__(self):
        super(TransitionNetwork, self).__init__()
        #self.transitions = {}
        #self.special_ensembles = {}

    @property
    def sampling_ensembles(self):
github openpathsampling / openpathsampling / openpathsampling / analysis / tis / core.py View on Github external
the ensemble (output of `steps_to_weighted_trajectories`)

        Returns
        -------
        dict of {:class:`.Ensemble`: :class:`.numerics.Histogram`}
            calculated histogram for each ensemble
        """
        for ens in self.hists:
            trajs = list(input_dict[ens].keys())
            weights = list(input_dict[ens].values())
            data = [self.f(traj) for traj in trajs]
            self.hists[ens].histogram(data, weights)
        return self.hists


class TISAnalysis(StorableNamedObject):
    """
    Generic class for TIS analysis. One of these for each network.

    In general, the TIS rate is split into the flux and the transition
    probability.

    Parameters
    ----------
    network : :class:`.TransitionNetwork`
        the reaction network to be analyzed
    flux_method : flux calculation method
        the method to use to calculate the flux; typical classes are
        :class:`.MinusMoveFlux` and :class:`.DictFlux`
    transition_probability_methods : dict of :class:`.Transition` to method
        the method for calculating the transition probability (one for each
        transition).
github openpathsampling / openpathsampling / openpathsampling / pathmover.py View on Github external
def __init__(self):
        StorableNamedObject.__init__(self)

        self._in_ensembles = None
        self._out_ensembles = None
        self._len = None
        self._inout = None
        self._trust_candidate = False
github openpathsampling / openpathsampling / openpathsampling / high_level / ms_outer_interface.py View on Github external
import openpathsampling as paths
import openpathsampling.netcdfplus as netcdfplus

class MSOuterTISInterface(netcdfplus.StorableNamedObject):
    """
    Object to manage multiple-state outer interface in TIS.

    The MS outer interface needs to know what the interface volume is for
    each interface set, and needs to know which interface sets it is
    associated with.

    Can also be initialized from a dictionary of interface sets to lambda
    values (assuming those interface sets have a .new_interface method). See
    :meth:`.from_lambdas`.

    This also includes a convenience to create the appropriate MS outer
    ensemble.

    Much of this currently depends on the idea that there is a one-to-one
    mapping from :class:`.Transition` to :class:`.InterfaceSet` (at least,
github openpathsampling / openpathsampling / openpathsampling / analysis / tis / core.py View on Github external
order = set(idx_vols + col_vols)
        index = [key_map(k) for k in order if k in idx_vols]
        columns = [key_map(k) for k in order if k in col_vols]
        result = pd.DataFrame(index=index, columns=columns)
        for k in keys:
            result.set_value(key_map(k[0]), key_map(k[1]),
                             self.results_dict[k])
        return result

    def __str__(self):  # pragma: no cover
        return self.to_pandas().__str__()

    def __repr__(self):
        return self.to_pandas().__repr__()

class MultiEnsembleSamplingAnalyzer(StorableNamedObject):
    """
    Abstract class for statistics from MC steps sampling multiple ensembles.

    Parameters
    ----------
    ensembles : list of :class:`.Ensemble`
        ensembles to be used in the calculation; can be overridden by
        :meth:`.calculate`
    """
    def __init__(self, ensembles=None):
        self.ensembles = ensembles

    def calculate(self, steps, ensembles=None):
        """Perform the analysis, using `steps` as input.

        This is the main analysis for the abstract
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
Notes
    -----
    Maybe replace - by / to get better notation. So far it has not been used
    """

    #__metaclass__ = abc.ABCMeta

    def __init__(self):
        """
        A path volume defines a set of paths.
        """
        super(Ensemble, self).__init__()
        self._saved_str = None  # cached first time it is requested

    # https://docs.python.org/3/reference/datamodel.html#object.__hash__
    __hash__ = StorableNamedObject.__hash__

    def __eq__(self, other):
        if self is other:
            return True
        return str(self) == str(other)

    def __ne__(self, other):
        return not self == other

    @abc.abstractmethod
    def __call__(self, trajectory, trusted=None, candidate=False):
        """
        Return `True` if the trajectory is part of the path ensemble.

        Parameters
        ----------
github openpathsampling / openpathsampling / openpathsampling / ensemble.py View on Github external
else:
                self.bad_direction_error()
        else:
            self.trusted = True
        # by returning reset, we allow the functions that call this to reset
        # other things as well
        if self.direction > 0:
            self.prev_last_frame = trajectory.get_as_proxy(-1)
        elif self.direction < 0:
            self.prev_last_frame = trajectory.get_as_proxy(0)
        else:
            self.bad_direction_error()

        return reset

class Ensemble(StorableNamedObject):
    '''
    Path ensemble object.

    An Ensemble represents a path ensemble, effectively a set of trajectories.
    Typical set operations are allowed, here: and, or, xor, -(without), ~
    (inverse = all - x)     
    
    Examples
    --------    
    >>> EnsembleFactory.TISEnsemble(
    >>>     CVRangeVolume(collectivevariable_A, 0.0, 0.02),
    >>>     CVRangeVolume(collectivevariable_A, 0.0, 0.02),
    >>>     CVRangeVolume(collectivevariable_A, 0.0, 0.08),
    >>>     True
    >>>     )
github openpathsampling / openpathsampling / openpathsampling / high_level / move_strategy.py View on Github external
indices = [i for i in range(len(distances)) if distances[i]==mindist]
        if len(indices) > 1:
            return None
        else:
            return levels[indices[0]]

# possible rename to make available as paths.strategy_levels?
levels = StrategyLevels(
    SIGNATURE=10,
    MOVER=30,
    GROUP=50,
    SUPERGROUP=70,
    GLOBAL=90
)

class MoveStrategy(StorableNamedObject):
    """
    Each MoveStrategy describes one aspect of the approach to the overall
    MoveScheme. Within path sampling, there's a near infinity of reasonable
    move schemes to be used; we use MoveStrategy to simplify mixing and
    matching of different approaches.

    Parameters
    ----------
    ensembles : list of list of Ensemble, list of Ensemble, Ensemble,  or None
        The ensembles used by this strategy
    group : string or None
        The group this strategy is associated with (if any).
    replace : bool
        Whether this strategy should replace existing movers. See also
        `MoveStrategy.set_replace` and `MoveScheme.apply_strategy`.
github openpathsampling / openpathsampling / openpathsampling / snapshot_modifier.py View on Github external
import random
import logging
import abc

import numpy as np

import openpathsampling as paths
from openpathsampling.netcdfplus import StorableNamedObject, StorableObject

logger = logging.getLogger(__name__)

class SnapshotModifier(StorableNamedObject):
    """Abstract class for snapshot modification.

    In general, a snapshot modifer will take a snapshot and return a
    modified version of that snapshot. These are useful for, e.g., two-way
    shooting or for committor analysis.

    Attributes
    ----------
    subset_mask : list of int or None
        the subset to use (default None, meaning no subset). The values
        select along the first axis of the input array. For example, in a
        typical shape=(n_atoms, 3) array, this will pick the atoms.

    Note
    ----
    It is tempting to use the various indexing tricks in numpy to get a view