def main(argv=(__name__)): """ the protein should have charges and radii but the ligand need not """ itf = oechem.OEInterface() if not oechem.OEConfigure(itf, InterfaceData): oechem.OEThrow.Fatal("Problem configuring OEInterface!") if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to parse command line") ligFile = itf.GetString("-l") ims = oechem.oemolistream() if not ims.open(ligFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % ligFile) lig = oechem.OEGraphMol() oechem.OEReadMolecule(ims, lig) contextFile = itf.GetString("-p") ims = oechem.oemolistream() if not ims.open(contextFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % contextFile) prot = oechem.OEGraphMol() oechem.OEReadMolecule(ims, prot) outputFile = itf.GetString("-o") oms = oechem.oemolostream() if not oms.open(outputFile): oechem.OEThrow.Fatal("Unable to open %s for writing" % outputFile) GenerateSzmapProbes(oms, itf.GetDouble("-prob"), lig, prot)
def main(argv=[__name__]): if len(argv) != 3: oechem.OEThrow.Usage("%s <reffile> <fitfile>" % argv[0]) reffs = oechem.oemolistream(argv[1]) fitfs = oechem.oemolistream(argv[2]) refmol = oechem.OEGraphMol() oechem.OEReadMolecule(reffs, refmol) # Prepare reference molecule for calculation # With default options this will remove any explicit # hydrogens present, and add required color atoms prep = oeshape.OEOverlapPrep() prep.Prep(refmol) # Get appropriate function to calculate exact color colorFunc = oeshape.OEExactColorFunc() colorFunc.SetupRef(refmol) res = oeshape.OEOverlapResults() fitmol = oechem.OEGraphMol() while oechem.OEReadMolecule(fitfs, fitmol): prep.Prep(fitmol) colorFunc.Overlap(fitmol, res) print("title: %s color score = %.2f" % (fitmol.GetTitle(), res.GetColorScore()))
def main(argv=[__name__]): if len(argv) != 4: oechem.OEThrow.Usage("%s <prot-infile> <lig-infile> <max-distance>" % argv[0]) ifs = oechem.oemolistream() if not ifs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open protein %s for reading" % argv[1]) prot = oechem.OEGraphMol() oechem.OEReadMolecule(ifs, prot) if not oechem.OEHasResidues(prot): oechem.OEPerceiveResidues(prot, oechem.OEPreserveResInfo_All) ifs = oechem.oemolistream() if not ifs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open ligand %s for reading" % argv[2]) lig = oechem.OEGraphMol() oechem.OEReadMolecule(ifs, lig) if not oechem.OEHasResidues(lig): oechem.OEPerceiveResidues(lig, oechem.OEPreserveResInfo_All) maxgap = float(argv[3]) PrintCloseContacts(prot, lig, maxgap)
def create_bound_receptor(protein_pdb_path, ligand_file_path): """Create an OpenEye receptor from a PDB file and ligand file. Parameters ---------- protein_pdb_path : str Path to the receptor PDB file. ligand_file_path : str Path to the ligand file (e.g. Tripos mol2). Can be any file format supported by openeye. Returns ------- receptor : openeye.oedocking.OEReceptor The OpenEye receptor object """ from openeye import oechem, oedocking # Load in protein input_mol_stream = oechem.oemolistream(protein_pdb_path) protein_oemol = oechem.OEGraphMol() oechem.OEReadMolecule(input_mol_stream, protein_oemol) # Load in ligand input_mol_stream = oechem.oemolistream(ligand_file_path) ligand_oemol = oechem.OEGraphMol() oechem.OEReadMolecule(input_mol_stream, ligand_oemol) receptor = oechem.OEGraphMol() oedocking.OEMakeReceptor(receptor, protein_oemol, ligand_oemol) return receptor
def main(argv=(__name__)): """ the protein should have charges and radii but the ligand need not """ itf = oechem.OEInterface() if not oechem.OEConfigure(itf, InterfaceData): oechem.OEThrow.Fatal("Problem configuring OEInterface!") if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to parse command line") ligFile = itf.GetString("-l") ims = oechem.oemolistream() if not ims.open(ligFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % ligFile) lig = oechem.OEGraphMol() oechem.OEReadMolecule(ims, lig) contextFile = itf.GetString("-p") ims = oechem.oemolistream() if not ims.open(contextFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % contextFile) prot = oechem.OEGraphMol() oechem.OEReadMolecule(ims, prot) highRes = itf.GetBool("-high_res") GetSzmapEnergies(lig, prot, highRes)
def main(args): if len(args) != 4: oechem.OEThrow.Usage("%s <protein> <ligand> <surface>" % args[0]) pfs = oechem.oemolistream(args[1]) prot = oechem.OEGraphMol() oechem.OEReadMolecule(pfs, prot) oechem.OEAssignBondiVdWRadii(prot) lfs = oechem.oemolistream(args[2]) lig = oechem.OEGraphMol() oechem.OEReadMolecule(lfs, lig) surf = oespicoli.OESurface() oespicoli.OEMakeMolecularSurface(surf, prot) oespicoli.OESurfaceToMoleculeDistance(surf, lig) # Mark the vertices to keep for i in range(surf.GetNumVertices()): if surf.GetDistanceElement(i) < MAX_DIST: surf.SetVertexCliqueElement(i, 1) # Crop to the binding site and output oespicoli.OESurfaceCropToClique(surf, 1) oespicoli.OEWriteSurface(args[3], surf) return 0
def main(argv=[__name__]): if len(argv) != 3: oechem.OEThrow.Usage("calc_et.py <reffile> <fitfile>") refmol = oechem.OEGraphMol() ifs = oechem.oemolistream() if not ifs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) oechem.OEReadMolecule(ifs, refmol) oechem.OEAssignBondiVdWRadii(refmol) oechem.OEMMFFAtomTypes(refmol) oechem.OEMMFF94PartialCharges(refmol) et = oezap.OEET() et.SetRefMol(refmol) oechem.OEThrow.Info("dielectric: %.4f" % et.GetDielectric()) oechem.OEThrow.Info("inner mask: %.4f" % et.GetInnerMask()) oechem.OEThrow.Info("outer mask: %.4f" % et.GetOuterMask()) oechem.OEThrow.Info("salt conc : %.4f" % et.GetSaltConcentration()) oechem.OEThrow.Info("join : %d" % et.GetJoin()) if not ifs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2]) fitmol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, fitmol): oechem.OEAssignBondiVdWRadii(fitmol) oechem.OEMMFFAtomTypes(fitmol) oechem.OEMMFF94PartialCharges(fitmol) oechem.OEThrow.Info("Title: %s, ET %4.2f" % (fitmol.GetTitle(), et.Tanimoto(fitmol))) return 0
def main(argv=[__name__]): if len(argv) != 4: oechem.OEThrow.Usage("%s <molfile> <protein> <outfile>" % argv[0]) lfs = oechem.oemolistream() if not lfs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) pfs = oechem.oemolistream() if not pfs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2]) ofs = oechem.oemolostream() if not ofs.open(argv[3]): oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3]) mol = oechem.OEGraphMol() oechem.OEReadMolecule(lfs, mol) protein = oechem.OEGraphMol() oechem.OEReadMolecule(pfs, protein) opts = oeszybki.OESzybkiOptions() sz = oeszybki.OESzybki(opts) sz.SetProtein(protein) res = oeszybki.OESzybkiResults() if not sz(mol, res): return 1 oechem.OEWriteMolecule(ofs, mol) res.Print(oechem.oeout) return 0
def main(args): if len(args) != 4: oechem.OEThrow.Usage("%s <protein> <ligand> <surface>" % args[0]) pfs = oechem.oemolistream(args[1]) prot = oechem.OEGraphMol() oechem.OEReadMolecule(pfs, prot) oechem.OEAssignBondiVdWRadii(prot) lfs = oechem.oemolistream(args[2]) lig = oechem.OEGraphMol() oechem.OEReadMolecule(lfs, lig) surf = oespicoli.OESurface() oespicoli.OEMakeMolecularSurface(surf, prot) # Iterate through all the protein surface vertices for i in range(surf.GetNumVertices()): vert = surf.GetVertex(i) # Check the distance to each atom for atom in lig.GetAtoms(): dist2 = GetDist2(lig.GetCoords(atom), vert) if dist2 < MAX_DIST * MAX_DIST: surf.SetVertexCliqueElement(i, 1) # Crop to the binding site and output oespicoli.OESurfaceCropToClique(surf, 1) oespicoli.OEWriteSurface(args[3], surf) return 0
def test_success(self): print('Testing cube:', self.cube.name) # File name fn_protein = ommutils.get_data_filename('examples', 'data/Bace_solvated.oeb.gz') fn_ligand = ommutils.get_data_filename('examples', 'data/lig_CAT13a_chg.oeb.gz') # Read Protein molecule protein = oechem.OEMol() with oechem.oemolistream(fn_protein) as ifs: oechem.OEReadMolecule(ifs, protein) # Read Ligand molecule ligand = oechem.OEMol() with oechem.oemolistream(fn_ligand) as ifs: oechem.OEReadMolecule(ifs, ligand) # Process the molecules self.cube.process(protein, self.cube.intake.name) # Why do I have to manually set these on? self.cube.check_system = True self.cube.system = protein self.cube.process(ligand, self.cube.system_port) # Assert that one molecule was emitted on the success port self.assertEqual(self.runner.outputs['success'].qsize(), 1) # Assert that zero molecules were emitted on the failure port self.assertEqual(self.runner.outputs['failure'].qsize(), 0) complex = self.runner.outputs["success"].get() self.assertEquals(complex.GetMaxAtomIdx(), 52312)
def setup_yank_calculation(receptor_file_name, ligand_file_name, setup_directory_name, solvate=False): # Cleanup setup directory if os.path.exists(setup_directory_name): shutil.rmtree(setup_directory_name) os.makedirs(setup_directory_name) # Read ligand and receptor molecule ifs_mol2 = oechem.oemolistream() ifs_mol2.open(ligand_file_name) ligand_oemol = oechem.OEGraphMol() oechem.OEReadMolecule(ifs_mol2, ligand_oemol) ifs_mol2.close() ifs_mol2 = oechem.oemolistream() ifs_mol2.open(receptor_file_name) receptor_oemol = oechem.OEGraphMol() oechem.OEReadMolecule(ifs_mol2, receptor_oemol) ifs_mol2.close() # Push ligand close to receptor pull_close(receptor_oemol, ligand_oemol, MIN_DISTANCE, MAX_DISTANCE) # Add residue name 'MOL' residue = oechem.OEResidue() residue.SetName('MOL') for atom in ligand_oemol.GetAtoms(): oechem.OEAtomSetResidue(atom, residue) # Parametrize ligand with working_directory(setup_directory_name): # Save translated ligand ofs = oechem.oemolostream() ofs.open('ligand.mol2') oechem.OEWriteMolecule(ofs, ligand_oemol) ofs.close() # Parametrize ligand print "Parameterizing ligand with GAFF..." run_command( 'antechamber -fi mol2 -i ligand.mol2 -fo mol2 -o ligand.gaff.mol2') run_command( 'parmchk -i ligand.gaff.mol2 -o ligand.gaff.frcmod -f mol2') # Copy receptor so that leap will know the PDB file name shutil.copyfile(receptor_file_name, 'receptor.pdb') # Create AMBER prmtop/inpcrd files. print "Creating AMBER prmtop/inpcrd files..." cmd = 'tleap -f {!s} > setup.leap.out' if solvate: run_command(cmd.format(LEAP_IN_EXPLICIT)) else: run_command(cmd.format(LEAP_IN_IMPLICIT))
def split_complex_from_system(self): with self.logger("split_complex_from_system") as logger: if self.input_pdb is not None: pdb = oechem.OEMol() prot = oechem.OEMol() lig = oechem.OEMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() ifs = oechem.oemolistream() ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default | oechem.OEIFlavor_PDB_DATA | oechem.OEIFlavor_PDB_ALTLOC) # noqa if ifs.open(self.input_pdb): oechem.OEReadMolecule(ifs, pdb) else: logger.error("Could not open file!") ifs.close() logger.log(f"Reading input PDB {self.input_pdb}") if not oechem.OESplitMolComplex(lig, prot, wat, other, pdb): logger.failure("could not split complex. exiting", exit_all=True) else: logger.log( f"Split complex. atom sizes-- lig: {len(list(lig.GetAtoms()))}, prot: {len(list(prot.GetAtoms()))}, water: {len(list(wat.GetAtoms()))}, other: {len(list(other.GetAtoms()))}" ) else: pdb = oechem.OEMol() prot = oechem.OEMol() lig = oechem.OEMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() ifs = oechem.oemolistream() ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default | oechem.OEIFlavor_PDB_DATA | oechem.OEIFlavor_PDB_ALTLOC) # noqa if ifs.open(self.input_pdb): oechem.OEReadMolecule(ifs, pdb) else: logger.error("Could not open file!") ifs.close() logger.log(f"Reading input PDB {self.input_pdb}") if not oechem.OESplitMolComplex(lig, prot, wat, other, pdb): logger.failure("could not split complex. exiting", exit_all=True) else: logger.log( f"Split complex. atom sizes-- lig: {len(list(lig.GetAtoms()))}, prot: {len(list(prot.GetAtoms()))}, water: {len(list(wat.GetAtoms()))}, other: {len(list(other.GetAtoms()))}" ) ifs = oechem.oemolistream(self.lig) lig = oechem.OEMol() oechem.OEReadMolecule(ifs, lig) ifs.close() return prot, lig
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) # Set up best overlay to the query molecule qfs = oechem.oemolistream() if not qfs.open(itf.GetString("-q")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-q")) qmol = oechem.OEMol() oechem.OEReadMolecule(qfs, qmol) # Set up overlap to protein exclusion volume efs = oechem.oemolistream() if not efs.open(itf.GetString("-e")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-e")) emol = oechem.OEMol() oechem.OEReadMolecule(efs, emol) evol = oeshape.OEExactShapeFunc() evol.SetupRef(emol) # open database and output streams ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-d")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-d")) ofs = oechem.oemolostream() if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-o")) print("Title Combo Rescore") for mol in ifs.GetOEMols(): res = oeshape.OEROCSResult() oeshape.OEROCSOverlay(res, qmol, mol) outmol = res.GetOverlayConf() # calculate overlap with protein eres = oeshape.OEOverlapResults() evol.Overlap(outmol, eres) frac = eres.GetOverlap() / eres.GetFitSelfOverlap() rescore = res.GetTanimotoCombo() - frac # attach data to molecule and write it oechem.OESetSDData(outmol, "TanimotoCombo", "%-.3f" % res.GetTanimotoCombo()) oechem.OESetSDData(outmol, "Exclusion Volume", "%-.3f" % eres.overlap) oechem.OESetSDData(outmol, "Fraction Overlap", "%-.3f" % frac) oechem.OESetSDData(outmol, "Rescore", "%-.3f" % rescore) oechem.OEWriteMolecule(ofs, outmol) print("%-20s %.3f %.3f" % (outmol.GetTitle(), res.GetTanimotoCombo(), rescore))
def main(args): if len(args) != 3: oechem.OEThrow.Usage("%s <protein> <ligand>" % args[0]) pifs = oechem.oemolistream() if not pifs.open(args[1]): oechem.OEThrow.Fatal("Unable to open %s for reading protein." % args[1]) prot = oechem.OEGraphMol() if not oechem.OEReadMolecule(pifs, prot): oechem.OEThrow.Fatal("Unable to read protein") oechem.OEAddExplicitHydrogens(prot) oechem.OEAssignBondiVdWRadii(prot) lifs = oechem.oemolistream() if not lifs.open(args[2]): oechem.OEThrow.Fatal("Unable to open %s for reading ligand." % args[2]) lig = oechem.OEGraphMol() if not oechem.OEReadMolecule(lifs, lig): oechem.OEThrow.Fatal("Unable to read ligand") oechem.OEAddExplicitHydrogens(lig) oechem.OEAssignBondiVdWRadii(lig) comp = oechem.OEGraphMol(prot) oechem.OEAddMols(comp, lig) compSurf = oespicoli.OESurface() oespicoli.OEMakeMolecularSurface(compSurf, comp) protSurf = oespicoli.OESurface() oespicoli.OEMakeMolecularSurface(protSurf, prot) ligSurf = oespicoli.OESurface() oespicoli.OEMakeMolecularSurface(ligSurf, lig) compVol = oespicoli.OESurfaceVolume(compSurf) protVol = oespicoli.OESurfaceVolume(protSurf) ligVol = oespicoli.OESurfaceVolume(ligSurf) oespicoli.OEWriteSurface("comp.oesrf", compSurf) oespicoli.OEWriteSurface("prot.oesrf", protSurf) oespicoli.OEWriteSurface("lig.oesrf", ligSurf) oechem.OEThrow.Info( "%s-%s: dV(C-P) = %.1f V(L) = %.1f V(C) = %.1f V(P) = %.1f" % (prot.GetTitle(), lig.GetTitle(), compVol - protVol, ligVol, compVol, protVol)) return 0
def main(args): if len(args) != 4: oechem.OEThrow.Usage("%s <protein> <ligand> <output>" % args[0]) ips = oechem.oemolistream() if not ips.open(args[1]): oechem.OEThrow.Fatal("Unable to open %s for reading protein" % args[1]) ils = oechem.oemolistream() if not ils.open(args[2]): oechem.OEThrow.Fatal("Unable to open %s for reading ligand" % args[2]) ofs = oechem.oemolostream() if not ofs.open(args[3]): oechem.OEThrow.Fatal("Unable to open %s for writing" % args[3]) # Load the protein molecule and Prepare with MMFF protein = oechem.OEGraphMol() oechem.OEReadMolecule(ips, protein) oechem.OEAddExplicitHydrogens(protein) mmff = oeff.OEMMFFAmber(protein) mmff.PrepMol(protein) mol = oechem.OEMol() while oechem.OEReadMolecule(ils, mol): oechem.OEAddExplicitHydrogens(mol) if (not mmff.PrepMol(mol)) or (not mmff.Setup(mol)): oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" % mol.GetTitle()) oechem.OEWriteMolecule(ofs, mol) continue vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx()) for conf in mol.GetConfs(): oechem.OEThrow.Info("Molecule: %s Conformer: %d" % (mol.GetTitle(), conf.GetIdx() + 1)) conf.GetCoords(vecCoords) # Calculate energy energy = mmff(vecCoords) oechem.OEThrow.Info("Initial energy: %d kcal/mol" % energy) # Optimize the ligand optimizer = oeff.OEBFGSOpt() energy = optimizer(mmff, vecCoords, vecCoords) oechem.OEThrow.Info("Optimized energy: %d kcal/mol" % energy) conf.SetCoords(vecCoords) oechem.OEWriteMolecule(ofs, mol) return 0
def load_database(database, mol2_directory, verbose=False): """ This function prepares the database that will be use in sampling. Arguments --------- database : dict an unpickled version of the FreeSolv database mol2_directory : String the path to the FreeSolv mol2 files containing geometry and charges verbose : Boolean, optional verbosity Returns ------- database : dict An updated version of the database dict containing OEMols """ start_time = time.time() if verbose: print( "Reading all molecules in dataset. Will use charges and coordinates from dataset." ) for cid in database.keys(): entry = database[cid] # Store temperature # TODO: Get this from database? entry['temperature'] = 300.0 * units.kelvin # Extract relevant entry data from database. smiles = entry['smiles'] iupac_name = entry['iupac'] experimental_DeltaG = entry['expt'] * units.kilocalories_per_mole experimental_dDeltaG = entry['d_expt'] * units.kilocalories_per_mole # Read molecule. molecule = openeye.oechem.OEMol() # Load the mol2 file. tripos_mol2_filename = os.path.join(mol2_directory, cid + '.mol2') omolstream = oechem.oemolistream(tripos_mol2_filename) oechem.OEReadMolecule(omolstream, molecule) omolstream.close() molecule.SetTitle(iupac_name) molecule.SetData('cid', cid) # Add explicit hydrogens. oechem.OEAddExplicitHydrogens(molecule) # Store molecule. entry['molecule'] = oechem.OEMol(molecule) if verbose: print "%d molecules read" % len(database.keys()) end_time = time.time() elapsed_time = end_time - start_time print "%.3f s elapsed" % elapsed_time return database
def get_stage_topology(self, stg_name='last'): """ This method returns the MD topology of the selected stage name. If no stage name is passed the last stage is selected. Parameters ----------- stg_name: String The MD stage name Returns ------- topology : OEMol The topology of the selected MD stage """ stage = self.get_stage_by_name(stg_name) stage_name = stage.get_value(Fields.stage_name) dir_stage = self.processed[stage_name] topology_fn = os.path.join(dir_stage, MDFileNames.topology) topology = oechem.OEMol() with oechem.oemolistream(topology_fn) as ifs: oechem.OEReadMolecule(ifs, topology) return topology
def read_molecule(filename): ifs = oechem.oemolistream() ifs.open(filename) molecule = oechem.OEMol() oechem.OEReadMolecule(ifs, molecule) ifs.close() return molecule
def main(args): if len(args) != 3: oechem.OEThrow.Usage("%s input_molecule output_molecule" % args[0]) ifs = oechem.oemolistream() if not ifs.open(args[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1]) ofs = oechem.oemolostream() if not ofs.open(args[2]): oechem.OEThrow.Fatal("Unable to open %s for writing" % args[2]) mol = oechem.OEMol() oechem.OEReadMolecule(ifs, mol) opts = oeszybki.OESzybkiOptions() opts.GetOptOptions().SetOptimizerType(oeszybki.OEOptType_NEWTON) opts.GetSolventOptions().SetSolventModel(oeszybki.OESolventModel_Sheffield) sz = oeszybki.OESzybki(opts) res = oeszybki.OESzybkiResults() if (sz(mol, res)): oechem.OEWriteMolecule(ofs, mol) res.Print(oechem.oeout) return 0
def test_generat_torsions(self): """ Tests finding torsion to drive """ from openeye import oechem infile = get_fn('butane.pdb') ifs = oechem.oemolistream(infile) inp_mol = oechem.OEMol() oechem.OEReadMolecule(ifs, inp_mol) outfile_path = tempfile.mkdtemp()[1] qmscan.generate_torsions(inp_mol=inp_mol, output_path=outfile_path, interval=30, tar=False) input_files = [] pattern = '*.pdb' for path, subdir, files in os.walk(outfile_path): for name in files: if fnmatch(name, pattern): input_files.append(os.path.join(path, name)) contents = open(input_files[0]).read() pdb = get_fn('butane_10_7_4_3_0.pdb') compare_contents = open(pdb).read() self.assertEqual(contents, compare_contents) shutil.rmtree(outfile_path)
def main(argv=[__name__]): if len(argv) != 3: oechem.OEThrow.Usage("%s <reffile> <fitfile>" % argv[0]) reffs = oechem.oemolistream(argv[1]) fitfs = oechem.oemolistream(argv[2]) refmol = oechem.OEGraphMol() oechem.OEReadMolecule(reffs, refmol) # Prepare reference molecule for calculation # With default options this will remove any explicit # hydrogens present and add color atoms prep = oeshape.OEOverlapPrep() prep.Prep(refmol) # Get appropriate function to calculate both shape and color # By default the OEOverlapFunc contains OEGridShapeFunc for shape # and OEExactColorFunc for color func = oeshape.OEOverlapFunc() func.SetupRef(refmol) res = oeshape.OEOverlapResults() for fitmol in fitfs.GetOEGraphMols(): prep.Prep(fitmol) func.Overlap(fitmol, res) print("title: %s tanimoto combo = %.2f shape tanimoto = %.2f color tanimoto = %.2f" % (fitmol.GetTitle(), res.GetTanimotoCombo(), res.GetTanimoto(), res.GetColorTanimoto()))
def _create_receptor(self): """Create an OpenEye receptor from a mol2 file. Returns ------- openeye.oedocking.OEReceptor The OpenEye receptor object. """ from openeye import oechem, oedocking input_stream = oechem.oemolistream(self.receptor_coordinate_file) original_receptor_molecule = oechem.OEGraphMol() oechem.OEReadMolecule(input_stream, original_receptor_molecule) center_of_mass = oechem.OEFloatArray(3) oechem.OEGetCenterOfMass(original_receptor_molecule, center_of_mass) receptor = oechem.OEGraphMol() oedocking.OEMakeReceptor( receptor, original_receptor_molecule, center_of_mass[0], center_of_mass[1], center_of_mass[2], ) return receptor
def file_to_oemols(filename): """Create OEMol from file. If more than one mol in file, return list of OEMols. Parameters ---------- filename: str absolute path to oeb file Returns ------- mollist: list list of OEMol for multiple molecules. OEMol if file only has one molecule. """ from openeye import oechem if not os.path.exists(filename): raise Exception("File {} not found".format(filename)) ifs = oechem.oemolistream(filename) mollist = [] molecule = oechem.OEMol() while oechem.OEReadMolecule(ifs, molecule): molecule_copy = oechem.OEMol(molecule) oechem.OEPerceiveChiral(molecule_copy) oechem.OE3DToAtomStereo(molecule_copy) oechem.OE3DToBondStereo(molecule_copy) mollist.append(molecule_copy) ifs.close() if len(mollist) is 1: mollist = mollist[0] return mollist
def test_smirnoff_energies_vs_parmatfrosst(verbose=False): """Test evaluation of energies from parm@frosst ffxml files versus energies of equivalent systems.""" from openeye import oechem prefix = 'AlkEthOH_' molecules = ['r118', 'r12', 'c1161', 'r0', 'c100', 'c38', 'c1266'] # Loop over molecules, load OEMols and prep for comparison/do comparison for molnm in molecules: f_prefix = os.path.join('molecules', prefix + molnm) mol2file = get_data_filename(f_prefix + '.mol2') prmtop = get_data_filename(f_prefix + '.top') crd = get_data_filename(f_prefix + '.crd') # Load special parm@frosst with parm99/parm@frosst bugs re-added for testing forcefield = ForceField( get_data_filename('forcefield/Frosst_AlkEthOH_parmAtFrosst.ffxml')) # Load OEMol 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) # Do comparison results = compare_molecule_energies(prmtop, crd, forcefield, mol, verbose=verbose)
def test_improper(verbose=False): """Test implement of impropers on benzene.""" from openeye import oechem # Load benzene ifs = oechem.oemolistream(get_data_filename('molecules/benzene.mol2')) mol = oechem.OEMol() flavor = oechem.OEIFlavor_Generic_Default | oechem.OEIFlavor_MOL2_Default | oechem.OEIFlavor_MOL2_Forcefield ifs.SetFlavor(oechem.OEFormat_MOL2, flavor) oechem.OEReadMolecule(ifs, mol) ifs.close() # Load forcefield ffxml = get_data_filename('forcefield/benzene_minimal.ffxml') ff = ForceField(ffxml) # Load AMBER files and compare crd = get_data_filename('molecules/benzene.crd') top = get_data_filename('molecules/benzene.top') g0, g1, e0, e1 = compare_molecule_energies(top, crd, ff, mol, skip_assert=True) # Check that torsional energies the same to 1 in 10^6 rel_error = np.abs((g0['torsion'] - g1['torsion']) / g0['torsion']) if rel_error > 2e-5: #Note that this will not be tiny because we use six-fold impropers and they use a single improper raise Exception( "Improper torsion energy for benzene differs too much (relative error %.4g) between AMBER and SMIRNOFF." % rel_error)
def test_merge_system(): """Test merging of a system created from AMBER and another created from SMIRNOFF.""" #Create System from AMBER prefix = os.path.join('systems', 'amber', 'cyclohexane_ethanol_0.4_0.6') prmtop = get_data_filename(prefix + '.prmtop') incrd = get_data_filename(prefix + '.inpcrd') from openforcefield.typing.engines.smirnoff import create_system_from_amber topology0, system0, positions0 = create_system_from_amber(prmtop, incrd) from openeye import oechem # Load simple OEMol ifs = oechem.oemolistream( get_data_filename('molecules/AlkEthOH_c100.mol2')) mol = oechem.OEMol() 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) # Load forcefield file forcefield = ForceField( get_data_filename('forcefield/Frosst_AlkEthOH.ffxml')) topology1, system1, positions1 = create_system_from_molecule( forcefield, mol) merge_system(topology0, topology1, system0, system1, positions0, positions1, verbose=True)
def test_excipient_successGaff2(self): print('Testing cube:', self.cube.name) # File name fn_complex = ommutils.get_data_filename( 'examples', 'data/pbace_lcat13a_solvated_complex.oeb.gz') # Read Protein molecule complex = oechem.OEMol() with oechem.oemolistream(fn_complex) as ifs: oechem.OEReadMolecule(ifs, complex) # Selecting ligand and excipient parametrization self.cube.args.ligand_forcefield = 'GAFF2' self.cube.args.other_forcefield = 'GAFF2' # Process the molecules self.cube.process(complex, self.cube.intake.name) # Assert that one molecule was emitted on the success port self.assertEqual(self.runner.outputs['success'].qsize(), 1) # Assert that zero molecules were emitted on the failure port self.assertEqual(self.runner.outputs['failure'].qsize(), 0) complex = self.runner.outputs["success"].get()
def run_select_final(args): """Generates an SMI file with final selected molecules from SELECT mode.""" logging.info("STARTING SELECT-FINAL") directory = args["select_final_dir"] output_file = args["select_final_output_file"] ofs = oechem.oemolostream(output_file) n = args["select_final_n"] logging.info( f"Reading molecules in {directory}, selecting and writing to {output_file}" ) for f in glob.iglob(f"{directory}/*.smi"): ifs = oechem.oemolistream(f) mols = [] mol = oechem.OEMol() while oechem.OEReadMolecule(ifs, mol): mols.append(oechem.OEMol(mol)) ifs.close() logging.debug(f"Found {len(mols)} mols in {f}") mols.sort(key=lambda m: m.NumAtoms()) for m in mols[:n]: oechem.OEWriteMolecule(ofs, m) ofs.close() logging.info("FINISHED SELECT-FINAL")
def convert_mdtraj_to_oemol(traj: md.Trajectory) -> oechem.OEMol: """ This method converts an mdtraj Trajectory to an OEMol via saving as a PDBfile and reading in with OpenEye. Although this seems hacky, it seems less error-prone than trying to manually construct the OEMol. Parameters ---------- mdtraj: md.Trajectory The trajectory to turn into an OEMol Returns ------- mol : oechem.OEMol The trajectory represented as an OEMol """ # create a temporary file with a PDB suffix and save with MDTraj pdb_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdb") traj.save(pdb_file.name) pdb_file.close() # Now use the openeye oemolistream to read in this file as an OEMol: ifs = oechem.oemolistream() ifs.open(pdb_file.name) ifs.SetFormat(oechem.OEFormat_PDB) mol = oechem.OEMol() oechem.OEReadMolecule(ifs, mol) # close the stream and delete the temporary pdb file ifs.close() os.unlink(pdb_file.name) return mol
def main(argv=[__name__]): if len(argv) != 2: oechem.OEThrow.Usage("%s <molfile>" % argv[0]) epsin = 1.0 zap = oezap.OEZap() zap.SetInnerDielectric(epsin) zap.SetGridSpacing(0.5) area = oezap.OEArea() mol = oechem.OEGraphMol() ifs = oechem.oemolistream() if not ifs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) oechem.OEThrow.Info("%-20s %6s\n" % ("Title", "Vacuum->Water(kcal)")) while oechem.OEReadMolecule(ifs, mol): oechem.OEAssignBondiVdWRadii(mol) oechem.OEMMFFAtomTypes(mol) oechem.OEMMFF94PartialCharges(mol) zap.SetMolecule(mol) solv = zap.CalcSolvationEnergy() aval = area.GetArea(mol) oechem.OEThrow.Info("%-20s %6.2f" % (mol.GetTitle(), KCalsPerKT*solv+KCalsPerSqAngstrom*aval)) return 0