Exemplo n.º 1
0
 public Nonbonded FindNonbonded(string type0, ITextLogger logger)
 {
     if (_FindNonbonded.ContainsKey(type0) == false)
     {
         Nonbonded found = null;
         foreach (Nonbonded nonbonded in nonbondeds)
         {
             if (nonbonded.types[0] == type0)
             {
                 if (found != null)
                 {
                     bool writelog = ((found.epsilon != nonbonded.epsilon) ||
                                      (found.Rmin2 != nonbonded.Rmin2) ||
                                      (found.eps_14 != nonbonded.eps_14) ||
                                      (found.Rmin2_14 != nonbonded.Rmin2_14));
                     if (writelog)
                     {
                         logger.Log(string.Format("Nonbonded params of {0}-(eps {1}, rmin2 {2}, esp_14 {3}, rmin2_14 {4}) is replaced to ({5}, {6}, {7}, {8})",
                                                  type0, found.epsilon, found.Rmin2, found.eps_14, found.Rmin2_14,
                                                  nonbonded.epsilon, nonbonded.Rmin2, nonbonded.eps_14, nonbonded.Rmin2_14));
                     }
                 }
                 found = nonbonded;
             }
         }
         HDebug.Assert(found != null);
         HDebug.AssertIf(double.IsNaN(found.Rmin2) == false, found.Rmin2 > 0);
         HDebug.AssertIf(double.IsNaN(found.Rmin2_14) == false, found.Rmin2_14 > 0);
         _FindNonbonded.Add(type0, found);
     }
     return(_FindNonbonded[type0]);
 }
Exemplo n.º 2
0
                public static Nonbonded FromString(string line, ITextLogger logger)
                {
                    Element elem = Element.FromString(line, 1, 6);

                    //Debug.Assert(0  == elem.parms[0]); // "FE     0.010000   0.000000     0.650000" happens
                    if (!(0 == elem.parms[0]))
                    {
                        logger.Log(string.Format("Warning: Nonbonded params ({0}): 1st parameter should be in general == 0", line));
                    }
                    double epsilon = elem.parms[1];
                    double Rmin2   = elem.parms[2]; //Debug.Assert(Rmin2   > 0);

                    if (!(Rmin2 > 0))
                    {
                        logger.Log(string.Format("Error  : Nonbonded params ({0}): 3rd parameter (Rmin2) must be '> 0'", line));
                    }
                    double eps_14   = double.NaN;
                    double Rmin2_14 = double.NaN;

                    if (elem.parms.Length > 3)
                    {
                        HDebug.Assert(0 == elem.parms[3]);
                        eps_14   = elem.parms[4];
                        Rmin2_14 = elem.parms[5];    //Debug.Assert(Rmin2_14 > 0);
                        if (!(Rmin2_14 > 0))
                        {
                            logger.Log(string.Format("Error  : Nonbonded params ({0}): 6th parameter (Rmin2_14) must be '> 0'", line));
                        }
                    }
                    Nonbonded nonbonded = new Nonbonded(line, elem.types, epsilon, Rmin2, eps_14, Rmin2_14);

                    return(nonbonded);
                }
Exemplo n.º 3
0
            public static Prm FromFileXPlor(string filepath, ITextLogger logger)
            {
                List <string> lines = new List <string>(System.IO.File.ReadAllLines(filepath));

                RemoveComments(ref lines);

                string[] keywards = CollectKeywards(lines);

                List <Bond>      bonds      = new List <Bond>();
                List <Angle>     angles     = new List <Angle>();
                List <Dihedral>  dihedrals  = new List <Dihedral>();
                List <Improper>  impropers  = new List <Improper>();
                List <Nonbonded> nonbondeds = new List <Nonbonded>();

                for (int i = 0; i < lines.Count; i++)
                {
                    string line    = lines[i];
                    string keyward = line.Split(separator, StringSplitOptions.RemoveEmptyEntries).First().ToUpper();
                    line = line.Substring(keyward.Length);
                    switch (keyward)
                    {
                    case "REMARK": break;

                    case "SET": break;

                    case "BOND": bonds.Add(Bond.FromString(line, logger)); break;

                    case "ANGLE": angles.Add(Angle.FromString(line, logger)); break;

                    case "DIHE": dihedrals.Add(Dihedral.FromString(line, logger)); break;

                    case "IMPR": impropers.Add(Improper.FromString(line, logger)); break;

                    case "{*": break;                     // comment

                    case "NONBONDED": nonbondeds.Add(Nonbonded.FromStringXPlor(line, logger)); break;

                    default:
                        HDebug.Assert(false);
                        break;
                    }
                }

                Prm prm = new Prm();

                prm.bonds      = bonds.ToArray();
                prm.angles     = angles.ToArray();
                prm.dihedrals  = dihedrals.ToArray();
                prm.impropers  = impropers.ToArray();
                prm.nonbondeds = nonbondeds.ToArray();

                return(prm);
            }
Exemplo n.º 4
0
                public static Nonbonded FromStringXPlor(string line, ITextLogger logger)
                {
                    Element elem    = Element.FromString(line, 1, 4);
                    double  epsilon = elem.parms[0];
                    double  Rmin2   = elem.parms[1]; //Debug.Assert(Rmin2   > 0);

                    if (!(Rmin2 > 0))
                    {
                        logger.Log(string.Format("Error  : Nonbonded params ({0}): 3rd parameter (Rmin2) must be '> 0'", line));
                    }
                    double eps_14   = elem.parms[2];
                    double Rmin2_14 = elem.parms[3]; //Debug.Assert(Rmin2_14 > 0);

                    if (!(Rmin2_14 > 0))
                    {
                        logger.Log(string.Format("Error  : Nonbonded params ({0}): 4th parameter (Rmin2_14) must be '> 0'", line));
                    }
                    Nonbonded nonbonded = new Nonbonded(line, elem.types, epsilon, Rmin2, eps_14, Rmin2_14);

                    return(nonbonded);
                }
Exemplo n.º 5
0
            public static Nonbonded[] FromFileXXX_CollectNonbondeds(List <string> lines, ITextLogger logger)
            {
                RemoveComments(ref lines);
                HDebug.Assert(lines[0].Split(separator).First().ToUpper() == "NONBONDED");

                List <Nonbonded> nonbondeds = new List <Nonbonded>();
                bool             skip       = false;

                foreach (string line in lines)
                {
                    if (line.Split(separator).First().ToUpper() == "NONBONDED")
                    {
                        skip = true; continue;
                    }
                    if (skip)
                    {
                        skip = false; continue;
                    }
                    nonbondeds.Add(Nonbonded.FromString(line, logger));
                }

                return(nonbondeds.ToArray());
            }