private static void Map2DCoordsToCML(CMLAtom cmlAtom, IAtom cdkAtom) { if (cdkAtom.Point2D != null) { cmlAtom.X2 = cdkAtom.Point2D.Value.X; cmlAtom.Y2 = cdkAtom.Point2D.Value.Y; } }
private static void MapFractionalCoordsToCML(CMLAtom cmlAtom, IAtom cdkAtom) { if (cdkAtom.FractionalPoint3D != null) { cmlAtom.XFract = cdkAtom.FractionalPoint3D.Value.X; cmlAtom.YFract = cdkAtom.FractionalPoint3D.Value.Y; cmlAtom.ZFract = cdkAtom.FractionalPoint3D.Value.Z; } }
private static void Map3DCoordsToCML(CMLAtom cmlAtom, IAtom cdkAtom) { if (cdkAtom.Point3D != null) { cmlAtom.X3 = cdkAtom.Point3D.Value.X; cmlAtom.Y3 = cdkAtom.Point3D.Value.Y; cmlAtom.Z3 = cdkAtom.Point3D.Value.Z; } }
public void Add(CMLAtom atom) { var aa = this.Element(XName_CML_atomArray); if (aa == null) { aa = new CMLAtomArray(); this.Add(aa); } aa.Add(atom); }
private static bool AddAtomID(IAtom cdkAtom, CMLAtom cmlAtom) { if (!string.IsNullOrEmpty(cdkAtom.Id)) { cmlAtom.Id = cdkAtom.Id; } else { cmlAtom.Id = "a" + cdkAtom.GetHashCode().ToString(NumberFormatInfo.InvariantInfo); } return(true); }
/// <summary> /// Customize Molecule. /// </summary> /// <param name="molecule"></param> /// <param name="nodeToAdd"></param> public void Customize(IAtomContainer molecule, object nodeToAdd) { if (!(nodeToAdd is CMLMolecule)) { throw new CDKException("NodeToAdd must be of type nu.xom.Element!"); } //The nodeToAdd CMLMolecule molToCustomize = (CMLMolecule)nodeToAdd; if ((molecule is MDMolecule)) { MDMolecule mdmol = (MDMolecule)molecule; molToCustomize.Convention = "md:mdMolecule"; molToCustomize.SetAttributeValue(XNamespace.Xmlns + "md", NS_MD.NamespaceName); //Residues if (mdmol.GetResidues().Count > 0) { foreach (var residue in mdmol.GetResidues()) { int number = residue.GetNumber(); CMLMolecule resMol = new CMLMolecule { DictRef = "md:residue", Title = residue.Name }; //Append resNo CMLScalar residueNumber = new CMLScalar(number); residueNumber.SetAttributeValue(Attribute_dictRef, "md:resNumber"); resMol.Add(residueNumber); // prefix for residue atom id string rprefix = "r" + number; //Append atoms CMLAtomArray ar = new CMLAtomArray(); for (int i = 0; i < residue.Atoms.Count; i++) { CMLAtom cmlAtom = new CMLAtom { // Console.Out.WriteLine("atom ID: "+ residue.Atoms[i].Id); // cmlAtom.AddAttribute(new Attribute("ref", residue.Atoms[i].Id)); // the next thing is better, but exception // // setRef to keep consistent usage // setId to satisfy Jumbo 54. need for all atoms to have id Ref = residue.Atoms[i].Id, Id = rprefix + "_" + residue.Atoms[i].Id }; ar.Add(cmlAtom); } resMol.Add(ar); molToCustomize.Add(resMol); } } //Chargegroups if (mdmol.GetChargeGroups().Count > 0) { foreach (var chargeGroup in mdmol.GetChargeGroups()) { int number = chargeGroup.GetNumber(); //FIXME: persist the ChargeGroup CMLMolecule cgMol = new CMLMolecule { DictRef = "md:chargeGroup" }; // etc: add name, refs to atoms etc //Append chgrpNo CMLScalar cgNo = new CMLScalar(number) { DictRef = "md:cgNumber" }; cgMol.Add(cgNo); // prefix for residue atom id string cprefix = "cg" + number; //Append atoms from chargeGroup as it is an AC CMLAtomArray ar = new CMLAtomArray(); for (int i = 0; i < chargeGroup.Atoms.Count; i++) { CMLAtom cmlAtom = new CMLAtom { // setRef to keep consistent usage // setId to satisfy Jumbo 5.4 need for all atoms to have id Ref = chargeGroup.Atoms[i].Id, Id = cprefix + "_" + chargeGroup.Atoms[i].Id }; //Append switching atom? if (chargeGroup.Atoms[i].Equals(chargeGroup.GetSwitchingAtom())) { CMLScalar scalar = new CMLScalar { DictRef = "md:switchingAtom" }; cmlAtom.Add(scalar); } ar.Add(cmlAtom); } cgMol.Add(ar); molToCustomize.Add(cgMol); } } } }
public CMLAtom CDKAtomToCMLAtom(IAtomContainer container, IAtom cdkAtom) { var cmlAtom = new CMLAtom(); this.CheckPrefix(cmlAtom); AddAtomID(cdkAtom, cmlAtom); AddDictRef(cdkAtom, cmlAtom); cmlAtom.ElementType = cdkAtom.Symbol; if (cdkAtom is IPseudoAtom) { var label = ((IPseudoAtom)cdkAtom).Label; if (label != null) { cmlAtom.Title = label; } cmlAtom.ElementType = "Du"; } Map2DCoordsToCML(cmlAtom, cdkAtom); Map3DCoordsToCML(cmlAtom, cdkAtom); MapFractionalCoordsToCML(cmlAtom, cdkAtom); var formalCharge = cdkAtom.FormalCharge; if (formalCharge != null) { cmlAtom.FormalCharge = formalCharge.Value; } // CML's hydrogen count consists of the sum of implicit and explicit // hydrogens (see bug #1655045). var totalHydrogen = cdkAtom.ImplicitHydrogenCount; if (totalHydrogen != null) { if (container != null) { foreach (var bond in container.GetConnectedBonds(cdkAtom)) { foreach (var atom in bond.Atoms) { if (AtomicNumbers.H.Equals(atom.AtomicNumber) && atom != cdkAtom) { totalHydrogen++; } } } } // else: it is the implicit hydrogen count cmlAtom.HydrogenCount = totalHydrogen.Value; } // else: don't report it, people can count the explicit Hs themselves var massNumber = cdkAtom.MassNumber; if (!(cdkAtom is IPseudoAtom)) { if (massNumber != null) { cmlAtom.IsotopeNumber = massNumber.Value; } } if (cdkAtom.Charge != null) { var scalar = new CMLScalar(); this.CheckPrefix(scalar); scalar.DictRef = "cdk:partialCharge"; scalar.SetValue(cdkAtom.Charge.Value); cmlAtom.Add(scalar); } WriteProperties(cdkAtom, cmlAtom); if (cdkAtom.IsAromatic) { var aromAtom = new CMLScalar { DictRef = "cdk:aromaticAtom" }; cmlAtom.Add(aromAtom); } foreach (var element in customizers.Keys) { var customizer = customizers[element]; try { customizer.Customize(cdkAtom, cmlAtom); } catch (Exception exception) { Trace.TraceError("Error while customizing CML output with customizer: ", customizer.GetType().Name); Debug.WriteLine(exception); } } return(cmlAtom); }
private CMLMolecule CDKAtomContainerToCMLMolecule(IAtomContainer structure, bool setIDs, bool isRef) { CMLMolecule cmlMolecule = new CMLMolecule(); if (useCMLIDs && setIDs) { IDCreator.CreateIDs(structure); } this.CheckPrefix(cmlMolecule); if (!string.IsNullOrEmpty(structure.Id)) { if (!isRef) { cmlMolecule.Id = structure.Id; } else { cmlMolecule.Ref = structure.Id; } } if (structure.Title != null) { cmlMolecule.Title = structure.Title; } if (structure.GetProperty <string>(CDKPropertyName.InChI) != null) { CMLIdentifier ident = new CMLIdentifier { Convention = "iupac:inchi" }; ident.SetAttributeValue(CMLElement.Attribute_value, structure.GetProperty <string>(CDKPropertyName.InChI)); cmlMolecule.Add(ident); } if (!isRef) { for (int i = 0; i < structure.Atoms.Count; i++) { IAtom cdkAtom = structure.Atoms[i]; CMLAtom cmlAtom = CDKAtomToCMLAtom(structure, cdkAtom); if (structure.GetConnectedSingleElectrons(cdkAtom).Count() > 0) { cmlAtom.SpinMultiplicity = structure.GetConnectedSingleElectrons(cdkAtom).Count() + 1; } cmlMolecule.Add(cmlAtom); } for (int i = 0; i < structure.Bonds.Count; i++) { CMLBond cmlBond = CDKJBondToCMLBond(structure.Bonds[i]); cmlMolecule.Add(cmlBond); } } // ok, output molecular properties, but not TITLE, INCHI, or DictRef's var props = structure.GetProperties(); foreach (var propKey in props.Keys) { if (propKey is string key) { // but only if a string if (!isRef) { object value = props[key]; switch (key) { case CDKPropertyName.Title: case CDKPropertyName.InChI: break; default: // ok, should output this var scalar = new CMLScalar(); this.CheckPrefix(scalar); scalar.DictRef = "cdk:molecularProperty"; scalar.Title = (string)key; scalar.SetValue(value.ToString()); cmlMolecule.Add(scalar); break; } } // FIXME: At the moment the order writing the formula is into properties // but it should be that IMolecularFormula is a extension of IAtomContainer if (!isRef && string.Equals(key, CDKPropertyName.Formula, StringComparison.Ordinal)) { switch (props[key]) { case IMolecularFormula cdkFormula: { var cmlFormula = new CMLFormula(); var isotopesList = MolecularFormulaManipulator.PutInOrder(MolecularFormulaManipulator.OrderEle, cdkFormula); foreach (var isotope in isotopesList) { cmlFormula.Add(isotope.Symbol, cdkFormula.GetCount(isotope)); } cmlMolecule.Add(cmlFormula); } break; case IMolecularFormulaSet cdkFormulaSet: foreach (var cdkFormula in cdkFormulaSet) { var isotopesList = MolecularFormulaManipulator.PutInOrder(MolecularFormulaManipulator.OrderEle, cdkFormula); var cmlFormula = new CMLFormula { DictRef = "cdk:possibleMachts" }; foreach (var isotope in isotopesList) { cmlFormula.Add(isotope.Symbol, cdkFormula.GetCount(isotope)); } cmlMolecule.Add(cmlFormula); } break; } } } } foreach (var element in customizers.Keys) { var customizer = customizers[element]; try { customizer.Customize(structure, cmlMolecule); } catch (Exception exception) { Trace.TraceError($"Error while customizing CML output with customizer: {customizer.GetType().Name}"); Debug.WriteLine(exception); } } return(cmlMolecule); }
public void Add(CMLAtom atom) { base.Add(atom); }