Esempio n. 1
0
    def calculate_eng(self, oe_mol):
        # Extract starting MD data from OEMol
        mdData = utils.MDData(oe_mol)
        topology = mdData.topology
        positions = mdData.positions
        structure = mdData.structure
        box = mdData.box

        # 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 Box dimensions
        simulation.context.setPeriodicBoxVectors(box[0], box[1], box[2])

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

        # Potential Energy
        peng = state.getPotentialEnergy()

        return peng
Esempio n. 2
0
    def process(self, mol, port):
        try:
            # The copy of the dictionary option as local variable
            # is necessary to avoid filename collisions due to
            # the parallel cube processes
            opt = dict(self.opt)
            if utils.PackageOEMol.checkTags(mol, ['Structure']):
                gd = utils.PackageOEMol.unpack(mol)
                opt['outfname'] = '{}-{}'.format(gd['IDTag'],
                                                 self.opt['outfname'])

            mdData = utils.MDData(mol)

            opt['molecule'] = mol

            self.log.info('START NPT SIMULATION %s' % gd['IDTag'])
            simtools.simulation(mdData, **opt)

            packedmol = mdData.packMDData(mol)

            self.success.emit(packedmol)

        except Exception as e:
            # Attach error message to the molecule that failed
            self.log.error(traceback.format_exc())
            mol.SetData('error', str(e))
            # Return failed mol
            self.failure.emit(mol)

        return
Esempio n. 3
0
    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)

        # Add Force Barostat to the system
        system.addForce(openmm.MonteCarloBarostat(self.cube.args.pressure * unit.atmospheres,
                                                  self.cube.args.temperature*unit.kelvin, 25))

        # 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
Esempio n. 4
0
    def process(self, mol, port):
        try:
            # The copy of the dictionary option as local variable
            # is necessary to avoid filename collisions due to
            # the parallel cube processes
            opt = dict(self.opt)

            # Update cube simulation parameters with the eventually molecule SD tags
            new_args = {
                dp.GetTag(): dp.GetValue()
                for dp in oechem.OEGetSDDataPairs(mol)
                if dp.GetTag() in ["temperature", "pressure"]
            }

            if new_args:
                for k in new_args:
                    try:
                        new_args[k] = float(new_args[k])
                    except:
                        pass
                self.log.info(
                    "Updating parameters for molecule: {}\n{}".format(
                        mol.GetTitle(), new_args))

                opt.update(new_args)

            if utils.PackageOEMol.checkTags(mol, ['Structure']):
                gd = utils.PackageOEMol.unpack(mol)
                opt['outfname'] = '{}-{}'.format(gd['IDTag'],
                                                 self.opt['outfname'])

            mdData = utils.MDData(mol)

            opt['molecule'] = mol

            self.log.info('START NPT SIMULATION %s' % gd['IDTag'])
            simtools.simulation(mdData, **opt)

            packedmol = mdData.packMDData(mol)

            self.success.emit(packedmol)

        except Exception as e:
            # Attach error message to the molecule that failed
            self.log.error(traceback.format_exc())
            mol.SetData('error', str(e))
            # Return failed mol
            self.failure.emit(mol)

        return