Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, samples, accepted=True, mover=None):
super(SampleMovePath, self).__init__(accepted=accepted, mover=mover)
if samples is None:
return
if type(samples) is paths.Sample:
samples = [samples]
self._local_samples.extend(samples)
partial_traj : :class:`openpathsampling.trajectory.Trajectory`
trajectory to extend
minus_replica_id : int or str
replica ID for this sample
engine : :class:`openpathsampling.dynamicsengine.DynamicsEngine`
engine to use for MD extension
"""
last_frame = partial_traj[-1]
if not self._segment_ensemble(partial_traj):
raise RuntimeError(
"Invalid input trajectory for minus extension. (Not A-to-A?)"
)
extension = engine.generate(last_frame,
[self.can_append])
first_minus = paths.Trajectory(partial_traj + extension[1:])
minus_samp = paths.Sample(
replica=minus_replica_id,
trajectory=first_minus,
ensemble=self
)
logger.info(first_minus.summarize_by_volumes_str(
{"A" : self.state_vol,
"I" : ~self.state_vol & self.innermost_vol,
"X" : ~self.innermost_vol})
)
return minus_samp
logger.info("Hop ends in legal ensemble: "+str(ens_to(trajectory)))
sample_details = SampleDetails()
if type(self.bias) is float:
bias = self.bias
elif type(self.bias) is dict:
# special dict
ens = self.bias['ensembles']
e1 = ens.index(ens_from)
e2 = ens.index(ens_to)
bias = float(self.bias['values'][e1,e2])
else:
bias = 1.0
trial = paths.Sample(
replica=replica,
trajectory=trajectory,
ensemble=ens_to,
details=sample_details,
mover=self,
parent=rep_sample,
bias=bias
)
details = MoveDetails()
setattr(details, 'initial_ensemble', ens_from)
setattr(details, 'trial_ensemble', ens_to)
setattr(details, 'bias', bias)
return [trial]
def _create_storages(self):
"""
Register all Stores used in the OpenPathSampling Storage
"""
# objects with special storages
stores = {
'trajectories' : paths.Trajectory,
'snapshots' : paths.BaseSnapshot,
'samples' : paths.Sample,
'samplesets' : paths.SampleSet,
'pathmovechanges' : paths.PathMoveChange,
'steps' : paths.MCStep,
'cvs' : paths.CollectiveVariable,
'details' : paths.Details,
'topologies' : peng.Topology,
'pathmovers' : paths.PathMover,
'shootingpointselectors' : paths.ShootingPointSelector,
'engines' : peng.DynamicsEngine,
'pathsimulators' : paths.PathSimulator,
'transitions' : paths.Transition,
'schemes' : paths.MoveScheme,
'volumes' : paths.Volume,
'ensembles' : paths.Ensemble,
'statics' : paths.engines.openmm.features.StaticContainer,
'kinetics' : paths.engines.openmm.features.KineticContainer
trajectories not taken into account in the first attempt
reuse_strategy : str
if `avoid` then in a second attempt the used trajectories are
tried
"""
trajectories = paths.Trajectory._to_list_of_trajectories(trajectories)
used_and_possible = []
for idx, traj in enumerate(trajectories):
if traj not in used_trajectories and (
not reuse_strategy.endswith('symmetric') or
traj.reversed not in used_trajectories):
if self(traj):
return paths.Sample(
trajectory=traj,
ensemble=self,
replica=replica
)
else:
used_and_possible.append(traj)
return self._handle_used_trajectories(
used_trajectories,
used_and_possible,
reuse_strategy)
" into ensemble " + repr(ensemble2) +
" : " + str(from1to2))
from2to1 = ensemble1(trajectory2)
logger.debug("trajectory " + repr(trajectory2) +
" into ensemble " + repr(ensemble1) +
" : " + str(from2to1))
trial1 = paths.Sample(
replica=replica1,
trajectory=trajectory1,
ensemble=ensemble2,
parent=sample1,
details=SampleDetails(),
mover=self
)
trial2 = paths.Sample(
replica=replica2,
trajectory=trajectory2,
ensemble=ensemble1,
parent=sample2,
details=SampleDetails(),
mover=self
)
return [trial1, trial2]
trajectory2 = sample2.trajectory.reversed
ensemble1 = sample1.ensemble
ensemble2 = sample2.ensemble
replica1 = sample1.replica
replica2 = sample2.replica
from1to2 = ensemble2(trajectory1)
logger.debug("trajectory " + repr(trajectory1) +
" into ensemble " + repr(ensemble2) +
" : " + str(from1to2))
from2to1 = ensemble1(trajectory2)
logger.debug("trajectory " + repr(trajectory2) +
" into ensemble " + repr(ensemble1) +
" : " + str(from2to1))
trial1 = paths.Sample(
replica=replica1,
trajectory=trajectory1,
ensemble=ensemble2,
parent=sample1,
mover=self
)
trial2 = paths.Sample(
replica=replica2,
trajectory=trajectory2,
ensemble=ensemble1,
parent=sample2,
mover=self
)
return [trial1, trial2], {}
def _to_list_of_trajectories(trajectories):
if isinstance(trajectories, Trajectory):
trajectories = [trajectories]
elif isinstance(trajectories, paths.Sample):
trajectories = [trajectories.trajectory]
elif isinstance(trajectories, paths.SampleSet):
trajectories = [s.trajectory for s in trajectories]
elif isinstance(trajectories, list):
if len(trajectories) > 0:
trajectories = [
obj.trajectory if isinstance(obj, paths.Sample) else obj
for obj in trajectories
]
elif isinstance(trajectories, paths.BaseSnapshot):
return paths.Trajectory([trajectories])
elif isinstance(trajectories, paths.BaseSnapshot):
return paths.Trajectory([trajectories])
return trajectories
trajectory2 = sample2.trajectory.reversed
ensemble1 = sample1.ensemble
ensemble2 = sample2.ensemble
replica1 = sample1.replica
replica2 = sample2.replica
from1to2 = ensemble2(trajectory1)
logger.debug("trajectory " + repr(trajectory1) +
" into ensemble " + repr(ensemble2) +
" : " + str(from1to2))
from2to1 = ensemble1(trajectory2)
logger.debug("trajectory " + repr(trajectory2) +
" into ensemble " + repr(ensemble1) +
" : " + str(from2to1))
trial1 = paths.Sample(
replica=replica1,
trajectory=trajectory1,
ensemble=ensemble2,
parent=sample1,
details=SampleDetails(),
mover=self
)
trial2 = paths.Sample(
replica=replica2,
trajectory=trajectory2,
ensemble=ensemble1,
parent=sample2,
details=SampleDetails(),
mover=self
)
used_trajectories,
used_and_possible,
reuse_strategy):
if reuse_strategy.startswith('avoid') \
and used_trajectories is not None:
for part in used_trajectories:
if part in used_and_possible:
if self(part):
# move the used one to the back of the list to
# not reuse it directly
del used_trajectories[used_trajectories.index(part)]
used_trajectories.append(part)
return paths.Sample(
trajectory=part,
ensemble=self
)
if reuse_strategy.endswith('symmetric'):
if part.reversed in used_and_possible:
if self(part):
# move the used one to the back of the list to
# not reuse it directly
del used_trajectories[used_trajectories.index(part)]
used_trajectories.append(part)
return paths.Sample(
trajectory=part,
ensemble=self
)