Esempio n. 1
0
def load_lj(cutoff=None,
            dispersion_correction=False,
            switch_width=None,
            shift=False,
            charge=None,
            ewaldErrorTolerance=None):
    reduced_density = 0.90
    testsystem = testsystems.LennardJonesFluid(
        nparticles=2048,
        reduced_density=reduced_density,
        dispersion_correction=dispersion_correction,
        cutoff=cutoff,
        switch_width=switch_width,
        shift=shift,
        lattice=True,
        charge=charge,
        ewaldErrorTolerance=ewaldErrorTolerance)

    system, positions = testsystem.system, testsystem.positions

    timestep = 2 * u.femtoseconds
    langevin_timestep = 0.5 * u.femtoseconds
    # optimal xcghmc parms determined via hyperopt
    xcghmc_parms = dict(timestep=32.235339 * u.femtoseconds,
                        steps_per_hmc=16,
                        extra_chances=1,
                        collision_rate=None)

    return testsystem, system, positions, timestep, langevin_timestep
Esempio n. 2
0
def test_harmonic_standard_state():
    """
    Test that the expected harmonic standard state correction is close to our approximation

    Also ensures that PBC bonds are being computed and disabled correctly as expected
    """
    LJ_fluid = testsystems.LennardJonesFluid()

    # Create Harmonic restraint.
    restraint = yank.restraints.create_restraint('Harmonic',
                                                 restrained_receptor_atoms=1)

    # Determine other parameters.
    ligand_atoms = [3, 4, 5]
    topography = Topography(LJ_fluid.topology, ligand_atoms=ligand_atoms)
    sampler_state = states.SamplerState(positions=LJ_fluid.positions)
    thermodynamic_state = states.ThermodynamicState(system=LJ_fluid.system,
                                                    temperature=300.0 *
                                                    unit.kelvin)
    restraint.determine_missing_parameters(thermodynamic_state, sampler_state,
                                           topography)
    spring_constant = restraint.spring_constant

    # Compute standard-state volume for a single molecule in a box of size (1 L) / (avogadros number)
    liter = 1000.0 * unit.centimeters**3  # one liter
    box_volume = liter / (unit.AVOGADRO_CONSTANT_NA * unit.mole
                          )  # standard state volume
    analytical_shell_volume = (
        2 * math.pi / (spring_constant * thermodynamic_state.beta))**(3.0 / 2)
    analytical_standard_state_G = -math.log(
        box_volume / analytical_shell_volume)
    restraint_standard_state_G = restraint.get_standard_state_correction(
        thermodynamic_state)
    np.testing.assert_allclose(analytical_standard_state_G,
                               restraint_standard_state_G)
Esempio n. 3
0
def test_harmonic_standard_state():
    """
    Test that the expected harmonic standard state correction is close to our approximation

    Also ensures that PBC bonds are being computed and disabled correctly as expected
    """
    LJ_fluid = testsystems.LennardJonesFluid()
    receptor_atoms = [0, 1, 2]
    ligand_atoms = [3, 4, 5]
    thermodynamic_state = ThermodynamicState(temperature=300.0 * unit.kelvin)
    restraint = yank.restraints.create_restraints(
        'Harmonic', LJ_fluid.topology, thermodynamic_state, LJ_fluid.system,
        LJ_fluid.positions, receptor_atoms, ligand_atoms)
    spring_constant = restraint._determine_bond_parameters()[0]
    # Compute standard-state volume for a single molecule in a box of size (1 L) / (avogadros number)
    liter = 1000.0 * unit.centimeters**3  # one liter
    box_volume = liter / (unit.AVOGADRO_CONSTANT_NA * unit.mole
                          )  # standard state volume
    analytical_shell_volume = (2 * math.pi /
                               (spring_constant * restraint.beta))**(3.0 / 2)
    analytical_standard_state_G = -math.log(
        box_volume / analytical_shell_volume)
    restraint_standard_state_G = restraint.get_standard_state_correction()
    np.testing.assert_allclose(analytical_standard_state_G,
                               restraint_standard_state_G)
Esempio n. 4
0
def load_lj(cutoff=None,
            dispersion_correction=False,
            switch_width=None,
            shift=False,
            charge=None,
            ewaldErrorTolerance=None):
    reduced_density = 0.90
    testsystem = testsystems.LennardJonesFluid(
        nparticles=2048,
        reduced_density=reduced_density,
        dispersion_correction=dispersion_correction,
        cutoff=cutoff,
        switch_width=switch_width,
        shift=shift,
        lattice=True,
        charge=charge,
        ewaldErrorTolerance=ewaldErrorTolerance)

    system, positions = testsystem.system, testsystem.positions
    parameters = dict(
        timestep=2 * u.femtoseconds,
        langevin_timestep=0.5 * u.femtoseconds,
    )

    return testsystem, system, positions, parameters
Esempio n. 5
0
def test_BoreschLike_standard_state_analytical():
    """
    Perform some analytical tests of the Boresch standard state correction.
    Also ensures that PBC is being handled correctly
    """
    LJ_fluid = testsystems.LennardJonesFluid()

    # Define receptor and ligand atoms
    receptor_atoms = [0, 1, 2]
    ligand_atoms = [3, 4, 5]

    # Create restraint
    K_r = 1.0 * unit.kilocalories_per_mole / unit.angstrom**2
    r_0 = 0.0 * unit.angstrom
    K_theta = 0.0 * unit.kilocalories_per_mole / unit.degrees**2
    theta_0 = 30.0 * unit.degrees

    topography = Topography(LJ_fluid.topology, ligand_atoms=ligand_atoms)
    sampler_state = states.SamplerState(positions=LJ_fluid.positions)
    thermodynamic_state = states.ThermodynamicState(system=LJ_fluid.system,
                                                    temperature=300.0 *
                                                    unit.kelvin)

    for restraint_name in ['Boresch', 'PeriodicTorsionBoresch']:
        restraint = yank.restraints.create_restraint(
            'Boresch',
            restrained_receptor_atoms=receptor_atoms,
            restrained_ligand_atoms=ligand_atoms,
            K_r=K_r,
            r_aA0=r_0,
            K_thetaA=K_theta,
            theta_A0=theta_0,
            K_thetaB=K_theta,
            theta_B0=theta_0,
            K_phiA=K_theta,
            phi_A0=theta_0,
            K_phiB=K_theta,
            phi_B0=theta_0,
            K_phiC=K_theta,
            phi_C0=theta_0)

        # Determine other parameters
        restraint.determine_missing_parameters(thermodynamic_state,
                                               sampler_state, topography)

        # Compute standard-state volume for a single molecule in a box of size (1 L) / (avogadros number)
        liter = 1000.0 * unit.centimeters**3  # one liter
        box_volume = liter / (unit.AVOGADRO_CONSTANT_NA * unit.mole
                              )  # standard state volume
        analytical_shell_volume = (2 * math.pi /
                                   (K_r * thermodynamic_state.beta))**(3.0 / 2)
        analytical_standard_state_G = -math.log(
            box_volume / analytical_shell_volume)
        restraint_standard_state_G = restraint.get_standard_state_correction(
            thermodynamic_state)
        msg = 'Failed test for restraint {}'.format(restraint_name)
        np.testing.assert_allclose(analytical_standard_state_G,
                                   restraint_standard_state_G,
                                   err_msg=msg)
Esempio n. 6
0
# Set parameters for number of simulation replicates, number of iterations per simulation, and number of steps per iteration.
nreplicates = 100
niterations = 10000
nsteps_per_iteration = 25

# Compute real units.
kB = unit.BOLTZMANN_CONSTANT_kB * unit.AVOGADRO_CONSTANT_NA
density = reduced_density / (sigma**3)
temperature = reduced_temperature * epsilon / kB
pressure = reduced_pressure * epsilon / (sigma**3)
kT = kB * temperature

# Create the Lennard-Jones fluid.
testsystem = testsystems.LennardJonesFluid(nparticles=nparticles,
                                           mass=mass,
                                           sigma=sigma,
                                           epsilon=epsilon,
                                           reduced_density=reduced_density)

# Construct initial positions by minimization.
print "Minimizing to obtain initial positions..."
integrator = openmm.LangevinIntegrator(temperature, collision_rate, timestep)
context = openmm.Context(testsystem.system, integrator)
context.setPositions(testsystem.positions)
openmm.LocalEnergyMinimizer.minimize(context)
state = context.getState(getPositions=True)
initial_positions = state.getPositions(asNumpy=True)
del context, integrator, state

# DEBUG: Write initial positions.
outfile = open("initial.pdb", 'w')
Esempio n. 7
0
                 test_system['receptor_atoms'], test_system['ligand_atoms'])
    return


#=============================================================================================
# TEST SYSTEM DEFINITIONS
#=============================================================================================

test_systems = dict()
test_systems['Lennard-Jones cluster'] = {
    'test': testsystems.LennardJonesCluster(),
    'ligand_atoms': range(0, 1),
    'receptor_atoms': range(1, 2)
}
test_systems['Lennard-Jones fluid without dispersion correction'] = {
    'test': testsystems.LennardJonesFluid(dispersion_correction=False),
    'ligand_atoms': range(0, 1),
    'receptor_atoms': range(1, 2)
}
test_systems['Lennard-Jones fluid with dispersion correction'] = {
    'test': testsystems.LennardJonesFluid(dispersion_correction=True),
    'ligand_atoms': range(0, 1),
    'receptor_atoms': range(1, 2)
}
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':
Esempio n. 8
0
import pymbar
import itertools
import pandas as pd
import lb_loader
import simtk.openmm.app as app
import numpy as np
import simtk.openmm as mm
from simtk import unit as u
from openmmtools import hmc_integrators, testsystems
pd.set_option('display.width', 1000)

collision_rate = 10000.0 / u.picoseconds
temperature = 25. * u.kelvin

testsystem = testsystems.LennardJonesFluid()

system, positions = testsystem.system, testsystem.positions
system.addForce(mm.MonteCarloBarostat(1.0 * u.atmospheres, temperature, 50))

integrator = mm.LangevinIntegrator(temperature, 1.0 / u.picoseconds,
                                   0.5 * u.femtoseconds)
context = mm.Context(system, integrator)
context.setPositions(positions)
context.setPeriodicBoxVectors(*boxes)
context.setVelocitiesToTemperature(temperature)
integrator.step(25000)
positions = context.getState(getPositions=True).getPositions()

x = []
for i in range(1000):
    state = context.getState(getParameters=True, getPositions=True)
Esempio n. 9
0
import simtk.openmm.app as app
import simtk.openmm as mm
from simtk import unit as u
from openmmtools import hmc_integrators, testsystems, integrators

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


platform_name = "OpenCL"

temperature = 300. * u.kelvin
testsystem = testsystems.LennardJonesFluid(nparticles=2048)
timestep = 0.01 * u.femtoseconds
nsteps = 10
steps_per_hmc = 1
groups = [(0, 1)]
collision_rate = None

integrators = [
hmc_integrators.GHMCRESPAIntegrator(temperature=temperature, steps_per_hmc=steps_per_hmc, timestep=timestep, groups=groups, collision_rate=collision_rate),
hmc_integrators.GHMCIntegrator(temperature=temperature, steps_per_hmc=steps_per_hmc, timestep=timestep, collision_rate=collision_rate),
]

platform = mm.Platform.getPlatformByName(platform_name)

for integrator in integrators:
    print(integrator)

    simulation = app.Simulation(testsystem.topology, testsystem.system, integrator, platform=platform)
    simulation.context.setPositions(testsystem.positions)
    simulation.context.setVelocitiesToTemperature(temperature)