예제 #1
0
 public FunctionalGroupOutput(ChemInfo.FunctionalGroup group)
 {
     Name        = group.Name;
     Smarts      = group.Smart;
     m_Reactions = new List <ReactionOutput>();
     foreach (ChemInfo.NamedReaction reaction in group.NamedReactions)
     {
         m_Reactions.Add(new ReactionOutput(reaction));
     }
 }
 private void productComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     this.ReactionNameComboBox.Items.Clear();
     m_FunctionalGroup = m_FunctionalGroups[productComboBox.SelectedItem.ToString()];
     foreach (ChemInfo.NamedReaction r in m_FunctionalGroup.NamedReactions)
     {
         this.ReactionNameComboBox.Items.Add(r.Name);
     }
     reactantAComboBox.Text             = string.Empty;
     reactantBComboBox.Text             = string.Empty;
     pictureBox1.Image                  = m_FunctionalGroup.Image;
     ReactionNameComboBox.SelectedIndex = 0;
 }
 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;
     }
 }
예제 #4
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.tableLayoutPanel1.Controls.Clear();
            ChemInfo.FunctionalGroup g = this.m_FunctGroups[this.comboBox1.SelectedItem.ToString()];
            int i = 0;

            foreach (ChemInfo.NamedReaction r in g.NamedReactions)
            {
                NamedReactionViewControl myControl = new NamedReactionViewControl();
                myControl.ReactionName = r.Name;
                this.tableLayoutPanel1.Controls.Add(myControl, 0 /* Column Index */, i++ /* Row index */);
                List <string> temp = new List <string>();
                if (!string.IsNullOrEmpty(r.ReactantA))
                {
                    temp.Add(r.ReactantA);
                }
                if (!string.IsNullOrEmpty(r.ReactantB))
                {
                    temp.Add(r.ReactantB);
                }
                if (!string.IsNullOrEmpty(r.ReactantC))
                {
                    temp.Add(r.ReactantC);
                }
                string[] reactants = temp.ToArray <string>();;
                if (reactants.Length == 2)
                {
                    ChemInfo.FunctionalGroup react0 = this.m_FunctGroups[reactants[0]];
                    ChemInfo.FunctionalGroup react1 = this.m_FunctGroups[reactants[1]];
                    myControl.Reactant1     = react0.Image;
                    myControl.Reactant2     = react1.Image;
                    myControl.Reactant1Name = react0.Name;
                    myControl.Reactant2Name = react1.Name;
                }
                myControl.Product             = g.Image;
                myControl.FunctionalGroupName = g.Name;
                myControl.Catalyst            = r.Catalyst;
            }
        }
예제 #5
0
        private void OpenFunctionGroupExcelResource()
        {
            // Reads functional Groups from Excel file.
            //List<string> functionalGroupStrs = new List<string>();// SustainableChemistry.Properties.Resources.Full_Functional_Group_List;
            string fileName = "..\\..\\Data\\Full Functional Group List 20180731.xlsx";

            FunctionalGroups.Columns.Add("Name", typeof(System.String));
            FunctionalGroups.Columns.Add("Smart", typeof(System.String));
            FunctionalGroups.Columns.Add("Image", typeof(System.Drawing.Image));
            using (DocumentFormat.OpenXml.Packaging.SpreadsheetDocument document = DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(fileName, false))
            {
                DocumentFormat.OpenXml.Packaging.WorkbookPart wbPart    = document.WorkbookPart;
                DocumentFormat.OpenXml.Spreadsheet.SheetData  sheetData = GetWorkSheetFromSheet(wbPart, GetSheetFromName(wbPart, "Full Functional Group List")).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';
                        }
                        System.Data.DataRow      row  = FunctionalGroups.NewRow();
                        ChemInfo.FunctionalGroup temp = fGroups.Add(text, row);
                        FunctionalGroups.Rows.Add(row);
                        //string filename = "..\\..\\Images\\" + temp.Name.ToLower() + ".jpg";
                        //if (System.IO.File.Exists(filename)) temp.Image = System.Drawing.Image.FromFile(filename);
                    }
                    text  = string.Empty;
                    first = false;
                }
                //using (System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection(string.Format("Data Source=..\\..\\Data\\SustainableChemistry.sqlite;Version=3;;New=False;Compress=True;Max Pool Size=100;")))
                //{
                //    con.Open();
                //    using (System.Data.SQLite.SQLiteTransaction transaction = con.BeginTransaction())
                //    {
                //        foreach (DataRow row in FunctionalGroups.Rows)
                //        {
                //            using (System.Data.SQLite.SQLiteCommand sqlitecommand = new System.Data.SQLite.SQLiteCommand("insert into table(fh,ch,mt,pn) values ('" + Convert.ToString(row[0]) + "','" + Convert.ToString(row[1]) + "','"
                //                                                                                                                  + Convert.ToString(row[2]) + "','" + Convert.ToString(row[3]) + "')", con))
                //            {
                //                sqlitecommand.ExecuteNonQuery();
                //            }
                //        }
                //        transaction.Commit();
                //        //new General().WriteApplicationLog("Data successfully imported.");
                //        //return true;
                //    }
                //}
                sheetData = GetWorkSheetFromSheet(wbPart, GetSheetFromName(wbPart, "Reaction List")).Elements <DocumentFormat.OpenXml.Spreadsheet.SheetData>().First();
                text      = string.Empty;
                first     = true;
                NamedReactions.Columns.Add("Name", typeof(System.String));
                NamedReactions.Columns.Add("FunctionalGroup", typeof(System.String));
                NamedReactions.Columns.Add("Image", typeof(System.Drawing.Image));
                NamedReactions.Columns.Add("URL", typeof(System.String));
                NamedReactions.Columns.Add("ReactantA", typeof(System.String));
                NamedReactions.Columns.Add("ReactantB", typeof(System.String));
                NamedReactions.Columns.Add("ReactantC", typeof(System.String));
                NamedReactions.Columns.Add("Product", typeof(System.String));
                NamedReactions.Columns.Add("Heat", typeof(System.String));
                NamedReactions.Columns.Add("AcidBase", typeof(System.String));
                NamedReactions.Columns.Add("Catalyst", typeof(System.String));
                NamedReactions.Columns.Add("Solvent", typeof(System.String));
                NamedReactions.Columns.Add("ByProducts", typeof(System.String));

                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';
                        }
                        System.Data.DataRow row = NamedReactions.NewRow();
                        fGroups.AddReaction(new ChemInfo.NamedReaction(text, row));
                        NamedReactions.Rows.Add(row);
                    }
                    text  = string.Empty;
                    first = false;
                }
                document.Close();
            }

            //// This next line creates a list of strings that don't have images. Can be commented out!
            //List<string> missingImages = new List<string>();

            //// Creates the collection of functional groups.
            //foreach (string line in functionalGroupStrs)
            //{
            //    ChemInfo.FunctionalGroup temp = fGroups.Add(line);
            //    string filename = documentPath + "\\Images\\" + temp.Name.ToLower() + ".jpg";
            //    if (System.IO.File.Exists(filename)) temp.Image = System.Drawing.Image.FromFile(filename);

            //    //this line adds the missing image to the list of missing images. Can be commented out.
            //    else missingImages.Add(temp.Name);
            //}
            //// Writes the missing images to a file.

            //// Write the string array to a new file named "WriteLines.txt".
            //using (System.IO.StreamWriter outputFile = new System.IO.StreamWriter(documentPath + @"\MissingImages.txt"))
            //{
            //    foreach (string line in missingImages)
            //        outputFile.WriteLine(line);
            //}

            //string[] imageFiles = System.IO.Directory.GetFiles(documentPath + "\\Images\\");
            //string[] groupNames = fGroups.FunctionalGroups;
            //List<string> extraImages = new List<string>();
            //foreach (string name in imageFiles)
            //{
            //    string temp = name.Replace(documentPath + "\\Images\\", string.Empty);
            //    temp = temp.Replace(".jpg", string.Empty);
            //    bool add = true;
            //    foreach (string gName in groupNames)
            //    {
            //        if (temp.ToUpper() == gName.ToUpper()) add = false;
            //    }
            //    if (add) extraImages.Add(temp);
            //}

            //// Write the string array to a new file named "WriteLines.txt".
            //using (System.IO.StreamWriter outputFile = new System.IO.StreamWriter(documentPath + @"\ExtraImages.txt"))
            //{
            //    foreach (string line in extraImages)
            //        outputFile.WriteLine(line);
            //}
        }
예제 #6
0
 public Results(ChemInfo.FunctionalGroup functionalGroup, ChemInfo.References references)
 {
     groupOutput = new FunctionalGroupOutput(functionalGroup);
     References  = references.GetReferences(functionalGroup.Name);
 }