public static bool DeleteAllDuplicateStructures(string filename, out int totalreccnt, out int dupreccnt) { bool blStatus = false; int intDupRecCnt = 0; int intTotalRecCnt = 0; try { MolInputStream molInStream = new MolInputStream(new FileInputStream(filename)); MolImporter molImp = new MolImporter(molInStream); Molecule objMol = new Molecule(); DataOutputStream dOutStream = new DataOutputStream(new FileOutputStream(filename)); MolExporter molExpt = new MolExporter(dOutStream, "sdf"); bool blIsChiral = false; string strInchiKey = ""; ArrayList molInchiList = new ArrayList(); while (molImp.read(objMol)) { objMol = StandardizeMolecule(objMol, out blIsChiral); strInchiKey = objMol.toFormat("inchi:key"); strInchiKey = GetInchiKeyFromInchiString(strInchiKey); if (!molInchiList.Contains(strInchiKey)) { molInchiList.Add(strInchiKey); molExpt.write(objMol); } else { intDupRecCnt++; } intTotalRecCnt++; } //Close all the import & export objects molImp.close(); molInStream.close(); dOutStream.close(); molExpt.close(); blStatus = true; } catch (Exception ex) { ErrorHandling.WriteErrorLog(ex.ToString()); } totalreccnt = intTotalRecCnt; dupreccnt = intDupRecCnt; return(blStatus); }
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); }
public static bool EmportToSdFile(string _filename, DataTable _dtTanDetails, ArrayList _selproplist) { bool blWriteStatus = false; try { if (_filename.Trim() != "" && _dtTanDetails != null) { if (_dtTanDetails.Rows.Count > 0) { FileOutputStream fOutStream = new FileOutputStream(_filename, true); MolExporter objmExporter = new MolExporter(fOutStream, "sdf"); MolHandler objmHandler = null; Molecule objMol = null; for (int rIndx = 0; rIndx < _dtTanDetails.Rows.Count; rIndx++) { objmHandler = new MolHandler(_dtTanDetails.Rows[rIndx]["structure"].ToString()); objMol = objmHandler.getMolecule(); if (_selproplist.Contains("Mol Weight")) { objMol.setProperty("Mol Weight", _dtTanDetails.Rows[rIndx]["mol_weight"].ToString()); } if (_selproplist.Contains("Mol Formula")) { objMol.setProperty("Mol Formula", _dtTanDetails.Rows[rIndx]["mol_formula"].ToString()); } if (_selproplist.Contains("Page Number")) { objMol.setProperty("Page Number", _dtTanDetails.Rows[rIndx]["page_number"].ToString()); } if (_selproplist.Contains("Page Label")) { objMol.setProperty("Page Label", _dtTanDetails.Rows[rIndx]["page_label"].ToString()); } if (_selproplist.Contains("Example Number")) { objMol.setProperty("Example Number", _dtTanDetails.Rows[rIndx]["example_number"].ToString()); } if (_selproplist.Contains("Table Number")) { objMol.setProperty("Table Number", _dtTanDetails.Rows[rIndx]["table_number"].ToString()); } if (_selproplist.Contains("en name")) { objMol.setProperty("en name", _dtTanDetails.Rows[rIndx]["en_name"].ToString()); } if (_selproplist.Contains("IUPAC Name")) { objMol.setProperty("IUPAC Name", _dtTanDetails.Rows[rIndx]["iupac_name"].ToString()); } objmExporter.write(objMol); } fOutStream.close(); objmExporter.close(); blWriteStatus = true; return(blWriteStatus); } } } catch (Exception ex) { ErrorHandling_NTS.WriteErrorLog(ex.ToString()); } return(blWriteStatus); }
public static bool ExportToSDF(SpectralInfo compSpectralData, string outputFolderPath) { bool blStatus = false; try { if (compSpectralData != null && !string.IsNullOrEmpty(outputFolderPath)) { MolHandler objMolHandler = null; Molecule objMol = null; int intMolRegNo = 0; string strOutFileName = ""; //NMR Spectral for (int i = 0; i < compSpectralData.NMRSpectralList.Count; i++) { intMolRegNo = intMolRegNo + 1; strOutFileName = strOutFileName + "_" + compSpectralData.NMRSpectralList[i].Nucleus + ".sdf"; FileOutputStream fOutStream = new FileOutputStream(strOutFileName, true); MolExporter objmExporter = new MolExporter(fOutStream, "sdf"); //Compound Molecule objMolHandler = new MolHandler(compSpectralData.CompoundInformation.Compound.ToString()); objMol = objMolHandler.getMolecule(); //Article Information objMol.setProperty("journal name", compSpectralData.ArticleInformation.JournalName); objMol.setProperty("article doi", compSpectralData.ArticleInformation.DOI); objMol.setProperty("authors", compSpectralData.ArticleInformation.Authors); //Compound Information objMol.setProperty("MOLREGNO", intMolRegNo.ToString()); objMol.setProperty("chemical name", compSpectralData.CompoundInformation.IUPACName); objMol.setProperty("mol comments", compSpectralData.CompoundInformation.Comments); objMol.setProperty("pagenumber", compSpectralData.CompoundInformation.PageNo); //NMR information objMol.setProperty("nmr spectrometer", compSpectralData.NMRSpectralList[i].SpectroMeter); objMol.setProperty("nucleus", compSpectralData.NMRSpectralList[i].Nucleus); objMol.setProperty("solvent", compSpectralData.NMRSpectralList[i].Solvent); objMol.setProperty("nmr frequency", compSpectralData.NMRSpectralList[i].Frequency); objMol.setProperty("nmr shift values", compSpectralData.NMRSpectralList[i].ShiftValues); objMol.setProperty("nmr standard", compSpectralData.NMRSpectralList[i].StdSolvent); objmExporter.write(objMol); fOutStream.close(); objmExporter.close(); } //Other Spectral for (int i = 0; i < compSpectralData.OtherSpectralList.Count; i++) { intMolRegNo = intMolRegNo + 1; strOutFileName = strOutFileName + "_" + compSpectralData.OtherSpectralList[i].ValueType + ".sdf"; FileOutputStream fOutStream = new FileOutputStream(strOutFileName, true); MolExporter objmExporter = new MolExporter(fOutStream, "sdf"); //Compound Molecule objMolHandler = new MolHandler(compSpectralData.CompoundInformation.Compound.ToString()); objMol = objMolHandler.getMolecule(); //Article Information objMol.setProperty("journal name", compSpectralData.ArticleInformation.JournalName); objMol.setProperty("article doi", compSpectralData.ArticleInformation.DOI); objMol.setProperty("authors", compSpectralData.ArticleInformation.Authors); //Compound Information objMol.setProperty("MOLREGNO", intMolRegNo.ToString()); objMol.setProperty("chemical name", compSpectralData.CompoundInformation.IUPACName); objMol.setProperty("mol comments", compSpectralData.CompoundInformation.Comments); objMol.setProperty("pagenumber", compSpectralData.CompoundInformation.PageNo); //IR information if (compSpectralData.OtherSpectralList[i].ValueType.ToUpper() == "IR") { objMol.setProperty("ir spectrometer", compSpectralData.OtherSpectralList[i].SpectroMeter); objMol.setProperty("ir spectral peaks", compSpectralData.OtherSpectralList[i].PeakValues); objMol.setProperty("sample prep", compSpectralData.OtherSpectralList[i].SamplePreparation); } //Mass information if (compSpectralData.OtherSpectralList[i].ValueType.ToUpper() == "MASS") { objMol.setProperty("mass spectrometer", compSpectralData.OtherSpectralList[i].SpectroMeter); objMol.setProperty("mass spectral peaks", compSpectralData.OtherSpectralList[i].PeakValues); objMol.setProperty("mass.method", compSpectralData.OtherSpectralList[i].Method); objMol.setProperty("eV", compSpectralData.OtherSpectralList[i].ElectronVolts); } //UV information if (compSpectralData.OtherSpectralList[i].ValueType.ToUpper() == "UV") { objMol.setProperty("mass spectrometer", compSpectralData.OtherSpectralList[i].SpectroMeter); objMol.setProperty("mass spectral peaks", compSpectralData.OtherSpectralList[i].PeakValues); objMol.setProperty("comments", compSpectralData.OtherSpectralList[i].Comments); } objmExporter.write(objMol); fOutStream.close(); objmExporter.close(); } blStatus = true; } } catch (Exception ex) { ErrorHandling.WriteErrorLog(ex.ToString()); } return(blStatus); }
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); }