def test_potential(self, pdbfname ): """ tests amber potential for pdbfname Input ----- pdbfname = full path to pdb file """ # read a conformation from pdb file print 'reading conformation from coords.pdb' from simtk.openmm.app import pdbfile as openmmpdb pdb = openmmpdb.PDBFile(pdbfname) coords = pdb.getPositions() / openmm_angstrom coords = np.reshape(np.transpose(coords), 3*len(coords), 1) e = self.potential.getEnergy(coords) print 'Energy (kJ/mol) = ' print e e, g = self.potential.getEnergyGradient(coords) gnum = self.potential.NumericalDerivative(coords, eps=1e-6) print 'Energy (kJ/mol) = ' print e print 'Analytic Gradient = ' print g[1:3] print 'Numerical Gradient = ' print gnum[1:3] print 'Num vs Analytic Gradient =' print np.max(np.abs(gnum-g)), np.max(np.abs(gnum)) print np.max(np.abs(gnum-g)) / np.max(np.abs(gnum))
def get_random_configuration(self): """a starting point for basinhopping, etc.""" from simtk.openmm.app import pdbfile as openmmpdbReader pdb = openmmpdbReader.PDBFile('coords.pdb') # todo: coords.pdb is hardcoded coords = pdb.getPositions() / openmm_angstrom coords = np.reshape(np.transpose(coords), 3*len(coords), 1) return coords
def test_potential(self, pdbfname): """ tests amber potential for pdbfname Input ----- pdbfname = full path to pdb file """ # read a conformation from pdb file print('reading conformation from coords.pdb') from simtk.openmm.app import pdbfile as openmmpdb from simtk.unit import angstrom as openmm_angstrom pdb = openmmpdb.PDBFile(pdbfname) coords = old_div(pdb.getPositions(), openmm_angstrom) coords = np.reshape(np.transpose(coords), 3 * len(coords), 1) self.potential = self.get_potential() e = self.potential.getEnergy(coords) print('Energy (kJ/mol) = ') print(e) e, g = self.potential.getEnergyGradient(coords) gnum = self.potential.NumericalDerivative(coords, eps=1e-6) print('Energy (kJ/mol) = ') print(e) print('Analytic Gradient = ') print(g[1:3]) print('Numerical Gradient = ') print(gnum[1:3]) print('Num vs Analytic Gradient =') print(np.max(np.abs(gnum - g)), np.max(np.abs(gnum))) print(old_div(np.max(np.abs(gnum - g)), np.max(np.abs(gnum))))
if __name__ == "__main__": # create topology from prmtop file from simtk.openmm.app import AmberPrmtopFile prmtop = AmberPrmtopFile('../../examples/amber/coords.prmtop') scheck = sanity_check(prmtop.topology) # get coordinates from a pdb file from simtk.openmm.app import pdbfile as openmmpdbReader from simtk.unit import angstrom as openmm_angstrom pdb = openmmpdbReader.PDBFile( '../../examples/amber/coords.pdb') # todo: coords.pdb is hardcoded coords = pdb.getPositions() / openmm_angstrom coords = np.reshape(np.transpose(coords), 3 * len(coords), 1) # test if scheck.check_CAchirality(coords): print '\nCA chirality test passed (all L)' else: print '\nCA chirality test passed (atleast one D-amino acid)' if scheck.check_cistrans(coords): print '\npeptide cis-trans test passed (all trans)' else: print '\npeptide cis-trans test failed (atleast one cis)'
from simtk.unit import kilocalories_per_mole, kilojoules_per_mole, nanometer, angstrom, picosecond import numpy # --- Test OpenMMAmberPotential from pele.amber.openmm_potential import OpenMMAmberPotential # create potential for the molecule in coords.pdb prmtopFname = '../aladipep/coords.prmtop' inpcrdFname = '../aladipep/coords.inpcrd' pot = OpenMMAmberPotential(prmtopFname, inpcrdFname) # read coordinates from pdb file from simtk.openmm.app import pdbfile as openmmpdb pdb = openmmpdb.PDBFile('../aladipep/coords.pdb') coords = pdb.getPositions() / angstrom coords = numpy.reshape(numpy.transpose(coords), 3*len(coords), 1) # compute energy and gradients e = pot.getEnergy(coords) print 'Energy (kJ/mol) = ' print e e, g = pot.getEnergyGradient(coords) gnum = pot.NumericalDerivative(coords, eps=1e-6) print 'Energy (kJ/mol) = ' print e print 'Analytic Gradient = ' print g[60:65] print 'Numerical Gradient = ' print gnum[60:65]
#from sys import stdout # ----- OpenMM # setup using inpcrd and prmtop prmtop = AmberPrmtopFile('coords.prmtop') inpcrd = AmberInpcrdFile('coords.inpcrd') system1 = prmtop.createSystem(nonbondedMethod=openmmff.NoCutoff) integrator1 = VerletIntegrator(0.001 * picosecond) simulation1 = Simulation(prmtop.topology, system1, integrator1) simulation1.context.setPositions(inpcrd.positions) # get energy ener1 = simulation1.context.getState(getEnergy=True).getPotentialEnergy() # setup using pdb and built-in amber ff pdb = openmmpdb.PDBFile('coords.pdb') forcefield = openmmff.ForceField('amber99sb.xml', 'tip3p.xml') system2 = forcefield.createSystem(pdb.topology, nonbondedMethod=openmmff.NoCutoff) integrator2 = VerletIntegrator(0.001 * picosecond) simulation2 = Simulation(pdb.topology, system2, integrator2) simulation2.context.setPositions(pdb.positions) # get energy ener2 = simulation2.context.getState(getEnergy=True).getPotentialEnergy() # print all energies print("Energies (kJ/mol)") print("inpcrd/prmtop pdb (+built-in amb99sb) ") print("-------------------------------------------------------- ") print(ener1, ener2)
grad = np.array(grad, dtype=float) return float(E), grad.reshape(-1) ''' ------------------------------------------------------------------- ''' if __name__ == "__main__": # create potential for the molecule in coords.pdb prmtopFname = '../../examples/amber/aladipep/coords.prmtop' inpcrdFname = '../../examples/amber/aladipep/coords.inpcrd' pot = OpenMMAmberPotential(prmtopFname, inpcrdFname) # read coordinates from pdb file from simtk.openmm.app import pdbfile as openmmpdb pdb = openmmpdb.PDBFile('../../examples/amber/aladipep/coords.pdb') coords = pdb.getPositions() / angstrom coords = numpy.reshape(numpy.transpose(coords), 3 * len(coords), 1) # compute energy and gradients e = pot.getEnergy(coords) print 'Energy (kJ/mol) = ' print e e, g = pot.getEnergyGradient(coords) gnum = pot.NumericalDerivative(coords, eps=1e-6) print 'Energy (kJ/mol) = ' print e print 'Analytic Gradient = '