import simtk.openmm.app as app # ParmEd Imports from chemistry.amber import AmberParm from chemistry.openmm.reporters import StateDataReporter, NetCDFReporter from chemistry import unit as u # Load the Amber files print('Loading Amber files...') ala5_gas = AmberParm('ala5_gas.parm7', 'ala5_gas.rst7') # Create the OpenMM system print('Creating OpenMM System') system = ala5_gas.createSystem( nonbondedMethod=app.NoCutoff, constraints=app.HBonds, implicitSolvent=app.GBn2, implicitSolventSaltConc=0.1 * u.moles / u.liter, ) # Create the integrator to do Langevin dynamics integrator = mm.LangevinIntegrator( 300 * u.kelvin, # Temperature of heat bath 1.0 / u.picoseconds, # Friction coefficient 2.0 * u.femtoseconds, # Time step ) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not specify # the platform to use the default (fastest) platform platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision='mixed') # Use mixed single/double precision
def get_rmsd(initparas): global idxs, mcresids2, atompairs #Modify the C4 terms in the prmtop file for i in range(0, len(idxs)): prmtop.parm_data['LENNARD_JONES_CCOEF'][idxs[i]] = initparas[i] #Overwrite the prmtop file prmtop.write_parm('OptC4.top') #Perform the OpenMM optimization #Use AmberParm function to transfer the topology and #coordinate file to the object OpenMM can use Ambermol = AmberParm('OptC4.top', options.cfile) # Create the OpenMM system print('Creating OpenMM System') if options.simupha == 'gas': system = Ambermol.createSystem(nonbondedMethod=app.NoCutoff) elif options.simupha == 'liquid': system = Ambermol.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=8.0*u.angstroms, constraints=app.HBonds,) #Add restraints force = mm.CustomExternalForce("k*((x-x0)^2+(y-y0)^2+(z-z0)^2)") force.addGlobalParameter("k", 200.0) force.addPerParticleParameter("x0") force.addPerParticleParameter("y0") force.addPerParticleParameter("z0") #for i in range(0, len(Ambermol.atoms)): for i, atom_crd in enumerate(Ambermol.positions): #if (Ambermol.atoms[i].residue.number+1 not in mcresids2) and \ if (i+1 not in mcresids2) and \ (Ambermol.atoms[i].residue.name not in ['WAT', 'HOH']) and \ (Ambermol.atoms[i].name in ['CA', 'C', 'N']): force.addParticle(i, atom_crd.value_in_unit(u.nanometers)) system.addForce(force) # Create the integrator to do Langevin dynamics # Temperature of heat bath, Friction coefficient, Time step integrator = mm.LangevinIntegrator(300*u.kelvin, 1.0/u.picoseconds, 1.0*u.femtoseconds,) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not # specify the platform to use the default (fastest) platform # Create the Simulation object if options.platf == 'ref': platform = mm.Platform.getPlatformByName('Reference') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cpu': platform = mm.Platform.getPlatformByName('CPU') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cuda': platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision='mixed') sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) elif options.platf == 'opencl': platform = mm.Platform.getPlatformByName('OpenCL') prop = dict(CudaPrecision='mixed') sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) # Set the particle positions sim.context.setPositions(Ambermol.positions) # Output the rst file restrt = RestartReporter(options.rfile, 100, write_velocities=False) sim.reporters.append(restrt) # Minimize the energy print('Minimizing energy ' + str(options.maxsteps) + ' steps.') sim.minimizeEnergy(maxIterations=options.maxsteps) # Overwrite the final file state = sim.context.getState(getPositions=True, enforcePeriodicBox=True) restrt.report(sim, state) val_aft_min = [] crds_aft_min = read_rstf(options.rfile) for i in atompairs: if len(i) == 2: crd1 = crds_aft_min[i[0]-1] crd2 = crds_aft_min[i[1]-1] bond = calc_bond(crd1, crd2) val_aft_min.append(('bond', bond)) elif len(i) == 3: crd1 = crds_aft_min[i[0]-1] crd2 = crds_aft_min[i[1]-1] crd3 = crds_aft_min[i[2]-1] angle = calc_angle(crd1, crd2, crd3) val_aft_min.append(('angle', angle)) elif len(i) == 4: crd1 = crds_aft_min[i[0]-1] crd2 = crds_aft_min[i[1]-1] crd3 = crds_aft_min[i[2]-1] crd4 = crds_aft_min[i[3]-1] dih = calc_dih(crd1, crd2, crd3, crd4) val_aft_min.append(('dih', dih)) valdiffs = [] for i in range(0, len(atompairs)): if val_bf_min[i][0] == 'bond': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) * 1.0 / 100.0 elif val_bf_min[i][0] == 'angle': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) * 1.0 / 2.0 elif val_bf_min[i][0] == 'dih': valdiff = abs(val_aft_min[i][1] - val_bf_min[i][1]) if (360.0 - valdiff < valdiff): valdiff = 360.0 - valdiff valdiffs.append(valdiff) fnldiff = numpy.sum(valdiffs) print(fnldiff) return fnldiff
import simtk.openmm as mm import simtk.openmm.app as app # ParmEd Imports from chemistry.amber import AmberParm from chemistry.openmm.reporters import StateDataReporter, NetCDFReporter from chemistry import unit as u # Load the Amber files print('Loading Amber files...') ala5_gas = AmberParm('ala5_gas.parm7', 'ala5_gas.rst7') # Create the OpenMM system print('Creating OpenMM System') system = ala5_gas.createSystem(nonbondedMethod=app.NoCutoff, constraints=app.HBonds, implicitSolvent=app.GBn2, implicitSolventSaltConc=0.1*u.moles/u.liter, ) # Create the integrator to do Langevin dynamics integrator = mm.LangevinIntegrator( 300*u.kelvin, # Temperature of heat bath 1.0/u.picoseconds, # Friction coefficient 2.0*u.femtoseconds, # Time step ) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not specify # the platform to use the default (fastest) platform platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision='mixed') # Use mixed single/double precision # Create the Simulation object
import simtk.openmm as mm import simtk.openmm.app as app # ParmEd Imports from chemistry.amber import AmberParm from chemistry.openmm.reporters import StateDataReporter, NetCDFReporter from chemistry import unit as u # Load the Amber files print('Loading AMBER files...') ala2_solv = AmberParm('ala2_solv.parm7', 'ala2_solv.rst7') # Create the OpenMM system print('Creating OpenMM System') system = ala2_solv.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=8.0*u.angstroms, constraints=app.HBonds, ) # Create the integrator to do Langevin dynamics integrator = mm.LangevinIntegrator( 300*u.kelvin, # Temperature of heat bath 1.0/u.picoseconds, # Friction coefficient 2.0*u.femtoseconds, # Time step ) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not specify # the platform to use the default (fastest) platform platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision='mixed') # Use mixed single/double precision # Create the Simulation object
def get_rmsd(initparas): global idxs print(initparas) #Modify the C4 terms in the prmtop file for i in range(0, len(idxs)): prmtop.parm_data['LENNARD_JONES_CCOEF'][idxs[i]] = initparas[i] #Overwrite the prmtop file prmtop.write_parm('OptC4.top') #Perform the OpenMM optimization #Use AmberParm function to transfer the topology and #coordinate file to the object OpenMM can use Ambermol = AmberParm('OptC4.top', options.cfile) # Create the OpenMM system print('Creating OpenMM System') if options.simupha == 'gas': system = Ambermol.createSystem(nonbondedMethod=app.NoCutoff) elif options.simupha == 'liquid': system = Ambermol.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=8.0*u.angstroms, constraints=app.HBonds,) # Create the integrator to do Langevin dynamics # Temperature of heat bath, Friction coefficient, Time step integrator = mm.LangevinIntegrator(300*u.kelvin, 1.0/u.picoseconds, 1.0*u.femtoseconds,) # Define the platform to use; CUDA, OpenCL, CPU, or Reference. Or do not # specify the platform to use the default (fastest) platform # Create the Simulation object if options.platf == 'ref': platform = mm.Platform.getPlatformByName('Reference') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cpu': platform = mm.Platform.getPlatformByName('CPU') sim = app.Simulation(Ambermol.topology, system, integrator, platform) elif options.platf == 'cuda': platform = mm.Platform.getPlatformByName('CUDA') prop = dict(CudaPrecision='mixed') sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) elif options.platf == 'opencl': platform = mm.Platform.getPlatformByName('OpenCL') prop = dict(CudaPrecision='mixed') sim = app.Simulation(Ambermol.topology, system, integrator, platform, prop) # Set the particle positions sim.context.setPositions(Ambermol.positions) # Output the rst file restrt = RestartReporter(options.rfile, 100, write_velocities=False) sim.reporters.append(restrt) # Minimize the energy print('Minimizing energy ' + str(options.maxsteps) + ' steps.') sim.minimizeEnergy(maxIterations=options.maxsteps) # Overwrite the final file state = sim.context.getState(getPositions=True, enforcePeriodicBox=True) restrt.report(sim, state) print('Calculate the RMSD') # Perform the RMSD calcualtion, using ptraj in AmberTools os.system("cpptraj -p OptC4.top -i OptC4_ptraj.in > OptC4_ptraj.out") ptrajof = open('OptC4_rmsd.txt', 'r') ln = 1 for line in ptrajof: if ln == 3: rmsd = float(line[12:21]) ln += 1 ptrajof.close() print('RMSD is: ', rmsd) return rmsd
#!/usr/bin/env python from __future__ import division from simtk.unit import * from simtk.openmm import * from simtk.openmm.app import * from chemistry.amber import AmberParm parm = AmberParm('4LYT.solv10.parm7', '4LYT.solv10.equil.rst7') system = parm.createSystem(nonbondedCutoff=8.0*angstroms, nonbondedMethod=PME, rigidWater=True) integrator = VerletIntegrator(1.0e-10*picoseconds) context = Context(system, integrator) context.setPositions(parm.positions) state = context.getState(getEnergy=True)