Example #1
0
            public MoleCulePostion(string smiles)
            {
                Mol = MolImporter.importMol(smiles);
                //将苯环的圈改为双线
                Mol.dearomatize();
                chemaxon.calculations.clean.Cleaner.clean(Mol, 2);

                //重置类参数
                InitPosition();
                //重置原子垂直坐标
                InitAtom();
            }
Example #2
0
        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);
        }
Example #3
0
        public static bool DeleteRecordFromSDFile(string _infilename, int _recindex)
        {
            bool blStatus = false;

            try
            {
                int intRecIndex = 0;

                MolInputStream molInStream = new MolInputStream(new FileInputStream(_infilename));
                MolImporter    molImp      = new MolImporter(molInStream);

                string strInputFilePath = System.IO.Path.GetDirectoryName(_infilename);

                string strExecPath = Application.StartupPath;
                string strFileName = System.IO.Path.GetFileName(_infilename);

                string strOutFile = strExecPath + "\\" + strFileName;

                DataOutputStream dOutStream = new DataOutputStream(new FileOutputStream(strOutFile));
                MolExporter      mExpt      = new MolExporter(dOutStream, "sdf");

                Molecule objMol = new Molecule();

                while (molImp.read(objMol))
                {
                    intRecIndex++;
                    if (intRecIndex != _recindex)
                    {
                        mExpt.write(objMol);
                    }
                }

                molImp.close();
                molInStream.close();

                mExpt.close();
                dOutStream.close();

                System.IO.File.Copy(strOutFile, _infilename, true);
                System.IO.File.Delete(strOutFile);

                blStatus = true;
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            return(blStatus);
        }
Example #4
0
        public static DataTable GetDuplicateRecords(string filename, string qrymolstring, out int totalrecs_out)
        {
            DataTable dtDupRecs   = null;
            int       totalRecCnt = 0;

            try
            {
                dtDupRecs = CreateTANDetailsTable();

                dtDupRecs.Columns.Add("OrigRecIndex", typeof(Int32));

                bool   blIsChiral    = false;
                string InchiKey_Qry  = "";
                string InchiKey_Trgt = "";

                MolHandler mHandler = new MolHandler(qrymolstring);
                Molecule   qryMol   = mHandler.getMolecule();
                StandardizeMolecule(qryMol, out blIsChiral);

                InchiKey_Qry = qryMol.toFormat("inchi:key");
                InchiKey_Qry = Validations.GetInchiKeyFromInchiString(InchiKey_Qry);

                MolInputStream molInStream = new MolInputStream(new FileInputStream(filename));
                MolImporter    molImp      = new MolImporter(molInStream);
                Molecule       objMol      = new Molecule();

                DataRow dtRow = null;

                while (molImp.read(objMol))
                {
                    objMol = StandardizeMolecule(objMol, out blIsChiral);

                    InchiKey_Trgt = objMol.toFormat("inchi:key");
                    InchiKey_Trgt = Validations.GetInchiKeyFromInchiString(InchiKey_Trgt);

                    if (InchiKey_Qry == InchiKey_Trgt)
                    {
                        dtRow = dtDupRecs.NewRow();

                        //Mol Structure
                        dtRow["Structure"] = objMol.toFormat("mol");

                        //Mol Weight
                        dtRow["MolWeight"] = objMol.getMass().ToString();

                        //Mol Formula
                        dtRow["MolFormula"] = objMol.getFormula();

                        //Page No
                        dtRow["PageNumber"] = objMol.getProperty("Page Number").Trim();

                        //Page Label
                        dtRow["PageLabel"] = objMol.getProperty("Page Label").Trim();

                        //Example Number
                        dtRow["ExampleNumber"] = objMol.getProperty("Example Number").Trim();

                        //IUPAC Name
                        dtRow["IupacName"] = objMol.getProperty("IUPAC Name").Trim();

                        //en name
                        dtRow["EnName"] = objMol.getProperty("en name").Trim();

                        //Is Chiral
                        if (objMol.isAbsStereo())
                        {
                            dtRow["IsChiral"] = "True";
                        }
                        else
                        {
                            dtRow["IsChiral"] = "False";
                        }

                        dtRow["OrigRecIndex"] = totalRecCnt;

                        dtDupRecs.Rows.Add(dtRow);
                    }
                    totalRecCnt++;
                }
                molImp.close();
                molInStream.close();

                totalrecs_out = totalRecCnt;
                return(dtDupRecs);
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            totalrecs_out = totalRecCnt;
            return(dtDupRecs);
        }
Example #5
0
        public static bool UpdateRecordInSdFile(string filename, int recindex, string molstring, string pagenum, string pagelabel, string examplenum, string iupacname, string enname)
        {
            bool blStatus = false;

            try
            {
                int intRecIndex = 0;

                MolInputStream molInStream = new MolInputStream(new FileInputStream(filename));
                MolImporter    molImp      = new MolImporter(molInStream);

                string strInputFilePath = System.IO.Path.GetDirectoryName(filename);

                string strExecPath = Application.StartupPath;
                string strFileName = System.IO.Path.GetFileName(filename);

                string strOutFile = strExecPath + "\\" + strFileName;

                DataOutputStream dOutStream = new DataOutputStream(new FileOutputStream(strOutFile));
                MolExporter      mExpt      = new MolExporter(dOutStream, "sdf");

                Molecule objMolecule = new Molecule();

                try
                {
                    while (molImp.read(objMolecule))
                    {
                        intRecIndex++;
                        if (intRecIndex == recindex)
                        {
                            MolHandler molHandler = new MolHandler(molstring);
                            Molecule   molObj     = molHandler.getMolecule();

                            objMolecule = molObj;

                            objMolecule.setProperty("Page Number", pagenum);
                            objMolecule.setProperty("Page Label", pagelabel);
                            objMolecule.setProperty("Example Number", examplenum);
                            objMolecule.setProperty("IUPAC Name", iupacname);
                            objMolecule.setProperty("en name", enname);

                            blStatus = true;
                        }
                        mExpt.write(objMolecule);
                    }

                    molImp.close();
                    molInStream.close();

                    mExpt.close();
                    dOutStream.close();

                    System.IO.File.Copy(strOutFile, filename, true);
                    System.IO.File.Delete(strOutFile);
                }
                catch (Exception ex)
                {
                    ErrorHandling_NTS.WriteErrorLog(ex.ToString());
                }
                finally
                {
                    molImp.close();
                    molInStream.close();

                    mExpt.close();
                    dOutStream.close();
                }
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            return(blStatus);
        }
Example #6
0
        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);
        }