Skip to content

Commit

Permalink
Merge 4d20d6b into eb62600
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhswenson committed May 18, 2016
2 parents eb62600 + 4d20d6b commit d7512d2
Show file tree
Hide file tree
Showing 8 changed files with 1,072 additions and 20 deletions.
238 changes: 238 additions & 0 deletions examples/ipython/alanine_dipeptide_tps_analysis.ipynb

Large diffs are not rendered by default.

555 changes: 555 additions & 0 deletions examples/ipython/alanine_dipeptide_tps_first_traj.ipynb

Large diffs are not rendered by default.

211 changes: 211 additions & 0 deletions examples/ipython/alanine_dipeptide_tps_run.ipynb

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions openpathsampling/analysis/move_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class MoveScheme(StorableNamedObject):
root_mover : PathMover
Root of the move decision tree (`None` until tree is built)
"""
def __init__(self, network):
def __init__(self, network, engine=None):
super(MoveScheme, self).__init__()
self.movers = {}
self.network = network
self.strategies = {}
self.balance_partners = {}
self.choice_probability = {}
self.root_mover = None
self.engine = engine

self._mover_acceptance = {} # used in analysis

Expand All @@ -45,14 +46,15 @@ def to_dict(self):
'network' : self.network,
'choice_probability' : self.choice_probability,
'balance_partners' : self.balance_partners,
'root_mover' : self.root_mover
'root_mover' : self.root_mover,
'engine' : self.engine
}
return ret_dict

@classmethod
def from_dict(cls, dct):
scheme = cls.__new__(cls)
scheme.__init__(dct['network'])
scheme.__init__(dct['network'], engine=dct['engine'])
scheme.movers = dct['movers']
scheme.choice_probability = dct['choice_probability']
scheme.balance_partners = dct['balance_partners']
Expand Down Expand Up @@ -759,12 +761,12 @@ class DefaultScheme(MoveScheme):
move.
"""
def __init__(self, network, engine=None):
super(DefaultScheme, self).__init__(network)
super(DefaultScheme, self).__init__(network, engine)
n_ensembles = len(network.sampling_ensembles)
self.append(strategies.NearestNeighborRepExStrategy())
self.append(strategies.OneWayShootingStrategy(engine=engine))
self.append(strategies.OneWayShootingStrategy(engine=self.engine))
self.append(strategies.PathReversalStrategy())
self.append(strategies.MinusMoveStrategy(engine=engine))
self.append(strategies.MinusMoveStrategy(engine=self.engine))
global_strategy = strategies.OrganizeByMoveGroupStrategy()
self.append(global_strategy)

Expand All @@ -773,7 +775,7 @@ def __init__(self, network, engine=None):
self.append(strategies.OneWayShootingStrategy(
ensembles=[ms],
group="ms_outer_shooting",
engine=engine
engine=self.engine
))
self.append(strategies.PathReversalStrategy(
ensembles=[ms],
Expand Down Expand Up @@ -849,9 +851,9 @@ class OneWayShootingMoveScheme(MoveScheme):
Useful for building on top of. Useful as default for TPS.
"""
def __init__(self, network, selector=None, ensembles=None, engine=None):
super(OneWayShootingMoveScheme, self).__init__(network)
super(OneWayShootingMoveScheme, self).__init__(network, engine)
self.append(strategies.OneWayShootingStrategy(selector=selector,
ensembles=ensembles,
engine=engine))
engine=self.engine))
self.append(strategies.OrganizeByMoveGroupStrategy())

37 changes: 31 additions & 6 deletions openpathsampling/analysis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def sampling_ensembles(self):
"""
return sum([t.ensembles for t in self.sampling_transitions], [])

@property
def analysis_ensembles(self):
"""
Ensembles from the analysis transitions, excluding special ensembles.
"""
return sum([t.ensembles for t in self.transitions.values()], [])

@property
def all_ensembles(self):
"""
Expand Down Expand Up @@ -83,7 +90,8 @@ class into a simple subclass of this GeneralizedTPSNetwork, which acts
pathlengths.
"""
TransitionType = NotImplemented
def __init__(self, initial_states, final_states, **kwargs):
def __init__(self, initial_states, final_states,
allow_self_transitions=False, **kwargs):
# **kwargs gets passed to the transition
super(GeneralizedTPSNetwork, self).__init__()
try:
Expand All @@ -101,23 +109,40 @@ def __init__(self, initial_states, final_states, **kwargs):
self.final_states = final_states

all_initial = paths.join_volumes(initial_states)
all_initial.name = "|".join([v.name for v in initial_states])
if len(initial_states) > 1:
all_initial.name = "|".join([v.name for v in initial_states])

if set(initial_states) == set(final_states):
if set(initial_states) == set(final_states) or len(final_states) == 1:
all_final = all_initial
else:
all_final = paths.join_volumes(final_states)
all_final.name = "|".join([v.name for v in final_states])
self._sampling_transitions = [
self.TransitionType(all_initial, all_final, **kwargs)
]

self._sampling_transitions = []
for my_initial in initial_states:
my_final_states = [final for final in final_states
if my_initial != final or allow_self_transitions]
my_final = paths.join_volumes(my_final_states)
if len(my_final_states) > 1:
my_final.name = "|".join([v.name for v in my_final_states])
if len(self._sampling_transitions) == 0:
self._sampling_transitions = [
self.TransitionType(my_initial, my_final, **kwargs)
]
elif len(self._sampling_transitions) == 1:
self._sampling_transitions[0].add_transition(my_initial,
my_final)
else:
raise RuntimeError("More than one sampling transition for TPS?")

self.transitions = {
(initial, final) : self.TransitionType(initial, final, **kwargs)
for (initial, final) in itertools.product(initial_states,
final_states)
if initial != final
}


def to_dict(self):
ret_dict = {
'transitions' : self.transitions,
Expand Down
4 changes: 2 additions & 2 deletions openpathsampling/analysis/tis_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def _tps_ensemble(self, stateA, stateB):
paths.AllInXEnsemble(stateB) & paths.LengthEnsemble(1)
])

def add_transition(self, stateA, stateB):
new_ens = self._tps_ensemble(stateA, stateB)
def add_transition(self, stateA, stateB, **kwargs):
new_ens = self._tps_ensemble(stateA, stateB, **kwargs)
try:
self.ensembles[0] = self.ensembles[0] | new_ens
except AttributeError:
Expand Down
12 changes: 9 additions & 3 deletions openpathsampling/engines/features/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ def __init__(self, coordinates, box_vectors):
coords = self.coordinates

if np.any(np.isnan(coords)):
raise ValueError(
"Some coordinates became 'nan'; simulation is unstable or buggy.")
try:
import pandas as pd
except ImportError:
df=""
else:
df=str(pd.Dataframe(coords)) + "\n"
raise ValueError(df + "Some coordinates became 'nan'; " +
"simulation is unstable or buggy.")

return

Expand Down Expand Up @@ -312,4 +318,4 @@ def _init(self):
"'coordinate' of momentum 'momentum'.",
chunksizes=(1, n_atoms, n_spatial),
simtk_unit=unit
)
)
15 changes: 15 additions & 0 deletions openpathsampling/tests/testnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def setup(self):
self.stateB = paths.CVRangeVolume(xval, -0.1, 0.1)
self.stateC = paths.CVRangeVolume(xval, 0.5, float("inf"))
self.states = [self.stateA, self.stateB, self.stateC]
self.traj = {}
self.traj['AA'] = make_1d_traj([-0.51, -0.49, -0.42])

# define all the test networks as properties: we can do something
# similar then for the fixed path length, and just need to override
Expand Down Expand Up @@ -235,6 +237,12 @@ def test_storage(self):
if os.path.isfile(fname):
os.remove(fname)

def test_allow_self_transitions_false(self):
raise SkipTest

def test_allow_self_transitions_true(self):
raise SkipTest

class testFixedLengthTPSNetwork(testTPSNetwork):
@property
def network2a(self):
Expand Down Expand Up @@ -280,3 +288,10 @@ def test_lengths(self):
self.network3a, self.network3b, self.network3c]:
assert_equal(network.sampling_transitions[0].length, 10)
assert_equal(network.transitions.values()[0].length, 10)

def test_allow_self_transitions_false(self):
raise SkipTest

def test_allow_self_transitions_true(self):
raise SkipTest

0 comments on commit d7512d2

Please sign in to comment.