示例#1
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)
示例#2
0
    def plot_curves(results):
        plt.figure()
        for marginal in results.keys():
            schemes = get_schemes(results[marginal])
            timesteps = get_timesteps(results[marginal])

            for scheme in schemes:
                DeltaF_neqs = []
                sq_uncs = []

                for timestep in timesteps:
                    W_shads_F, W_shads_R = results[marginal][(scheme,
                                                              timestep)][:2]
                    W_shads_F = np.array(W_shads_F)[:, -1]
                    W_shads_R = np.array(W_shads_R)[:, -1]
                    DeltaF_neq, sq_unc = estimate_nonequilibrium_free_energy(
                        W_shads_F, W_shads_R)
                    DeltaF_neqs.append(DeltaF_neq)
                    sq_uncs.append(sq_unc)

                DeltaF_neqs = np.array(DeltaF_neqs)
                sq_uncs = np.array(sq_uncs)
                uncs = np.sqrt(sq_uncs)
                plt.hlines(0, min(timesteps), max(timesteps), linestyles="--")
                plt.errorbar(timesteps,
                             DeltaF_neqs,
                             yerr=uncs,
                             label="{} ({})".format(scheme, marginal))
                # plt.plot(timesteps, DeltaF_neqs, label="{} ({})".format(scheme, marginal))
                # plt.fill_between(timesteps, DeltaF_neqs - uncs, DeltaF_neqs + uncs, alpha=0.3, color='grey')

        plt.legend(loc='best', fancybox=True)
        plt.xlabel("$\Delta t$")
        plt.ylabel("$\Delta F_{neq}$")
        plt.savefig(generate_figure_filename("scheme_comparison_{}{}".format(
            name, figure_format)),
                    dpi=300)
        plt.close()
示例#3
0
    for marginal in ["configuration", "full"]:
        results[marginal] = {}
        for name, simulator in noneq_simulators.items():
            print(marginal, name)
            W_shads_F, W_shads_R, xs_F, xs_R = simulator.collect_protocol_samples(
                n_protocol_samples, protocol_length, marginal)

            # summarize xs_F and xs_R into histograms:
            xs_F_hists = np.array([
                np.histogram(np.nan_to_num(xs_F[:, i]), bins=edges)[0]
                for i in range(xs_F.shape[1])
            ])
            xs_R_hists = np.array([
                np.histogram(np.nan_to_num(xs_R[:, i]), bins=edges)[0]
                for i in range(xs_R.shape[1])
            ])

            results[marginal][name] = np.array(W_shads_F, dtype=np.float16),\
                                      np.array(W_shads_R, dtype=np.float16),\
                                      edges, xs_F_hists, xs_R_hists

            DeltaF_neq, squared_uncertainty = estimate_nonequilibrium_free_energy(
                W_shads_F[:, -1], W_shads_R[:, -1])
            print("\t{:.5f} +/- {:.5f}".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)
示例#4
0
                                   "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:
        pickle.dump(results, f)

    plot_scheme_comparison(target_filename, system_name)