def report(self, simulation, state): """Generate a report. Parameters: - simulation (Simulation) The Simulation to generate a report for - state (State) The current state of the simulation """ if self._nextModel == 0: PDBxFile.writeHeader(simulation.topology, self._out) self._nextModel += 1 PDBxFile.writeModel(simulation.topology, state.getPositions(), self._out, self._nextModel) self._nextModel += 1 if hasattr(self._out, 'flush') and callable(self._out.flush): self._out.flush()
def report(self, simulation, _): """Generate a report. Parameters ---------- simulation : Simulation The Simulation to generate a report for _ : State The current state of the simulation """ state = simulation.context.getState(getPositions=True, enforcePeriodicBox=self._enforcePeriodicBox) if self._nextModel == 0: PDBxFile.writeHeader(simulation.topology, self._out) self._nextModel += 1 PDBxFile.writeModel(simulation.topology, state.getPositions(), self._out, self._nextModel) self._nextModel += 1 if hasattr(self._out, 'flush') and callable(self._out.flush): self._out.flush()
def report(self, simulation, _): """Generate a report. Parameters ---------- simulation : Simulation The Simulation to generate a report for _ : State The current state of the simulation """ state = simulation.context.getState( getPositions=True, enforcePeriodicBox=self._enforcePeriodicBox) if self._nextModel == 0: PDBxFile.writeHeader(simulation.topology, self._out) self._nextModel += 1 PDBxFile.writeModel(simulation.topology, state.getPositions(), self._out, self._nextModel) self._nextModel += 1 if hasattr(self._out, 'flush') and callable(self._out.flush): self._out.flush()
def _minimizeOverlaps(self, platform, membrane): hydrogen_mass = 3 * unit.amu system = self.structure.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=1 * unit.nanometer, rigidWater=True, flexibleConstraints=False, constraints=app.HBonds, hydrogenMass=hydrogen_mass, removeCMMotion=False) backup_system = deepcopy(system) for index in self.atom_to_freeze: system.setParticleMass(int(index), 0.0 * unit.dalton) integrator = mm.LangevinIntegrator(300 * unit.kelvin, 1.0 / unit.picoseconds, 2 * unit.femtosecond) simulation = app.Simulation(self.structure.topology, system, integrator, platform) simulation.context.setPositions(self.structure.positions) simulation.minimizeEnergy(tolerance=0.1 * unit.kilojoule / unit.mole, maxIterations=0) positions = simulation.context.getState( getPositions=True).getPositions() min_potential = atomsmm.splitPotentialEnergy(system, self.structure.topology, positions) for key, value in min_potential.items(): self.logger.debug(key, value) simulation.saveCheckpoint('porinMembraneSystem.chk') integrator = mm.LangevinIntegrator(300 * unit.kelvin, 1.0 / unit.picoseconds, 2 * unit.femtosecond) simulation = app.Simulation(self.structure.topology, backup_system, integrator, platform) simulation.context.setPositions(positions) simulation.context.setVelocitiesToTemperature(300 * unit.kelvin) simulation.reporters.append( app.StateDataReporter( 'relax-ligand-system.log', 100, step=True, temperature=True, potentialEnergy=True, totalEnergy=True, speed=True, )) topology = md.Topology.from_openmm(self.structure.topology) atom_indices = topology.select('(protein and not resname ' + membrane + ')' + ' or resname ' + self.lig_name) simulation.reporters.append( NetCDFReporter('relax-ligand-system.nc', 100, atomSubset=atom_indices)) simulation.step(100000) positions = simulation.context.getState( getPositions=True).getPositions() PDBxFile.writeFile(self.structure.topology, positions, open("atomistic-system-combined.pdbx", 'w'))
""" import argparse from pdbfixer import PDBFixer from simtk.openmm.app import PDBxFile ap = argparse.ArgumentParser() ap.add_argument('structure') ap.add_argument('--output', default=None, help='Output name for fixed structure') cmd = ap.parse_args() print('Reading PDB structure: {}'.format(cmd.structure)) fixer = PDBFixer(cmd.structure) print('Finding and adding missing heavy atoms') fixer.findMissingResidues() fixer.findMissingAtoms() fixer.addMissingAtoms() if cmd.output is None: ofname = cmd.structure[:-4] + '.cif' else: ofname = cmd.output print('Writing completed structure in CIF format: {}'.format(ofname)) with open('{}'.format(ofname), 'w') as handle: PDBxFile.writeFile(fixer.topology, fixer.positions, handle)
""" import argparse from pdbfixer import PDBFixer from simtk.openmm.app import PDBxFile ap = argparse.ArgumentParser() ap.add_argument('structure') ap.add_argument('--output', default=None, help='Output name for fixed structure') cmd = ap.parse_args() print('Reading PDB structure: {}'.format(cmd.structure)) fixer = PDBFixer(cmd.structure) print('Finding and adding missing heavy atoms') fixer.findMissingResidues() fixer.findMissingAtoms() fixer.addMissingAtoms() if cmd.output is None: ofname = cmd.structure[:-4] + '.cif' else: ofname = cmd.output print('Writing completed structure in CIF format: {}'.format(ofname)) with open('{}'.format(ofname), 'w') as handle: PDBxFile.writeFile(fixer.topology, fixer.positions, handle, keepIds=True)
def addHydrogens(): if 'addHydrogens' in request.form: pH = float(request.form.get('ph', '7')) fixer.addMissingHydrogens(pH) if 'addWater' in request.form: padding, boxSize, boxVectors = None, None, None if request.form['boxType'] == 'geometry': geompadding = float(request.form['geomPadding']) * unit.nanometer geometry = request.form['geometryDropdown'] maxSize = max( max((pos[i] for pos in fixer.positions)) - min((pos[i] for pos in fixer.positions)) for i in range(3)) if geometry == 'cube': padding = geompadding elif geometry == 'truncatedOctahedron': vectors = mm.Vec3(1, 0, 0), mm.Vec3(1 / 3, 2 * sqrt(2) / 3, 0), mm.Vec3( -1 / 3, 1 / 3, sqrt(6) / 3) boxVectors = [(maxSize + geompadding) * v for v in vectors] elif geometry == 'rhombicDodecahedron': vectors = mm.Vec3(1, 0, 0), mm.Vec3(0, 1, 0), mm.Vec3( 0.5, 0.5, sqrt(2) / 2) boxVectors = [(maxSize + geompadding) * v for v in vectors] else: boxSize = (float(request.form['boxx']), float( request.form['boxy']), float( request.form['boxz'])) * unit.nanometer ionicStrength = float(request.form['ionicstrength']) * unit.molar positiveIon = request.form['positiveion'] + '+' negativeIon = request.form['negativeion'] + '-' fixer.addSolvent(boxSize, padding, boxVectors, positiveIon, negativeIon, ionicStrength) elif 'addMembrane' in request.form: lipidType = request.form['lipidType'] padding = float(request.form['membranePadding']) * unit.nanometer ionicStrength = float(request.form['ionicstrength']) * unit.molar positiveIon = request.form['positiveion'] + '+' negativeIon = request.form['negativeion'] + '-' fixer.addMembrane(lipidType=lipidType, minimumPadding=padding, positiveIon=positiveIon, negativeIon=negativeIon, ionicStrength=ionicStrength) # Save the new PDB file. uploadedFiles['originalFile'] = uploadedFiles['file'] pdb = StringIO() if session['pdbType'] == 'pdb': try: PDBFile.writeFile(fixer.topology, fixer.positions, pdb, True) except: # This can happen if the ids are too large to fit in the allowed space. pdb = StringIO() PDBFile.writeFile(fixer.topology, fixer.positions, pdb, False) else: PDBxFile.writeFile(fixer.topology, fixer.positions, pdb, True) temp = tempfile.TemporaryFile() temp.write(pdb.getvalue().encode('utf-8')) name = uploadedFiles['file'][0][1] dotIndex = name.rfind('.') if dotIndex == -1: prefix = name suffix = '' else: prefix = name[:dotIndex] suffix = name[dotIndex:] uploadedFiles['file'] = [(temp, prefix + '-processed' + suffix)] return showSimulationOptions()
molecule = Modeller(pdb.topology, pdb.positions) print("Done loading pdb to Modeller.") # load force field forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml') print("Done loading force field.") print("OpenMM version:", version.version) # prepare system molecule.addSolvent(forcefield, padding=12 * unit.angstrom, model='tip3p', positiveIon='Na+', negativeIon='Cl-', ionicStrength=0 * unit.molar) print("Done adding solvent.") PDBxFile.writeFile(molecule.topology, molecule.positions, open(f'{pdbid}_chain{chain}.pdbx', 'w'), keepIds=True) PDBFile.writeFile(molecule.topology, molecule.positions, open(f'{pdbid}_chain{chain}_solvated.pdb', 'w'), keepIds=True) print("Done outputing pdbx and solvated pdb.") system = forcefield.createSystem(molecule.topology, nonbondedMethod=PME, rigidWater=True, nonbondedCutoff=1 * unit.nanometer) # specify the rest of the context for minimization integrator = mm.VerletIntegrator(0.5 * unit.femtoseconds) print("Done specifying integrator.") platform = mm.Platform.getPlatformByName('CUDA')
import logging import yank import mdtraj as md import porinMembraneSystem from porinMembraneSystem import PorinMembraneSystem logger = logging.getLogger(__name__) # Setup general logging logging.root.setLevel(logging.DEBUG) logging.basicConfig(level=logging.DEBUG) yank.utils.config_root_logger(verbose=True, log_file_path=None) forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml') pdbx = PDBxFile('atomistic-system-with-hydrogens.pdbx') system = forcefield.createSystem(pdbx.topology, nonbondedMethod=app.PME, rigidWater=False, nonbondedCutoff=1 * unit.nanometer) integrator = mm.VerletIntegrator(0.5 * unit.femtosecond) platform = mm.Platform.getPlatformByName('CUDA') simulation = app.Simulation(pdbx.topology, system, integrator, platform) simulation.loadCheckpoint('state.chk') positions = simulation.context.getState(getPositions=True).getPositions() #rigidWater = False is necessary because water parameters are required by Parmed #when loading the ligand ligand_atomistic_system = PorinMembraneSystem('comp7',
from porinMembraneSystem import PorinMembraneSystem logger = logging.getLogger(__name__) # Setup general logging logging.root.setLevel(logging.DEBUG) logging.basicConfig(level=logging.DEBUG) yank.utils.config_root_logger(verbose=True, log_file_path=None) # File from MemProt Data Base pdb = PDBFile('atomistic-system.pdb') modeller = Modeller(pdb.topology, pdb.positions) modeller.changeAtomNames() forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml') modeller.addHydrogens(forcefield=forcefield) PDBxFile.writeFile(modeller.topology, modeller.positions, open("atomistic-system-with-hydrogens.pdbx", 'w')) system = forcefield.createSystem(modeller.topology, nonbondedMethod=app.PME, rigidWater=True, nonbondedCutoff=1 * unit.nanometer) integrator = mm.VerletIntegrator(0.5 * unit.femtoseconds) platform = mm.Platform.getPlatformByName('CUDA') simulation = app.Simulation(modeller.topology, system, integrator, platform) simulation.context.setPositions(modeller.positions) simulation.context.setVelocitiesToTemperature(300 * unit.kelvin) # Minimize the system after adding hydrogens to the membrane tolerance = 0.1 * unit.kilojoules_per_mole / unit.angstroms simulation.minimizeEnergy(tolerance=tolerance, maxIterations=0) simulation.reporters.append( app.StateDataReporter('relax-hydrogens.log',
pdb = PDBFile('5UG9_fixed.pdb') molecule = Modeller(pdb.topology, pdb.positions) print("Done loading pdb to Modeller.") # load force field forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml') print("Done loading force field.") print("OpenMM version:", version.version) # prepare system molecule.addSolvent(forcefield, padding=12 * unit.angstrom, model='tip3p', positiveIon='Na+', negativeIon='Cl-', ionicStrength=0 * unit.molar) print("Done adding solvent.") PDBxFile.writeFile(molecule.topology, molecule.positions, open("5UG9_fixed.pdbx", 'w')) PDBFile.writeFile(molecule.topology, molecule.positions, open("5UG9_fixed_solvated.pdb", 'w')) print("Done outputing pdbx and solvated pdb.") system = forcefield.createSystem(molecule.topology, nonbondedMethod=PME, rigidWater=True, nonbondedCutoff=1 * unit.nanometer) # add the custom cv force # Specify the set of key atoms and calculate key dihedrals and distances (dih, dis) = pf.main('5UG9', 'A') # dihedrals dih_0 = mm.CustomTorsionForce("theta") dih_0.addTorsion(int(dih[0][0]), int(dih[0][1]), int(dih[0][2]), int(dih[0][3]))
pdb = PDBFile('{}_fixed.pdb'.format(pdbid)) molecule = Modeller(pdb.topology, pdb.positions) print("Done loading pdb to Modeller.") # load force field forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml') print("Done loading force field.") print("OpenMM version:", version.version) # prepare system molecule.addSolvent(forcefield, padding=12 * unit.angstrom, model='tip3p', positiveIon='Na+', negativeIon='Cl-', ionicStrength=0 * unit.molar) print("Done adding solvent.") PDBxFile.writeFile(molecule.topology, molecule.positions, open("{}_fixed.pdbx".format(pdbid), 'w')) PDBFile.writeFile(molecule.topology, molecule.positions, open("{}_fixed_solvated.pdb".format(pdbid), 'w')) print("Done outputing pdbx and solvated pdb.") system = forcefield.createSystem(molecule.topology, nonbondedMethod=PME, rigidWater=True, nonbondedCutoff=1 * unit.nanometer) # specify the rest of the context for minimization integrator = mm.VerletIntegrator(0.5 * unit.femtoseconds) print("Done specifying integrator.") platform = mm.Platform.getPlatformByName('CUDA') print("Done specifying platform.") platform.setPropertyDefaultValue('Precision', 'single') print("Done setting the precision to single.")