// <cml:name id="m1.n1" dictRef="chem4word:Synonym">m1.n1</cml:name> private static TextualProperty GetName(XElement cmlElement) { var name = new TextualProperty(); name.Id = cmlElement.Attribute(CMLConstants.AttributeId)?.Value; if (cmlElement.Attribute(CMLConstants.AttributeDictRef) == null) { name.FullType = CMLConstants.ValueChem4WordSynonym; } else { name.FullType = cmlElement.Attribute(CMLConstants.AttributeDictRef)?.Value; } // Correct import from legacy Add-In if (string.IsNullOrEmpty(name.FullType) || name.FullType.Equals(CMLConstants.ValueNameDictUnknown)) { name.FullType = CMLConstants.ValueChem4WordSynonym; } name.Value = cmlElement.Value; return(name); }
// <cml:formula id="m1.f1" convention="chemspider:Smiles" inline="m1.f1" concise="C 6 H 14 Li 1 N 1" /> // <cml:formula id="m1.f0" concise="C 6 H 14 Li 1 N 1" /> private static TextualProperty GetFormula(XElement cmlElement) { var formula = new TextualProperty(); if (cmlElement.Attribute(CMLConstants.AttributeId) != null) { formula.Id = cmlElement.Attribute(CMLConstants.AttributeId)?.Value; } if (cmlElement.Attribute(CMLConstants.AttributeConvention) == null) { formula.FullType = CMLConstants.ValueChem4WordFormula; } else { formula.FullType = cmlElement.Attribute(CMLConstants.AttributeConvention)?.Value; } // Correct import from legacy Add-In if (string.IsNullOrEmpty(formula.FullType)) { formula.FullType = CMLConstants.ValueChem4WordFormula; } if (cmlElement.Attribute(CMLConstants.AttributeInline) != null) { formula.Value = cmlElement.Attribute(CMLConstants.AttributeInline)?.Value; } return(formula); }
// <cml:formula id="m1.f1" convention="chemspider:Smiles" inline="m1.f1" concise="C 6 H 14 Li 1 N 1" /> private XElement GetXElement(TextualProperty f, string concise) { XElement result = new XElement(CMLNamespaces.cml + CMLConstants.TagFormula); if (f.Id != null) { result.Add(new XAttribute(CMLConstants.AttributeId, f.Id)); } if (f.FullType != null) { result.Add(new XAttribute(CMLConstants.AttributeConvention, f.FullType)); } if (f.Value != null) { result.Add(new XAttribute(CMLConstants.AttributeInline, f.Value)); } if (concise != null) { result.Add(new XAttribute(CMLConstants.AttributeConcise, concise)); } return(result); }
// <cml:label id="" dictRef="chem4word:Caption" value="C19 /> private static TextualProperty GetCaption(XElement cmlElement) { if (cmlElement.Attribute(CMLConstants.AttributeDictRef) != null) { var dictrefValue = cmlElement.Attribute(CMLConstants.AttributeDictRef)?.Value; if (dictrefValue != null && dictrefValue.Equals(CMLConstants.ValueChem4WordCaption)) { var result = new TextualProperty(); result.FullType = CMLConstants.ValueChem4WordCaption; if (cmlElement.Attribute(CMLConstants.AttributeId) != null) { result.Id = cmlElement.Attribute(CMLConstants.AttributeId)?.Value; } if (cmlElement.Attribute(CMLConstants.AttributeNameValue) != null) { result.Value = cmlElement.Attribute(CMLConstants.AttributeNameValue)?.Value; } result.CanBeDeleted = true; return(result); } } return(null); }
private void ImportStructure() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; if (_lastModel != null) { using (new WaitCursor()) { CMLConverter conv = new CMLConverter(); double before = _lastModel.MeanBondLength; _lastModel.ScaleToAverageBondLength(Core.Helpers.Constants.StandardBondLength); double after = _lastModel.MeanBondLength; Telemetry.Write(module, "Information", $"Structure rescaled from {before.ToString("#0.00")} to {after.ToString("#0.00")}"); _lastModel.Relabel(true); var expModel = _lastModel; using (new WaitCursor()) { if (expModel.Molecules.Values.Any()) { var mol = expModel.Molecules.Values.First(); mol.Names.Clear(); if (_allResults.IupacNames != null) { foreach (var di in _allResults.IupacNames) { var cn = new TextualProperty(); cn.Value = di.data; cn.FullType = "chebi:Iupac"; mol.Names.Add(cn); } } if (_allResults.Synonyms != null) { foreach (var di in _allResults.Synonyms) { var cn = new TextualProperty(); cn.Value = di.data; cn.FullType = "chebi:Synonym"; mol.Names.Add(cn); } } Cml = conv.Export(expModel); } } } } }
// <cml:name id="m1.n1" dictRef="chem4word:Synonym">m1.n1</cml:name> private XElement GetNameXElement(TextualProperty name) { XElement result = new XElement(CMLNamespaces.cml + CMLConstants.TagName, name.Value); if (name.Id != null) { result.Add(new XAttribute(CMLConstants.AttributeId, name.Id)); } if (name.FullType != null) { result.Add(new XAttribute(CMLConstants.AttributeDictRef, name.FullType)); } return(result); }
// <cml:label id="m1.l1" dictRef="chem4word:Label "value="C19"/> private XElement GetLabelXElement(TextualProperty label) { XElement result = new XElement(CMLNamespaces.cml + CMLConstants.TagLabel); if (label.Id != null) { result.Add(new XAttribute(CMLConstants.AttributeId, label.Id)); } result.Add(new XAttribute(CMLConstants.AttributeDictRef, CMLConstants.ValueChem4WordLabel)); if (label.Value != null) { result.Add(new XAttribute(CMLConstants.AttributeNameValue, label.Value)); } return(result); }
// <cml:label id="" dictRef="chem4word:Label" value="C19 /> private static TextualProperty GetLabel(XElement cmlElement) { var result = new TextualProperty(); result.FullType = CMLConstants.ValueChem4WordLabel; if (cmlElement.Attribute(CMLConstants.AttributeId) != null) { result.Id = cmlElement.Attribute(CMLConstants.AttributeId)?.Value; } if (cmlElement.Attribute(CMLConstants.AttributeNameValue) != null) { result.Value = cmlElement.Attribute(CMLConstants.AttributeNameValue)?.Value; } result.CanBeDeleted = true; return(result); }
private void ImportStructure() { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; using (new WaitCursor()) { CMLConverter conv = new CMLConverter(); var expModel = _lastModel; expModel.Relabel(true); using (new WaitCursor()) { expModel.Molecules.Values.First().Names.Clear(); if (_allResults.IupacNames != null) { foreach (var di in _allResults.IupacNames) { var cn = new TextualProperty(); cn.Value = di.data; cn.FullType = "chebi:Iupac"; expModel.Molecules.Values.First().Names.Add(cn); } } if (_allResults.Synonyms != null) { foreach (var di in _allResults.Synonyms) { var cn = new TextualProperty(); cn.Value = di.data; cn.FullType = "chebi:Synonym"; expModel.Molecules.Values.First().Names.Add(cn); } } Cml = conv.Export(expModel); } } }
public void CheckNamesCanBeAltered() { Model model = new Model(); Molecule molecule = new Molecule(); molecule.Id = "m1"; model.AddMolecule(molecule); molecule.Parent = model; var name = new TextualProperty(); name.FullType = ""; name.Value = ""; molecule.Names.Add(name); Assert.True(molecule.Names.Count == 1, "Expected count to be 1"); Assert.Equal("", molecule.Names[0].FullType); molecule.Names[0].FullType = "dictref"; Assert.Equal("dictref", molecule.Names[0].FullType); }
public void CheckFormulasCanBeAltered() { Model model = new Model(); Molecule molecule = new Molecule(); molecule.Id = "m1"; model.AddMolecule(molecule); molecule.Parent = model; var formula = new TextualProperty(); formula.FullType = ""; formula.Value = ""; molecule.Formulas.Add(formula); Assert.True(molecule.Formulas.Count == 1, "Expected count to be 1"); Assert.Equal("", molecule.Formulas[0].FullType); molecule.Formulas[0].FullType = "convention"; Assert.Equal("convention", molecule.Formulas[0].FullType); }
public override SdfState ImportFromStream(StreamReader reader, Molecule molecule, out string message) { message = null; _molecule = molecule; SdfState result = SdfState.Null; try { bool isFormula = false; string internalName = ""; while (!reader.EndOfStream) { string line = SdFileConverter.GetNextLine(reader); //reader.ReadLine();; if (!string.IsNullOrEmpty(line)) { if (line.Equals(MDLConstants.SDF_END)) { // End of SDF Section result = SdfState.EndOfData; break; } if (line.StartsWith(">")) { // Clear existing Property Name internalName = string.Empty; // See if we can find the property in our translation table foreach (var property in _propertyTypes) { if (line.Equals(property.ExternalName)) { isFormula = property.IsFormula; internalName = property.InternalName; break; } } } else { // Property Data if (!string.IsNullOrEmpty(internalName)) { if (isFormula) { var formula = new TextualProperty(); formula.FullType = internalName; formula.Value = line; _molecule.Formulas.Add(formula); } else { var name = new TextualProperty(); name.FullType = internalName; name.Value = line; _molecule.Names.Add(name); } } } } else { internalName = string.Empty; } } } catch (System.Exception ex) { Debug.WriteLine(ex.Message); result = SdfState.Error; } return(result); }