Esempio n. 1
0
        public void WaterAtom()
        {
            IAtom a = g2c.ToCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Oxygen).NumOfHydrogens(2).Build(), 2);

            Assert.AreEqual("O", a.Symbol);
            Assert.AreEqual(2, a.ImplicitHydrogenCount);
        }
Esempio n. 2
0
        public void MethaneAtom()
        {
            IAtom a = g2c.ToCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Carbon).NumOfHydrogens(4).Build(), 4);

            Assert.AreEqual("C", a.Symbol);
            Assert.AreEqual(4, a.ImplicitHydrogenCount);
        }
Esempio n. 3
0
        public void NewUnknownAtom()
        {
            IAtom a = g2c.NewCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Unknown).Build());

            Assert.IsInstanceOfType(a, typeof(IPseudoAtom));
            Assert.AreEqual("*", ((IPseudoAtom)a).Label);
        }
Esempio n. 4
0
        public void AzaniumAtom()
        {
            IAtom a = g2c.ToCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Nitrogen).NumOfHydrogens(4).Cation.Build(), 4);

            Assert.AreEqual("N", a.Symbol);
            Assert.AreEqual(4, a.ImplicitHydrogenCount);
            Assert.AreEqual(+1, a.FormalCharge);
        }
Esempio n. 5
0
        public void Oxidanide()
        {
            IAtom a = g2c.ToCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Oxygen).NumOfHydrogens(1).Anion.Build(), 1);

            Assert.AreEqual("O", a.Symbol);
            Assert.AreEqual(1, a.ImplicitHydrogenCount);
            Assert.AreEqual(-1, a.FormalCharge);
        }
Esempio n. 6
0
        public void NewNitrogenAtom()
        {
            IAtom a = g2c.NewCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Nitrogen).Build());

            Assert.IsInstanceOfType(a, typeof(IAtom));
            Assert.IsNotInstanceOfType(a, typeof(IPseudoAtom));
            Assert.AreEqual("N", a.Symbol);
        }
Esempio n. 7
0
        /// <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());
        }
Esempio n. 8
0
        public void Carbon_14()
        {
            IAtom a = g2c.ToCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Carbon).NumOfHydrogens(4).Isotope(14).Build(), 4);

            Assert.AreEqual(14, a.MassNumber);
        }
Esempio n. 9
0
        public void UnspecifiedMass()
        {
            IAtom a = g2c.ToCDKAtom(AtomBuilder.Aliphatic(Beam.Element.Carbon).NumOfHydrogens(4).Build(), 4);

            Assert.IsNull(a.MassNumber);
        }