Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if prev_ens.can_append(prev_subtraj, trusted=True):
logger.debug(
"Premature promotion: returning to ensemble " +
str(ens_num - 1)
)
ens_num -= 1
subtraj_first = "keep"
self.update_cache(cache, ens_num, ens_first,
subtraj_first)
logger.debug(
"All frames assigned, more ensembles to go: "
"returning True")
return True
elif self.ensembles[ens_num](paths.Trajectory([])):
logger.debug(
"Moving on because of allowed zero-length ensemble")
ens_num += 1
subtraj_first = subtraj_final
self.update_cache(cache, ens_num, ens_first, subtraj_first)
else:
# not all frames assigned, couldn't find a sequence
# start over with sequences that begin with the next
# ensemble
if ens_first == final_ens:
logger.debug(
"Started with the last ensemble, got nothin'")
return False
elif strict is False:
logger.debug(
if self._use_cache:
prev_slice = cache.contents['assignments'][ens_num-1]
prev_subtraj = trajectory[prev_slice]
prev_ens = self.ensembles[ens_num-1]
if prev_ens.can_append(prev_subtraj, trusted=True):
logger.debug(
"Premature promotion: returning to ensemble " +
str(ens_num-1)
)
ens_num -= 1
subtraj_first = "keep"
self.update_cache(cache, ens_num, ens_first, subtraj_first)
logger.debug("All frames assigned, more ensembles to go: returning True")
return True
elif self.ensembles[ens_num](paths.Trajectory([])):
logger.debug("Moving on because of allowed zero-length ensemble")
ens_num += 1
subtraj_first = subtraj_final
self.update_cache(cache, ens_num, ens_first, subtraj_first)
else:
# not all frames assigned, couldn't find a sequence
# start over with sequences that begin with the next
# ensemble
if ens_first == final_ens:
logger.debug("Started with the last ensemble, got nothin'")
return False
else:
logger.debug(
"Reassigning all frames, starting with ensemble " +
str(ens_first)
)
def _eval(self, items):
trajectory = paths.Trajectory(items)
return [self._instance(snap, **self.kwargs) for snap in trajectory]
part = doc.g(class_='legend-correlation')
part.add(
doc.label(0, 0, 'cor', css_class=['head'])
)
old_tc = 1
prev = self._plot_sample_list[0]['sample']
for pos_y, data in enumerate(self._plot_sample_list):
sample = data['sample']
css_class = data['css_class']
if pos_y > 0 and 'rejected' not in css_class:
if not paths.Trajectory.is_correlated(
sample.trajectory,
prev,
time_reversal=time_symmetric
):
part.add(
doc.vertical_region(
0,
old_tc,
1 + pos_y - old_tc,
css_class=['correlation']
)
)
old_tc = 1 + pos_y
prev = sample.trajectory
logger.debug(
"Premature promotion: returning to ensemble " +
str(ens_num + 1)
)
ens_num += 1
assign_final = "keep"
logger.debug("(first, final)" + str((subtraj_first,
subtraj_final)))
self.update_cache(cache, ens_num, ens_final,
assign_final)
logger.debug(
"All frames assigned, more ensembles to go: "
"returning True")
return True
elif self.ensembles[ens_num](paths.Trajectory([])):
logger.debug(
"Moving on because of allowed zero-length ensemble")
ens_num -= 1
subtraj_final = subtraj_first
self.update_cache(cache, ens_num, ens_final, subtraj_final)
else:
if ens_final == first_ens:
logger.debug(
"Started with the last ensemble, got nothin'")
return False
elif strict is False:
logger.debug(
"Reassigning all frames, starting with ensemble " +
str(ens_final)
)
ens_final -= 1
if parent not in self:
while parent not in self and parent is not None:
parent = parent.parent
if parent is None:
time_direction = +1
if parent is not None:
parent_shift = self[parent]['shift']
time_direction = self[parent]['time_direction']
parent_traj = parent.trajectory
if time_direction == -1:
traj = paths.Trajectory(list(reversed(traj.as_proxies())))
parent_traj = paths.Trajectory(list(reversed(parent_traj.as_proxies())))
overlap = parent_traj.shared_subtrajectory(traj, time_reversal=self.time_symmetric)
overlap_length = len(overlap)
if overlap is None or len(overlap) == 0:
# no overlap so we need to start new
if not self.trace_missing:
traj_shift = 0
elif parent is not None:
# if a parent is present but no overlap we could trace the missing chain
# and use this shift. This is "expensive" so by default it is switched off
current = paths.Sample(
replica=sample.replica,
trajectory=traj,
ensemble=sample.ensemble,
"""Adds data to the internal histogram counter.
Parameters
----------
trajectories : list of :class:`.Trajectory` or :class:`.Trajectory`
input data
weights : list or None
weight associated with each datapoint. Default `None` is same
weights for all
Returns
-------
collections.Counter :
copy of the current histogram counter
"""
if isinstance(trajectories, paths.Trajectory):
trajectories = [trajectories]
if weights is None:
weights = [1.0] * len(trajectories)
# TODO: add something so that we don't recalc the same traj twice
for (traj, w) in zip(trajectories, weights):
cv_traj = [cv(traj) for cv in self.cvs]
self.add_trajectory(list(zip(*cv_traj)), w)
return self._histogram.copy()
if parent not in self:
while parent not in self and parent is not None:
parent = parent.parent
if parent is None:
time_direction = +1
if parent is not None:
parent_shift = self[parent]['shift']
time_direction = self[parent]['time_direction']
parent_traj = parent.trajectory
if time_direction == -1:
traj = paths.Trajectory(list(reversed(traj.as_proxies())))
parent_traj = paths.Trajectory(list(reversed(parent_traj.as_proxies())))
overlap = parent_traj.shared_subtrajectory(traj, time_reversal=self.time_symmetric)
overlap_length = len(overlap)
if overlap is None or len(overlap) == 0:
# no overlap so we need to start new
if not self.trace_missing:
traj_shift = 0
elif parent is not None:
# if a parent is present but no overlap we could trace the missing chain
# and use this shift. This is "expensive" so by default it is switched off
current = paths.Sample(
replica=sample.replica,
trajectory=traj,
}
else:
new_fw = self._trajectory_index(traj, overlap.get_as_proxy(-1))
new_bw = self._trajectory_index(traj, overlap.get_as_proxy(0))
overlap_reversed = False
if new_bw > new_fw:
overlap_reversed = True
new_fw, new_bw = new_bw, new_fw
if flip_time_direction:
# reverse the time and adjust the shifting
traj = paths.Trajectory(list(reversed(traj.as_proxies())))
time_direction *= -1
overlap_reversed = False
new_fw, new_bw = length - 1 - new_bw, length - 1 - new_fw
else:
# after
overlap_length = 0
traj_shift = parent_shift + self._trajectory_index(parent_traj, overlap.get_as_proxy(0)) - new_bw
self[sample] = {
'shift': traj_shift,
'length_fw': length - 1 - new_fw,
'length_bw': new_bw,
'length_shared': overlap_length,
'length': length,
def map_trajectory_to_ensembles(trajectory, ensembles):
"""Return SampleSet mapping one trajectory to all ensembles.
One common approach to starting a simulation is to take a single
transition trajectory (which satisfies all ensembles) and use it as
the starting point for all ensembles.
"""
return SampleSet([
Sample.initial_sample(
replica=ensembles.index(e),
trajectory=paths.Trajectory(trajectory.as_proxies()), # copy
ensemble=e)
for e in ensembles
])