def compute_hydration_energy(molecule, parameters, platform_name="Reference"): """ Compute hydration energy of a specified molecule given the specified GBVI parameter set. ARGUMENTS molecule (OEMol) - molecule with GBVI atom types parameters (dict) - parameters for GBVI atom types RETURNS energy (float) - hydration energy in kcal/mol """ platform = openmm.Platform.getPlatformByName(platform_name) # Create OpenMM System. system = openmm.System() for atom in molecule.GetAtoms(): mass = OEGetDefaultMass(atom.GetAtomicNum()) system.addParticle(mass * units.amu) # Add GBVI term # gbvi_force = openmm.GBVISoftcoreForce() gbvi_force = openmm.GBVIForce() gbvi_force.setNonbondedMethod(openmm.GBVIForce.NoCutoff) # set no cutoff gbvi_force.setSoluteDielectric(1) gbvi_force.setSolventDielectric(78) # Use scaling method. # gbvi_force.setBornRadiusScalingMethod(openmm.GBVISoftcoreForce.QuinticSpline) # gbvi_force.setQuinticLowerLimitFactor(0.75) # gbvi_force.setQuinticUpperBornRadiusLimit(50.0*units.nanometers) # Build indexable list of atoms. atoms = [atom for atom in molecule.GetAtoms()] # Assign GB/VI parameters. for atom in molecule.GetAtoms(): atomtype = atom.GetStringData("gbvi_type") # GBVI atomtype charge = atom.GetPartialCharge() * units.elementary_charge try: radius = parameters['%s_%s' % (atomtype, 'radius')] * units.angstroms gamma = parameters['%s_%s' % (atomtype, 'gamma')] * units.kilocalories_per_mole except Exception, exception: print "Cannot find parameters for atomtype '%s' in molecule '%s'" % ( atomtype, molecule.GetTitle()) print parameters.keys() raise exception # gamma *= -1.0 # DEBUG lambda_ = 1.0 # fully interacting # gbvi_force.addParticle(charge, radius, gamma, lambda_) # for GBVISoftcoreForce gbvi_force.addParticle(charge, radius, gamma) # for GBVIForce
def hydration_energy_factory_cachesystem(molecule, default_parameters): """ A faster version of hydration_energy_factory that caches the system and coordinates. """ # Create OpenMM System. system = openmm.System() for atom in molecule.GetAtoms(): mass = OEGetDefaultMass(atom.GetAtomicNum()) system.addParticle(mass * units.amu) # Add GBVI term # gbvi_force = openmm.GBVISoftcoreForce() gbvi_force = openmm.GBVIForce() gbvi_force.setNonbondedMethod(openmm.GBVIForce.NoCutoff) # set no cutoff gbvi_force.setSoluteDielectric(1) gbvi_force.setSolventDielectric(78) # Use scaling method. # gbvi_force.setBornRadiusScalingMethod(openmm.GBVISoftcoreForce.QuinticSpline) # gbvi_force.setQuinticLowerLimitFactor(0.75) # gbvi_force.setQuinticUpperBornRadiusLimit(50.0*units.nanometers) # Build indexable list of atoms. atoms = [atom for atom in molecule.GetAtoms()] # Assign GB/VI parameters. for atom in molecule.GetAtoms(): atomtype = atom.GetStringData("gbvi_type") # GBVI atomtype charge = atom.GetPartialCharge() * units.elementary_charge try: radius = parameters['%s_%s' % (atomtype, 'radius')] * units.angstroms gamma = parameters['%s_%s' % (atomtype, 'gamma')] * units.kilocalories_per_mole except Exception, exception: print "Cannot find parameters for atomtype '%s' in molecule '%s'" % ( atomtype, molecule.GetTitle()) print parameters.keys() raise exception # gamma *= -1.0 # DEBUG lambda_ = 1.0 # fully interacting # gbvi_force.addParticle(charge, radius, gamma, lambda_) # for GBVISoftcoreForce gbvi_force.addParticle(charge, radius, gamma) # for GBVIForce
def compute_hydration_energies(molecules, parameters): """ Compute solvation energies of all specified molecules using given parameter set. ARGUMENTS molecules (list of OEMol) - molecules with atom types parameters (dict) - parameters for atom types RETURNS energies (dict) - energies[molecule] is the computed solvation energy of given molecule """ energies = dict( ) # energies[index] is the computed solvation energy of molecules[index] platform = openmm.Platform.getPlatformByName("Reference") for molecule in molecules: # Create OpenMM System. system = openmm.System() for atom in molecule.GetAtoms(): mass = OEGetDefaultMass(atom.GetAtomicNum()) system.addParticle(mass * units.amu) # Add nonbonded term. # nonbonded_force = openmm.NonbondedSoftcoreForce() # nonbonded_force.setNonbondedMethod(openmm.NonbondedForce.NoCutoff) # for atom in molecule.GetAtoms(): # charge = 0.0 * units.elementary_charge # sigma = 1.0 * units.angstrom # epsilon = 0.0 * units.kilocalories_per_mole # nonbonded_force.addParticle(charge, sigma, epsilon) # system.addForce(nonbonded_force) # Add GBVI term # gbvi_force = openmm.GBVISoftcoreForce() gbvi_force = openmm.GBVIForce() gbvi_force.setNonbondedMethod( openmm.GBVIForce.NoCutoff) # set no cutoff gbvi_force.setSoluteDielectric(1) gbvi_force.setSolventDielectric(78) # Use scaling method. # gbvi_force.setBornRadiusScalingMethod(openmm.GBVISoftcoreForce.QuinticSpline) # gbvi_force.setQuinticLowerLimitFactor(0.75) # gbvi_force.setQuinticUpperBornRadiusLimit(50.0*units.nanometers) # Build indexable list of atoms. atoms = [atom for atom in molecule.GetAtoms()] # Assign GB/VI parameters. for atom in molecule.GetAtoms(): atomtype = atom.GetStringData("gbvi_type") # GBVI atomtype charge = atom.GetPartialCharge() * units.elementary_charge radius = parameters['%s_%s' % (atomtype, 'radius')] * units.angstroms gamma = parameters['%s_%s' % (atomtype, 'gamma')] * units.kilocalories_per_mole # gamma *= -1.0 # DEBUG lambda_ = 1.0 # fully interacting # gbvi_force.addParticle(charge, radius, gamma, lambda_) # for GBVISoftcoreForce gbvi_force.addParticle(charge, radius, gamma) # for GBVIForce # Add bonds. for bond in molecule.GetBonds(): # Get atom indices. iatom = bond.GetBgnIdx() jatom = bond.GetEndIdx() # Get bond length. (xi, yi, zi) = molecule.GetCoords(atoms[iatom]) (xj, yj, zj) = molecule.GetCoords(atoms[jatom]) distance = math.sqrt((xi - xj)**2 + (yi - yj)**2 + (zi - zj)**2) * units.angstroms # Identify bonded atoms to GBVI. gbvi_force.addBond(iatom, jatom, distance) # Add the force to the system. system.addForce(gbvi_force) # Build coordinate array. natoms = len(atoms) coordinates = units.Quantity(numpy.zeros([natoms, 3]), units.angstroms) for (index, atom) in enumerate(atoms): (x, y, z) = molecule.GetCoords(atom) coordinates[index, :] = units.Quantity(numpy.array([x, y, z]), units.angstroms) # Create OpenMM Context. timestep = 1.0 * units.femtosecond # arbitrary integrator = openmm.VerletIntegrator(timestep) context = openmm.Context(system, integrator, platform) # Set the coordinates. context.setPositions(coordinates) # Get the energy state = context.getState(getEnergy=True) energies[molecule] = state.getPotentialEnergy() return energies
def __init__(self, molecule): # Create OpenMM System. system = openmm.System() for atom in molecule.GetAtoms(): mass = OEGetDefaultMass(atom.GetAtomicNum()) system.addParticle(mass * units.amu) # Add GBVI term # gbvi_force = openmm.GBVISoftcoreForce() gbvi_force = openmm.GBVIForce() gbvi_force.setNonbondedMethod( openmm.GBVIForce.NoCutoff) # set no cutoff gbvi_force.setSoluteDielectric(1) gbvi_force.setSolventDielectric(78) # Use scaling method. # gbvi_force.setBornRadiusScalingMethod(openmm.GBVISoftcoreForce.QuinticSpline) # gbvi_force.setQuinticLowerLimitFactor(0.75) # gbvi_force.setQuinticUpperBornRadiusLimit(50.0*units.nanometers) # Build indexable list of atoms. atoms = [atom for atom in molecule.GetAtoms()] # Assign GB/VI parameters. for atom in molecule.GetAtoms(): atomtype = atom.GetStringData("gbvi_type") # GBVI atomtype charge = atom.GetPartialCharge() * units.elementary_charge radius = parameters['%s_%s' % (atomtype, 'radius')] * units.angstroms gamma = parameters['%s_%s' % (atomtype, 'gamma')] * units.kilocalories_per_mole # gamma *= -1.0 # DEBUG lambda_ = 1.0 # fully interacting # gbvi_force.addParticle(charge, radius, gamma, lambda_) # for GBVISoftcoreForce gbvi_force.addParticle(charge, radius, gamma) # for GBVIForce # Add bonds. for bond in molecule.GetBonds(): # Get atom indices. iatom = bond.GetBgnIdx() jatom = bond.GetEndIdx() # Get bond length. (xi, yi, zi) = molecule.GetCoords(atoms[iatom]) (xj, yj, zj) = molecule.GetCoords(atoms[jatom]) distance = math.sqrt((xi - xj)**2 + (yi - yj)**2 + (zi - zj)**2) * units.angstroms # Identify bonded atoms to GBVI. gbvi_force.addBond(iatom, jatom, distance) # Add the force to the system. system.addForce(gbvi_force) # Serialize the system. serializer = openmm.XmlSerializer() self.serialized_system = serializer.serialize(system) # Build coordinate array. natoms = len(atoms) coordinates = units.Quantity(numpy.zeros([natoms, 3]), units.angstroms) for (index, atom) in enumerate(atoms): (x, y, z) = molecule.GetCoords(atom) coordinates[index, :] = units.Quantity(numpy.array([x, y, z]), units.angstroms) self.coordinates = coordinates return