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); }
/// <summary> /// writes all the molecules supplied in a MoleculeSet class to /// a single HIN file. You can also supply a single Molecule object /// as well /// </summary> /// <param name="som">the set of molecules to write</param> /// <exception cref="IOException">if there is a problem writing the molecule</exception> private void WriteAtomContainer(IEnumerableChemObject <IAtomContainer> som) { string sym; double chrg; int molnumber = 0; foreach (var mol in som) { molnumber++; try { string molname = "mol " + molnumber + " " + mol.Title; writer.Write(molname, 0, molname.Length); writer.Write('\n'); // Loop through the atoms and write them out: int i = 0; foreach (var atom in mol.Atoms) { string line = "atom "; sym = atom.Symbol; chrg = atom.Charge.Value; Vector3 point = atom.Point3D.Value; line = line + (i + 1).ToString(NumberFormatInfo.InvariantInfo) + " - " + sym + " ** - " + chrg.ToString(NumberFormatInfo.InvariantInfo) + " " + point.X.ToString(NumberFormatInfo.InvariantInfo) + " " + point.Y.ToString(NumberFormatInfo.InvariantInfo) + " " + point.Z.ToString(NumberFormatInfo.InvariantInfo) + " "; string abuf = ""; int ncon = 0; foreach (var bond in mol.Bonds) { if (bond.Contains(atom)) { // current atom is in the bond so lets get the connected atom IAtom connectedAtom = bond.GetOther(atom); BondOrder bondOrder = bond.Order; int serial; string bondType = ""; // get the serial no for this atom serial = mol.Atoms.IndexOf(connectedAtom); if (bondOrder == BondOrder.Single) { bondType = "s"; } else if (bondOrder == BondOrder.Double) { bondType = "d"; } else if (bondOrder == BondOrder.Triple) { bondType = "t"; } else if (bond.IsAromatic) { bondType = "a"; } abuf = abuf + (serial + 1).ToString(NumberFormatInfo.InvariantInfo) + " " + bondType + " "; ncon++; } } line = line + " " + ncon.ToString(NumberFormatInfo.InvariantInfo) + " " + abuf; writer.Write(line, 0, line.Length); writer.Write('\n'); i++; } string buf = "endmol " + molnumber; writer.Write(buf, 0, buf.Length); writer.Write('\n'); } catch (IOException) { throw; } } }
public CMLMoleculeList CDKAtomContainerSetToCMLList(IEnumerableChemObject <IAtomContainer> moleculeSet) { return(CDKAtomContainerSetToCMLList(moleculeSet, true)); }