Пример #1
0
def executeFarForceTest(OuterForceType, adjustment):
    rswitch_inner = 6.5 * unit.angstroms
    rcut_inner = 7.0 * unit.angstroms
    rswitch = 9.5 * unit.angstroms
    rcut = 10 * unit.angstroms
    case = 'tests/data/q-SPC-FW'
    pdb = app.PDBFile(case + '.pdb')
    forcefield = app.ForceField(case + '.xml')

    system = forcefield.createSystem(pdb.topology,
                                     nonbondedMethod=openmm.app.PME)
    nbforce = atomsmm.hijackForce(system, atomsmm.findNonbondedForce(system))
    innerforce = atomsmm.NearNonbondedForce(rcut_inner, rswitch_inner,
                                            adjustment)
    innerforce.importFrom(nbforce).addTo(system)
    outerforce = OuterForceType(innerforce, rcut, rswitch).setForceGroup(2)
    outerforce.importFrom(nbforce).addTo(system)
    potential = atomsmm.splitPotentialEnergy(system, pdb.topology,
                                             pdb.positions)["Total"]

    refsys = forcefield.createSystem(pdb.topology,
                                     nonbondedMethod=openmm.app.PME,
                                     nonbondedCutoff=rcut,
                                     removeCMMotion=True)
    force = refsys.getForce(refsys.getNumForces() - 2)
    force.setUseSwitchingFunction(True)
    force.setSwitchingDistance(rswitch)
    refpot = atomsmm.splitPotentialEnergy(refsys, pdb.topology,
                                          pdb.positions)["Total"]

    assert potential / potential.unit == pytest.approx(refpot / refpot.unit)
Пример #2
0
def execute(shifted):
    rswitch_inner = 6.5*unit.angstroms
    rcut_inner = 7.0*unit.angstroms
    rswitch = 9.5*unit.angstroms
    rcut = 10*unit.angstroms
    case = 'tests/data/q-SPC-FW'
    pdb = app.PDBFile(case + '.pdb')
    forcefield = app.ForceField(case + '.xml')

    system = forcefield.createSystem(pdb.topology)
    nbforce = atomsmm.hijackForce(system, atomsmm.findNonbondedForce(system))
    exceptions = atomsmm.NonbondedExceptionsForce()
    exceptions.importFrom(nbforce).addTo(system)
    innerforce = atomsmm.NearNonbondedForce(rcut_inner, rswitch_inner, shifted).setForceGroup(1)
    innerforce.importFrom(nbforce).addTo(system)
    outerforce = atomsmm.FarNonbondedForce(innerforce, rcut, rswitch).setForceGroup(2)
    outerforce.importFrom(nbforce).addTo(system)
    potential = atomsmm.splitPotentialEnergy(system, pdb.topology, pdb.positions)

    refsys = forcefield.createSystem(pdb.topology,
                                     nonbondedMethod=openmm.app.PME,
                                     nonbondedCutoff=rcut,
                                     removeCMMotion=True)
    force = refsys.getForce(refsys.getNumForces()-2)
    force.setUseSwitchingFunction(True)
    force.setSwitchingDistance(rswitch)
    refpot = atomsmm.splitPotentialEnergy(refsys, pdb.topology, pdb.positions)

    E = potential["Total"]
    refE = refpot["Total"]
    assert E/E.unit == pytest.approx(refE/refE.unit)

    E = potential["CustomBondForce"] + potential["NonbondedForce"]
    refE = refpot["NonbondedForce"]
    assert E/E.unit == pytest.approx(refE/refE.unit)
Пример #3
0
def executeNearForceTest(adjustment, target):
    rcut = 10 * unit.angstroms
    rswitch = 9.5 * unit.angstroms
    case = 'tests/data/q-SPC-FW'
    pdb = app.PDBFile(case + '.pdb')
    forcefield = app.ForceField(case + '.xml')
    system = forcefield.createSystem(pdb.topology,
                                     nonbondedMethod=app.CutoffPeriodic)
    force = atomsmm.NearNonbondedForce(rcut, rswitch, adjustment)
    force.importFrom(
        atomsmm.hijackForce(system,
                            atomsmm.findNonbondedForce(system))).addTo(system)
    integrator = openmm.VerletIntegrator(0.0 * unit.femtoseconds)
    platform = openmm.Platform.getPlatformByName('Reference')
    simulation = app.Simulation(pdb.topology, system, integrator, platform)
    simulation.context.setPositions(pdb.positions)
    state = simulation.context.getState(getEnergy=True)
    potential = state.getPotentialEnergy()
    assert potential / potential.unit == pytest.approx(target)
Пример #4
0
# case = 'q-SPC-FW'
case = 'emim_BCN4_Jiung2014'

pdb = app.PDBFile('../../tests/data/%s.pdb' % case)
forcefield = app.ForceField('../../tests/data/%s.xml' % case)
system = forcefield.createSystem(pdb.topology,
                                 nonbondedMethod=openmm.app.PME,
                                 nonbondedCutoff=rcut,
                                 rigidWater=False)

nbforceIndex = atomsmm.findNonbondedForce(system)
dof = atomsmm.countDegreesOfFreedom(system)
if mts:
    nbforce = atomsmm.hijackForce(system, nbforceIndex)
    exceptions = atomsmm.NonbondedExceptionsForce().setForceGroup(0)
    innerForce = atomsmm.NearNonbondedForce(rcutIn, rswitchIn,
                                            shift).setForceGroup(1)
    outerForce = atomsmm.FarNonbondedForce(innerForce, rcut,
                                           rswitch).setForceGroup(2)
    for force in [exceptions, innerForce, outerForce]:
        force.importFrom(nbforce)
        force.addTo(system)
    NVE = atomsmm.RespaPropagator([2, 2, 1])
    integrator = atomsmm.GlobalThermostatIntegrator(dt, NVE)
else:
    nbforce = system.getForce(nbforceIndex)
    nbforce.setUseSwitchingFunction(True)
    nbforce.setSwitchingDistance(rswitch)
    # thermostat = atomsmm.VelocityRescalingPropagator(temp, dof, 1/friction)
    thermostat = atomsmm.NoseHooverLangevinPropagator(temp, dof, 1 / friction,
                                                      friction)
    NVE = atomsmm.VelocityVerletPropagator()