private void enterSMILEToolStripMenuItem_Click(object sender, EventArgs e) { smilesInput smiles = new smilesInput(); smiles.ShowDialog(); if (string.IsNullOrEmpty(smiles.SMILES)) { return; } this.molecule = new ChemInfo.Molecule(smiles.SMILES); this.dataGridView1.Rows.Clear(); if (molecule == null) { return; } this.moleculeViewer1.Molecule = this.molecule; this.propertyGrid1.SelectedObject = this.molecule; foreach (System.Data.DataRow dr in app_functionalgroup.Rows) { string smarts = dr["Smarts"].ToString(); if (!string.IsNullOrEmpty(smarts)) { this.molecule.FindFunctionalGroup(dr); } } this.textBox1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(this.molecule, Newtonsoft.Json.Formatting.Indented); foreach (string group in this.molecule.FunctionalGroups) { this.functionalGroupComboBox.Items.Add(group); } }
public Form1() { InitializeComponent(); dataPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) + "\\SustainableChemistry\\Data"; if (!System.IO.Directory.Exists(dataPath)) { dataPath = "..\\..\\..\\..\\SustainableChemistryData\\SustainableChemistryData"; } imagePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData) + "\\SustainableChemistry\\Data"; if (!System.IO.Directory.Exists(imagePath)) { imagePath = "..\\..\\..\\..\\SustainableChemistryData\\SustainableChemistryData\\static\\media\\"; } m_dbConnection = new System.Data.SQLite.SQLiteConnection("Data Source=" + dataPath + "\\SustainableChemistry.sqlite3;Version=3;"); app_catalyst = GetDataTable("app_catalyst"); app_compound = GetDataTable("app_compound"); app_functionalgroup = GetDataTable("app_functionalgroup"); app_namedreaction = GetDataTable("app_namedreaction"); app_reference = GetDataTable("app_reference"); app_namedreaction_ByProd = GetDataTable("app_namedreaction_ByProducts"); app_namedreaction_ByProd.Rows.Clear(); app_namedreaction_Reactants = GetDataTable("app_namedreaction_Reactants"); app_namedreaction_Reactants.Rows.Clear(); app_reactant = GetDataTable("app_reactant"); app_solvent = GetDataTable("app_solvent"); //app_compound = GetDataTable("app_compound"); molecule = new ChemInfo.Molecule(); this.trackBar1.Value = (int)(this.moleculeViewer1.Zoom * 100); documentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\USEPA\\SustainableChemistry"; currentReferences = new List <Reference>(); }
public async Task <ActionResult <FunctionalGroup> > GetFunctionalGroups(string smiles) { var fG = await _context.AppFunctionalgroup.ToListAsync(); ChemInfo.Molecule molecule = new ChemInfo.Molecule(smiles); var retVal = new List <AppFunctionalgroupDTO>(); foreach (var group in fG) { string smarts = group.Smarts; if (!string.IsNullOrEmpty(group.Smarts)) { if (molecule.FindFunctionalGroup(group)) { retVal.Add(new AppFunctionalgroupDTO() { Id = group.Id, Name = group.Name, Smarts = group.Smarts } ); } } } return(Ok(retVal)); }
public Form1() { InitializeComponent(); //System.Data.SQLite.SQLiteConnection.CreateFile("MyDatabase.sqlite"); m_dbConnection = new System.Data.SQLite.SQLiteConnection("Data Source=..\\..\\Data\\SustainableChemistry.sqlite;Version=3;"); m_dbConnection.Open(); FunctionalGroups = new DataTable(); NamedReactions = new DataTable(); molecule = new ChemInfo.Molecule(); fGroups = new ChemInfo.FunctionalGroupCollection(); reactions = new ChemInfo.NamedReactionCollection(); this.trackBar1.Value = (int)(this.moleculeViewer1.Zoom * 100); documentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\USEPA\\SustainableChemistry"; this.OpenFunctionGroupExcelResource(); System.IO.FileStream fs = new System.IO.FileStream("..\\..\\Data\\references.dat", System.IO.FileMode.Open); // Construct a BinaryFormatter and use it to serialize the data to the stream. System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); try { m_References = (ChemInfo.References)formatter.Deserialize(fs); } catch (System.Runtime.Serialization.SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); } //Reads in functional groups from JSON file. This should be used after Excel file is completed. //var json = new System.Web.Script.Serialization.JavaScriptSerializer(); //functionalGroups = (List<ChemInfo.FunctionalGroup>)json.Deserialize(ChemInfo.Functionalities.AvailableFunctionalGroups(), typeof(List<ChemInfo.FunctionalGroup>)); // string text = ChemInfo.Functionalities.FunctionalGroups("P(c1ccccc1)(c1ccccc1)(N)=O", "json"); // Test code for generating a results file from a functional group name. //Results res = new Results("phosphoramidite", m_References); //string results = json.Serialize(res); // Initial code to load references from text RIS resource files. Can be deleted when done. //m_References = new ChemInfo.References(); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Diisoproprylethyamine Solvent", enc8.GetString(Properties.Resources.S0040403900813763))); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Diisoproprylethyamine Solvent", enc8.GetString(Properties.Resources.S0040403900942163))); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Diisoproprylethyamine Solvent", enc8.GetString(Properties.Resources.S0040403901904617))); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Diisoproprylethyamine Solvent", enc8.GetString(Properties.Resources.achs_jacsat105_661))); //m_References.Add(new ChemInfo.Reference("phosphate", "No Name", enc8.GetString(Properties.Resources.S1001841712003142))); //m_References.Add(new ChemInfo.Reference("phosphate", "Catalyst", Properties.Resources._10_1002_2Fchin_199605199)); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Catalyst Solvent", enc8.GetString(Properties.Resources.europepmc))); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Catalyst Solvent", enc8.GetString(Properties.Resources.europepmc1))); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Catalyst Solvent", enc8.GetString(Properties.Resources.achs_oprdfk4_175))); //m_References.Add(new ChemInfo.Reference("phosphoramidite", "Catalyst Solvent", enc8.GetString(Properties.Resources.BIB))); }
public ReactionEditor(System.Data.DataTable fGroups) { InitializeComponent(); molecule = null; this.m_FunctionalGroups = fGroups; //this.productComboBox.Items.AddRange(m_FunctionalGroups.FunctionalGroups); //reactantAComboBox.Items.AddRange(ChemInfo.Reactants.ReactantList); //reactantBComboBox.Items.AddRange(ChemInfo.Reactants.ReactantList); this.linkLabel1.Text = string.Empty; }
public async Task <ActionResult <IEnumerable <FunctionalGroupAPI> > > Smiles(string id) { var fgList = await _context.AppFunctionalgroup.ToListAsync(); List <FunctionalGroup> fgFound = new List <FunctionalGroup>(); ChemInfo.Molecule molecule = new ChemInfo.Molecule(id.Trim()); if (molecule == null) { return(NotFound()); } if (molecule.Atoms.Length != 0) { foreach (var fg in fgList) { string smarts = fg.Smarts; if (!string.IsNullOrEmpty(fg.Smarts)) { if (molecule.FindFunctionalGroup(fg)) { fgFound.Add(fg); } } } if (molecule.Aromatic) { fgFound.Add(_context.AppFunctionalgroup .FirstOrDefault(m => m.Id == 35)); } if (molecule.Heterocyclic) { fgFound.Add(_context.AppFunctionalgroup .FirstOrDefault(m => m.Id == 118)); } if (molecule.HeterocyclicAromatic) { fgFound.Add(_context.AppFunctionalgroup .FirstOrDefault(m => m.Id == 224)); } } List <FunctionalGroupAPI> retVal = new List <FunctionalGroupAPI>(); foreach (var fg in fgFound) { retVal.Add(new FunctionalGroupAPI { Id = fg.Id, Name = fg.Name, Smarts = fg.Smarts, URL = fg.URL, Image = fg.Image, }); } return(retVal); }
private void testChemicalListToolStripMenuItem_Click(object sender, EventArgs e) { List <DSSToxChemicals> chemicals = new List <DSSToxChemicals>(); // Open the document for editing. string fileName = documentPath + "\\DSSTox_ToxCastRelease_20151019.xlsx"; using (DocumentFormat.OpenXml.Packaging.SpreadsheetDocument document = DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(fileName, false)) { DocumentFormat.OpenXml.Packaging.WorkbookPart wbPart = document.WorkbookPart; DocumentFormat.OpenXml.Packaging.WorksheetPart wsPart = wbPart.WorksheetParts.First(); DocumentFormat.OpenXml.Spreadsheet.SheetData sheetData = wsPart.Worksheet.Elements <DocumentFormat.OpenXml.Spreadsheet.SheetData>().First(); string text = string.Empty; bool first = true; foreach (DocumentFormat.OpenXml.Spreadsheet.Row r in sheetData.Elements <DocumentFormat.OpenXml.Spreadsheet.Row>()) { if (!first) { foreach (DocumentFormat.OpenXml.Spreadsheet.Cell c in r.Elements <DocumentFormat.OpenXml.Spreadsheet.Cell>()) { text = text + this.GetExcelCellValue(c, wbPart) + '\t'; } chemicals.Add(new DSSToxChemicals(text)); } first = false; text = string.Empty; } document.Close(); } foreach (DSSToxChemicals chem in chemicals) { if (!string.IsNullOrEmpty(chem.Structure_SMILES)) { ChemInfo.Molecule mol = new ChemInfo.Molecule(chem.Structure_SMILES); if (mol != null) { foreach (ChemInfo.FunctionalGroup f in this.fGroups) { if ((f.Name != "ESTER-SULFIDE") || (f.Name != "KETENIMINE")) { mol.FindFunctionalGroup(f); } } } chem.AddFunctionalGroups(mol.FunctionalGroups); } } fileName = documentPath + "\\chemicals.json"; System.IO.File.WriteAllText(fileName, Newtonsoft.Json.JsonConvert.SerializeObject(chemicals, Newtonsoft.Json.Formatting.Indented)); }
private string[] GetFunctionalGroups(string smiles) { List <string> retVal = new List <string>(); ChemInfo.Molecule m = new ChemInfo.Molecule(smiles); foreach (System.Data.DataRow dr in app_functionalgroup.Rows) { string smarts = dr["Smarts"].ToString(); if (this.molecule.FindFunctionalGroup(dr)) { retVal.Add(dr["Name"].ToString()); } } return(retVal.ToArray <string>()); }
public async Task <ActionResult <AppFunctionalgroup> > GetMolecule(string smiles) { var fG = await _context.AppFunctionalgroup.ToListAsync(); ChemInfo.Molecule molecule = new ChemInfo.Molecule(smiles); var retVal = new List <AppFunctionalgroupDTO>(); foreach (var group in fG) { string smarts = group.Smarts; if (!string.IsNullOrEmpty(group.Smarts)) { molecule.FindFunctionalGroup(group); } } return(Ok(molecule)); }
private void enterSMILEToolStripMenuItem_Click(object sender, EventArgs e) { smilesInput smiles = new smilesInput(); smiles.ShowDialog(); if (string.IsNullOrEmpty(smiles.SMILES)) { return; } this.molecule = new ChemInfo.Molecule(smiles.SMILES); this.listBox1.Items.Clear(); if (molecule == null) { return; } this.moleculeViewer1.Molecule = this.molecule; this.propertyGrid1.SelectedObject = this.molecule; foreach (ChemInfo.FunctionalGroup f in this.fGroups) { if ((f.Name != "ESTER-SULFIDE") || (f.Name != "KETENIMINE")) { this.molecule.FindFunctionalGroup(f); } } this.textBox1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(this.molecule, Newtonsoft.Json.Formatting.Indented); foreach (ChemInfo.FunctionalGroup group in this.molecule.FunctionalGroups) { this.functionalGroupComboBox.Items.Add(group.Name); } //if (this.molecule.FunctionalGroups.Length > 0) // if (this.molecule.FunctionalGroups[0].NamedReactions.Count > 0) // { // this.pictureBox1.Image = this.molecule.FunctionalGroups[0].NamedReactions[0].ReactionImage[0]; // foreach (ChemInfo.Reference r in this.molecule.FunctionalGroups[0].NamedReactions[0].References) // { // this.listBox1.Items.Add(r.ToString()); // } // } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { System.Data.DataRow row = null; foreach (System.Data.DataRow dr in fGroups.Rows) { if (string.Equals(dr["Name"].ToString(), this.comboBox1.Text)) { row = dr; break; } } this.textBox2.Text = row["Smarts"].ToString(); molecule = new ChemInfo.Molecule(this.textBox2.Text); this.moleculeViewer1.Molecule = molecule; string filename = m_ImagePath + row["Image"].ToString().Replace("/", "\\");; if (System.IO.File.Exists(filename)) { this.pictureBox1.Image = System.Drawing.Image.FromFile(filename); } }
void PopulateForm(System.Data.DataRow group) { if (group == null) { this.pictureBox1.Image = null; //this.textBox1.Text = string.Empty; this.textBox2.Text = string.Empty; this.moleculeViewer1 = null; molecule = null; return; } //this.pictureBox1.Image = group.Image; //this.textBox1.Text = group["Name"].ToString(); this.textBox2.Text = group["Smart"].ToString(); if (!String.IsNullOrEmpty(this.textBox2.Text)) { molecule = new ChemInfo.Molecule(this.textBox2.Text); // molecule.FindRings(); //molecule.FindAllPaths(); this.moleculeViewer1.Molecule = molecule; } }
void PopulateForm(ChemInfo.FunctionalGroup group) { if (group == null) { this.pictureBox1.Image = null; this.textBox1.Text = string.Empty; this.textBox2.Text = string.Empty; this.moleculeViewer1 = null; molecule = null; return; } this.pictureBox1.Image = group.Image; this.textBox1.Text = group.Name; this.textBox2.Text = group.Smart; if (!String.IsNullOrEmpty(group.Smart)) { molecule = new ChemInfo.Molecule(group.Smart); // molecule.FindRings(); //molecule.FindAllPaths(); this.moleculeViewer1.Molecule = molecule; } }
private void importFormTESTToolStripMenuItem_Click(object sender, EventArgs e) { TestResults test = null; try { test = new TestResults(); } catch (Exception) { return; } test.ShowDialog(); string filepath = test.FilePath; if (string.IsNullOrEmpty(filepath)) { return; } molecule = ChemInfo.MoleFileReader.ReadMoleFile(test.FilePath); this.dataGridView1.Rows.Clear(); this.moleculeViewer1.Molecule = molecule; this.propertyGrid1.SelectedObject = this.molecule; foreach (System.Data.DataRow dr in app_functionalgroup.Rows) { string smarts = dr["Smarts"].ToString(); if (!string.IsNullOrEmpty(smarts)) { this.molecule.FindFunctionalGroup(dr); } } this.textBox1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(this.molecule, Newtonsoft.Json.Formatting.Indented); foreach (string group in this.molecule.FunctionalGroups) { this.functionalGroupComboBox.Items.Add(group); } }
private void importFormTESTToolStripMenuItem_Click(object sender, EventArgs e) { TestResults test = null; try { test = new TestResults(); } catch (Exception) { return; } test.ShowDialog(); string filepath = test.FilePath; if (string.IsNullOrEmpty(filepath)) { return; } molecule = ChemInfo.MoleFileReader.ReadMoleFile(test.FilePath); this.listBox1.Items.Clear(); this.moleculeViewer1.Molecule = molecule; }
private void button2_Click(object sender, EventArgs e) { checkedListBox1.Items.Clear(); List <DSSToxChemicals> .Enumerator enumerator = (List <DSSToxChemicals> .Enumerator)tabPage4.Tag; enumerator.MoveNext(); this.dataGridView1.Rows.Clear(); if (string.IsNullOrEmpty(enumerator.Current.Structure_SMILES)) { return; } molecule = new ChemInfo.Molecule(enumerator.Current.Structure_SMILES); if (molecule == null) { return; } // molecule.FindAllPaths(); this.moleculeViewer1.Molecule = molecule; this.propertyGrid1.SelectedObject = molecule; this.textBox1.Text = Newtonsoft.Json.JsonConvert.SerializeObject(this.molecule, Newtonsoft.Json.Formatting.Indented); pictureBox2.Image = PUGGetCompoundImage(enumerator.Current.Structure_SMILES, enumerator.Current.Substance_CASRN); checkedListBox1.Items.Add("Other"); if (molecule.Aromatic) { checkedListBox1.Items.Add("AROMATIC"); } if (molecule.Heterocyclic) { checkedListBox1.Items.Add("HETEROCYCLIC"); } if (molecule.HeterocyclicAromatic) { checkedListBox1.Items.Add("HETEROCYCLICAROMATIC"); } checkedListBox1.Items.AddRange(enumerator.Current.FunctionalGroups); tabPage4.Tag = enumerator; }
// GET: FunctionalGroups public async Task <IActionResult> Index(string nameSearchString, string smilesSearchString) { var retVal = new List <AppFunctionalgroup>(); var groups = from s in _context.AppFunctionalgroup select s; if (!String.IsNullOrEmpty(nameSearchString)) { groups = groups.Where(s => s.Name.Contains(nameSearchString, StringComparison.OrdinalIgnoreCase)); } if (!String.IsNullOrEmpty(smilesSearchString)) { await Task.Run(() => { ChemInfo.Molecule molecule = new ChemInfo.Molecule(smilesSearchString); foreach (var fg in groups) { string smarts = fg.Smarts; if (!string.IsNullOrEmpty(fg.Smarts)) { if (molecule.FindFunctionalGroup(fg.Smarts)) { retVal.Add(fg); } } } }); } else { retVal.AddRange(groups.ToList()); } return(View(retVal.ToAsyncEnumerable())); }
public async Task <IActionResult> Index(int?Id, int?funcGroupId, int?namedReactionId, string nameSearchString, string smilesSearchString) { if (!string.IsNullOrEmpty(smilesSearchString)) { ViewData["SearchString"] = smilesSearchString.Trim(); } var viewModel = new SustainableChemistryWeb.ViewModels.FunctionalGroupIndexData(); viewModel.FunctionalGroups = await _context.AppFunctionalgroup .Include(i => i.AppNamedreaction) .ThenInclude(i => i.AppReference) .AsNoTracking() .OrderBy(i => i.Name) .ToListAsync(); List <FunctionalGroup> fgFound = new List <FunctionalGroup>(); ChemInfo.Molecule molecule = null; string IUPacName = string.Empty; string CASNo = string.Empty; string DTXSID = string.Empty; if (!String.IsNullOrEmpty(smilesSearchString)) { if (TestCASNo(ref CASNo, ref smilesSearchString, ref IUPacName, ref DTXSID)) { molecule = new ChemInfo.Molecule(smilesSearchString.Trim()); if (molecule.Atoms.Length != 0) { foreach (var fg in viewModel.FunctionalGroups) { string smarts = fg.Smarts; if (!string.IsNullOrEmpty(fg.Smarts)) { if (molecule.FindFunctionalGroup(fg)) { fgFound.Add(fg); } } } if (molecule.Aromatic) { fgFound.Add(_context.AppFunctionalgroup .FirstOrDefault(m => m.Id == 35)); } if (molecule.Heterocyclic) { fgFound.Add(_context.AppFunctionalgroup .FirstOrDefault(m => m.Id == 118)); } if (molecule.HeterocyclicAromatic) { fgFound.Add(_context.AppFunctionalgroup .FirstOrDefault(m => m.Id == 224)); } } } else { return(RedirectToAction("Index", "Home", new { message = "Search String \"" + smilesSearchString + "\" was not found." })); } } else if (!String.IsNullOrEmpty(nameSearchString)) { ViewData["NameSearchString"] = nameSearchString.Trim(); fgFound.AddRange(viewModel.FunctionalGroups.Where(s => s.Name.Contains(nameSearchString, StringComparison.OrdinalIgnoreCase))); ViewData["FunctionalGroupName"] = nameSearchString.Trim(); } else if (funcGroupId != null) { ViewData["FunctionalGroupID"] = funcGroupId.Value; FunctionalGroup group = viewModel.FunctionalGroups.Where( i => i.Id == funcGroupId.Value).Single(); fgFound.Add(group); } if (funcGroupId != null) { ViewData["FunctionalGroupID"] = funcGroupId.Value; FunctionalGroup group = viewModel.FunctionalGroups.Where( i => i.Id == funcGroupId.Value).Single(); viewModel.NamedReactions = group.AppNamedreaction; ViewData["FunctionalGroupName"] = group.Name; } if (namedReactionId != null) { ViewData["NamedReactionID"] = namedReactionId.Value; NamedReaction rxn = viewModel.NamedReactions.Where( i => i.Id == namedReactionId.Value).Single(); var referenceViewModels = new List <SustainableChemistryWeb.ViewModels.ReferenceViewModel>(); ViewData["NamedReactionName"] = rxn.Name; foreach (var referecnce in rxn.AppReference) { referenceViewModels.Add(new SustainableChemistryWeb.ViewModels.ReferenceViewModel { Id = referecnce.Id, FunctionalGroupId = referecnce.FunctionalGroupId, FunctionalGroup = viewModel.FunctionalGroups.Where( i => i.Id == referecnce.FunctionalGroupId).Single(), ReactionId = referecnce.ReactionId, Reaction = referecnce.Reaction, Risdata = referecnce.Risdata }); } viewModel.References = referenceViewModels; } if (!string.IsNullOrEmpty(nameSearchString) || !string.IsNullOrEmpty(smilesSearchString) || funcGroupId != null) { viewModel.FunctionalGroups = fgFound.OrderBy(i => i.Name); } ViewData["SmilesString"] = smilesSearchString; ViewData["CASNO"] = CASNo; ViewData["IUPACName"] = IUPacName; ViewData["DTXSID"] = DTXSID; return(View(viewModel)); }
public Results(string smiles, System.Data.DataTable fGroups, System.Data.DataTable namedReactions, System.Data.DataTable reactants, System.Data.DataTable rxnReactants, System.Data.DataTable catalysts, System.Data.DataTable solvents, System.Data.DataTable byProducts, System.Data.DataTable references) { Molecule = new ChemInfo.Molecule(smiles); groups = new List <FunctionalGroup>(); this.AddFunctionalGroups(smiles, fGroups, namedReactions, reactants, rxnReactants, catalysts, solvents, byProducts, references); }