# Path: openpathsampling/pathsimulators/sshooting_simulator.py
# class SShootingSimulation(ShootFromSnapshotsSimulation):
#     """ S-Shooting simulations.
# 
#     Parameters
#     ----------
#     storage : :class:`.Storage`
#         the file to store simulations in
#     engine : :class:`.DynamicsEngine`
#         the dynamics engine to use to run the simulation
#     state_S : :class:`.Volume`
#         the volume representing saddle region S.
#     randomizer : :class:`.SnapshotModifier`
#         the method used to modify the input snapshot before each shot
#     initial_snapshots : list of :class:`.Snapshot`
#         initial snapshots to use.
#     trajectory_length : int
#         Trajectory length l of backward/forward shot, total length of generated
#         trajectories is 2*l+1. The harvested subtrajectories have length l+1.
#     """
#     def __init__(self, storage, engine=None, state_S=None, randomizer=None,
#                  initial_snapshots=None, trajectory_length=None):
# 
#         # Defintion of state S (A and B are only required for analysis).
#         self.state_S = state_S
# 
#         # Set forward/backward shot length.
#         self.trajectory_length = trajectory_length
#         l = self.trajectory_length
# 
#         # Define backward ensemble:
#         # trajectory starts in S and has fixed length l.
#         backward_ensemble = paths.SequentialEnsemble([
#             paths.LengthEnsemble(l),
#             paths.AllInXEnsemble(state_S) & paths.LengthEnsemble(1)
#         ])
# 
#         # Define forward ensemble:
#         # CAUTION: first trajectory is in backward ensemble,
#         # then continues with fixed length l.
#         forward_ensemble = paths.SequentialEnsemble([
#             paths.LengthEnsemble(l),
#             paths.AllInXEnsemble(state_S) & paths.LengthEnsemble(1),
#             paths.LengthEnsemble(l)
#         ])
# 
#         super(SShootingSimulation, self).__init__(
#             storage=storage,
#             engine=engine,
#             starting_volume=state_S,
#             forward_ensemble=forward_ensemble,
#             backward_ensemble=backward_ensemble,
#             randomizer=randomizer,
#             initial_snapshots=initial_snapshots
#         )
# 
#         # Create backward mover (starting from single point).
#         self.backward_mover = paths.BackwardExtendMover(
#             ensemble=self.starting_ensemble,
#             target_ensemble=self.backward_ensemble
#         )
# 
#         # Create forward mover (starting from the backward ensemble).
#         self.forward_mover = paths.ForwardExtendMover(
#             ensemble=self.backward_ensemble,
#             target_ensemble=self.forward_ensemble
#         )
# 
#         # Create mover combining forward and backward shooting. No condition
#         # here, shots in both directions are executed in any case.
#         self.mover = paths.NonCanonicalConditionalSequentialMover([
#             self.backward_mover,
#             self.forward_mover
#         ])
# 
#     def to_dict(self):
#         ret_dict = {
#             'state_S' : self.state_S,
#             'trajectory_length' : self.trajectory_length
#         }
#         return ret_dict
# 
#     @classmethod
#     def from_dict(cls, dct):
#         sshooting = cls.__new__(cls)
# 
#         # replace automatically created attributes with stored ones
#         sshooting.state_S = dct['state_S']
#         sshooting.trajectory_length = dct['trajectory_length']
#         return sshooting


from openpathsampling.tests.test_helpers import (data_filename)
from openpathsampling.pathsimulators.sshooting_simulator import SShootingSimulation
import openpathsampling as paths
import openpathsampling.engines.toy as toys
import numpy as np
import os
        steps = sim.storage.steps
        # Check if trajectory length has not been altered.
        assert sim.trajectory_length == self.l
        # Check if state S has not been altered.
        assert sim.state_S == self.state_S
        for i in range(len(steps)):
            step = steps[i]
            # there should be two trials
            assert len(step.change.trials) == 2
            # backward shot (first trial) should have length l+1
            assert len(step.change.trials[0].trajectory) == self.l+1
            # total trajectory (second trial = backward + forward shot should
            # have length 2*l+1
            assert len(step.change.trials[1].trajectory) == 2*self.l+1
            # middle point of trajectory should be initial snapshot
            t = step.change.trials[1].trajectory
            np.testing.assert_almost_equal(
                t[self.l].coordinates, self.initial_snapshots[i].coordinates
            )
            # all trajectories have intermediate points in S
            traj_summary = t.summarize_by_volumes(self.state_labels)
            assert traj_summary[0][0] == 'NotS'
            assert traj_summary[1][0] == 'S'
            assert traj_summary[2][0] == 'NotS'
            # last mover should be forward mover of simulation
            expected_mover = self.simulation.forward_mover
            assert step.change.canonical.mover == expected_mover

    def test_serialization_cycle(self):
        dct = self.simulation.to_dict()

# Path: openpathsampling/pathsimulators/sshooting_simulator.py
# class SShootingSimulation(ShootFromSnapshotsSimulation):
#     """ S-Shooting simulations.
# 
#     Parameters
#     ----------
#     storage : :class:`.Storage`
#         the file to store simulations in
#     engine : :class:`.DynamicsEngine`
#         the dynamics engine to use to run the simulation
#     state_S : :class:`.Volume`
#         the volume representing saddle region S.
#     randomizer : :class:`.SnapshotModifier`
#         the method used to modify the input snapshot before each shot
#     initial_snapshots : list of :class:`.Snapshot`
#         initial snapshots to use.
#     trajectory_length : int
#         Trajectory length l of backward/forward shot, total length of generated
#         trajectories is 2*l+1. The harvested subtrajectories have length l+1.
#     """
#     def __init__(self, storage, engine=None, state_S=None, randomizer=None,
#                  initial_snapshots=None, trajectory_length=None):
# 
#         # Defintion of state S (A and B are only required for analysis).
#         self.state_S = state_S
# 
#         # Set forward/backward shot length.
#         self.trajectory_length = trajectory_length
#         l = self.trajectory_length
# 
#         # Define backward ensemble:
#         # trajectory starts in S and has fixed length l.
#         backward_ensemble = paths.SequentialEnsemble([
#             paths.LengthEnsemble(l),
#             paths.AllInXEnsemble(state_S) & paths.LengthEnsemble(1)
#         ])
# 
#         # Define forward ensemble:
#         # CAUTION: first trajectory is in backward ensemble,
#         # then continues with fixed length l.
#         forward_ensemble = paths.SequentialEnsemble([
#             paths.LengthEnsemble(l),
#             paths.AllInXEnsemble(state_S) & paths.LengthEnsemble(1),
#             paths.LengthEnsemble(l)
#         ])
# 
#         super(SShootingSimulation, self).__init__(
#             storage=storage,
#             engine=engine,
#             starting_volume=state_S,
#             forward_ensemble=forward_ensemble,
#             backward_ensemble=backward_ensemble,
#             randomizer=randomizer,
#             initial_snapshots=initial_snapshots
#         )
# 
#         # Create backward mover (starting from single point).
#         self.backward_mover = paths.BackwardExtendMover(
#             ensemble=self.starting_ensemble,
#             target_ensemble=self.backward_ensemble
#         )
# 
#         # Create forward mover (starting from the backward ensemble).
#         self.forward_mover = paths.ForwardExtendMover(
#             ensemble=self.backward_ensemble,
#             target_ensemble=self.forward_ensemble
#         )
# 
#         # Create mover combining forward and backward shooting. No condition
#         # here, shots in both directions are executed in any case.
#         self.mover = paths.NonCanonicalConditionalSequentialMover([
#             self.backward_mover,
#             self.forward_mover
#         ])
# 
#     def to_dict(self):
#         ret_dict = {
#             'state_S' : self.state_S,
#             'trajectory_length' : self.trajectory_length
#         }
#         return ret_dict
# 
#     @classmethod
#     def from_dict(cls, dct):
#         sshooting = cls.__new__(cls)
# 
#         # replace automatically created attributes with stored ones
#         sshooting.state_S = dct['state_S']
#         sshooting.trajectory_length = dct['trajectory_length']
#         return sshooting


# Path: openpathsampling/tests/test_sshooting_simulator.py
from openpathsampling.tests.test_helpers import (data_filename)
from openpathsampling.pathsimulators.sshooting_simulator import SShootingSimulation
import openpathsampling as paths
import openpathsampling.engines.toy as toys
import numpy as np
import os

        steps = sim.storage.steps
        # Check if trajectory length has not been altered.
        assert sim.trajectory_length == self.l
        # Check if state S has not been altered.
        assert sim.state_S == self.state_S
        for i in range(len(steps)):
            step = steps[i]
            # there should be two trials
            assert len(step.change.trials) == 2
            # backward shot (first trial) should have length l+1
            assert len(step.change.trials[0].trajectory) == self.l+1
            # total trajectory (second trial = backward + forward shot should
            # have length 2*l+1
            assert len(step.change.trials[1].trajectory) == 2*self.l+1
            # middle point of trajectory should be initial snapshot
            t = step.change.trials[1].trajectory
            np.testing.assert_almost_equal(
                t[self.l].coordinates, self.initial_snapshots[i].coordinates
            )
            # all trajectories have intermediate points in S
            traj_summary = t.summarize_by_volumes(self.state_labels)
            assert traj_summary[0][0] == 'NotS'
            assert traj_summary[1][0] == 'S'
            assert traj_summary[2][0] == 'NotS'
            # last mover should be forward mover of simulation
            expected_mover = self.simulation.forward_mover
            assert step.change.canonical.mover == expected_mover

    def test_serialization_cycle(self):
        dct = self.simulation.to_dict()

        obj = SShootingSimulation.from_dict(dct)