/// <summary> /// Convert an CDK <see cref="IAtom"/> to a Beam Atom. The symbol and implicit /// hydrogen count are not optional. If the symbol is not supported by the /// SMILES notation (e.g. 'R1') the element will automatically default to /// Unknown ('*'). /// </summary> /// <param name="a">cdk Atom instance</param> /// <returns>a Beam atom</returns> /// <exception cref="NullReferenceException">the atom had an undefined symbol or implicit hydrogen count</exception> static Beam.IAtom ToBeamAtom(IAtom a, SmiFlavors flavour) { var aromatic = SmiFlavorTool.IsSet(flavour, SmiFlavors.UseAromaticSymbols) && a.IsAromatic; var charge = a.FormalCharge; string symbol = CheckNotNull(a.Symbol, "An atom had an undefined symbol"); var element = Beam.Element.OfSymbol(symbol); if (element == null) { element = Beam.Element.Unknown; } var ab = aromatic ? AtomBuilder.Aromatic(element) : AtomBuilder.Aliphatic(element); // CDK leaves nulls on pseudo atoms - we need to check this special case var hCount = a.ImplicitHydrogenCount; if (element == Beam.Element.Unknown) { ab.NumOfHydrogens(hCount ?? 0); } else { ab.NumOfHydrogens(CheckNotNull(hCount, "One or more atoms had an undefined number of implicit hydrogens")); } if (charge.HasValue) { ab.Charge(charge.Value); } // use the mass number to specify isotope? if (SmiFlavorTool.IsSet(flavour, SmiFlavors.AtomicMass | SmiFlavors.AtomicMassStrict)) { var massNumber = a.MassNumber; if (massNumber != null) { ab.Isotope(massNumber.Value); } } var atomClass = a.GetProperty <int?>(CDKPropertyName.AtomAtomMapping); if (SmiFlavorTool.IsSet(flavour, SmiFlavors.AtomAtomMap) && atomClass != null) { ab.AtomClass(atomClass.Value); } return(ab.Build()); }
public void Aromatic() { IAtom a = g2c.ToCDKAtom(AtomBuilder.Aromatic(Beam.Element.Carbon).Build(), 0); Assert.IsTrue(a.IsAromatic); }