Beispiel #1
0
    def simulation_factory(timestep, scheme):
        """Factory for biased simulations"""
        lsi = LangevinSplittingIntegrator(scheme,
                                          timestep=timestep,
                                          temperature=temperature,
                                          collision_rate=collision_rate)

        simulation = app.Simulation(topology, system, lsi, platform)
        simulation.context.setPositions(positions)
        simulation.context.setVelocitiesToTemperature(temperature)
        return simulation
Beispiel #2
0
def run_experiment(n_geodesic_step_list=range(1, 5),
                   n_protocol_samples=500,
                   protocol_length=100,
                   collision_rate="high"):
    if collision_rate == "high":
        gamma = 91.0 / unit.picosecond
    elif collision_rate == "low":
        gamma = 1.0 / unit.picosecond
    else:
        print("Defaulting to low collision_rate")
        gamma = 1.0 / unit.picosecond

    system_name = "dhfr_constrained"
    equilibrium_simulator = dhfr_constrained
    target_filename = os.path.join(
        DATA_PATH,
        "gbaoab_{}_{}_collision_rate.pkl".format(system_name, collision_rate))

    timesteps = np.linspace(1.0, 8.0, 7)
    noneq_simulators = {}
    for timestep in timesteps:
        for n_geodesic_steps in n_geodesic_step_list:
            name = "g-BAOAB ({})".format(n_geodesic_steps)
            Rs = ["R"] * n_geodesic_steps
            scheme = " ".join(["V"] + Rs + ["O"] + Rs + ["V"])
            noneq_simulators[(name, timestep)] = scheme

    results = {}
    for marginal in ["configuration", "full"]:
        results[marginal] = {}
        for ((name, timestep), scheme) in noneq_simulators.items():
            print(marginal, name, timestep)

            simulator = NonequilibriumSimulator(
                equilibrium_simulator,
                LangevinSplittingIntegrator(splitting=scheme,
                                            timestep=timestep *
                                            unit.femtosecond,
                                            collision_rate=gamma))
            results[marginal][name] = simulator.collect_protocol_samples(
                n_protocol_samples, protocol_length, marginal)
            del (simulator)
            gc.collect()

            DeltaF_neq, squared_uncertainty = estimate_nonequilibrium_free_energy(
                *results[marginal][name])
            print("\t{:.3f} +/- {:.3f}".format(DeltaF_neq,
                                               np.sqrt(squared_uncertainty)))

    with open(target_filename, "wb") as f:
        pickle.dump(results, f)

    plot_scheme_comparison(target_filename, system_name)
Beispiel #3
0
if __name__ == "__main__":
    n_protocol_samples, protocol_length = 10000, 100
    system_name = "alanine_unconstrained_low_friction"
    equilibrium_simulator = alanine_unconstrained
    target_filename = os.path.join(DATA_PATH,
                                   "baoab_vs_vvvr_{}.pkl".format(system_name))

    schemes = {"BAOAB": "V R O R V", "VVVR": "O V R V O"}
    timesteps = np.linspace(0.1, 3, 10)
    noneq_simulators = {}
    for name, scheme in schemes.items():
        for timestep in timesteps:
            noneq_simulators[(name, timestep)] = NonequilibriumSimulator(
                equilibrium_simulator,
                LangevinSplittingIntegrator(
                    splitting=scheme,
                    timestep=timestep * unit.femtosecond,
                    collision_rate=1.0 / unit.picoseconds))
    results = {}
    for marginal in ["configuration", "full"]:
        results[marginal] = {}
        for name, simulator in noneq_simulators.items():
            print(marginal, name)
            results[marginal][name] = simulator.collect_protocol_samples(
                n_protocol_samples, protocol_length, marginal)

            DeltaF_neq, squared_uncertainty = estimate_nonequilibrium_free_energy(
                *results[marginal][name])
            print("\t{:.3f} +/- {:.3f}".format(DeltaF_neq,
                                               np.sqrt(squared_uncertainty)))

    with open(target_filename, "wb") as f:
Beispiel #4
0
step_type_dict = {
    0: "{target} <- {expr}",
    1: "{target} <- {expr}",
    2: "{target} <- sum({expr})",
    3: "constrain positions",
    4: "constrain velocities",
    5: "allow forces to update the context state",
    6: "if:",
    7: "while:",
    8: "end"
}

for scheme in schemes:
    print(scheme)
    integrator = LangevinSplittingIntegrator(scheme)

    # Export integrator to XML
    with open(os.path.join(DATA_PATH, "{}.xml".format(scheme), "wt")) as f:
        f.writelines(XmlSerializer.serialize(integrator))

    # Also pretty-print (using `step_type_dict`)
    readable_lines = []
    for i in range(integrator.getNumComputations()):
        step_type, target, expr = integrator.getComputationStep(i)
        readable_lines.append(
            step_type_dict[step_type].format(target=target, expr=expr) + "\n")
    print(readable_lines)

    # Save pretty-printed results to .txt
    with open(os.path.join(DATA_PATH, "{}.txt".format(scheme), "wt")) as f:
Beispiel #5
0
        thinning_interval=10,
        name="coupled_power_oscillators_{}".format(coupling_strength))
    return coupled_power_oscillators


if __name__ == "__main__":
    n_protocol_samples, protocol_length = 100, 100
    target_filename = os.path.join(DATA_PATH, "self_averaging_experiment.pkl")
    scheme = "V R O R V"

    results = {}
    coupling_strengths = np.linspace(0.0, 10000.0, 10)
    for coupling_strength in coupling_strengths:
        eq_sim = oscillator_factory(coupling_strength)
        integrator = LangevinSplittingIntegrator(splitting=scheme,
                                                 temperature=temperature,
                                                 timestep=3.5 *
                                                 unit.femtosecond)
        noneq_sim = NonequilibriumSimulator(eq_sim, integrator)

        W_shads = np.zeros(n_protocol_samples)
        for i in tqdm(range(n_protocol_samples)):
            x_0 = eq_sim.sample_x_from_equilibrium()
            v_0 = eq_sim.sample_v_given_x(x_0)
            W_shads[i] = noneq_sim.accumulate_shadow_work(
                x_0, v_0, protocol_length)

        print("\n\nmean(W) = {:.3f}, stdev(W) = {:.3f}\n\n".format(
            np.mean(W_shads), np.std(W_shads)))
        results[coupling_strength] = W_shads

    with open(target_filename, "wb") as f: