Пример #1
0
 public void SetMMFF94Parameters()
 {
     if (mmff94 == null)
     {
         mmff94 = new MMFF94BasedParameterSetReader();
     }
     mmff94.ReadParameterSets();
     parameterSet = mmff94.GetParamterSet();
     atomTypes    = mmff94.AtomTypes;
 }
Пример #2
0
        /// <summary>
        ///Constructor for the ForceFieldConfigurator object
        /// </summary>
        /// <param name="ffname">name of the force field data file</param>
        public void SetForceFieldConfigurator(string ffname)
        {
            ffname = ffname.ToLowerInvariant();
            bool check = false;

            if (ffname == ffName && parameterSet != null)
            {
            }
            else
            {
                check  = this.CheckForceFieldType(ffname);
                ffName = ffname;
                if (string.Equals(ffName, "mm2", StringComparison.Ordinal))
                {
                    ins = ResourceLoader.GetAsStream("NCDK.Modelings.ForceField.Data.mm2.prm");
                    mm2 = new MM2BasedParameterSetReader();
                    mm2.SetInputStream(ins);
                    try
                    {
                        this.SetMM2Parameters();
                    }
                    catch (Exception ex1)
                    {
                        throw new CDKException("Problems with set MM2Parameters due to " + ex1.ToString(), ex1);
                    }
                }
                else if (ffName.Equals("mmff94", StringComparison.Ordinal) || !check)
                {
                    ins    = ResourceLoader.GetAsStream("NCDK.Modelings.ForceField.Data.mmff94.prm");
                    mmff94 = new MMFF94BasedParameterSetReader();

                    mmff94.SetInputStream(ins);
                    try
                    {
                        this.SetMMFF94Parameters();
                    }
                    catch (Exception ex2)
                    {
                        throw new CDKException("Problems with set MM2Parameters due to" + ex2.ToString(), ex2);
                    }
                }
            }
        }
        public void TestReadParameterSets()
        {
            MMFF94BasedParameterSetReader mmff94bpsr = new MMFF94BasedParameterSetReader();

            mmff94bpsr.ReadParameterSets();
            var parameterSet = mmff94bpsr.GetParamterSet();

            //test atom type
            var       atomtypes = mmff94bpsr.AtomTypes;
            IAtomType atomtype  = atomtypes[0];
            string    sid       = "C";

            Assert.AreEqual(sid, atomtype.AtomTypeName);
            string rootType = "C";

            Assert.AreEqual(rootType, atomtype.Symbol);
            string smaxbond = "4";

            Assert.AreEqual(int.Parse(smaxbond, NumberFormatInfo.InvariantInfo), (int)atomtype.FormalNeighbourCount);
            string satomNr = "6";

            Assert.AreEqual(int.Parse(satomNr, NumberFormatInfo.InvariantInfo), (int)atomtype.AtomicNumber);

            //atom
            //TODO testing

            //bond
            //        string scode = "0";
            string sid1     = "C";
            string sid2     = "C";
            string slen     = "1.508";
            string sk2      = "306.432";
            string sk3      = "-612.865";
            string sk4      = "715.009";
            string sbci     = "0.0000";
            string bondkey  = "bond" + sid1 + ";" + sid2;
            var    bonddata = new List <double>
            {
                (double)(double.Parse(slen, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(sk2, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(sk3, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(sk4, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(sbci, NumberFormatInfo.InvariantInfo))
            };

            //strbnd
            //        scode = "0";
            sid1 = "C";
            sid2 = "C";
            string sid3       = "C";
            string value1     = "14.82507";
            string value2     = "14.82507";
            string strbndkey  = "strbnd" + sid1 + ";" + sid2 + ";" + sid3;
            var    strbnddata = new List <double>
            {
                (double)(double.Parse(value1, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value2, NumberFormatInfo.InvariantInfo))
            };

            //angle
            //      scode = "0";
            sid1   = "C=";
            sid2   = "C";
            sid3   = "N";
            value1 = "105.837";
            value2 = "86.1429";
            string value3    = "-34.5494";
            string value4    = "0";
            string anglekey  = "angle" + sid1 + ";" + sid2 + ";" + sid3;
            var    angledata = new List <double>
            {
                (double)(double.Parse(value1, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value2, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value3, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value4, NumberFormatInfo.InvariantInfo))
            };

            //torsion
            //        scode = "0";
            sid1 = "HC";
            sid2 = "C";
            sid3 = "C";
            string sid4 = "HC";

            value1 = "0.142";
            value2 = "0.693";
            value3 = "0.157";
            value4 = "0.000";
            string value5      = "0.000";
            string torsionkey  = "torsion" + ";" + sid1 + ";" + sid2 + ";" + sid3 + ";" + sid4;
            var    torsiondata = new List <double>
            {
                (double)(double.Parse(value1, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value2, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value3, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value4, NumberFormatInfo.InvariantInfo)),
                (double)(double.Parse(value5, NumberFormatInfo.InvariantInfo))
            };

            //opbend
            //      scode = "0";
            sid1   = "O=";
            sid2   = "C=";
            sid3   = "CR4R";
            sid4   = "CR4R";
            value1 = "10.86681780";
            string opbendkey  = "opbend" + ";" + sid1 + ";" + sid2 + ";" + sid3 + ";" + sid4;
            var    opbenddata = new List <double>
            {
                (double)(double.Parse(value1, NumberFormatInfo.InvariantInfo))
            };

            //TODO data lines testing

            foreach (var e in parameterSet)
            {
                if (e.Key.Equals(bondkey))
                {
                    Assert.IsTrue(Compares.AreDeepEqual(bonddata, e.Value));
                }
                else if (e.Key.Equals(strbndkey))
                {
                    Assert.IsTrue(Compares.AreDeepEqual(strbnddata, e.Value));
                }
                else if (e.Key.Equals(anglekey))
                {
                    Assert.IsTrue(Compares.AreDeepEqual(angledata, e.Value));
                }
                else if (e.Key.Equals(torsionkey))
                {
                    Assert.IsTrue(Compares.AreDeepEqual(torsiondata, e.Value));
                }
                else if (e.Key.Equals(opbendkey))
                {
                    Assert.IsTrue(Compares.AreDeepEqual(opbenddata, e.Value));
                }
            }
        }