示例#1
0
        public void TestReadAtomTypes_CDK()
        {
            string data = "<atomTypeList xmlns=\"http://www.xml-cml.org/schema/cml2/core\"                              \n"
                          + "  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"                                    \n"
                          + "  xsi:schemaLocation=\"http://www.xml-cml.org/schema/cml2/core ../../io/cml/data/cmlAll.xsd\"\n"
                          + "  id=\"mol2\" title=\"MOL2 AtomTypes\">                                                      \n"
                          + "                                                                                             \n"
                          + "  <atomType id=\"C.sp\">\n" + "    <atom elementType=\"C\" formalCharge=\"0\">\n"
                          + "      <scalar dataType=\"xsd:integer\" dictRef=\"cdk:formalNeighbourCount\">2</scalar>\n"
                          + "      <scalar dataType=\"xsd:integer\" dictRef=\"cdk:lonePairCount\">0</scalar>\n"
                          + "      <scalar dataType=\"xsd:integer\" dictRef=\"cdk:piBondCount\">2</scalar>\n" + "    </atom>\n"
                          + "    <scalar dataType=\"xsd:string\" dictRef=\"cdk:hybridization\">sp1</scalar>\n"
                          + "  </atomType>                                                                                "
                          + "</atomTypeList>";

            AtomTypeReader reader = new AtomTypeReader(new StringReader(data));

            Assert.IsNotNull(reader);
            var types = reader.ReadAtomTypes().ToReadOnlyList();

            Assert.IsNotNull(types);
            Assert.AreEqual(1, types.Count);

            object obj = types[0];

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is IAtomType);
            IAtomType atomType = (IAtomType)obj;

            Assert.AreEqual(0, atomType.FormalCharge.Value);
            Assert.AreEqual(Hybridization.SP1, atomType.Hybridization);
            Assert.AreEqual(0, atomType.GetProperty <int?>(CDKPropertyName.LonePairCount));
            Assert.AreEqual(2, atomType.GetProperty <int?>(CDKPropertyName.PiBondCount));
        }
示例#2
0
        public void TestReadAtomTypes_CDK()
        {
            OWLAtomTypeReader reader = new OWLAtomTypeReader(new StringReader(OWL_CONTENT));

            Assert.IsNotNull(reader);
            var types = reader.ReadAtomTypes();

            Assert.IsNotNull(types);
            Assert.AreEqual(1, types.Count);

            object obj = types[0];

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is IAtomType);
            IAtomType atomType = (IAtomType)obj;

            Assert.AreEqual("C", atomType.Symbol);
            Assert.AreEqual("C.sp3.0", atomType.AtomTypeName);
            Assert.AreEqual(0, atomType.FormalCharge.Value);
            Assert.AreEqual(Hybridization.SP3, atomType.Hybridization);
            Assert.AreEqual(4, atomType.FormalNeighbourCount.Value);
            Assert.AreEqual(0, atomType.GetProperty <int>(CDKPropertyName.LonePairCount));
            Assert.AreEqual(0, atomType.GetProperty <int>(CDKPropertyName.PiBondCount));
            Assert.AreEqual(0, atomType.GetProperty <int>(CDKPropertyName.SingleElectronCount));
        }
示例#3
0
        /// <summary>
        /// Method that assign properties to an atom given a particular atomType.
        /// An <see cref="ArgumentException"/> is thrown if the given <see cref="IAtomType"/>
        /// is null. <b>This method overwrites non-null values.</b>
        /// </summary>
        /// <param name="atom">Atom to configure</param>
        /// <param name="atomType">AtomType. Must not be null.</param>
        public static void Configure(IAtom atom, IAtomType atomType)
        {
            if (atomType == null)
            {
                throw new ArgumentNullException(nameof(atomType));
            }

            if (string.Equals("X", atomType.AtomTypeName, StringComparison.Ordinal))
            {
                atom.AtomTypeName = "X";
                return;
            }

            // we set the atom type name, but nothing else
            atom.AtomTypeName = atomType.AtomTypeName;

            // configuring atom type information is not really valid
            // for pseudo atoms - first because they basically have no
            // type information and second because they may have information
            // associated with them from another context, which should not be
            // overwritten. So we only do the stuff below if we have a non pseudoatom
            //
            // a side effect of this is that it is probably not valid to get the atom
            // type of a pseudo atom. I think this is OK, since you can always check
            // whether an atom is a pseudo atom without looking at its atom type
            if (!(atom is IPseudoAtom))
            {
                atom.Symbol                 = atomType.Symbol;
                atom.MaxBondOrder           = atomType.MaxBondOrder;
                atom.BondOrderSum           = atomType.BondOrderSum;
                atom.CovalentRadius         = atomType.CovalentRadius;
                atom.Valency                = atomType.Valency;
                atom.FormalCharge           = atomType.FormalCharge;
                atom.Hybridization          = atomType.Hybridization;
                atom.FormalNeighbourCount   = atomType.FormalNeighbourCount;
                atom.IsHydrogenBondAcceptor = atomType.IsHydrogenBondAcceptor;
                atom.IsHydrogenBondDonor    = atomType.IsHydrogenBondDonor;
                var constant = atomType.GetProperty <int?>(CDKPropertyName.ChemicalGroupConstant);
                if (constant != null)
                {
                    atom.SetProperty(CDKPropertyName.ChemicalGroupConstant, constant);
                }
                if (atomType.IsAromatic)
                {
                    atom.IsAromatic = atomType.IsAromatic;
                }

                object color = atomType.GetProperty <object>(CDKPropertyName.Color);
                if (color != null)
                {
                    atom.SetProperty(CDKPropertyName.Color, color);
                }
                atom.AtomicNumber = atomType.AtomicNumber;
                if (atomType.ExactMass != null)
                {
                    atom.ExactMass = atomType.ExactMass;
                }
            }
        }
示例#4
0
        public void TestReadAtomTypes_FF()
        {
            string data = "<atomTypeList xmlns=\"http://www.xml-cml.org/schema/cml2/core\"                              \n"
                          + "  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"                                    \n"
                          + "  xsi:schemaLocation=\"http://www.xml-cml.org/schema/cml2/core ../../io/cml/data/cmlAll.xsd\"\n"
                          + "  id=\"mol2\" title=\"MOL2 AtomTypes\">                                                      \n"
                          + "                                                                                             \n"
                          + " <atomType id=\"C\">\n" + "    <!-- for example in CC-->\n"
                          + "   <atom elementType=\"C\" formalCharge=\"0\">\n"
                          + "     <scalar dataType=\"xsd:double\" dictRef=\"cdk:maxBondOrder\">1.0</scalar>\n"
                          + "     <scalar dataType=\"xsd:double\" dictRef=\"cdk:bondOrderSum\">4.0</scalar>\n"
                          + "     <scalar dataType=\"xsd:integer\" dictRef=\"cdk:formalNeighbourCount\">4</scalar>\n"
                          + "     <scalar dataType=\"xsd:integer\" dictRef=\"cdk:valency\">4</scalar>\n"
                          + "     <scalar dataType=\"xsd:string\" dictRef=\"cdk:hybridization\">sp3</scalar>\n"
                          + "     <scalar dataType=\"xsd:string\" dictRef=\"cdk:DA\">-</scalar>\n"
                          + "     <scalar dataType=\"xsd:string\" dictRef=\"cdk:sphericalMatcher\">[CSP]-[0-4][-]?+;</scalar>\n"
                          + "     <scalar dataType=\"xsd:integer\" dictRef=\"cdk:ringSize\">3</scalar>\n"
                          + "     <scalar dataType=\"xsd:integer\" dictRef=\"cdk:ringConstant\">3</scalar>\n" + "   </atom>\n"
                          + " </atomType>\n" + "</atomTypeList>\n";

            AtomTypeReader reader = new AtomTypeReader(new StringReader(data));

            Assert.IsNotNull(reader);
            var types = reader.ReadAtomTypes().ToReadOnlyList();

            Assert.IsNotNull(types);
            Assert.AreEqual(1, types.Count);

            object obj = types[0];

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is IAtomType);
            IAtomType atomType = (IAtomType)obj;

            Assert.AreEqual("[CSP]-[0-4][-]?+;", atomType.GetProperty <string>(CDKPropertyName.SphericalMatcher));
            Assert.IsFalse(atomType.IsHydrogenBondAcceptor);
            Assert.IsFalse(atomType.IsHydrogenBondDonor);

            Assert.AreEqual(3, atomType.GetProperty <int?>(CDKPropertyName.PartOfRingOfSize));
            Assert.AreEqual(3, atomType.GetProperty <int?>(CDKPropertyName.ChemicalGroupConstant));
        }
示例#5
0
        public virtual void TestGetAtomTypeFromMM2()
        {
            AtomTypeFactory factory;

            factory = AtomTypeFactory.GetInstance("NCDK.Config.Data.mm2_atomtypes.xml");

            IAtomType atomType = factory.GetAtomType("C");

            Assert.IsNotNull(atomType);
            Assert.AreEqual("C", atomType.Symbol);
            Assert.AreEqual("C", atomType.AtomTypeName);
            Assert.AreEqual("[CSP]-[0-4][-]?+;[A-Za-z\\+\\-&&[^=%]]{0,6}[(].*+",
                            atomType.GetProperty <string>(CDKPropertyName.SphericalMatcher));
            Assert.AreEqual(Hybridization.SP3, atomType.Hybridization);

            atomType = factory.GetAtomType("Sthi");
            Assert.IsNotNull(atomType);
            Assert.AreEqual("S", atomType.Symbol);
            Assert.AreEqual("Sthi", atomType.AtomTypeName);
            Assert.AreEqual("S-[2];[H]{0,3}+=C.*+", atomType.GetProperty <string>(CDKPropertyName.SphericalMatcher));
            Assert.AreEqual(Hybridization.SP2, atomType.Hybridization);
            Assert.IsTrue(atomType.IsHydrogenBondAcceptor);
            Assert.AreEqual(5, atomType.GetProperty <int?>(CDKPropertyName.PartOfRingOfSize));
        }
示例#6
0
 internal ImmutableAtomType(IAtomType type)
 {
     this.element                = type.Element;
     this.symbol                 = type.Symbol;
     this.atomicNumber           = type.AtomicNumber;
     this.abundance              = type.Abundance;
     this.exactMass              = type.ExactMass;
     this.massNumber             = type.MassNumber;
     this.formalCharge           = type.FormalCharge;
     this.hybridization          = type.Hybridization;
     this.formalNeighbourCount   = type.FormalNeighbourCount;
     this.atomTypeName           = type.AtomTypeName;
     this.maxBondOrder           = type.MaxBondOrder;
     this.bondOrderSum           = type.BondOrderSum;
     this.covalentRadius         = type.CovalentRadius;
     this.isHydrogenBondAcceptor = type.IsHydrogenBondAcceptor;
     this.isHydrogenBondDonor    = type.IsHydrogenBondDonor;
     this.isAromatic             = type.IsAromatic;
     this.isAliphatic            = type.IsAliphatic;
     this.isInRing               = this.IsInRing;
     this.baseAtomType           = type;
     if (type.Valency != null)
     {
         this.valency = type.Valency;
     }
     else
     {
         var piBondCount = type.GetProperty <int?>(CDKPropertyName.PiBondCount);
         if (piBondCount != null && formalNeighbourCount != null)
         {
             this.valency = (int)piBondCount + (int)formalNeighbourCount;
         }
         else
         {
             this.valency = null;
         }
     }
 }
        /// <summary>
        ///  Assigns an atom type to an atom
        /// </summary>
        /// <param name="atom">The atom to be aasigned</param>
        /// <param name="ID">the atom type id</param>
        /// <exception cref="NoSuchAtomTypeException"> atomType is not known</exception>
        /// <returns>the assigned atom</returns>
        private IAtom SetAtom(IAtom atom, string ID)
        {
            IAtomType at = GetAtomType(ID);

            if (atom.Symbol == null)
            {
                atom.Symbol = at.Symbol;
            }
            atom.AtomTypeName         = at.AtomTypeName;
            atom.FormalNeighbourCount = at.FormalNeighbourCount;
            string key   = "vdw" + ID;
            var    data  = (System.Collections.IList)parameterSet[key];
            double value = (double)data[0];

            key = "charge" + ID;
            if (parameterSet.ContainsKey(key))
            {
                data        = (System.Collections.IList)parameterSet[key];
                value       = (double)data[0];
                atom.Charge = value;
            }
            var color = at.GetProperty <object>(CDKPropertyName.Color);

            if (color != null)
            {
                atom.SetProperty(CDKPropertyName.Color, color);
            }
            if (at.AtomicNumber != 0)
            {
                atom.AtomicNumber = at.AtomicNumber;
            }
            if (at.ExactMass > 0.0)
            {
                atom.ExactMass = at.ExactMass;
            }
            return(atom);
        }
示例#8
0
 public T GetProperty <T>(object description) => baseAtomType.GetProperty <T>(description);