def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) if not itf.HasString("-smirks") and not itf.HasString("-rxn"): oechem.OEThrow.Fatal( "Please provide SMIRKS string or MDL reaction file") if itf.HasString("-smirks") and itf.HasString("-rxn"): oechem.OEThrow.Fatal( "Please provide only SMIRKS string or MDL reaction file") reaction = oechem.OEQMol() if itf.HasString("-smirks"): smirks = itf.GetString("-smirks") if not oechem.OEParseSmirks(reaction, smirks): oechem.OEThrow.Fatal("Unable to parse SMIRKS: %s" % smirks) else: rxn = itf.GetString("-rxn") rfile = oechem.oemolistream(rxn) opt = oechem.OEMDLQueryOpts_ReactionQuery | oechem.OEMDLQueryOpts_SuppressExplicitH if not oechem.OEReadMDLReactionQueryFile(rfile, reaction, opt): oechem.OEThrow.Fatal("Unable to read reaction file: %s" % rxn) relax = itf.GetBool("-relax") unique = itf.GetBool("-unique") implicitH = itf.GetBool("-implicitH") valcorrect = itf.GetBool("-valence") isomeric = itf.GetBool("-isomeric") libgen = oechem.OELibraryGen() if not libgen.Init(reaction, not relax): oechem.OEThrow.Fatal("failed to initialize library generator") libgen.SetValenceCorrection(valcorrect) libgen.SetExplicitHydrogens(not implicitH) libgen.SetClearCoordinates(True) ofs = oechem.oemolostream(".smi") if itf.HasString("-product"): ofs.open(itf.GetString("-product")) nrReacts = 0 while itf.HasString("-reactants", nrReacts): fileName = itf.GetString("-reactants", nrReacts) if nrReacts >= libgen.NumReactants(): oechem.OEThrow.Fatal("Number of reactant files exceeds number of \ reactants specified in reaction") ifs = oechem.oemolistream() if not ifs.open(fileName): oechem.OEThrow.Fatal("Unable to read %s reactant file" % fileName) for mol in ifs.GetOEGraphMols(): libgen.AddStartingMaterial(mol, nrReacts, unique) nrReacts += 1 if nrReacts != libgen.NumReactants(): oechem.OEThrow.Fatal("Reactions requires %d reactant files!" % libgen.NumReactants()) LibGen(libgen, ofs, unique, isomeric)
rfile = oechem.oemolistream("amide.rxn") reaction = oechem.OEQMol() # reading reaction # @ <SNIPPET-RXN-OPT> opt = oechem.OEMDLQueryOpts_ReactionQuery | oechem.OEMDLQueryOpts_SuppressExplicitH # @ </SNIPPET-RXN-OPT> # @ <SNIPPET-READREACTION> oechem.OEReadMDLReactionQueryFile(rfile, reaction, opt) # @ </SNIPPET-READREACTION> # @ <SNIPPET-RXN-ATOMS> printatoms("Reactant atoms:", reaction.GetQAtoms(oechem.OEAtomIsInReactant())) printatoms("Product atoms :", reaction.GetQAtoms(oechem.OEAtomIsInProduct())) # @ </SNIPPET-RXN-ATOMS> # initializing library generator libgen = oechem.OELibraryGen() libgen.Init(reaction) # @ <SNIPPET-RXN-EXPH> libgen.SetExplicitHydrogens(False) # @ </SNIPPET-RXN-EXPH> # @ <SNIPPET-RXN-VCORRECT> libgen.SetValenceCorrection(True) # @ </SNIPPET-RXN-VCORRECT> # adding reactants mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "c1ccc(cc1)C(=O)O") libgen.AddStartingMaterial(mol, 0) mol.Clear() oechem.OESmilesToMol(mol, "CC(C)CN") libgen.AddStartingMaterial(mol, 1) # accessing generated products
# subject to these terms. OpenEye claims no rights to Customer's # modifications. Modification of Sample Code is at Customer's sole and # exclusive risk. Sample Code may require Customer to have a then # current license or subscription to the applicable OpenEye offering. # THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT # NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be # liable for any damages or liability in connection with the Sample Code # or its use. # @ <SNIPPET> from __future__ import print_function from openeye import oechem libgen = oechem.OELibraryGen("[O:1]=[C:2][Cl:3].[N:4]>>[O:1]=[C:2][N:4]") libgen.SetExplicitHydrogens(False) libgen.SetValenceCorrection(True) mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "CC(=O)Cl") libgen.SetStartingMaterial(mol, 0) mol.Clear() oechem.OESmilesToMol(mol, "NCC") libgen.SetStartingMaterial(mol, 1) for product in libgen.GetProducts(): print("product smiles =", oechem.OEMolToSmiles(product)) # @ </SNIPPET>
# subject to these terms. OpenEye claims no rights to Customer's # modifications. Modification of Sample Code is at Customer's sole and # exclusive risk. Sample Code may require Customer to have a then # current license or subscription to the applicable OpenEye offering. # THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT # NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be # liable for any damages or liability in connection with the Sample Code # or its use. # @ <SNIPPET> from __future__ import print_function from openeye import oechem lg = oechem.OELibraryGen() lg.Init( "[N:3][c:4]1[n:2][c:7][c:6][c:5][n:1]1>>[c:6]1[c:7][n:2][c:4]2[n:3]cc[n:1]2[c:5]1" ) lg.SetExplicitHydrogens(False) lg.SetValenceCorrection(True) mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "c1cnc(nc1O)N") matches = lg.AddStartingMaterial(mol, 0, False) print("number of matches =", matches) for product in lg.GetProducts(): print("product smiles =", oechem.OEMolToSmiles(product)) # @ </SNIPPET>