예제 #1
0
def test_parallel_tempering_explicit_temperature_input(mpicomm):

    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T0 = 1.0 * unit.kelvin
    temperatures = [T0, T0 * 2, T0 * 4]
    n_temps = len(temperatures)

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    parameters = {"number_of_iterations": 100}
    replica_exchange = ParallelTempering.create(system,
                                                coordinates,
                                                nc_filename,
                                                temperatures=temperatures,
                                                mpicomm=mpicomm,
                                                parameters=parameters)
    replica_exchange.run()

    eq(replica_exchange.n_replicas, n_temps)
예제 #2
0
def test_parallel_tempering_save_and_load(mpicomm):

    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    parameters = {"number_of_iterations": 200}
    replica_exchange = ParallelTempering.create(system,
                                                coordinates,
                                                nc_filename,
                                                T_min=T_min,
                                                T_max=T_max,
                                                n_temps=n_temps,
                                                mpicomm=mpicomm,
                                                parameters=parameters)
    replica_exchange.run()

    replica_exchange.extend(100)

    replica_exchange = resume(nc_filename, mpicomm=mpicomm)
    eq(replica_exchange.iteration, 200)
    replica_exchange.run()
def test_parallel_tempering():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions


    coordinates = [positions] * n_temps

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations":1000}
    replica_exchange = ParallelTempering.create(system, coordinates, nc_filename, T_min=T_min, T_max=T_max, n_temps=n_temps, mpicomm=mpicomm, parameters=parameters)
    
    eq(replica_exchange.n_replicas, n_temps)

    replica_exchange.run()

    u_permuted = replica_exchange.database.ncfile.variables["energies"][:]
    s = replica_exchange.database.ncfile.variables["states"][:]

    u = permute_energies(u_permuted, s)

    states = replica_exchange.thermodynamic_states
    u0 = np.array([[ho.reduced_potential_expectation(s0, s1) for s1 in states] for s0 in states])

    l0 = np.log(u0)  # Compare on log scale because uncertainties are proportional to values
    l1 = np.log(u.mean(0))
    eq(l0, l1, decimal=1)
def test_parallel_tempering_save_and_load():

    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions


    coordinates = [positions] * n_temps
    
    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations":200}
    replica_exchange = ParallelTempering.create(system, coordinates, nc_filename, T_min=T_min, T_max=T_max, n_temps=n_temps, mpicomm=mpicomm, parameters=parameters)
    replica_exchange.run()
    
    replica_exchange.extend(100)
    
    replica_exchange = resume(nc_filename)
    eq(replica_exchange.iteration, 200)
    replica_exchange.run()
예제 #5
0
def test_double_set_thermodynamic_states():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations": 3}
    replica_exchange = ParallelTempering.create(system,
                                                coordinates,
                                                nc_filename,
                                                T_min=T_min,
                                                T_max=T_max,
                                                n_temps=n_temps,
                                                mpicomm=mpicomm,
                                                parameters=parameters)

    eq(replica_exchange.n_replicas, n_temps)

    replica_exchange.run()

    states = replica_exchange.thermodynamic_states
    replica_exchange.database.thermodynamic_states = states
예제 #6
0
def test_parallel_tempering_all_testsystems():
    T_min = 1.0 * u.kelvin
    T_max = 10.0 * u.kelvin
    n_temps = 3

    testsystem_classes = testsystems.TestSystem.__subclasses__()

    for testsystem_class in testsystem_classes:
        class_name = testsystem_class.__name__
        if class_name in fast_testsystems:
            logging.info("Testing replica exchange with testsystem %s" %
                         class_name)
        else:
            logging.info("Skipping replica exchange with testsystem %s." %
                         class_name)
            continue

        testsystem = testsystem_class()

        system = testsystem.system
        positions = [testsystem.positions] * n_temps

        nc_filename = tempfile.mkdtemp() + "/out.nc"
        parameters = {"number_of_iterations": 3}
        replica_exchange = ParallelTempering.create(system,
                                                    positions,
                                                    nc_filename,
                                                    T_min=T_min,
                                                    T_max=T_max,
                                                    n_temps=n_temps,
                                                    parameters=parameters)
        replica_exchange.run()
예제 #7
0
def test_double_set_thermodynamic_states():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations": 3}
    replica_exchange = ParallelTempering.create(
        system,
        coordinates,
        nc_filename,
        T_min=T_min,
        T_max=T_max,
        n_temps=n_temps,
        mpicomm=mpicomm,
        parameters=parameters,
    )

    eq(replica_exchange.n_replicas, n_temps)

    replica_exchange.run()

    states = replica_exchange.thermodynamic_states
    replica_exchange.database.thermodynamic_states = states
예제 #8
0
def test_parallel_tempering_pressure():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3
    pressure = 1.0 * unit.atmospheres

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations": 4}
    replica_exchange = ParallelTempering.create(system,
                                                coordinates,
                                                nc_filename,
                                                T_min=T_min,
                                                T_max=T_max,
                                                n_temps=n_temps,
                                                pressure=pressure,
                                                mpicomm=mpicomm,
                                                parameters=parameters)

    eq(replica_exchange.n_replicas, n_temps)

    replica_exchange.run()
예제 #9
0
def test_parallel_tempering():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations": 1000}
    replica_exchange = ParallelTempering.create(system,
                                                coordinates,
                                                nc_filename,
                                                T_min=T_min,
                                                T_max=T_max,
                                                n_temps=n_temps,
                                                mpicomm=mpicomm,
                                                parameters=parameters)

    eq(replica_exchange.n_replicas, n_temps)

    replica_exchange.run()

    u_permuted = replica_exchange.database.ncfile.variables["energies"][:]
    s = replica_exchange.database.ncfile.variables["states"][:]

    u = permute_energies(u_permuted, s)

    states = replica_exchange.thermodynamic_states
    u0 = np.array([[ho.reduced_potential_expectation(s0, s1) for s1 in states]
                   for s0 in states])

    l0 = np.log(
        u0
    )  # Compare on log scale because uncertainties are proportional to values
    l1 = np.log(u.mean(0))
    eq(l0, l1, decimal=1)
예제 #10
0
def test_parallel_tempering_explicit_temperature_input(mpicomm):

    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T0 = 1.0 * unit.kelvin
    temperatures = [T0, T0 * 2, T0 * 4]
    n_temps = len(temperatures)

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions

    coordinates = [positions] * n_temps

    parameters = {"number_of_iterations":100}
    replica_exchange = ParallelTempering.create(system, coordinates, nc_filename, temperatures=temperatures, mpicomm=mpicomm, parameters=parameters)
    replica_exchange.run()
    
    eq(replica_exchange.n_replicas, n_temps)
def test_parallel_tempering_pressure():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 1.0 * unit.kelvin
    T_max = 10.0 * unit.kelvin
    n_temps = 3
    pressure = 1.0 * unit.atmospheres

    ho = testsystems.HarmonicOscillator()

    system = ho.system
    positions = ho.positions


    coordinates = [positions] * n_temps

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations":4}
    replica_exchange = ParallelTempering.create(system, coordinates, nc_filename, T_min=T_min, T_max=T_max, n_temps=n_temps, pressure=pressure, mpicomm=mpicomm, parameters=parameters)
    
    eq(replica_exchange.n_replicas, n_temps)

    replica_exchange.run()
예제 #12
0
def notest_parallel_tempering_all_testsystems():
    T_min = 1.0 * u.kelvin
    T_max = 10.0 * u.kelvin
    n_temps = 3

    testsystem_classes = testsystems.TestSystem.__subclasses__()

    for testsystem_class in testsystem_classes:
        class_name = testsystem_class.__name__
        if class_name in fast_testsystems:
            logging.info("Testing replica exchange with testsystem %s" % class_name)
        else:
            logging.info("Skipping replica exchange with testsystem %s." % class_name)
            continue

        testsystem = testsystem_class()

        system = testsystem.system
        positions = [testsystem.positions] * n_temps

        nc_filename = tempfile.mkdtemp() + "/out.nc"
        parameters = {"number_of_iterations":3}
        replica_exchange = ParallelTempering.create(system, positions, nc_filename, T_min=T_min, T_max=T_max, n_temps=n_temps, parameters=parameters)
        replica_exchange.run()
예제 #13
0
import simtk.unit as u
from simtk.openmm import app
import simtk.openmm as mm
from repex.thermodynamics import ThermodynamicState
from repex.parallel_tempering import ParallelTempering
import repex.netcdf_io
from mpi4py import MPI # MPI wrapper

name = "1vii"
equil_filename = "./equil/%s.pdb" % name

nc_filename = "./%s.nc" % name

n_replicas = 50 # number of temperature replicas
T_min = 300.0 * u.kelvin # minimum temperature
T_max = 450.0 * u.kelvin # maximum temperature

parameters = dict(pressure=1.0 * u.atmospheres, number_of_iterations=1000)

T_i = [ T_min + (T_max - T_min) * (np.exp(float(i) / float(n_replicas-1)) - 1.0) / (np.e - 1.0) for i in range(n_replicas)]

forcefield = app.ForceField("amber10.xml", "tip3p.xml")
pdb = app.PDBFile(equil_filename)

system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.CutoffPeriodic, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HBonds)

coordinates = [pdb.positions] * n_replicas

rex = ParallelTempering.create(system, coordinates, nc_filename, T_min=T_min, T_max=T_max, n_temps=n_replicas, mpicomm=MPI.COMM_WORLD, parameters=parameters)
rex.run()