private CMLReactionScheme CDKReactionSchemeToCMLReactionScheme(IReactionScheme cdkScheme, bool setIDs) { var reactionScheme = new CMLReactionScheme(); if (useCMLIDs && setIDs) { IDCreator.CreateIDs(cdkScheme); } if (!string.IsNullOrEmpty(cdkScheme.Id)) { reactionScheme.Id = cdkScheme.Id; } foreach (var reaction in cdkScheme.Reactions) { reactionScheme.Add(CDKReactionToCMLReaction(reaction)); } foreach (var intScheme in cdkScheme.Schemes) { reactionScheme.Add(CDKReactionSchemeToCMLReactionScheme(intScheme)); } return(reactionScheme); }
private CMLList CDKChemModelToCMLList(IChemModel model, bool setIDs) { var cmlList = new CMLList { Convention = "cdk:model" }; if (useCMLIDs && setIDs) { IDCreator.CreateIDs(model); } if (!string.IsNullOrEmpty(model.Id)) { cmlList.Id = model.Id; } if (model.Crystal != null) { cmlList.Add(CDKCrystalToCMLMolecule(model.Crystal, false)); } if (model.ReactionSet != null) { cmlList.Add(CDKReactionSetToCMLReactionList(model.ReactionSet, false)); } if (model.MoleculeSet != null) { cmlList.Add(CDKAtomContainerSetToCMLList(model.MoleculeSet, false)); } return(cmlList); }
public void TestGetAllIDs_IChemModel() { Assert.AreEqual(0, ChemModelManipulator.GetAllIDs(chemModel).Count()); IDCreator.CreateIDs(chemModel); var allIDs = ChemModelManipulator.GetAllIDs(chemModel); Assert.AreEqual(16, ChemModelManipulator.GetAllIDs(chemModel).Count()); var uniq = new HashSet <string>(allIDs); Assert.AreEqual(10, uniq.Count); }
public void TestGetAllIDs_IChemSequence() { Assert.AreEqual(0, ChemSequenceManipulator.GetAllIDs(chemSequence).Count()); IDCreator.CreateIDs(chemSequence); var allIDs = ChemSequenceManipulator.GetAllIDs(chemSequence); Assert.AreEqual(18, ChemSequenceManipulator.GetAllIDs(chemSequence).Count()); var uniq = new HashSet <string>(allIDs); Assert.AreEqual(12, uniq.Count); }
private void WriteAtomContainer(IAtomContainer molecule) { writer.Write("{"); writer.Write('\n'); writer.Write(" IChemObjectBuilder builder = "); writer.Write(builder.Setting); writer.Write(".Instance;"); writer.Write('\n'); writer.Write(" IAtomContainer mol = builder.NewAtomContainer();"); writer.Write('\n'); IDCreator.CreateIDs(molecule); WriteAtoms(molecule); WriteBonds(molecule); writer.Write("}"); writer.Write('\n'); }
private CMLReactionList CDKReactionSetToCMLReactionList(IReactionSet reactionSet, bool setIDs) { var reactionList = new CMLReactionList(); if (useCMLIDs && setIDs) { IDCreator.CreateIDs(reactionSet); } if (!string.IsNullOrEmpty(reactionSet.Id)) { reactionList.Id = reactionSet.Id; } foreach (var reaction in reactionSet) { reactionList.Add(CDKReactionToCMLReaction(reaction, false)); } return(reactionList); }
private CMLMoleculeList CDKAtomContainerSetToCMLList(IEnumerableChemObject <IAtomContainer> moleculeSet, bool setIDs) { CMLMoleculeList cmlList = new CMLMoleculeList { Convention = "cdk:moleculeSet" }; if (useCMLIDs && setIDs) { IDCreator.CreateIDs(moleculeSet); } if (!string.IsNullOrEmpty(moleculeSet.Id)) { cmlList.Id = moleculeSet.Id; } foreach (var container in moleculeSet) { cmlList.Add(CDKAtomContainerToCMLMolecule(container, false, false)); } return(cmlList); }
private CMLList CDKChemSequenceToCMLList(IChemSequence sequence, bool setIDs) { var cmlList = new CMLList { Convention = "cdk:sequence" }; if (useCMLIDs && setIDs) { IDCreator.CreateIDs(sequence); } if (!string.IsNullOrEmpty(sequence.Id)) { cmlList.Id = sequence.Id; } foreach (var chemModel in sequence) { cmlList.Add(CDKChemModelToCMLList(chemModel)); } return(cmlList); }
private CMLCml CDKChemFileToCMLList(IChemFile file, bool setIDs) { var cmlList = new CMLCml { Convention = "cdk:document" }; if (useCMLIDs && setIDs) { IDCreator.CreateIDs(file); } if (!string.IsNullOrEmpty(file.Id)) { cmlList.Id = file.Id; } foreach (var sequence in file) { cmlList.Add(CDKChemSequenceToCMLList(sequence)); } return(cmlList); }
private CMLMolecule CDKCrystalToCMLMolecule(ICrystal crystal, bool setIDs) { var molecule = CDKAtomContainerToCMLMolecule(crystal, false, false); var cmlCrystal = new CMLCrystal(); if (useCMLIDs && setIDs) { IDCreator.CreateIDs(crystal); } if (!string.IsNullOrEmpty(crystal.Id)) { cmlCrystal.Id = crystal.Id; } this.CheckPrefix(cmlCrystal); cmlCrystal.Z = crystal.Z.Value; var params_ = CrystalGeometryTools.CartesianToNotional(crystal.A, crystal.B, crystal.C); Debug.WriteLine($"Number of cell params: {params_.Length}"); cmlCrystal.SetCellParameters(params_); molecule.Add(cmlCrystal); return(molecule); }
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); }
private CMLReaction CDKReactionToCMLReaction(IReaction reaction, bool setIDs) { var cmlReaction = new CMLReaction(); if (useCMLIDs && setIDs) { IDCreator.CreateIDs(reaction); } if (!string.IsNullOrEmpty(reaction.Id)) { cmlReaction.Id = reaction.Id; } var props = reaction.GetProperties(); foreach (var key in props.Keys) { var value = props[key]; if (value is string) { if (!string.Equals(key.ToString(), CDKPropertyName.Title, StringComparison.Ordinal)) { var scalar = new CMLScalar(); this.CheckPrefix(scalar); scalar.DictRef = "cdk:reactionProperty"; scalar.Title = key.ToString(); scalar.SetValue(value.ToString()); cmlReaction.Add(scalar); } } } // reactants var cmlReactants = new CMLReactantList(); foreach (var reactant in reaction.Reactants) { var cmlReactant = new CMLReactant(); cmlReactant.Add(CDKAtomContainerToCMLMolecule(reactant)); cmlReactants.Add(cmlReactant); } // products var cmlProducts = new CMLProductList(); foreach (var product in reaction.Products) { var cmlProduct = new CMLProduct(); cmlProduct.Add(CDKAtomContainerToCMLMolecule(product)); cmlProducts.Add(cmlProduct); } // substance var cmlSubstances = new CMLSubstanceList(); foreach (var agent in reaction.Agents) { var cmlSubstance = new CMLSubstance(); cmlSubstance.Add(CDKAtomContainerToCMLMolecule(agent)); cmlSubstances.Add(cmlSubstance); } if (reaction.Id != null) { cmlReaction.Id = reaction.Id; } cmlReaction.Add(cmlReactants); cmlReaction.Add(cmlProducts); cmlReaction.Add(cmlSubstances); return(cmlReaction); }