Example #1
0
picosec (float): Number of picoseconds to warm up the complex
temperature (decimal): target final temperature after warming

Outputs:
--------
ofs: Outputs the constant temperature and volume system
"""

job.classification = [['NVT']]
job.tags = [tag for lists in job.classification for tag in lists]

ifs = OEMolIStreamCube("complex", title="Complex Reader")
ifs.promote_parameter("data_in", promoted_name="complex", title='Complex Input File',
                      description="protein:ligand complex input file")

nvt = OpenMMnvtCube('nvt')
nvt.promote_parameter('time', promoted_name='picosec', default=10.0)
nvt.promote_parameter('temperature', promoted_name='temperature', default=300.0,
                      description='Selected temperature in K')
# Restraints
nvt.promote_parameter('restraints', promoted_name='restraints', default='noh (ligand or protein)')
nvt.promote_parameter('restraintWt', promoted_name='restraintWt', default=2.0)
# Trajectory and logging info frequency intervals
nvt.promote_parameter('trajectory_interval', promoted_name='trajectory_interval', default=100,
                      description='Trajectory saving interval')
nvt.promote_parameter('reporter_interval', promoted_name='reporter_interval', default=1000,
                      description='Reporter saving interval')

nvt.promote_parameter('outfname', promoted_name='suffix', default='nvt',
                      description='Equilibration suffix name')
Example #2
0
class NVTCubeTester(unittest.TestCase):
    """
    Test the OpenMM NVT cube
    Example inputs from `openmm_orion/examples/data`
    """

    def calculate_VT(self, oe_mol):
        # Extract starting MD data from OEMol
        mdData = utils.MDData(oe_mol)
        structure = mdData.structure
        topology = mdData.topology
        positions = mdData.positions
        velocities = mdData.velocities
        box = mdData.box

        volume = box[0][0] * box[1][1] * box[2][2]

        # OpenMM system
        system = structure.createSystem(nonbondedMethod=eval("app.%s" % self.cube.args.nonbondedMethod),
                                        nonbondedCutoff=self.cube.args.nonbondedCutoff * unit.angstroms,
                                        constraints=eval("app.%s" % self.cube.args.constraints))
        # OpenMM Integrator
        integrator = openmm.LangevinIntegrator(self.cube.args.temperature * unit.kelvin,
                                               1.0 / unit.picoseconds, 0.002 * unit.picoseconds)
        # Set Simulation
        simulation = app.Simulation(topology, system, integrator)

        # Set Positions
        simulation.context.setPositions(positions)
        # Set Velocities
        simulation.context.setVelocities(velocities)

        # Set Box dimensions
        simulation.context.setPeriodicBoxVectors(box[0], box[1], box[2])

        # Collect the OpenMM state energy info
        state = simulation.context.getState(getEnergy=True)

        # Kinetic Energy
        keng = state.getKineticEnergy()

        # Calculate system degrees of freedom:
        dof = 0
        for i in range(system.getNumParticles()):
            if system.getParticleMass(i) > 0 * unit.dalton:
                dof += 3

        dof -= system.getNumConstraints()

        if any(type(system.getForce(i)) == openmm.CMMotionRemover for i in range(system.getNumForces())):
            dof -= 3

        # Calculate the temperature from the equipartition theorem
        temperature = ((2*keng)/(dof*unit.MOLAR_GAS_CONSTANT_R))

        return volume, temperature

    def setUp(self):
        self.cube = OpenMMnvtCube('NVT')
        self.runner = CubeTestRunner(self.cube)
        self.runner.start()

    def _test_success(self):
        print('Testing cube:', self.cube.name)
        # Complex file name
        complex_fname = utils.get_data_filename('examples', 'data/pP38_lp38a_2x_complex.oeb.gz')

        # Read OEMol molecule
        mol = oechem.OEMol()

        with oechem.oemolistream(complex_fname) as ifs:
            oechem.OEReadMolecule(ifs, mol)

        # Process the molecules
        self.cube.process(mol, self.cube.intake.name)
        # Assert that one molecule was emitted on the success port
        self.assertEqual(self.runner.outputs['success'].qsize(), 1)
        # Assert that zero molecules were emitted on the failure port
        self.assertEqual(self.runner.outputs['failure'].qsize(), 0)

        outmol = self.runner.outputs["success"].get()

        # Calculate final volume and temperature
        vol_f, temp_f = self.calculate_VT(outmol)

        # Check 3*std volume
        # Average volume and its standard deviation (in nm^3) measured along
        # one 10ns run for the selected system
        avg_volume = 682.7474608 * (unit.nanometers ** 3)
        std_volume = 0.000001

        self.assertAlmostEqual(avg_volume/(unit.nanometers ** 3),
                               vol_f.in_units_of(unit.nanometers ** 3) / (unit.nanometers ** 3),
                               delta=3*std_volume)

        # Check temperature
        # Average temperature and its standard deviation (in K) measured along
        # one 10ns run for the selected system
        avg_temperature = 300.0 * unit.kelvin
        std_temperature = 1.1
        self.assertAlmostEqual(avg_temperature/unit.kelvin,
                               temp_f.in_units_of(unit.kelvin)/unit.kelvin,
                               delta=3*std_temperature)

    @pytest.mark.slow
    def test_success(self):
        self.cube.args.time = 50.0  # in picoseconds
        self._test_success()

    def test_failure(self):
        pass

    def tearDown(self):
        self.runner.finalize()
ff = ForceFieldPrep("ForceField")
# ff.promote_parameter('ligand_forcefield', promoted_name='ligand_forcefield', default='SMIRNOFF')

# Minimization
minimize = OpenMMminimizeCube("Minimize")
minimize.promote_parameter('restraints',
                           promoted_name='m_restraints',
                           default="noh ligand",
                           description='Select mask to apply restarints')
minimize.promote_parameter('restraintWt',
                           promoted_name='m_restraintWt',
                           default=5.0,
                           description='Restraint weight in kcal/(mol A^2')

# NVT Warm-up
warmup = OpenMMnvtCube('warmup', title='warmup')
warmup.promote_parameter('time',
                         promoted_name='warm_psec',
                         default=20.0,
                         description='Length of MD run in picoseconds')
warmup.promote_parameter('restraints',
                         promoted_name='w_restraints',
                         default="noh ligand",
                         description='Select mask to apply restarints')
warmup.promote_parameter('restraintWt',
                         promoted_name='w_restraintWt',
                         default=2.0,
                         description='Restraint weight in kcal/(mol A^2')
warmup.promote_parameter('trajectory_interval',
                         promoted_name='w_trajectory_interval',
                         default=0,
Example #4
0
 def setUp(self):
     self.cube = OpenMMnvtCube('NVT')
     self.runner = CubeTestRunner(self.cube)
     self.runner.start()