Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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):
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).
def __init__(self):
super(StorableNamedObject, self).__init__()
def __init__(self):
StorableNamedObject.__init__(self)
self._in_ensembles = None
self._out_ensembles = None
self._len = None
self._inout = None
self._trust_candidate = False
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,
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
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
----------
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
>>> )
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`.
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