コード例 #1
0
    def test_write_xml_parameters_methanol_ions_energy(self):
        """ Test writing XML parameter files from Charmm parameter files, reading them back into OpenMM ForceField, and computing energy of methanol and NaCl """

        params = openmm.OpenMMParameterSet.from_parameterset(
                pmd.charmm.CharmmParameterSet(get_fn('par_all36_cgenff.prm'),
                                              get_fn('top_all36_cgenff.rtf'),
                                              get_fn('toppar_water_ions.str')) # WARNING: contains duplicate water templates
        )
        del params.residues['TP3M'] # Delete to avoid duplicate water template topologies
        ffxml_filename = get_fn('charmm_conv.xml', written=True)
        params.write(ffxml_filename,
                     provenance=dict(
                         OriginalFile='par_all36_cgenff.prm, top_all36_cgenff.rtf, toppar_water_ions.str',
                         Reference='MacKerrell'
                     )
        )
        forcefield = app.ForceField(ffxml_filename)
        # Parameterize methanol and ions in vacuum
        pdbfile = app.PDBFile(get_fn('methanol_ions.pdb'))
        system = forcefield.createSystem(pdbfile.topology, nonbondedMethod=app.NoCutoff)
        integrator = mm.VerletIntegrator(1.0*u.femtoseconds)
        context = mm.Context(system, integrator, CPU)
        context.setPositions(pdbfile.positions)
        ffxml_potential = context.getState(getEnergy=True).getPotentialEnergy() / u.kilocalories_per_mole
        del context, integrator
        # Compute energy via ParmEd reader
        psf = CharmmPsfFile(get_fn('methanol_ions.psf'))
        system = psf.createSystem(params)
        integrator = mm.VerletIntegrator(1.0*u.femtoseconds)
        context = mm.Context(system, integrator, CPU)
        context.setPositions(pdbfile.positions)
        parmed_potential = context.getState(getEnergy=True).getPotentialEnergy() / u.kilocalories_per_mole
        del context, integrator
        # Ensure potentials are almost equal
        self.assertAlmostEqual(ffxml_potential, parmed_potential)
コード例 #2
0
    def test_round_trip(self):
        """ Test ParmEd -> OpenMM round trip with Gromacs system """
        # Use DPPC to get RB-torsions tested. Also check that it initially fails
        # with the CustomNonbondedForce
        top = load_file(os.path.join(get_fn('12.DPPC'), 'topol.top'),
                        xyz=os.path.join(get_fn('12.DPPC'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        system = top.createSystem()

        def bad_system():
            return openmm.load_topology(top.topology, system).createSystem()

        self.assertTrue(
            openmm.load_topology(top.topology, system).unknown_functional)
        self.assertRaises(ParmedError, bad_system)
        for i in range(len(system.getForces())):
            if isinstance(system.getForce(i), mm.CustomNonbondedForce):
                system.removeForce(i)
                break
        system2 = openmm.load_topology(top.topology, system).createSystem()
        con1 = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        con2 = mm.Context(system2, mm.VerletIntegrator(0.001), CPU)
        con1.setPositions(top.positions)
        con2.setPositions(top.positions)
        ene1 = energy_decomposition(top, con1)
        ene2 = energy_decomposition(top, con2)
        self.assertAlmostEqual(ene1['bond'], ene2['bond'])
        self.assertAlmostEqual(ene1['angle'], ene2['angle'])
        self.assertAlmostEqual(ene1['dihedral'], ene2['dihedral'])
        self.assertAlmostEqual(ene1['improper'], ene2['improper'])
        self.assertAlmostEqual(ene1['rb_torsion'], ene2['rb_torsion'])
        self.assertAlmostEqual(ene1['nonbonded'], ene2['nonbonded'])
コード例 #3
0
 def test_chamber_expanded_exclusions(self):
     """ Tests converting Gromacs to Chamber parm w/ modified exceptions """
     # Now let's modify an exception parameter so that it needs type
     # expansion, and ensure that it is handled correctly
     top = load_file(get_fn('1aki.charmm27.solv.top'),
                     xyz=get_fn('1aki.charmm27.solv.gro'))
     gsystem1 = top.createSystem(nonbondedCutoff=8 * u.angstroms,
                                 nonbondedMethod=app.PME)
     gcon1 = mm.Context(gsystem1, mm.VerletIntegrator(1 * u.femtosecond),
                        CPU)
     gcon1.setPositions(top.positions)
     top.adjust_types.append(to.NonbondedExceptionType(0, 0, 1))
     top.adjust_types.claim()
     top.adjusts[10].type = top.adjust_types[-1]
     gsystem2 = top.createSystem(nonbondedCutoff=8 * u.angstroms,
                                 nonbondedMethod=app.PME)
     gcon2 = mm.Context(gsystem2, mm.VerletIntegrator(1 * u.femtosecond),
                        CPU)
     gcon2.setPositions(top.positions)
     e1 = gcon1.getState(getEnergy=True).getPotentialEnergy()
     e1 = e1.value_in_unit(u.kilocalories_per_mole)
     e2 = gcon2.getState(getEnergy=True).getPotentialEnergy()
     e2 = e2.value_in_unit(u.kilocalories_per_mole)
     self.assertGreater(abs(e2 - e1), 1e-2)
     # Convert to chamber now
     parm = amber.ChamberParm.from_structure(top)
     asystem = parm.createSystem(nonbondedCutoff=8 * u.angstroms,
                                 nonbondedMethod=app.PME)
     acon = mm.Context(asystem, mm.VerletIntegrator(1 * u.femtosecond), CPU)
     acon.setPositions(top.positions)
     e3 = acon.getState(getEnergy=True).getPotentialEnergy()
     e3 = e3.value_in_unit(u.kilocalories_per_mole)
     self.assertLess(abs(e2 - e3), 1e-2)
コード例 #4
0
    def test_geometric_combining_rule_energy(self):
        """ Tests converting geom. comb. rule energy from Gromacs to Amber """
        top = load_file(os.path.join(get_fn('05.OPLS'), 'topol.top'),
                        xyz=os.path.join(get_fn('05.OPLS'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'geometric')
        del top.rb_torsions[:]
        parm = load_file(get_saved_fn('opls.parm7'),
                         xyz=os.path.join(get_fn('05.OPLS'), 'conf.gro'))
        self.assertEqual(parm.combining_rule, 'geometric')
        self.assertFalse(parm.has_NBFIX())

        sysg = top.createSystem()
        sysa = parm.createSystem()

        cong = mm.Context(sysg, mm.VerletIntegrator(0.001), CPU)
        cona = mm.Context(sysa, mm.VerletIntegrator(0.001), CPU)

        cong.setPositions(top.positions)
        cona.setPositions(top.positions)

        self.check_energies(top, cong, parm, cona)

        # Make an NBFIX
        self.assertFalse(parm.has_NBFIX())
        parm.parm_data['LENNARD_JONES_ACOEF'][-4] = 10.0
        self.assertTrue(parm.has_NBFIX())
        parm.createSystem()
コード例 #5
0
 def test_gb1_energy(self): # HCT (uses mbondi radii internally)
     """ Compare OpenMM and CHARMM GB (igb=1) energies """
     parm = charmm_gas
     system = parm.createSystem(param22, implicitSolvent=app.HCT)
     self.assertEqual(parm.combining_rule, 'lorentz')
     integrator = mm.VerletIntegrator(1.0*u.femtoseconds)
     sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
     sim.context.setPositions(charmm_gas_crds.positions)
     energies = energy_decomposition(parm, sim.context)
     self.assertAlmostEqual(energies['bond'], 1.3351, places=3)
     self.assertAlmostEqual(energies['angle'], 14.1158, places=3)
     self.assertAlmostEqual(energies['urey_bradley'], 0.3669, places=3)
     self.assertAlmostEqual(energies['dihedral'], 14.2773, places=3)
     self.assertAlmostEqual(energies['improper'], 0.3344, places=3)
     self.assertAlmostEqual(energies['cmap'], -0.5239, places=3)
     self.assertRelativeEqual(energies['nonbonded'], -102.1598379, places=5)
     system = parm.createSystem(param22, implicitSolvent=app.HCT,
                                implicitSolventSaltConc=1.0*u.molar)
     integrator = mm.VerletIntegrator(1.0*u.femtoseconds)
     sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
     sim.context.setPositions(charmm_gas_crds.positions)
     energies = energy_decomposition(parm, sim.context)
     self.assertAlmostEqual(energies['bond'], 1.3351, places=3)
     self.assertAlmostEqual(energies['angle'], 14.1158, places=3)
     self.assertAlmostEqual(energies['urey_bradley'], 0.3669, places=3)
     self.assertAlmostEqual(energies['dihedral'], 14.2773, places=3)
     self.assertAlmostEqual(energies['improper'], 0.3344, places=3)
     self.assertAlmostEqual(energies['cmap'], -0.5239, places=3)
     self.assertRelativeEqual(energies['nonbonded'], -102.5012873, places=5)
コード例 #6
0
    def test_unconvertable_rb_torsion(self):
        """ Check equal energies for Gromacs -> Amber conversion of Amber FF """
        top = self.get_fn(
            os.path.join('gmxtops', 'unconvertable_rb_torsion.top'))
        gro = self.get_fn(os.path.join('gmxtops', 'rb_torsions.gro'))
        top = load_file(top, xyz=gro)

        # 4 types are defined but parmed adds entries to the dict for each
        # ordering of the bondingtypes and one dihedral is symmetric
        assert len(top.parameterset.rb_torsion_types) == 7

        parm = amber.AmberParm.from_structure(top)
        parm.save(self.get_fn('rb_torsions.prmtop', written=True))
        parm.save(self.get_fn('rb_torsions.rst7', written=True))

        sysg = top.createSystem()
        sysa = parm.createSystem()

        cong = mm.Context(sysg, mm.VerletIntegrator(0.001), CPU)
        cona = mm.Context(sysa, mm.VerletIntegrator(0.001), CPU)

        cong.setPositions(top.positions)
        cona.setPositions(top.positions)

        self.check_energies(top, cong, parm, cona)
コード例 #7
0
ファイル: test_openmm_charmm.py プロジェクト: zyguostx/ParmEd
 def test_dispersion_correction(self):
     """ Compare OpenMM and CHARMM PME energies w/out vdW correction """
     parm = charmm_nbfix
     system = parm.createSystem(
         param36,
         nonbondedMethod=app.PME,
         nonbondedCutoff=8 * u.angstroms,
     )
     self.assertEqual(parm.combining_rule, 'lorentz')
     for force in system.getForces():
         if isinstance(force, mm.NonbondedForce):
             force.setUseDispersionCorrection(False)
         elif isinstance(force, mm.CustomNonbondedForce):
             force.setUseLongRangeCorrection(False)
     integrator = mm.VerletIntegrator(1.0 * u.femtoseconds)
     sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
     sim.context.setPositions(charmm_nbfix_crds.positions)
     energies = energy_decomposition(parm, sim.context)
     self.assertAlmostEqual(energies['bond'], 1.1324212, places=4)
     self.assertAlmostEqual(energies['angle'], 1.06880188, places=4)
     self.assertAlmostEqual(energies['urey_bradley'], 0.06142407, places=4)
     self.assertAlmostEqual(energies['dihedral'], 7.81143025, places=4)
     self.assertAlmostEqual(energies['improper'], 0, places=4)
     self.assertAlmostEqual(energies['cmap'], 0.126790, places=4)
     self.assertRelativeEqual(energies['nonbonded'],
                              6584.01821319,
                              places=4)
コード例 #8
0
    def test_simple(self):
        """ Test OpenMM System/Topology -> Amber prmtop conversion """
        parm = load_file(get_fn('ash.parm7'), get_fn('ash.rst7'))
        self.assertEqual(parm.combining_rule, 'lorentz')
        system = parm.createSystem()
        amber.AmberParm.from_structure(
            openmm.load_topology(parm.topology, system)).write_parm(
                get_fn('ash_from_omm.parm7', written=True))
        parm2 = load_file(get_fn('ash_from_omm.parm7', written=True))
        system2 = parm2.createSystem()
        con1 = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        con2 = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        con1.setPositions(parm.positions)
        con2.setPositions(parm.positions)

        self.check_energies(parm, con1, parm2, con2)
コード例 #9
0
    def test_dppc(self):
        """ Tests non-standard Gromacs force fields and nonbonded exceptions """
        # We know what we're doing
        top = load_file(os.path.join(get_fn('12.DPPC'), 'topol.top'),
                        xyz=os.path.join(get_fn('12.DPPC'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # Create the system and context, then calculate the energy decomposition
        system = top.createSystem()
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Lee-Ping's answers.
        self.assertAlmostEqual(energies['bond'], 0)
        self.assertAlmostEqual(energies['angle'], 1405.7354199, places=4)
        self.assertAlmostEqual(energies['dihedral'], 236.932663255, places=4)
        self.assertAlmostEqual(energies['improper'], 33.201541811, places=4)
        self.assertAlmostEqual(energies['rb_torsion'], 428.0550599, places=4)
        self.assertRelativeEqual(energies['nonbonded'],
                                 -16432.8092955,
                                 places=4)
        gmxfrc = get_forces_from_xvg(
            os.path.join(get_fn('12.DPPC'), 'force.xvg'))
        ommfrc = context.getState(getForces=True).getForces().value_in_unit(
            u.kilojoules_per_mole / u.nanometer)
        zero_ep_frc(ommfrc, top)
        max_diff = get_max_diff(gmxfrc, ommfrc)
        self.assertLess(max_diff, 5)
コード例 #10
0
    def test_small_double_peptide(self):
        """ Test interacting peptides Gromacs system nrg and frc (no PBC) """
        # Load the top and gro files
        top = load_file(os.path.join(get_fn('03.AlaGlu'), 'topol.top'),
                        xyz=os.path.join(get_fn('03.AlaGlu'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # create the system and context, then calculate the energy decomposition
        system = top.createSystem()
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Lee-Ping's answers. Make sure we zero-out forces for
        # virtual sites, since OMM doesn't do this and Gromacs does.
        self.assertAlmostEqual(energies['bond'], 1.5307999, places=4)
        self.assertAlmostEqual(energies['angle'], 6.5804488, places=4)
        self.assertAlmostEqual(energies['dihedral'], 80.379714, places=4)
        self.assertAlmostEqual(energies['nonbonded'], -275.142487, places=3)
        gmxfrc = get_forces_from_xvg(
            os.path.join(get_fn('03.AlaGlu'), 'force.xvg'))
        ommfrc = context.getState(getForces=True).getForces().value_in_unit(
            u.kilojoules_per_mole / u.nanometer)
        zero_ep_frc(ommfrc, top)
        max_diff = get_max_diff(gmxfrc, ommfrc)
        self.assertLess(max_diff, 0.05)
コード例 #11
0
    def test_pme_switch(self):
        """ Tests the DHFR Gromacs system nrg and force (PME w/ switch) """
        # Load the top and gro files
        top = load_file(get_fn('ildn.solv.top'), xyz=get_fn('ildn.solv.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # Create the system and context, then calculate the energy decomposition
        system = top.createSystem(nonbondedMethod=app.PME,
                                  constraints=app.HBonds,
                                  flexibleConstraints=True,
                                  nonbondedCutoff=0.9 * u.nanometers,
                                  ewaldErrorTolerance=1.0e-5,
                                  switchDistance=0.7 * u.nanometers)
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Lee-Ping's answers. Make sure we zero-out forces for
        # virtual sites, since OMM doesn't do this and Gromacs does.
        self.assertAlmostEqual(energies['bond'], 399.925189, places=4)
        self.assertAlmostEqual(energies['angle'], 36.18562, places=4)
        self.assertAlmostEqual(energies['dihedral'], 101.92265, places=4)
        self.assertRelativeEqual(energies['nonbonded'], -18587.09715, places=4)
コード例 #12
0
    def test_very_small(self):
        """ Test very small Gromacs system nrg and frc (no PBC) """
        # Load the top and gro files
        top = load_file(os.path.join(get_fn('02.6water'), 'topol.top'),
                        xyz=os.path.join(get_fn('02.6water'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # create the system and context, then calculate the energy decomposition
        system = top.createSystem(constraints=app.HBonds,
                                  rigidWater=True,
                                  flexibleConstraints=True)
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Lee-Ping's answers. Make sure we zero-out forces for
        # virtual sites, since OMM doesn't do this and Gromacs does.
        self.assertAlmostEqual(energies['bond'], 0, places=4)
        self.assertAlmostEqual(energies['nonbonded'], -108.277803, places=3)
        gmxfrc = get_forces_from_xvg(
            os.path.join(get_fn('02.6water'), 'force.xvg'))
        ommfrc = context.getState(getForces=True).getForces().value_in_unit(
            u.kilojoules_per_mole / u.nanometer)
        zero_ep_frc(ommfrc, top)
        max_diff = get_max_diff(gmxfrc, ommfrc)
        self.assertLess(max_diff, 0.05)
コード例 #13
0
    def test_jac(self):
        """ Tests the JAC benchmark Gromacs system nrg and force (no PBC) """
        # Load the top and gro files
        top = load_file(os.path.join(get_fn('07.DHFR-Liquid-NoPBC'),
                                     'topol.top'),
                        xyz=os.path.join(get_fn('07.DHFR-Liquid-NoPBC'),
                                         'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # Create the system and context, then calculate the energy decomposition
        system = top.createSystem()
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Lee-Ping's answers. Make sure we zero-out forces for
        # virtual sites, since OMM doesn't do this and Gromacs does.
        self.assertAlmostEqual(energies['bond'], 35.142565, places=3)
        self.assertAlmostEqual(energies['angle'], 3735.514669, places=3)
        self.assertAlmostEqual(energies['dihedral'], 7277.741635, delta=0.002)
        self.assertRelativeEqual(energies['nonbonded'],
                                 -288718.981405,
                                 places=4)
        gmxfrc = get_forces_from_xvg(
            os.path.join(get_fn('07.DHFR-Liquid-NoPBC'), 'force.xvg'))
        ommfrc = context.getState(getForces=True).getForces().value_in_unit(
            u.kilojoules_per_mole / u.nanometer)
        zero_ep_frc(ommfrc, top)
        max_diff = get_max_diff(gmxfrc, ommfrc)
        self.assertLess(max_diff, 0.5)
コード例 #14
0
    def test_jac_pme(self):
        """ Tests the JAC benchmark Gromacs system nrg and force (PME) """
        # Load the top and gro files
        top = load_file(os.path.join(get_fn('09.DHFR-PME'), 'topol.top'),
                        xyz=os.path.join(get_fn('09.DHFR-PME'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # Create the system and context, then calculate the energy decomposition
        system = top.createSystem(nonbondedMethod=app.PME,
                                  constraints=app.HBonds,
                                  nonbondedCutoff=0.9 * u.nanometers,
                                  ewaldErrorTolerance=1.0e-5)
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Lee-Ping's answers. Make sure we zero-out forces for
        # virtual sites, since OMM doesn't do this and Gromacs does.
        self.assertAlmostEqual(energies['bond'], 1628.54739, places=3)
        self.assertAlmostEqual(energies['angle'], 3604.58751, places=3)
        self.assertAlmostEqual(energies['dihedral'], 6490.00844, delta=0.002)
        self.assertRelativeEqual(energies['nonbonded'],
                                 23616.457584,
                                 delta=0.002)
        gmxfrc = get_forces_from_xvg(
            os.path.join(get_fn('09.DHFR-PME'), 'force.xvg'))
        ommfrc = context.getState(getForces=True).getForces().value_in_unit(
            u.kilojoules_per_mole / u.nanometer)
        zero_ep_frc(ommfrc, top)
        max_diff = get_max_diff(gmxfrc, ommfrc)
        self.assertLess(max_diff, 5)
コード例 #15
0
    def test_energy_simple(self):
        """ Check equal energies for Gromacs -> Amber conversion of Amber FF """
        top = load_file(get_fn(os.path.join('03.AlaGlu', 'topol.top')))
        gro = load_file(get_fn(os.path.join('03.AlaGlu', 'conf.gro')))
        parm = amber.AmberParm.from_structure(top)
        parm.write_parm(get_fn('ala_glu.parm7', written=True))
        parm = load_file(get_fn('ala_glu.parm7', written=True))

        sysg = top.createSystem()
        sysa = parm.createSystem()

        cong = mm.Context(sysg, mm.VerletIntegrator(0.001), CPU)
        cona = mm.Context(sysa, mm.VerletIntegrator(0.001), CPU)

        cong.setPositions(gro.positions)
        cona.setPositions(gro.positions)

        self.check_energies(top, cong, parm, cona)
コード例 #16
0
 def test_chamber_energies(self):
     """ Tests converting Gromacs to Chamber parm calculated energies """
     # Now let's modify an exception parameter so that it needs type
     # expansion, and ensure that it is handled correctly
     top = load_file(self.get_fn('1aki.charmm27.solv.top'), xyz=self.get_fn('1aki.charmm27.solv.gro'))
     gsystem = top.createSystem(nonbondedCutoff=8*u.angstroms, nonbondedMethod=app.PME)
     gcon = mm.Context(gsystem, mm.VerletIntegrator(1*u.femtosecond), CPU)
     gcon.setPositions(top.positions)
     eg = gcon.getState(getEnergy=True).getPotentialEnergy()
     eg = eg.value_in_unit(u.kilocalories_per_mole)
     # Convert to chamber now
     parm = amber.ChamberParm.from_structure(top)
     asystem = parm.createSystem(nonbondedCutoff=8*u.angstroms, nonbondedMethod=app.PME)
     acon = mm.Context(asystem, mm.VerletIntegrator(1*u.femtosecond), CPU)
     acon.setPositions(top.positions)
     ea = acon.getState(getEnergy=True).getPotentialEnergy()
     ea = ea.value_in_unit(u.kilocalories_per_mole)
     self.assertLess(abs(eg - ea), 1e-2)
コード例 #17
0
    def test_energy_complicated(self):
        """ Check equal energies for Gmx -> Amber conversion of complex FF """
        top = load_file(self.get_fn(os.path.join('12.DPPC', 'topol2.top')))
        gro = load_file(self.get_fn(os.path.join('12.DPPC', 'conf.gro')))
        parm = amber.AmberParm.from_structure(top)
        parm.write_parm(self.get_fn('dppc.parm7', written=True))
        parm = load_file(self.get_fn('dppc.parm7', written=True))

        sysg = top.createSystem()
        sysa = parm.createSystem()

        cong = mm.Context(sysg, mm.VerletIntegrator(0.001), CPU)
        cona = mm.Context(sysa, mm.VerletIntegrator(0.001), CPU)

        cong.setPositions(gro.positions)
        cona.setPositions(gro.positions)

        self.check_energies(top, cong, parm, cona)
コード例 #18
0
    def test_opls(self):
        """ Tests geometric combining rules with OPLS/AA in Gromacs topology """
        top = load_file(os.path.join(get_fn('05.OPLS'), 'topol.top'),
                        xyz=os.path.join(get_fn('05.OPLS'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'geometric')

        # Create the system and context, then calculate the energy decomposition
        system = top.createSystem()
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Compare with Gromacs energies
        self.assertAlmostEqual(energies['bond'], 332.178260935, places=4)
        self.assertAlmostEqual(energies['angle'], 29.2231806883, places=4)
        self.assertAlmostEqual(energies['dihedral'], 0.0057758656, places=4)
        self.assertAlmostEqual(energies['rb_torsion'], 55.603030624, places=4)
        self.assertRelativeEqual(energies['nonbonded'],
                                 327.954397827,
                                 places=4)
        # Now make sure it can be set with PME
        system = top.createSystem(nonbondedMethod=app.PME,
                                  nonbondedCutoff=8 * u.angstroms)
        n = 0
        for force in system.getForces():
            if isinstance(force, mm.NonbondedForce):
                self.assertAlmostEqualQuantities(force.getCutoffDistance(),
                                                 8 * u.angstroms)
                self.assertEqual(force.getNonbondedMethod(), force.PME)
                n += 1
            elif isinstance(force, mm.CustomNonbondedForce):
                self.assertAlmostEqualQuantities(force.getCutoffDistance(),
                                                 8 * u.angstroms)
                self.assertEqual(force.getNonbondedMethod(),
                                 force.CutoffPeriodic)
                n += 1
        self.assertEqual(n, 2)
        # Now try with non-periodic cutoff
        system = top.createSystem(nonbondedMethod=app.CutoffNonPeriodic,
                                  nonbondedCutoff=16 * u.angstroms,
                                  switchDistance=14 * u.angstroms)
        n = 0
        for force in system.getForces():
            if isinstance(force, mm.NonbondedForce) or isinstance(
                    force, mm.CustomNonbondedForce):
                self.assertAlmostEqualQuantities(force.getCutoffDistance(),
                                                 16 * u.angstroms)
                self.assertEqual(force.getNonbondedMethod(),
                                 force.CutoffNonPeriodic)
                self.assertTrue(force.getUseSwitchingFunction())
                self.assertAlmostEqualQuantities(force.getSwitchingDistance(),
                                                 14 * u.angstroms)
                n += 1
        self.assertEqual(n, 2)
コード例 #19
0
 def test_round_trip(self):
     """ Test ParmEd -> OpenMM round trip with CHARMM gas phase """
     parm = charmm_gas
     system = parm.createSystem(param22)
     self.assertEqual(parm.combining_rule, 'lorentz')
     system2 = openmm.load_topology(parm.topology, system).createSystem()
     con1 = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
     con2 = mm.Context(system2, mm.VerletIntegrator(0.001), CPU)
     con1.setPositions(charmm_gas_crds.positions)
     con2.setPositions(charmm_gas_crds.positions)
     energies = energy_decomposition(parm, con1)
     energies2 = energy_decomposition(parm, con2)
     self.assertAlmostEqual(energies['bond'], energies2['bond'])
     self.assertAlmostEqual(energies['angle'], energies2['angle'])
     self.assertAlmostEqual(energies['urey_bradley'], energies2['urey_bradley'])
     self.assertAlmostEqual(energies['dihedral'], energies2['dihedral'])
     self.assertAlmostEqual(energies['improper'], energies2['improper'])
     self.assertAlmostEqual(energies['cmap'], energies2['cmap'])
     self.assertRelativeEqual(energies['nonbonded'], energies2['nonbonded'])
コード例 #20
0
    def test_rb_torsion_conversion2(self):
        """ Check equal energies for Gromacs -> Amber conversion of Amber FF """
        top = self.get_fn(os.path.join('05.OPLS', 'topol.top'))
        gro = self.get_fn(os.path.join('05.OPLS', 'conf.gro'))
        top = load_file(top, xyz=gro)

        parm = amber.AmberParm.from_structure(top)
        parm.save(self.get_fn('05opls.prmtop', written=True))
        parm.save(self.get_fn('05opls.rst7', written=True))

        sysg = top.createSystem()
        sysa = parm.createSystem()

        cong = mm.Context(sysg, mm.VerletIntegrator(0.001), CPU)
        cona = mm.Context(sysa, mm.VerletIntegrator(0.001), CPU)

        cong.setPositions(top.positions)
        cona.setPositions(top.positions)

        self.check_energies(top, cong, parm, cona)
コード例 #21
0
    def test_rb_torsion_conversion3(self):
        """ Check equal energies for Gromacs -> Amber conversion of Amber FF """
        top = get_fn('2PPN_bulk.top')
        gro = get_fn('2PPN_bulk.gro')
        top = load_file(top, xyz=gro)

        parm = amber.AmberParm.from_structure(top)
        parm.save(get_fn('2PPN_bulk.prmtop', written=True))
        parm.save(get_fn('2PPN_bulk.rst7', written=True))

        sysg = top.createSystem()
        sysa = parm.createSystem()

        cong = mm.Context(sysg, mm.VerletIntegrator(0.001), CPU)
        cona = mm.Context(sysa, mm.VerletIntegrator(0.001), CPU)

        cong.setPositions(top.positions)
        cona.setPositions(top.positions)

        self.check_energies(top, cong, parm, cona)
コード例 #22
0
    def test_load_topology_use_atom_id_as_typename(self):
        """ Tests loading an OpenMM Topology and using Atom.id to name types """
        ommparm = load_file(get_fn('ash.parm7'), get_fn('ash.rst7'))
        parm = load_file(get_fn('ash.parm7'), get_fn('ash.rst7'))
        system = ommparm.createSystem(implicitSolvent=app.OBC1)

        for pmd_atom, omm_atom in zip(parm.atoms, ommparm.topology.atoms()):
            omm_atom.id = pmd_atom.type
        structure = openmm.load_topology(ommparm.topology, system,
                                         xyz=parm.positions)

        self.assertEqual(len(parm.atoms), len(structure.atoms))
        self.assertEqual([a.type for a in parm.atoms],
                         [a.type for a in structure.atoms])
        self.assertEqual(len(parm.residues), len(structure.residues))
        self.assertEqual(len(parm.bonds), len(structure.bonds))

        con1 = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        con2 = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        con1.setPositions(parm.positions)
        con2.setPositions(structure.positions)

        self.check_energies(parm, con1, structure, con2)
コード例 #23
0
    def test_gas_energy_conf_4(self):
        """ Compare Amber and OpenMM gas phase energies and forces (topology 4) """
        parm = AmberParm(get_fn('ethanol_T0.prmtop'),
                         get_fn('ethanol_T0.rst7'))
        self.assertEqual(parm.combining_rule, 'geometric')
        system = parm.createSystem()  # Default, no cutoff
        integrator = mm.VerletIntegrator(1.0 * u.femtoseconds)
        sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
        sim.context.setPositions(parm.positions)
        energies = energy_decomposition(parm, sim.context)
        #BOND    =        0.0239  ANGLE   =        0.0298  DIHED      =        0.0093
        #VDWAALS =        0.0000  EEL     =        6.7526  HBOND      =        0.0000
        #1-4 VDW =        0.0492  1-4 EEL =       -6.0430  RESTRAINT  =        0.0000
        # Compare OpenMM energies with the Amber energies (above)
        self.assertAlmostEqual(energies['bond'], 0.0239, places=4)
        self.assertAlmostEqual(energies['angle'], 0.0298, places=4)
        self.assertAlmostEqual(energies['dihedral'], 0.0093, places=4)
        self.assertRelativeEqual(energies['nonbonded'],
                                 0.0000 + 6.7526 + 0.0492 - 6.0430,
                                 places=3)

        # Now test the forces to make sure that they are computed correctly in
        # the presence of extra points
        pstate = sim.context.getState(getForces=True)
        pf = pstate.getForces().value_in_unit(u.kilojoule_per_mole /
                                              u.nanometer)
        # gmx forces:
        #      f[    0]={ 1.73101e+02,  5.67250e+01, -4.02950e+01}
        #      f[    1]={-8.13704e+00, -1.79612e+01,  9.88537e+01}
        #      f[    2]={-2.83120e+01,  6.23352e+00, -5.47393e+00}
        #      f[    3]={-1.03312e+01, -1.00966e+01, -5.12129e+00}
        #      f[    4]={-1.69636e+02,  3.34850e+01, -1.73612e+02}
        #      f[    5]={ 4.19932e+00, -2.58283e+00,  1.29999e+02}
        #      f[    6]={ 3.02865e+01, -6.68331e+00, -2.99153e+01}
        #      f[    7]={ 1.00113e+02, -5.22480e+01,  4.80526e+01}
        #      f[    8]={-9.12828e+01, -6.87157e+00, -2.24877e+01}

        gf = [(1.73101e+02, 5.67250e+01, -4.02950e+01),
              (-8.13704e+00, -1.79612e+01, 9.88537e+01),
              (-2.83120e+01, 6.23352e+00, -5.47393e+00),
              (-1.03312e+01, -1.00966e+01, -5.12129e+00),
              (-1.69636e+02, 3.34850e+01, -1.73612e+02),
              (4.19932e+00, -2.58283e+00, 1.29999e+02),
              (3.02865e+01, -6.68331e+00, -2.99153e+01),
              (1.00113e+02, -5.22480e+01, 4.80526e+01),
              (-9.12828e+01, -6.87157e+00, -2.24877e+01)]
        for p, s in zip(pf, gf):
            for x1, x2 in zip(p, s):
                self.assertAlmostEqual(x1, x2, places=3)
コード例 #24
0
 def test_gas_energy(self):
     """ Compare OpenMM and CHARMM gas phase energies """
     parm = charmm_gas
     system = parm.createSystem(param22)
     self.assertEqual(parm.combining_rule, 'lorentz')
     integrator = mm.VerletIntegrator(1.0*u.femtoseconds)
     sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
     sim.context.setPositions(charmm_gas_crds.positions)
     energies = energy_decomposition(parm, sim.context)
     self.assertAlmostEqual(energies['bond'], 1.3351, places=4)
     self.assertAlmostEqual(energies['angle'], 14.1158, places=4)
     self.assertAlmostEqual(energies['urey_bradley'], 0.3669, places=4)
     self.assertAlmostEqual(energies['dihedral'], 14.2773, places=4)
     self.assertAlmostEqual(energies['improper'], 0.3344, places=4)
     self.assertAlmostEqual(energies['cmap'], -0.5239, places=4)
     self.assertRelativeEqual(energies['nonbonded'], 9.2210, places=4)
コード例 #25
0
 def test_nbfix(self):
     """ Test PME energies of systems with NBFIX modifications """
     parm = charmm_nbfix
     system = parm.createSystem(param36, nonbondedMethod=app.PME,
                                nonbondedCutoff=8*u.angstroms)
     self.assertEqual(parm.combining_rule, 'lorentz')
     integrator = mm.VerletIntegrator(1.0*u.femtoseconds)
     sim = app.Simulation(parm.topology, system, integrator, platform=Reference)
     sim.context.setPositions(charmm_nbfix_crds.positions)
     energies = energy_decomposition(parm, sim.context)
     self.assertAlmostEqual(energies['bond'], 1.1324212, places=4)
     self.assertAlmostEqual(energies['angle'], 1.06880188, places=4)
     self.assertAlmostEqual(energies['urey_bradley'], 0.06142407, places=4)
     self.assertAlmostEqual(energies['dihedral'], 7.81143025, places=4)
     self.assertAlmostEqual(energies['improper'], 0, places=4)
     self.assertAlmostEqual(energies['cmap'], 0.126790, places=4)
     self.assertRelativeEqual(energies['nonbonded'], 6514.283116, places=4)
コード例 #26
0
    def test_gas_energy_conf_3(self):
        """ Compare Amber and OpenMM gas phase energies and forces (topology 3) """
        parm = AmberParm(get_fn('methanol_T0.prmtop'),
                         get_fn('methanol_T0.rst7'))
        self.assertEqual(parm.combining_rule, 'geometric')
        system = parm.createSystem()  # Default, no cutoff
        integrator = mm.VerletIntegrator(1.0 * u.femtoseconds)
        sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
        sim.context.setPositions(parm.positions)
        energies = energy_decomposition(parm, sim.context)
        #BOND    =        0.0224  ANGLE   =        0.0469  DIHED      =        0.0039
        #VDWAALS =        0.0000  EEL     =        0.0000  HBOND      =        0.0000
        #1-4 VDW =        0.0000  1-4 EEL =        3.3789  RESTRAINT  =        0.0000
        # Compare OpenMM energies with the Amber energies (above)
        self.assertAlmostEqual(energies['bond'], 0.0224, places=4)
        self.assertAlmostEqual(energies['angle'], 0.0469, places=4)
        self.assertAlmostEqual(energies['dihedral'], 0.0039, places=4)
        self.assertRelativeEqual(energies['nonbonded'], 3.3789, places=3)

        # Now test the forces to make sure that they are computed correctly in
        # the presence of extra points
        pstate = sim.context.getState(getForces=True)
        pf = pstate.getForces().value_in_unit(u.kilojoule_per_mole /
                                              u.nanometer)
        # gmx forces:
        #     f[    0]={ 2.19935e+01,  8.60143e+01,  1.77895e+02}
        #     f[    1]={ 5.25347e+01,  3.46119e+01, -9.73738e+01}
        #     f[    2]={ 1.76138e+01, -7.13778e+01, -1.08807e+00}
        #     f[    3]={-3.74994e+01, -5.39602e+01, -6.75679e+01}
        #     f[    4]={-8.35142e+01, -7.86616e+01, -1.60611e+02}
        #     f[    5]={ 2.88716e+01,  8.33735e+01,  1.48746e+02}

        gf = [(2.19935e+01, 8.60143e+01, 1.77895e+02),
              (5.25347e+01, 3.46119e+01, -9.73738e+01),
              (1.76138e+01, -7.13778e+01, -1.08807e+00),
              (-3.74994e+01, -5.39602e+01, -6.75679e+01),
              (-8.35142e+01, -7.86616e+01, -1.60611e+02),
              (2.88716e+01, 8.33735e+01, 1.48746e+02)]
        for p, s in zip(pf, gf):
            for x1, x2 in zip(p, s):
                self.assertAlmostEqual(x1, x2, places=3)
コード例 #27
0
    def test_gas_energy_conf_2(self):
        """ Compare Amber and OpenMM gas phase energies and forces (topology 2) """
        parm = AmberParm(get_fn('hydrogen-peroxide_T0_2.prmtop'),
                         get_fn('hydrogen-peroxide_T0_2.rst7'))
        self.assertEqual(parm.combining_rule, 'lorentz')
        system = parm.createSystem()  # Default, no cutoff
        integrator = mm.VerletIntegrator(1.0 * u.femtoseconds)
        sim = app.Simulation(parm.topology, system, integrator, platform=CPU)
        sim.context.setPositions(parm.positions)
        energies = energy_decomposition(parm, sim.context)
        #BOND    =        0.0319  ANGLE   =        2.1690  DIHED      =       -2.7931
        #VDWAALS =        0.0000  EEL     =        0.0000  HBOND      =        0.0000
        #1-4 VDW =        0.0000  1-4 EEL =        0.0000  RESTRAINT  =        0.0000
        # Compare OpenMM energies with the Amber energies (above)
        self.assertAlmostEqual(energies['bond'], 0.0319, places=4)
        self.assertAlmostEqual(energies['angle'], 2.1690, places=4)
        self.assertAlmostEqual(energies['dihedral'], -2.7931, places=4)
        self.assertRelativeEqual(energies['nonbonded'], 0.0, places=3)

        # Now test the forces to make sure that they are computed correctly in
        # the presence of extra points
        pstate = sim.context.getState(getForces=True)
        pf = pstate.getForces().value_in_unit(u.kilojoule_per_mole /
                                              u.nanometer)
        # gmx forces:
        #     f[    0]={ 3.14357e+02, -5.90363e+02,  2.11410e+02}
        #     f[    1]={-3.14357e+02,  5.90363e+02,  2.11410e+02}
        #     f[    2]={ 2.70641e+02,  5.90363e+02, -2.11410e+02}
        #     f[    3]={-2.70641e+02, -5.90363e+02, -2.11410e+02}
        gf = [(3.14357e+02, -5.90363e+02, 2.11410e+02),
              (-3.14357e+02, 5.90363e+02, 2.11410e+02),
              (2.70641e+02, 5.90363e+02, -2.11410e+02),
              (-2.70641e+02, -5.90363e+02, -2.11410e+02)]
        for p, s in zip(pf, gf):
            for x1, x2 in zip(p, s):
                self.assertAlmostEqual(x1, x2, places=3)
コード例 #28
0
    def test_tiny(self):
        """ Test tiny Gromacs system nrg and frc (no PBC) """
        # Load the top and gro files
        top = load_file(os.path.join(get_fn('01.1water'), 'topol.top'),
                        xyz=os.path.join(get_fn('01.1water'), 'conf.gro'))
        self.assertEqual(top.combining_rule, 'lorentz')

        # create the system and context, then calculate the energy decomposition
        system = top.createSystem(constraints=app.HBonds, rigidWater=True)
        context = mm.Context(system, mm.VerletIntegrator(0.001), CPU)
        context.setPositions(top.positions)
        energies = energy_decomposition(top,
                                        context,
                                        nrg=u.kilojoules_per_mole)

        # Make sure they match Lee-Ping's answers (both energies and forces)
        self.assertAlmostEqual(energies['bond'], 1.63805, places=4)
        self.assertAlmostEqual(energies['angle'], 0.014803, places=4)
        gmxfrc = get_forces_from_xvg(
            os.path.join(get_fn('01.1water'), 'force.xvg'))
        ommfrc = context.getState(getForces=True).getForces().value_in_unit(
            u.kilojoules_per_mole / u.nanometer)
        max_diff = get_max_diff(gmxfrc, ommfrc)
        self.assertLess(max_diff, 0.01)