Example #1
0
        public static double GetStructureMolWeight_MolFormula(string _molfilestring, out string _molformula)
        {
            double dblMolWeight  = 0.0;
            string strMolFormula = "";

            try
            {
                MolHandler mHandler = new MolHandler(_molfilestring);
                dblMolWeight = mHandler.calcMolWeight();

                strMolFormula = mHandler.calcMolFormula();

                _molformula = strMolFormula;
                return(dblMolWeight);
            }
            catch (Exception ex)
            {
            }
            _molformula = strMolFormula;
            return(dblMolWeight);
        }
Example #2
0
        public static string GetMoleculeWeightAndMolFormula(string molstring, out string molformula_out)
        {
            string strMolWeight  = "";
            string strMolFormula = "";

            try
            {
                MolHandler mHandler     = new MolHandler(molstring);
                float      fltMolWeight = mHandler.calcMolWeight();

                strMolFormula = mHandler.calcMolFormula();
                strMolWeight  = fltMolWeight.ToString();

                molformula_out = strMolFormula;
                return(strMolWeight);
            }
            catch (Exception ex)
            {
                ErrorHandling.WriteErrorLog(ex.ToString());
            }
            molformula_out = strMolFormula;
            return(strMolWeight);
        }
Example #3
0
        public static DataTable GetRGroupEnumerationResults(DataTable _enumDataTbl, string _qryRCore)
        {
            DataTable dtEnumResData = new DataTable();

            try
            {
                dtEnumResData.Columns.Add("id", typeof(string));
                dtEnumResData.Columns.Add("structure", typeof(object));
                dtEnumResData.Columns.Add("mol_weight", typeof(double));
                dtEnumResData.Columns.Add("mol_formula", typeof(string));
                dtEnumResData.Columns.Add("iupac_name", typeof(string));
                dtEnumResData.Columns.Add("inchi_key", typeof(string));

                int rgrpNum = 1;

                Molecule   molEnum      = null;
                MolHandler mHandler     = null;
                Molecule   rCoreMol     = null;
                RgMolecule rgMol        = null;
                MolHandler mHand_Result = null;

                DataRow dtRow = null;

                string strMolFile   = "";
                string strIUPACName = "";
                string strErrMsg    = "";

                if (_enumDataTbl != null)
                {
                    if (_enumDataTbl.Rows.Count > 0)
                    {
                        for (int rowindx = 0; rowindx < _enumDataTbl.Rows.Count; rowindx++)
                        {
                            molEnum  = new Molecule();
                            mHandler = new MolHandler(_qryRCore);
                            rCoreMol = mHandler.getMolecule();

                            try
                            {
                                for (int colindx = 1; colindx < _enumDataTbl.Columns.Count; colindx++)
                                {
                                    rgrpNum = GetRgroupNumFromRGroupName(_enumDataTbl.Columns[colindx].ColumnName);
                                    rgMol   = ReturnRGroupMolecule(_enumDataTbl.Rows[rowindx][colindx].ToString(), rgrpNum);
                                    //molEnum = AddRGrpMolToCoreMolecule(rgMol, rCoreMol, rgrpNum);
                                    AddRGrpMolToCoreMolecule(ref rCoreMol, rgMol, rgrpNum);
                                }
                                //Set Radical Empty to Result Mol
                                SetRadicalEmptyToResultMol(ref rCoreMol);

                                mHand_Result = new MolHandler(rCoreMol);
                                strMolFile   = "";
                                strMolFile   = mHand_Result.toFormat("mol");
                            }
                            catch
                            {
                            }
                            dtRow = dtEnumResData.NewRow();

                            dtRow["id"]        = _enumDataTbl.Rows[rowindx][0].ToString();
                            dtRow["structure"] = strMolFile;
                            if (strMolFile != "")
                            {
                                dtRow["mol_weight"]  = mHand_Result.calcMolWeight();
                                dtRow["mol_formula"] = mHand_Result.calcMolFormula();
                                dtRow["inchi_key"]   = ChemistryOperations.GetStructureInchiKey(strMolFile);

                                strIUPACName = "";
                                strErrMsg    = "";
                                if (ChemistryOperations.GetIUPACNameFromStructure(strMolFile, out strIUPACName, out strErrMsg))
                                {
                                    strIUPACName = Validations.GetConvertedIUPACName(strIUPACName);
                                }
                                else
                                {
                                    strIUPACName = "IUPAC name not provided";
                                }

                                dtRow["iupac_name"] = strIUPACName;
                            }

                            dtEnumResData.Rows.Add(dtRow);
                        }

                        return(dtEnumResData);
                    }
                }
            }
            catch (Exception ex)
            {
                PepsiLiteErrorHandling.WriteErrorLog(ex.ToString());
            }
            return(dtEnumResData);
        }