def test_nose_hoover_integrator():
    """
    Test Nose-Hoover thermostat by ensuring that a short run
    conserves the system and bath energy to a reasonable tolerance.
    The temperature could, in principle, be tested also but that would
    require longer runs to guarantee stabilization.

    """
    temperature = 298*unit.kelvin
    testsystem = testsystems.WaterBox()
    integrator = NoseHooverChainVelocityVerletIntegrator(temperature)
    # Create Context and initialize positions.
    context = openmm.Context(testsystem.system, integrator)
    context.setPositions(testsystem.positions)
    context.setVelocitiesToTemperature(temperature)
    integrator.step(150) # Short equilibration
    energies = []
    for n in range(100):
        integrator.step(1)
        state = context.getState(getEnergy=True)
        KE = state.getKineticEnergy().value_in_unit(unit.kilojoules_per_mole)
        PE = state.getPotentialEnergy().value_in_unit(unit.kilojoules_per_mole)
        bathKE = integrator.getGlobalVariableByName('bathKE')
        bathPE = integrator.getGlobalVariableByName('bathPE')
        conserved = KE + PE + bathKE + bathPE
        energies.append(conserved)
    # Compute maximum deviation from the mean for conserved energies
    meanenergies = np.mean(energies)
    maxdeviation = np.amax(np.abs(energies - meanenergies)/meanenergies)
    assert maxdeviation < 1e-3
Exemple #2
0
def tip3p():
    # Create a TIP3P water box
    from openmmtools import testsystems
    testsystem = testsystems.WaterBox(box_edge=25.0 * unit.angstroms,
                                      cutoff=9 * unit.angstroms,
                                      model='tip3p',
                                      switch_width=1.5 * unit.angstroms,
                                      constrained=True,
                                      dispersion_correction=True,
                                      nonbondedMethod=app.PME,
                                      ewaldErrorTolerance=1.0e-6)
    testsystem_name = testsystem.__class__.__name__
    fix_system(testsystem.system)
    return [testsystem.system, testsystem.positions, testsystem_name]
def test_nose_hoover_integrator():
    """
    Test Nose-Hoover thermostat by ensuring that a short run
    conserves the system and bath energy to a reasonable tolerance.
    Also test that the target temperature is rougly matched (+- 10 K).
    """
    temperature = 298 * unit.kelvin
    testsystem = testsystems.WaterBox()
    num_dof = 3 * testsystem.system.getNumParticles(
    ) - testsystem.system.getNumConstraints()
    integrator = NoseHooverChainVelocityVerletIntegrator(
        testsystem.system, temperature)
    # Create Context and initialize positions.
    context = openmm.Context(testsystem.system, integrator)
    context.setPositions(testsystem.positions)
    context.setVelocitiesToTemperature(temperature)
    integrator.step(200)  # Short equilibration
    energies = []
    temperatures = []
    for n in range(100):
        integrator.step(1)
        state = context.getState(getEnergy=True)
        # temperature
        kinE = state.getKineticEnergy()
        temp = (2.0 * kinE /
                (num_dof * unit.MOLAR_GAS_CONSTANT_R)).value_in_unit(
                    unit.kelvin)
        temperatures.append(temp)
        # total energy
        KE = kinE.value_in_unit(unit.kilojoules_per_mole)
        PE = state.getPotentialEnergy().value_in_unit(unit.kilojoules_per_mole)
        bathKE = integrator.getGlobalVariableByName('bathKE')
        bathPE = integrator.getGlobalVariableByName('bathPE')
        conserved = KE + PE + bathKE + bathPE
        energies.append(conserved)

    # Compute maximum deviation from the mean for conserved energies
    meanenergies = np.mean(energies)
    maxdeviation = np.amax(np.abs(energies - meanenergies) / meanenergies)
    assert maxdeviation < 1e-3

    # Coarse check for target temperature
    mean_temperature = np.mean(temperatures)
    assert abs(mean_temperature -
               temperature.value_in_unit(unit.kelvin)) < 10.0, mean_temperature
Exemple #4
0
    def setup_class(cls):
        """Create the thermodynamic states used in the test suite."""
        water_test = testsystems.WaterBox(box_edge=2.0*unit.nanometer)
        cls.water_300k = states.ThermodynamicState(water_test.system, 300*unit.kelvin)
        cls.water_310k = states.ThermodynamicState(water_test.system, 310*unit.kelvin)
        cls.water_310k_1atm = states.ThermodynamicState(water_test.system, 310*unit.kelvin,
                                                        1*unit.atmosphere)

        cls.verlet_2fs = openmm.VerletIntegrator(2.0*unit.femtosecond)
        cls.verlet_3fs = openmm.VerletIntegrator(3.0*unit.femtosecond)
        cls.langevin_2fs_310k = openmm.LangevinIntegrator(310*unit.kelvin, 5.0/unit.picosecond,
                                                          2.0*unit.femtosecond)

        cls.compatible_states = [cls.water_300k, cls.water_310k]
        cls.compatible_integrators = [cls.verlet_2fs, cls.verlet_3fs]

        cls.incompatible_states = [cls.water_310k, cls.water_310k_1atm]
        cls.incompatible_integrators = [cls.verlet_2fs, cls.langevin_2fs_310k]
import numpy as np
import pandas as pd
import simtk.openmm as mm
from simtk import unit as u
from openmmtools import hmc_integrators, testsystems

steps_per_hmc = 12
collision_rate = 1.0 / u.picoseconds
n_steps = 5000
temperature = 300. * u.kelvin

#testsystem = testsystems.FlexibleWaterBox(box_edge=3.18 * u.nanometers)  # Around 1060 molecules of water
testsystem = testsystems.WaterBox(box_edge=3.18 * u.nanometers)  # Around 1060 molecules of water
system = testsystem.system

integrator = mm.LangevinIntegrator(temperature, 1.0 / u.picoseconds, 0.25 * u.femtoseconds)
context = mm.Context(testsystem.system, integrator)
context.setPositions(testsystem.positions)
context.setVelocitiesToTemperature(temperature)
integrator.step(5000)
positions = context.getState(getPositions=True).getPositions()

def test_hmc(timestep, steps_per_hmc, alpha):
    timestep = timestep * u.femtoseconds
    integrator = hmc_integrators.RampedHMCIntegrator(temperature, steps_per_hmc, timestep, max_boost=alpha)
    context = mm.Context(system, integrator)
    context.setPositions(positions)
    context.setVelocitiesToTemperature(temperature)
    integrator.step(n_steps)
    return integrator.acceptance_rate
Exemple #6
0
def load(sysname):
    cutoff = 0.9 * u.nanometers
    temperature = 300. * u.kelvin
    langevin_timestep = 0.5 * u.femtoseconds
    timestep = 2 * u.femtoseconds
    equil_steps = 40000
    groups = [(0, 1)]
    steps_per_hmc = 25

    if sysname == "chargedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            charge=0.15 * u.elementary_charge)

    if sysname == "chargedswitchedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers)

    if sysname == "chargedlongljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers, charge=0.15 * u.elementary_charge)

    if sysname == "chargedswitchedlongljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers,
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers)

    if sysname == "chargedswitchedaccuratelongljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers,
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers,
            ewaldErrorTolerance=5E-5)

    if sysname == "chargedswitchedaccurateljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers,
            ewaldErrorTolerance=5E-5)

    if sysname == "ljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj()

    if sysname == "longljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers)

    if sysname == "shortljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=0.90 * u.nanometers)

    if sysname == "shiftedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            shift=True)

    if sysname == "switchedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            switch_width=0.34 * u.nanometers)

    if sysname == "switchedshortljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=0.90 * u.nanometers, switch_width=0.34 * u.nanometers)

    if sysname == "cluster":
        testsystem = testsystems.LennardJonesCluster(nx=8, ny=8, nz=8)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 40 * u.femtoseconds

    if sysname == "shortbigcluster":
        testsystem = testsystems.LennardJonesCluster(nx=20,
                                                     ny=20,
                                                     nz=20,
                                                     cutoff=0.75 *
                                                     u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 10 * u.femtoseconds

    if sysname == "switchedshortbigcluster":
        testsystem = testsystems.LennardJonesCluster(
            nx=20,
            ny=20,
            nz=20,
            cutoff=0.75 * u.nanometers,
            switch_width=0.1 * u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 10 * u.femtoseconds

    if sysname == "bigcluster":
        testsystem = testsystems.LennardJonesCluster(nx=20,
                                                     ny=20,
                                                     nz=20,
                                                     cutoff=1.25 *
                                                     u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 10 * u.femtoseconds

    if sysname == "shortcluster":
        testsystem = testsystems.LennardJonesCluster(nx=8,
                                                     ny=8,
                                                     nz=8,
                                                     cutoff=0.75 *
                                                     u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 40 * u.femtoseconds

    if sysname == "shortwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=0.9 * u.nanometers,
            switch_width=None)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "shortswitchedwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=0.9 * u.nanometers,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "water":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=None)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "switchedwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "switchedaccuratewater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(
            system, nonbonded=0, fft=1, others=0)  # We may want to try reduce

    if sysname == "switchedaccurateflexiblewater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5,
            constrained=False)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        # Using these groups for hyperopt-optimal RESPA integrators
        #hmc_integrators.guess_force_groups(system, nonbonded=0, others=1, fft=0)
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           others=1,
                                           fft=0)
        equil_steps = 100000
        langevin_timestep = 0.25 * u.femtoseconds

    if sysname == "switchedaccuratebigflexiblewater":
        testsystem = testsystems.WaterBox(
            box_edge=10.0 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5,
            constrained=False)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        # Using these groups for hyperopt-optimal RESPA integrators
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           others=0,
                                           fft=1)
        equil_steps = 100000
        langevin_timestep = 0.1 * u.femtoseconds

    if sysname == "switchedaccuratestiffflexiblewater":

        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5,
            constrained=False)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        # Using these groups for hyperopt-optimal RESPA integrators
        #hmc_integrators.guess_force_groups(system, nonbonded=0, others=1, fft=0)
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           others=1,
                                           fft=0)
        equil_steps = 100000
        langevin_timestep = 0.25 * u.femtoseconds

        FACTOR = 10.0
        # Make bonded terms stiffer to highlight RESPA advantage
        for force in system.getForces():
            if type(force) == mm.HarmonicBondForce:
                for i in range(force.getNumBonds()):
                    (a0, a1, length, strength) = force.getBondParameters(i)
                    force.setBondParameters(i, a0, a1, length,
                                            strength * FACTOR)

            elif type(force) == mm.HarmonicAngleForce:
                for i in range(force.getNumAngles()):
                    (a0, a1, a2, length,
                     strength) = force.getAngleParameters(i)
                    force.setAngleParameters(i, a0, a1, a2, length,
                                             strength * FACTOR)

    if sysname == "switchedaccuratenptwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        system.addForce(
            mm.MonteCarloBarostat(1.0 * u.atmospheres, temperature, 1))

    if sysname == "longswitchedwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.5 * u.nanometers,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "rfwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            nonbondedMethod=app.CutoffPeriodic,
            switch_width=None)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "switchedrfwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            nonbondedMethod=app.CutoffPeriodic,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "longswitchedrfwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.5 * u.nanometers,
            nonbondedMethod=app.CutoffPeriodic,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "density":
        system, positions = load_lb(hydrogenMass=3.0 * u.amu)
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           fft=1,
                                           others=0)
        groups = [(0, 4), (1, 1)]
        timestep = 2.0 * u.femtoseconds

    if sysname == "dhfr":
        testsystem = testsystems.DHFRExplicit(nonbondedCutoff=1.1 *
                                              u.nanometers,
                                              nonbondedMethod=app.PME,
                                              switch_width=2.0 * u.angstroms,
                                              ewaldErrorTolerance=5E-5)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           fft=2,
                                           others=0)
        groups = [(0, 4), (1, 2), (2, 1)]
        timestep = 0.75 * u.femtoseconds
        equil_steps = 10000

    if sysname == "src":
        testsystem = testsystems.SrcExplicit(nonbondedCutoff=1.1 *
                                             u.nanometers,
                                             nonbondedMethod=app.PME,
                                             switch_width=2.0 * u.angstroms,
                                             ewaldErrorTolerance=5E-5)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           fft=1,
                                           others=0)
        groups = [(0, 2), (1, 1)]
        timestep = 0.25 * u.femtoseconds
        equil_steps = 1000

    if sysname == "ho":
        K = 90.0 * u.kilocalories_per_mole / u.angstroms**2
        mass = 39.948 * u.amu
        timestep = np.sqrt(mass / K) * 0.4
        testsystem = testsystems.HarmonicOscillatorArray()
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 1)]

    if sysname == "customho":
        timestep = 1000.0 * u.femtoseconds
        testsystem = testsystems.CustomExternalForcesTestSystem()
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 1)]

    if sysname == "customsplitho":
        timestep = 1000.0 * u.femtoseconds
        energy_expressions = ("0.75 * (x^2 + y^2 + z^2)",
                              "0.25 * (x^2 + y^2 + z^2)")
        testsystem = testsystems.CustomExternalForcesTestSystem(
            energy_expressions=energy_expressions)
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 2), (1, 1)]

    if sysname == "alanine":
        testsystem = testsystems.AlanineDipeptideImplicit()
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 2), (1, 1)]
        timestep = 2.0 * u.femtoseconds
        hmc_integrators.guess_force_groups(system, nonbonded=1, others=0)
        #remove_cmm(system)  # Unrolled shouldn't need this
        equil_steps = 10000

    if sysname == "alanineexplicit":
        testsystem = testsystems.AlanineDipeptideExplicit(
            cutoff=1.1 * u.nanometers,
            switch_width=2 * u.angstrom,
            ewaldErrorTolerance=5E-5)
        system, positions = testsystem.system, testsystem.positions
        #groups = [(0, 2), (1, 1), (2, 1)]
        #groups = [(0, 2), (1, 1)]
        timestep = 1.0 * u.femtoseconds
        #hmc_integrators.guess_force_groups(system, nonbonded=1, others=0, fft=2)
        #hmc_integrators.guess_force_groups(system, nonbonded=0, others=0, fft=1)
        groups = [(0, 1), (1, 2)]
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=0,
                                           others=1,
                                           fft=0)

        #remove_cmm(system)  # Unrolled doesn't need this
        equil_steps = 4000

    # guess force groups

    if "ljbox" in sysname:
        timestep = 25 * u.femtoseconds
        temperature = 25. * u.kelvin
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0, fft=1)
        groups = [(0, 2), (1, 1)]
        equil_steps = 10000
        steps_per_hmc = 15

    if sysname == "amoeba":
        testsystem = testsystems.AMOEBAIonBox()
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=0,
                                           fft=1,
                                           others=0)

    return system, positions, groups, temperature, timestep, langevin_timestep, testsystem, equil_steps, steps_per_hmc
Exemple #7
0
file1.write('%1.3f \t %1.3f\n\n'%(L_side, pme_cutoff))

for Method in [openmm.app.NoCutoff ,openmm.app.Ewald, openmm.app.PME]:
    
    print(Method)
    file1.write('\t' + str(Method) + '\n\n')

    Ns = numpy.arange(200, 1200, 200)
    file1.write('N\t\t time\n')
    for N in Ns:
#        print(N)
        N_steps = int(N)

# Try: nonbondedMethod: NoCutoff, Ewald, PME
        if str(Method) == "NoCutoff":
             water_box = testsystems.WaterBox(box_edge=L_side*unit.nanometer, nonbondedMethod = Method)
#             print(str(Method) + 'check')

        else:
            water_box = testsystems.WaterBox(box_edge=L_side*unit.nanometer, nonbondedMethod = Method, nonbondedCutoff=pme_cutoff*unit.nanometers, ewaldErrorTolerance = 0.001)
        system = water_box.system

        integrator = openmm.LangevinIntegrator(300*unit.kelvin, 1/unit.picosecond, 2*unit.femtoseconds)
        simulation = openmm.app.simulation.Simulation(water_box.topology, system, integrator)
        simulation.context.setPositions(water_box.positions)
        simulation.reporters.append(openmm.app.StateDataReporter(stdout, N_steps, step = False, potentialEnergy = True))

#        if N == 500:
#            print("check!")

        tic = time.time()
    def test_ncmc_update_parameters_in_context(self):
        """
        Testing that the protocol work is correctly calculated in cases when the parameters are updated using
        context.updateParametersInContext() and the integrator is a compound integrator. The NCMC scheme tested below
        is based on the one used by the saltswap and protons code-bases.
        """
        from simtk.openmm import app
        from openmmtools.constants import kB

        size = 20.0
        temperature = 298.0 * unit.kelvin
        kT = kB * temperature
        nonbonded_method = 'CutoffPeriodic'
        platform_name = 'CPU'
        timestep = 1. * unit.femtoseconds
        collision_rate = 90. / unit.picoseconds

        wbox = testsystems.WaterBox(box_edge=size*unit.angstrom, cutoff=9.*unit.angstrom, nonbondedMethod=getattr(app, nonbonded_method))

        integrator = integrators.ExternalPerturbationLangevinIntegrator(splitting="V R O R V", temperature=temperature, timestep=timestep, collision_rate=collision_rate)

        # Create context
        platform = openmm.Platform.getPlatformByName(platform_name)
        context = openmm.Context(wbox.system, integrator, platform)
        context.setPositions(wbox.positions)
        context.setPositions(wbox.positions)
        context.setVelocitiesToTemperature(temperature)

        def switchoff(force, context, frac=0.9):
            force.setParticleParameters(0, charge=-0.834 * frac, sigma=0.3150752406575124*frac, epsilon=0.635968 * frac)
            force.setParticleParameters(1, charge=0.417 * frac, sigma=0, epsilon=1 * frac)
            force.setParticleParameters(2, charge=0.417 * frac, sigma=0, epsilon=1 * frac)
            force.updateParametersInContext(context)

        def switchon(force, context):
            force.setParticleParameters(0, charge=-0.834, sigma=0.3150752406575124, epsilon=0.635968)
            force.setParticleParameters(1, charge=0.417, sigma=0, epsilon=1)
            force.setParticleParameters(2, charge=0.417, sigma=0, epsilon=1)
            force.updateParametersInContext(context)

        force = wbox.system.getForce(2)  # Non-bonded force.

        # Number of NCMC steps
        nsteps = 20
        niterations = 3

        for i in range(niterations):
            external_protocol_work = 0.0
            integrator.reset_protocol_work()
            integrator.step(1)
            for step in range(nsteps):
                fraction = float(step + 1) / float(nsteps)
                initial_energy = context.getState(getEnergy=True).getPotentialEnergy()
                switchoff(force, context, frac=fraction)
                final_energy = context.getState(getEnergy=True).getPotentialEnergy()
                external_protocol_work += (final_energy - initial_energy) / kT
                integrator.step(1)
            integrator_protocol_work = integrator.get_protocol_work(dimensionless=True)
            assert abs(external_protocol_work - integrator_protocol_work) < 1.E-5
            # Return to unperturbed state
            switchon(force, context)
Exemple #9
0
}
test_systems[
    'TIP3P with reaction field, no charges, no switch, no dispersion correction'] = {
        'test':
        testsystems.DischargedWaterBox(dispersion_correction=False,
                                       switch=False,
                                       nonbondedMethod=app.CutoffPeriodic),
        'ligand_atoms':
        range(0, 3),
        'receptor_atoms':
        range(3, 6)
    }
test_systems['TIP3P with reaction field, switch, no dispersion correction'] = {
    'test':
    testsystems.WaterBox(dispersion_correction=False,
                         switch=True,
                         nonbondedMethod=app.CutoffPeriodic),
    'ligand_atoms':
    range(0, 3),
    'receptor_atoms':
    range(3, 6)
}
test_systems['TIP3P with reaction field, no switch, dispersion correction'] = {
    'test':
    testsystems.WaterBox(dispersion_correction=True,
                         switch=False,
                         nonbondedMethod=app.CutoffPeriodic),
    'ligand_atoms':
    range(0, 3),
    'receptor_atoms':
    range(3, 6)
Exemple #10
0
        """The total number of attempted HMC moves."""
        return self.getGlobalVariableByName("ntrials")

    @property
    def acceptance_rate(self):
        """The acceptance rate: n_accept  / n_trials."""
        return self.n_accept / float(self.n_trials)


f = lambda x: (x.getPotentialEnergy(), x.getKineticEnergy(),
               x.getKineticEnergy() + x.getPotentialEnergy())

temperature = 300. * u.kelvin
testsystem = testsystems.WaterBox(box_edge=10.0 * u.nanometers,
                                  cutoff=1.1 * u.nanometers,
                                  switch_width=3.0 * u.angstroms,
                                  ewaldErrorTolerance=5E-5,
                                  constrained=False)
timestep = 0.1 * u.femtoseconds
nsteps = 300

print("*" * 80)
print("force groups:")
for force in testsystem.system.getForces():
    print(force, force.getForceGroup())

print("*" * 80)
print("Platform, integrator / acceptance rate, Enew")

for platform_name in ["CUDA", "OpenCL", "CPU"]:
    platform = mm.Platform.getPlatformByName(platform_name)