pdbatoms = list(pdb.topology.atoms()) labels = forcefield.labelMolecules([mol])[0] for key, val in labels.items(): print(key) for v in val: anames = '-'.join([pdbatoms[i].name for i in v[0]]) anums = '-'.join([str(i) for i in v[0]]) print("%20s %20s %5s %-s" % (anames, anums, v[1], v[2])) # The rest of this is not needed. sys.exit() # Create the OpenMM system system = forcefield.createSystem(pdb.topology, [mol], nonbondedMethod=PME, nonbondedCutoff=1.0*unit.nanometers, rigidWater=True) # Set up an OpenMM simulation integrator = openmm.LangevinIntegrator(temperature, friction, time_step) platform = openmm.Platform.getPlatformByName('CUDA') simulation = Simulation(pdb.topology, system, integrator) simulation.context.setPositions(pdb.positions) simulation.context.setVelocitiesToTemperature(temperature) netcdf_reporter = NetCDFReporter('water_traj.nc', trj_freq) simulation.reporters.append(netcdf_reporter) simulation.reporters.append(StateDataReporter('water_data.csv', data_freq, step=True, potentialEnergy=True, temperature= True, density=True)) print(simulation.context.getState(getEnergy=True).getPotentialEnergy()) simulation.minimizeEnergy() print(simulation.context.getState(getEnergy=True).getPotentialEnergy())
def build_mixture_prmtop(gaff_mol2_filenames, box_filename, out_top, out_gro, ffxml): """Analog of openmoltools.amber.build_mixture_prmtop which uses SMIRNOFF forcefield (from github.com/open-forcefield-group/smarty) to parameterize small molecules, rather than GAFF. Parameters ---------- mol2_filenames : list(str) Filenames of GAFF flavored mol2 files. Each must contain exactly ONE solute. box_filename : str Filename of PDB containing an arbitrary box of the mol2 molecules. out_top : str output GROMACS topology filename. Should have suffix .top out_gro : str output gro filename. Should have suffix .gro ffxml : str filename containing input SMIRNOFF FFXML file for use in parameterizing the system Returns ------- success : bool True or False as to success of operation Notes ----- This can be easily broken if there are missing, duplicated, or inconsistent ligand residue names in your box, mol2, and frcmod files. You can use mdtraj to edit the residue names with something like this: trj.top.residue(0).name = "L1" """ from openeye import oechem from openforcefield.typing.engines.smirnoff import ForceField, PME from openforcefield.utils import read_molecules, get_data_filename, generateTopologyFromOEMol # Read in molecules oemols = [] for mol2file in set(gaff_mol2_filenames): mol = oechem.OEGraphMol() ifs = oechem.oemolistream(mol2file) flavor = oechem.OEIFlavor_Generic_Default | oechem.OEIFlavor_MOL2_Default | oechem.OEIFlavor_MOL2_Forcefield ifs.SetFlavor(oechem.OEFormat_MOL2, flavor) oechem.OEReadMolecule(ifs, mol) oechem.OETriposAtomNames(mol) oemols.append(mol) # Read in PDB file to get topology pdb = app.PDBFile(box_filename) # Load forcefield ff = ForceField(ffxml) # Construct system; charging not needed as mol2 files already have charges here system = ff.createSystem(pdb.topology, oemols, nonbondedMethod=PME, nonbondedCutoff=CUTOFF) # Dump to AMBER format structure = parmed.openmm.topsystem.load_topology(pdb.topology, system, pdb.positions) structure.save(out_top, overwrite=True) structure.save(out_gro, overwrite=True) return True
def convert_parameters( source_directory="original/", source_crd="full.crds", source_top="full.topo", destination_directory="generated/", destination_crd="smirnoff.inpcrd", destination_top="smirnoff.prmtop", host_resname="MGO", guest_resname="BAM", atom_mapping=None, residue_mapping=None, ): create_pdb_with_conect( solvated_pdb=source_directory + source_crd, amber_prmtop=source_directory + source_top, output_pdb=destination_directory + "full.pdb", ) prune_conect(input_pdb="full.pdb", output_pdb="full_conect.pdb", path=destination_directory) components = split_topology(file_name=destination_directory + "full.pdb") hg_topology = create_host_guest_topology(components, host_resname=host_resname, guest_resname=guest_resname) create_host_mol2( solvated_pdb=destination_directory + "full.pdb", amber_prmtop=source_directory + source_top, mask=host_resname, output_mol2=destination_directory + host_resname + ".mol2", ) convert_mol2_to_sybyl_antechamber( input_mol2=destination_directory + host_resname + ".mol2", output_mol2=destination_directory + host_resname + "-sybyl.mol2", ac_doctor=True, ) host = load_mol2( filename=destination_directory + host_resname + "-sybyl.mol2", name=host_resname, add_tripos=True, ) guest = load_mol2( filename=source_directory + guest_resname.lower() + ".mol2", name=guest_resname, add_tripos=False, ) check_unique_atom_names(host) check_unique_atom_names(guest) molecules = [host, guest] ff = ForceField("forcefield/smirnoff99Frosst.ffxml") system = ff.createSystem( hg_topology.topology, molecules, nonbondedCutoff=1.1 * unit.nanometer, ewaldErrorTolerance=1e-4, ) hg_structure = pmd.openmm.topsystem.load_topology(hg_topology.topology, system, hg_topology.positions) check_bond_lengths(hg_structure, threshold=4) try: hg_structure.save(destination_directory + "hg.prmtop") except OSError: logging.warning( "Check if the host-guest parameter file already exists...") try: hg_structure.save(destination_directory + "hg.inpcrd") except OSError: logging.warning( "Check if the host-guest coordinate file already exists...") extract_water_and_ions( amber_prmtop=source_directory + source_top, amber_inpcrd=source_directory + source_crd, host_residue=":" + host_resname, guest_residue=":" + guest_resname, dummy=None, output_pdb=destination_directory + "water_ions.pdb", ) create_water_and_ions_parameters( input_pdb="water_ions.pdb", output_prmtop="water_ions.prmtop", output_inpcrd="water_ions.inpcrd", dummy_atoms=True, path=destination_directory, ) water_and_ions = pmd.amber.AmberParm( destination_directory + "water_ions.prmtop", xyz=destination_directory + "water_ions.inpcrd", ) merged = mergeStructure(hg_structure, water_and_ions) try: merged.save(destination_directory + destination_top) except: logging.warning("Check if solvated parameter file already exists...") try: merged.save(destination_directory + destination_crd) except: logging.warning("Check if solvated coordinate file already exists...") reference = pmd.load_file(source_directory + source_top, source_directory + source_crd) try: reference.save(destination_directory + "reference.pdb") reference.save(destination_directory + "reference.mol2") except OSError: logging.warning("Check if file exists...") target = pmd.load_file(destination_directory + destination_top, destination_directory + destination_crd) try: target.save(destination_directory + "target.pdb") target.save(destination_directory + "target.mol2") except OSError: logging.warning("Check if file exists...") if not atom_mapping: reference_mol = load_mol2(destination_directory + "reference.mol2") target_mol = load_mol2(destination_directory + "target.mol2") atom_mapping = map_atoms(reference_mol, target_mol) if not residue_mapping: reference_mol = load_pdb(destination_directory + "reference.pdb") target_mol = load_pdb(destination_directory + "target.pdb") residue_mapping = map_residues(atom_mapping, reference_mol, target_mol) # for file in ["mini.in", "therm1.in", "therm2.in", "eqnpt.in", "mdin"]: # rewrite_amber_input_file( # reference_input=source_directory + file, # target_input=destination_directory + file, # reference_to_target_mapping=residue_mapping, # dt_override=False, # target_prmtop=merged, # ) # rewrite_restraints_file( # reference_restraints=source_directory + "disang.rest", # target_restraints=destination_directory + "disang.rest", # reference_to_target_mapping=atom_mapping, # ) # For some reason, this must come last, otherwise it gets removed again merged.box = reference.box try: os.remove(destination_directory + destination_top) os.remove(destination_directory + destination_crd) except OSError: pass merged.save(destination_directory + destination_crd) merged.save(destination_directory + destination_top) return atom_mapping, residue_mapping