def test_harmonic_oscillators(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 1.0 * unit.kelvin T_i = [T_min, T_min * 10., T_min * 100.] n_replicas = len(T_i) ho = testsystems.HarmonicOscillator() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations":1000} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters) replica_exchange.run() u_permuted = replica_exchange.database.ncfile.variables["energies"][:] s = replica_exchange.database.ncfile.variables["states"][:] u = permute_energies(u_permuted, s) 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_harmonic_oscillators_save_and_load(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 1.0 * unit.kelvin T_i = [T_min, T_min * 10., T_min * 100.] n_replicas = len(T_i) ho = testsystems.HarmonicOscillator() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations":200} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, 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_check_positions(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 1.0 * unit.kelvin T_i = [T_min, T_min * 10., T_min * 100.] n_replicas = len(T_i) ho = testsystems.HarmonicOscillator() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations": 10} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters) replica_exchange.run() db = replica_exchange.database db.check_energies()
def test_harmonic_oscillators_save_and_load(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 1.0 * unit.kelvin T_i = [T_min, T_min * 10., T_min * 100.] n_replicas = len(T_i) ho = testsystems.HarmonicOscillator() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations": 200} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, 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_get_traj(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 300.0 * unit.kelvin T_i = [T_min, T_min * 1.01, T_min * 1.1] n_replicas = len(T_i) ho = testsystems.AlanineDipeptideExplicit() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations":3} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters) replica_exchange.run() db = replica_exchange.database trj0 = md.load("repex/data/alanine-dipeptide-explicit/alanine-dipeptide.pdb") db.set_traj(trj0) trj1 = db.get_traj(state_index=0) trj2 = db.get_traj(replica_index=0)
def test_output_diagnostics(): tempdir = tempfile.mkdtemp() nc_filename = tempdir + "/out.nc" T_min = 1.0 * unit.kelvin T_i = [T_min, T_min * 10., T_min * 100.] n_replicas = len(T_i) ho = testsystems.HarmonicOscillator() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations":10} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters) replica_exchange.run() db = replica_exchange.database db.check_energies() db.output_diagnostics(tempdir + "/diagnostics/")
def test_harmonic_oscillators(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 1.0 * unit.kelvin T_i = [T_min, T_min * 10., T_min * 100.] n_replicas = len(T_i) ho = testsystems.HarmonicOscillator() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations": 1000} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters) replica_exchange.run() u_permuted = replica_exchange.database.ncfile.variables["energies"][:] s = replica_exchange.database.ncfile.variables["states"][:] u = permute_energies(u_permuted, s) 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_get_traj(): nc_filename = tempfile.mkdtemp() + "/out.nc" T_min = 300.0 * unit.kelvin T_i = [T_min, T_min * 1.01, T_min * 1.1] n_replicas = len(T_i) ho = testsystems.AlanineDipeptideExplicit() system = ho.system positions = ho.positions states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [positions] * n_replicas mpicomm = dummympi.DummyMPIComm() parameters = {"number_of_iterations": 3} replica_exchange = ReplicaExchange.create(states, coordinates, nc_filename, mpicomm=mpicomm, parameters=parameters) replica_exchange.run() db = replica_exchange.database prmtop_filename = testsystems.get_data_filename( "data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop") crd_filename = testsystems.get_data_filename( "data/alanine-dipeptide-explicit/alanine-dipeptide.crd") trj0 = md.load_restrt(crd_filename, top=prmtop_filename) db.set_traj(trj0) trj1 = db.get_traj(state_index=0) trj2 = db.get_traj(replica_index=0)
pdb_filename = "./1vii.pdb" temperature = 300 * u.kelvin friction = 0.3 / u.picosecond timestep = 2.0 * u.femtosecond forcefield = app.ForceField("amber10.xml", "tip3p.xml") pdb = app.PDBFile(pdb_filename) model = app.modeller.Modeller(pdb.topology, pdb.positions) model.addSolvent(forcefield, padding=0.01 * u.nanometer) system = forcefield.createSystem( model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles ) states = [ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas)] coordinates = [model.getPositions()] * n_replicas # database = repex.netcdf_io.NetCDFDatabase(nc_filename, states, coordinates) # replica_exchange = ReplicaExchange(states, coordinates, nc_filename) # replica_exchange = ReplicaExchange.create_repex(states, coordinates, nc_filename, mpicomm=MPI.COMM_WORLD, **{}) replica_exchange = ReplicaExchange.resume_repex(nc_filename, mpicomm=MPI.COMM_WORLD, **{}) replica_exchange.number_of_iterations = 30 replica_exchange.run()
temperature = 300 * u.kelvin friction = 0.3 / u.picosecond timestep = 2.0 * u.femtosecond forcefield = app.ForceField("amber10.xml", "tip3p.xml") pdb = app.PDBFile(pdb_filename) model = app.modeller.Modeller(pdb.topology, pdb.positions) model.addSolvent(forcefield, padding=0.01 * u.nanometer) system = forcefield.createSystem(model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles) states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [model.getPositions()] * n_replicas #database = repex.netcdf_io.NetCDFDatabase(nc_filename, states, coordinates) #replica_exchange = ReplicaExchange(states, coordinates, nc_filename) #replica_exchange = ReplicaExchange.create_repex(states, coordinates, nc_filename, **{}) replica_exchange = ReplicaExchange.resume_repex(nc_filename, **{}) replica_exchange.number_of_iterations = 20 replica_exchange.run()
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) ] pdb_filename = "./1vii.pdb" temperature = 300 * u.kelvin friction = 0.3 / u.picosecond timestep = 2.0 * u.femtosecond forcefield = app.ForceField("amber10.xml", "tip3p.xml") pdb = app.PDBFile(pdb_filename) model = app.modeller.Modeller(pdb.topology, pdb.positions) model.addSolvent(forcefield, padding=0.01 * u.nanometer) system = forcefield.createSystem(model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles) states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [model.getPositions()] * n_replicas #database = repex.netcdf_io.NetCDFDatabase(nc_filename, states, coordinates) #replica_exchange = ReplicaExchange(states, coordinates, nc_filename) #replica_exchange = ReplicaExchange.create_repex(states, coordinates, nc_filename, mpicomm=MPI.COMM_WORLD, **{}) replica_exchange = ReplicaExchange.resume_repex(nc_filename, mpicomm=MPI.COMM_WORLD, **{}) replica_exchange.number_of_iterations = 30 replica_exchange.run()
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) ] pdb_filename = "./1vii.pdb" temperature = 300 * u.kelvin friction = 0.3 / u.picosecond timestep = 2.0 * u.femtosecond forcefield = app.ForceField("amber10.xml", "tip3p.xml") pdb = app.PDBFile(pdb_filename) model = app.modeller.Modeller(pdb.topology, pdb.positions) model.addSolvent(forcefield, padding=0.01 * u.nanometer) system = forcefield.createSystem(model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles) states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] coordinates = [model.getPositions()] * n_replicas #database = repex.netcdf_io.NetCDFDatabase(nc_filename, states, coordinates) #replica_exchange = ReplicaExchange(states, coordinates, nc_filename) #replica_exchange = ReplicaExchange.create_repex(states, coordinates, nc_filename, **{}) replica_exchange = ReplicaExchange.resume_repex(nc_filename, **{}) replica_exchange.number_of_iterations = 20 replica_exchange.run()
T_i = [ T_min + (T_max - T_min) * (math.exp(float(i) / float(n_replicas-1)) - 1.0) / (math.e - 1.0) for i in range(n_replicas) ] pdb_filename = "1VII.pdb" temperature = 300 * u.kelvin friction = 0.3 / u.picosecond timestep = 2.0 * u.femtosecond forcefield = app.ForceField("amber10.xml", "tip3p.xml") pdb = app.PDBFile(pdb_filename) model = app.modeller.Modeller(pdb.topology, pdb.positions) model.addSolvent(forcefield, padding=0.4 * u.nanometer) system = forcefield.createSystem(model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles) states = [ ThermodynamicState(system=system, temperature=T_i[i]) for i in range(n_replicas) ] simulation = ReplicaExchange(states, [model.getPositions()] * n_replicas, nc_filename) # initialize the replica-exchange simulation simulation.minimize = False simulation.number_of_iterations = 2 # set the simulation to only run 2 iterations simulation.timestep = 2.0 * u.femtoseconds # set the timestep for integration simulation.nsteps_per_iteration = 50 # run 50 timesteps per iteration simulation.run() # run the simulation database = repex.netdf_io.NetCDFDatabase(nc_filename) simulation = ReplicaExchange(states, [model.getPositions()] * n_replicas, database) # initialize the replica-exchange simulation