private CMLMolecule CDKPDBPolymerToCMLMolecule(IPDBPolymer pdbPolymer, bool setIDs) { var cmlMolecule = new CMLMolecule { Convention = "PDB", DictRef = "pdb:model" }; var mapS = pdbPolymer.GetStrandMap(); foreach (var key in mapS.Keys) { var strand = mapS[key]; var monomerNames = new List <string>(strand.GetMonomerNames()); monomerNames.Sort(); foreach (var name in monomerNames) { IMonomer monomer = strand.GetMonomer(name); CMLMolecule clmono = CDKMonomerToCMLMolecule(monomer, true); cmlMolecule.Add(clmono); } } return(cmlMolecule); }
private CMLMolecule CDKMonomerToCMLMolecule(IMonomer monomer, bool setIDs) { var cmlMolecule = new CMLMolecule { DictRef = "pdb:sequence" }; if (!string.IsNullOrEmpty(monomer.MonomerName)) { cmlMolecule.Id = monomer.MonomerName; } for (int i = 0; i < monomer.Atoms.Count; i++) { var cdkAtom = monomer.Atoms[i]; var cmlAtom = CDKAtomToCMLAtom(monomer, cdkAtom); if (monomer.GetConnectedSingleElectrons(cdkAtom).Count() > 0) { cmlAtom.SpinMultiplicity = monomer.GetConnectedSingleElectrons(cdkAtom).Count() + 1; } cmlMolecule.Add(cmlAtom); } return(cmlMolecule); }
/// <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); } } } }
private CMLMolecule CDKAtomContainerToCMLMolecule(IAtomContainer structure, bool setIDs, bool isRef) { var 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) { var 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++) { var cdkAtom = structure.Atoms[i]; var 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++) { var 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); }