public MoleCulePostion(string smiles) { Mol = MolImporter.importMol(smiles); //将苯环的圈改为双线 Mol.dearomatize(); chemaxon.calculations.clean.Cleaner.clean(Mol, 2); //重置类参数 InitPosition(); //重置原子垂直坐标 InitAtom(); }
private MemoryStream writeq() { //树绘图 MDocument md = new MDocument(MolImporter.importMol("O")); MPoint p1 = new MPoint(1, 1); MPoint p2 = new MPoint(1, 2); MPolyline arrow = new MRectangle(p1, p2); md.addObject(arrow); MemoryStream stream = new MemoryStream(MolExporter.exportToBinFormat(md, "mrv")); return(stream); }
public static bool MoleculeComparisonTest(string mol1, string mol2) { bool blStatus = false; try { string testMol1 = @" ACCLDraw01081514282D 22 23 0 0 0 0 0 0 0 0999 V2000 8.7283 -2.9723 0.0000 C 0 0 0 0 0 0 0 0 0 8 0 0 5.6037 -2.9121 0.0000 C 0 0 0 0 0 0 0 0 0 11 0 0 6.7270 -2.5471 0.0000 O 0 0 0 0 0 0 0 0 0 10 0 0 7.6048 -3.3374 0.0000 C 0 0 0 0 0 0 0 0 0 9 0 0 5.9904 -6.0131 0.0000 C 0 0 0 0 0 0 0 0 0 14 0 0 6.2360 -4.8578 0.0000 O 0 0 0 0 0 0 0 0 0 13 0 0 7.3593 -4.4927 0.0000 C 0 0 0 0 0 0 0 0 0 12 0 0 8.8692 -7.2288 0.0000 C 0 0 0 0 0 0 0 0 0 17 0 0 7.9915 -6.4384 0.0000 O 0 0 0 0 0 0 0 0 0 16 0 0 8.2371 -5.2831 0.0000 C 0 0 0 0 0 0 0 0 0 15 0 0 9.3604 -4.9180 0.0000 C 0 0 0 0 0 0 0 0 0 18 0 0 9.6059 -3.7626 0.0000 C 0 0 0 0 0 0 0 0 0 7 0 0 12.2755 -2.2744 0.0000 N 0 0 0 0 0 0 0 0 0 4 0 0 11.0943 -2.2744 0.0000 N 0 0 0 0 0 0 0 0 0 5 0 0 10.7293 -3.3978 0.0000 C 0 0 0 0 0 0 0 0 0 6 0 0 11.6848 -4.0921 0.0000 N 0 0 3 0 0 0 0 0 0 1 0 0 12.6405 -3.3978 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0 13.7638 -3.7626 0.0000 S 0 0 0 0 0 0 0 0 0 3 0 0 14.6416 -2.9723 0.0000 C 0 0 0 0 0 0 0 0 0 20 0 0 16.0106 -4.4927 0.0000 O 0 0 0 0 0 0 0 0 0 22 0 0 15.7649 -3.3374 0.0000 C 0 0 0 0 0 0 0 0 0 21 0 0 16.6427 -2.5471 0.0000 O 0 0 0 0 0 0 0 0 0 23 0 0 12 1 1 0 0 0 2 1 4 2 0 0 0 2 3 2 1 0 0 0 2 4 3 1 0 0 0 2 4 7 1 0 0 0 2 6 5 1 0 0 0 2 7 6 1 0 0 0 2 7 10 2 0 0 0 2 9 8 1 0 0 0 2 10 9 1 0 0 0 2 10 11 1 0 0 0 2 11 12 2 0 0 0 2 15 12 1 0 0 0 2 17 13 2 0 0 0 8 13 14 1 0 0 0 8 14 15 2 0 0 0 8 15 16 1 0 0 0 8 16 17 1 0 0 0 8 17 18 1 0 0 0 8 18 19 1 0 0 0 4 19 21 1 0 0 0 2 21 20 2 0 0 0 2 21 22 1 0 0 0 2 M END "; string testMol2 = @" ACCLDraw01081514312D 21 22 0 0 0 0 0 0 0 0999 V2000 9.0242 -4.6483 0.0000 N 0 0 0 0 0 0 0 0 0 9 0 0 10.2054 -4.6483 0.0000 N 0 0 3 0 0 0 0 0 0 8 0 0 14.5726 -4.9211 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 13.9404 -6.8668 0.0000 O 0 0 0 0 0 0 0 0 0 6 0 0 13.6947 -5.7114 0.0000 C 0 0 0 0 0 0 0 0 0 5 0 0 12.5714 -5.3464 0.0000 C 0 0 0 0 0 0 0 0 0 4 0 0 11.6936 -6.1367 0.0000 S 0 0 0 0 0 0 0 0 0 3 0 0 10.5703 -5.7718 0.0000 C 0 0 0 0 0 0 0 0 0 2 0 0 9.6148 -6.4660 0.0000 N 0 0 0 0 0 0 0 0 0 1 0 0 8.6592 -5.7718 0.0000 C 0 0 0 0 0 0 0 0 0 10 0 0 6.6580 -5.3464 0.0000 C 0 0 0 0 0 0 0 0 0 12 0 0 7.5359 -6.1367 0.0000 C 0 0 0 0 0 0 0 0 0 11 0 0 7.2902 -7.2921 0.0000 C 0 0 0 0 0 0 0 0 0 22 0 0 5.9214 -8.8123 0.0000 O 0 0 0 0 0 0 0 0 0 20 0 0 6.1669 -7.6571 0.0000 C 0 0 0 0 0 0 0 0 0 19 0 0 3.9203 -8.3871 0.0000 C 0 0 0 0 0 0 0 0 0 18 0 0 4.1658 -7.2317 0.0000 O 0 0 0 0 0 0 0 0 0 17 0 0 5.2891 -6.8666 0.0000 C 0 0 0 0 0 0 0 0 0 16 0 0 5.5347 -5.7114 0.0000 C 0 0 0 0 0 0 0 0 0 13 0 0 4.6570 -4.9211 0.0000 O 0 0 0 0 0 0 0 0 0 14 0 0 3.5336 -5.2860 0.0000 C 0 0 0 0 0 0 0 0 0 15 0 0 10 1 2 0 0 0 2 1 2 1 0 0 0 2 2 8 1 0 0 0 2 5 3 1 0 0 0 4 5 4 2 0 0 0 2 6 5 1 0 0 0 2 7 6 1 0 0 0 2 8 7 1 0 0 0 2 8 9 2 0 0 0 2 9 10 1 0 0 0 2 10 12 1 0 0 0 2 11 19 2 0 0 0 2 12 11 1 0 0 0 2 13 12 2 0 0 0 2 15 13 1 0 0 0 2 15 14 1 0 0 0 2 18 15 2 0 0 0 2 17 16 1 0 0 0 2 18 17 1 0 0 0 2 19 18 1 0 0 0 2 19 20 1 0 0 0 2 20 21 1 0 0 0 2 M END "; Molecule Molecule1 = MolImporter.importMol(testMol1); Molecule Molecule2 = MolImporter.importMol(testMol2); MolSearch s = new MolSearch(); s.setQuery(Molecule1); s.setTarget(Molecule2); if (s.isMatching()) { } } catch (Exception) { throw; } return(blStatus); }
public static bool ValidateReactantsAndProductsWithReactionScheme(DataTable rxnData, string rxnScheme, out string errMsg) { bool blStatus = true; string strErrMsg = ""; try { if (!string.IsNullOrEmpty(rxnScheme) && rxnData != null) { RxnMolecule rxnMolecule = RxnMolecule.getReaction(MolImporter.importMol(rxnScheme)); if (rxnMolecule != null) { int reactantsCnt = rxnMolecule.getReactantCount(); int productsCnt = rxnMolecule.getProductCount(); Molecule molReactant = null; int rctMatchCnt = 0; string schReactInchi = ""; string tblReactInchi = ""; Molecule molProduct = null; int prodMatchCnt = 0; string schProdInchi = ""; string tblProdInchi = ""; //Get Reactants count int tblRctCnt = (from r in rxnData.AsEnumerable() where r.Field <string>("PRPNT_TYPE") == "REACTANT" select r).Count(); //Get Products Count int tblProdCnt = (from r in rxnData.AsEnumerable() where r.Field <string>("PRPNT_TYPE") == "PRODUCT" select r).Count(); //Reactants for (int rctIndx = 0; rctIndx < reactantsCnt; rctIndx++) { molReactant = rxnMolecule.getReactant(rctIndx); schReactInchi = GetStructureInchiKey(molReactant.toFormat("mol")); for (int rxnIndx = 0; rxnIndx < rxnData.Rows.Count; rxnIndx++) { if (rxnData.Rows[rxnIndx]["PRPNT_TYPE"].ToString() == "REACTANT") { tblReactInchi = GetStructureInchiKey(rxnData.Rows[rxnIndx]["PRPNT_STRUCTURE"].ToString()); if (schReactInchi == tblReactInchi) { rctMatchCnt++; break; } } } } //Products for (int prodIndx = 0; prodIndx < productsCnt; prodIndx++) { molProduct = rxnMolecule.getProduct(prodIndx); schProdInchi = GetStructureInchiKey(molProduct.toFormat("mol")); for (int rxnIndx = 0; rxnIndx < rxnData.Rows.Count; rxnIndx++) { if (rxnData.Rows[rxnIndx]["PRPNT_TYPE"].ToString() == "PRODUCT") { tblProdInchi = GetStructureInchiKey(rxnData.Rows[rxnIndx]["PRPNT_STRUCTURE"].ToString()); if (schProdInchi == tblProdInchi) { prodMatchCnt++; break; } } } } //Reactants count matching if (tblRctCnt != reactantsCnt) { blStatus = false; strErrMsg = "Scheme reactants count not matching with reaction reactants"; } //Products count matching if (tblProdCnt != productsCnt) { blStatus = false; strErrMsg = "Scheme products count not matching with reaction products"; } if (rctMatchCnt != reactantsCnt) { blStatus = false; strErrMsg = "Scheme reactants are not matching with reaction reactants"; } if (prodMatchCnt != productsCnt) { blStatus = false; strErrMsg = strErrMsg.Trim() + "\r\n" + "Scheme products are not matching with reaction products"; } } } } catch (Exception ex) { ErrorHandling.WriteErrorLog(ex.ToString()); } errMsg = strErrMsg.Trim(); return(blStatus); }
public static string GetReactionSchemeFromReactionTable(DataTable rxnData, bool atomAutoMap) { string strMolFile = ""; try { if (rxnData != null) { RxnMolecule rxnMol = new RxnMolecule(); MolHandler mHandler1; //Add Reactants to RxnMol for (int i = 0; i < rxnData.Rows.Count; i++) { if (rxnData.Rows[i]["PRPNT_TYPE"].ToString().ToUpper() == "REACTANT") { mHandler1 = new MolHandler(rxnData.Rows[i]["PRPNT_STRUCTURE"].ToString()); rxnMol.addComponent(mHandler1.getMolecule(), 0, true); } } //Add Products to RxnMol for (int i = 0; i < rxnData.Rows.Count; i++) { if (rxnData.Rows[i]["PRPNT_TYPE"].ToString().ToUpper() == "PRODUCT") { mHandler1 = new MolHandler(rxnData.Rows[i]["PRPNT_STRUCTURE"].ToString()); rxnMol.addComponent(mHandler1.getMolecule(), 1, true); } } //string strSmiles = rxnMol.exportToFormat("smiles"); RxnMolecule rxnMolecule = RxnMolecule.getReaction(MolImporter.importMol(rxnMol.toFormat("mol"))); //If Auto mapping is checked if (atomAutoMap) { AutoMapper mapper = new AutoMapper(); mapper.setMappingStyle(AutoMapper.MATCHING); try { mapper.map(rxnMolecule); } catch { } } //MolHandler mh = new MolHandler(rxnMolecule.toFormat("mol")); //mh.clean(true, "2D"); //strMolFile = mh.toFormat("mol");// reaction.toFormat("mol"); strMolFile = rxnMolecule.toFormat("mol"); #region Code commented //AutoMapper mapper = new AutoMapper(); ////Molecule mol = MolImporter.importMol(rxnMol.exportToFormat("smiles")); //// RxnMolecule rm = RxnMolecule.getReaction(mol); //mapper.setReaction(rxnMol); //mapper.setMappingStyle(AutoMapper.CHANGING); //mapper.map(rxnMol, true); //AutoMapper.mapReaction(rxnMol); //MolImporter importer = new MolImporter("unmapped.smiles"); //MolExporter exporter = new MolExporter("mapped.mol", "sdf"); //AutoMapper.mapReaction(importer, exporter); //importer.close(); //exporter.close(); //MDL.Draw.Modules.Editor.Actions.Calcs. //GenericEditorModule mod = RenditorRxnScheme; //MDL.Draw.Modules.Editor.Actions.Calcs.AutoMapAction mp = new MDL.Draw.Modules.Editor.Actions.Calcs.AutoMapAction(); //mp.Editor.AppendStructureToEditor(rxnMol.toFormat("mol")); //RenditorRxnScheme.Preferences.AtomAtomDisplayMode = MDL.Draw.Renderer.Preferences.AtomAtomMappingDisplayMode.On; //RenditorRxnScheme.Preferences.AtomChargeDisplay = true; //RenditorRxnScheme.Preferences.StereoChemistryMode = MDL.Draw.Renderer.Preferences.StereoChemistryModeEnum.Absolute; //RenditorRxnScheme.Preferences.ReactionCenterSize = 5.5; //RenditorRxnScheme.Preferences. //RenditorRxnScheme.MolfileString = rxnMol.toFormat("mol"); #endregion } } catch (Exception ex) { ErrorHandling.WriteErrorLog(ex.ToString()); } return(strMolFile); }
private static bool CompareProductsAndReactantsInTables(DataTable productData, DataTable reactantData) { bool blStatus = true; try { int productsCnt = 0; int reactantsCnt = 0; RxnMolecule prodRxnMolecule = null; RxnMolecule rctRxnMolecule = null; Molecule molReactant = null; Molecule molProduct = null; MolSearch srchMol = new MolSearch(); MolSearchOptions so = new MolSearchOptions();//SearchConstants.DUPLICATE so.setQueryAbsoluteStereo(true); so.setChargeMatching(SearchConstants.__Fields.CHARGE_MATCHING_EXACT); so.setDoubleBondStereoMatchingMode(StereoConstants.__Fields.DBS_ALL); so.setImplicitHMatching(SearchConstants.__Fields.IMPLICIT_H_MATCHING_ENABLED); so.setExactBondMatching(true); so.setStereoSearchType(SearchConstants.__Fields.STEREO_EXACT); so.setTautomerSearch(true); so.setAttachedDataMatch(1); so.setOrderSensitiveSearch(true); so.setSearchType(5); srchMol.setSearchOptions(so); string rctInchi = ""; string prodInchi = ""; for (int prIndx = 0; prIndx < productData.Rows.Count; prIndx++) { if (!string.IsNullOrEmpty(productData.Rows[prIndx]["REACTION_SCHEME"].ToString())) { prodRxnMolecule = RxnMolecule.getReaction(MolImporter.importMol(productData.Rows[prIndx]["REACTION_SCHEME"].ToString())); productsCnt = prodRxnMolecule.getProductCount(); } for (int rctIndx = 0; rctIndx < reactantData.Rows.Count; rctIndx++) { if (!string.IsNullOrEmpty(reactantData.Rows[rctIndx]["REACTION_SCHEME"].ToString())) { rctRxnMolecule = RxnMolecule.getReaction(MolImporter.importMol(reactantData.Rows[rctIndx]["REACTION_SCHEME"].ToString())); reactantsCnt = rctRxnMolecule.getReactantCount(); } int rctLoopCnt = productsCnt < reactantsCnt ? productsCnt : reactantsCnt; for (int p = 0; p < productsCnt; p++) { molProduct = prodRxnMolecule.getProduct(p); for (int r = 0; r < rctLoopCnt; r++) { molReactant = rctRxnMolecule.getReactant(r); rctInchi = ChemistryOperations.GetStructureInchiKey(molReactant.toFormat("mol")); prodInchi = ChemistryOperations.GetStructureInchiKey(molProduct.toFormat("mol")); if (rctInchi == prodInchi) { srchMol.setQuery(molReactant); srchMol.setTarget(molProduct); if (!srchMol.isMatching()) { blStatus = false; return(blStatus); } } } } } } } catch (Exception) { throw; } return(blStatus); }