private void Load_Click(object sender, EventArgs e) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; StringBuilder sb = new StringBuilder(); sb.Append("All molecule files (*.mol, *.sdf, *.cml)|*.mol;*.sdf;*.cml"); sb.Append("|CML molecule files (*.cml)|*.cml"); sb.Append("|MDL molecule files (*.mol, *.sdf)|*.mol;*.sdf"); sb.Append("|JSON molecule files (*.json)|*.json"); openFileDialog1.Title = "Open Structure"; openFileDialog1.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); openFileDialog1.Filter = sb.ToString(); openFileDialog1.FileName = ""; openFileDialog1.ShowHelp = false; openFileDialog1.FilterIndex = 0; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = Path.GetFileName(openFileDialog1.FileName); _telemetry.Write(module, "Information", $"File: {filename}"); LoadModel(openFileDialog1.FileName); } }
private void LoadStructure_Click(object sender, EventArgs e) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; try { Model model = null; StringBuilder sb = new StringBuilder(); sb.Append("All molecule files (*.mol, *.sdf, *.cml)|*.mol;*.sdf;*.cml"); sb.Append("|CML molecule files (*.cml)|*.cml"); sb.Append("|MDL molecule files (*.mol, *.sdf)|*.mol;*.sdf"); openFileDialog1.Title = "Open Structure"; openFileDialog1.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); openFileDialog1.Filter = sb.ToString(); openFileDialog1.FileName = ""; openFileDialog1.ShowHelp = false; DialogResult dr = openFileDialog1.ShowDialog(); if (dr == DialogResult.OK) { string fileType = Path.GetExtension(openFileDialog1.FileName).ToLower(); string filename = Path.GetFileName(openFileDialog1.FileName); string mol = File.ReadAllText(openFileDialog1.FileName); CMLConverter cmlConvertor = new CMLConverter(); SdFileConverter sdFileConverter = new SdFileConverter(); switch (fileType) { case ".mol": case ".sdf": model = sdFileConverter.Import(mol); break; case ".cml": case ".xml": model = cmlConvertor.Import(mol); break; } if (model != null) { model.EnsureBondLength(20, false); if (string.IsNullOrEmpty(model.CustomXmlPartGuid)) { model.CustomXmlPartGuid = Guid.NewGuid().ToString("N"); } if (!string.IsNullOrEmpty(_lastCml)) { var clone = cmlConvertor.Import(_lastCml); Debug.WriteLine( $"Pushing F: {clone.ConciseFormula} BL: {clone.MeanBondLength.ToString("#,##0.00")} onto Stack"); _undoStack.Push(clone); } _lastCml = cmlConvertor.Export(model); _telemetry.Write(module, "Information", $"File: {filename}"); ShowChemistry(filename, model); } } } catch (Exception exception) { _telemetry.Write(module, "Exception", $"Exception: {exception.Message}"); _telemetry.Write(module, "Exception(Data)", $"Exception: {exception}"); MessageBox.Show(exception.StackTrace, exception.Message); } }