示例#1
0
def get_hmr_stability_threshold_curve(test_system,
                                      splitting="V R O R V",
                                      traj_length=1000):
    topology = test_system.topology
    default_system = deepcopy(test_system.system)

    h_masses = np.arange(0.5, 4.51, 0.25)
    stability_thresholds = []

    for h_mass in h_masses:
        hmr_system = repartition_hydrogen_mass_amber(topology,
                                                     default_system,
                                                     scale_factor=h_mass)
        test_system.system = hmr_system
        lsi = LangevinSplittingIntegrator(splitting)
        simulation = test_system.construct_simulation(lsi)

        def stability_oracle(dt):
            simulation.integrator.setStepSize(dt * unit.femtoseconds)
            stable = test_stability(test_system, simulation, 1, traj_length)
            if stable:
                return 1
            else:
                return -1

        x, _, fs_heavy_H = probabilistic_bisection(stability_oracle,
                                                   initial_limits=(0, 10),
                                                   p=0.6,
                                                   n_iterations=100)
        stability_thresholds.append(x[np.argmax(fs_heavy_H[-1])])
    test_system = repartition_hydrogen_mass_amber(topology,
                                                  default_system,
                                                  scale_factor=1)
    return h_masses, stability_thresholds
示例#2
0
    def run(self):
        exp = self.experiment_descriptor
        simulator = NonequilibriumSimulator(exp.equilibrium_simulator,
                                            LangevinSplittingIntegrator(
                                                splitting=exp.splitting_string,
                                                timestep=exp.timestep_in_fs * unit.femtosecond,
                                                collision_rate=exp.collision_rate))

        self.result = simulator.collect_protocol_samples(
            exp.n_protocol_samples, exp.protocol_length, exp.marginal,
            store_potential_energy_traces=(exp.marginal=="full" and self.store_potential_energy_traces))

        W_shads_F, W_shads_R = self.result["W_shads_F"], self.result["W_shads_R"]
        DeltaF_neq, squared_uncertainty = estimate_nonequilibrium_free_energy(W_shads_F, W_shads_R)
        print(self)
        print("\t{:.3f} +/- {:.3f}".format(DeltaF_neq, np.sqrt(squared_uncertainty)))
示例#3
0
def simulation_factory(scheme, system_loader, constrained=True):
    """Create and return a simulation that includes:
    * Langevin integrator with the prescribed operator splitting
    * AlanineDipeptideVacuum with or without restraints."""
    platform = configure_platform("Reference")
    temperature = simulation_parameters["temperature"]
    topology, system, positions = system_loader(constrained)

    lsi = LangevinSplittingIntegrator(scheme,
                                      temperature=temperature,
                                      timestep=2.0 * unit.femtosecond,
                                      measure_heat=True,
                                      measure_shadow_work=True)

    simulation = app.Simulation(topology, system, lsi, platform)
    simulation.context.setPositions(positions)
    simulation.context.setVelocitiesToTemperature(temperature)
    return simulation
示例#4
0
def noneq_sim_factory(testsystem_name, scheme, dt, collision_rate):
    """Generate a NonequilibriumSimulator object for a given experiment

    Parameters
    ----------
    testsystem_name : string
    scheme : string
    dt : in units compatible with unit.femtosecond
    collision_rate : in units compatible with (1 / unit.picosecond)

    Returns
    -------
    noneq_sim : NonequilibriumSimulator

    """
    # check that testsystem_name is valid
    assert (testsystem_name in testsystems)

    # check that scheme is valid
    assert (scheme in splittings)

    # check that dt is valid
    assert (type(dt) == unit.Quantity)
    assert (dt.unit.is_compatible(unit.femtosecond))

    # check that collision_rate is valid
    assert (type(collision_rate) == unit.Quantity)
    assert ((1 / collision_rate).unit.is_compatible(unit.picosecond))

    testsystem = testsystems[testsystem_name]
    integrator = LangevinSplittingIntegrator(splittings[scheme],
                                             temperature=temperature,
                                             collision_rate=collision_rate,
                                             timestep=dt)
    noneq_sim = NonequilibriumSimulator(testsystem, integrator)

    return noneq_sim
示例#5
0
def error_oracle_factory(test_system,
                         error_threshold,
                         scheme="O V R V O",
                         n_protocol_samples=100,
                         protocol_length=1000):
    integrator = LangevinSplittingIntegrator(scheme,
                                             timestep=1.0 * unit.femtosecond)
    sim = NonequilibriumSimulator(test_system, integrator)

    def error_oracle(dt):
        integrator.setStepSize(dt * unit.femtosecond)

        W_F, W_R = sim.collect_protocol_samples(n_protocol_samples,
                                                protocol_length)
        DeltaF_neq, sq_unc = estimate_nonequilibrium_free_energy(W_F, W_R)

        print("\t{:.3f} +/- {:.3f}".format(DeltaF_neq, np.sqrt(sq_unc)))

        if error_threshold > np.abs(DeltaF_neq):
            return 1
        else:
            return -1

    return error_oracle
示例#6
0
def integrator_factory(dt):
    return LangevinSplittingIntegrator(collision_rate=91.0 / unit.picosecond,
                                       timestep=dt)
示例#7
0
        DeltaF_neq, sq_unc = estimate_nonequilibrium_free_energy(W_F, W_R)

        print("\t{:.3f} +/- {:.3f}".format(DeltaF_neq, np.sqrt(sq_unc)))

        if error_threshold > np.abs(DeltaF_neq):
            return 1
        else:
            return -1

    return error_oracle


if __name__ == "__main__":
    test_system = alanine_constrained
    reference_integrator = LangevinSplittingIntegrator("O V R V O",
                                                       timestep=2.0 *
                                                       unit.femtosecond)
    reference_sim = NonequilibriumSimulator(test_system, reference_integrator)

    W_F, W_R = reference_sim.collect_protocol_samples(1000, 1000)
    DeltaF_neq, sq_unc = estimate_nonequilibrium_free_energy(W_F, W_R)

    results = {}
    for scheme in ["V R O R V", "R V O V R", "O V R V O", "O R V R O"]:
        print(scheme)
        error_oracle = error_oracle_factory(DeltaF_neq, scheme)

        results[scheme] = probabilistic_bisection(error_oracle, (0, 10),
                                                  n_iterations=100)

    from pickle import dump
示例#8
0
from benchmark.testsystems.bookkeepers import EquilibriumSimulator

top, sys, pos = load_alanine(constrained=True)
alanine_constrained = EquilibriumSimulator(
    platform=configure_platform("Reference"),
    topology=top,
    system=sys,
    positions=pos,
    temperature=temperature,
    timestep=1.0 * unit.femtosecond,
    burn_in_length=500,
    n_samples=n_samples,
    thinning_interval=thinning_interval,
    name="alanine_constrained_test")
print("Sample from cache: \n", alanine_constrained.sample_x_from_equilibrium())

sim = NonequilibriumSimulator(
    alanine_constrained,
    LangevinSplittingIntegrator("O V R V O", timestep=4.5 * unit.femtoseconds))
result = sim.collect_protocol_samples(100,
                                      100,
                                      store_potential_energy_traces=True,
                                      store_W_shad_traces=True)
print("<W>_(0 -> M): {:.3f}, <W>_(M -> 2M): {:.3f}".format(
    result["W_shads_F"].mean(), result["W_shads_R"].mean()))

forward_traces = np.array([t[0] for t in result["W_shad_traces"]])
print("0 -> M traces: mean W_shad per step: ", forward_traces.mean(0))
print("0 -> M traces: mean cumulative W_shad per step: ",
      np.cumsum(forward_traces, 1).mean(0))