Ejemplo n.º 1
0
        public static HessInfo GetHessSsNMA
            (Universe univ
            , IList <Vector> coords
            , IEnumerable <Universe.Bond> bonds
            , IEnumerable <Universe.Angle> angles
            , IEnumerable <Universe.Improper> impropers
            , IEnumerable <Universe.Dihedral> dihedrals
            , IEnumerable <Universe.Nonbonded> nonbondeds
            , IEnumerable <Universe.Nonbonded14> nonbonded14s
            , double?maxAbsSpring = null
            , double?K_r          = 340.00
            , double?K_theta      = 45.00
            , double?K_ub         = 10.00
            , double?K_psi        = 70.00
            , double?K_chi        = 1.00
            , double?n            = 1
            , string k_vdW        = "Unif"
            //, bool setNanForEmptyAtom                         // =true
            )
        {
            bool   vdW       = true;                    // use vdW
            bool   elec      = false;                   // ignore electrostatic
            double D         = double.PositiveInfinity; // dielectric constant for Tinker is "1"
            bool   ignNegSpr = true;                    // ignore negative spring (do not add the spring into hessian matrix)

            //maxAbsSpring = Math.Pow(10, 9);
            HessMatrix hess = null;

            hess = STeM.GetHessBond(coords, bonds, K_r, hessian: hess);
            hess = STeM.GetHessAngle(coords, angles, true, K_theta, K_ub, hessian: hess);
            hess = STeM.GetHessImproper(coords, impropers, K_psi, hessian: hess, useArnaud96: true);
            hess = STeM.GetHessDihedral(coords, dihedrals, K_chi, n, hessian: hess, useAbsSpr: true, useArnaud96: true);
            hess = HessSpr.GetHessNonbond(coords, nonbondeds, D, k_vdW, hessian: hess, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring);
            hess = HessSpr.GetHessNonbond(coords, nonbonded14s, D, k_vdW, hessian: hess, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring);

            //if(setNanForEmptyAtom)
            Hess.UpdateHessNaN(hess, coords);

            return(new HessInfo
            {
                hess = hess,
                mass = univ.GetMasses(),
                atoms = univ.atoms.ToArray(),
                coords = coords.HCloneVectors().ToArray(),
                numZeroEigval = 6,
            });
        }
Ejemplo n.º 2
0
            public static HessInfo GetHessSbNMA
                (Universe univ
                , IList <Vector> coords
                , double nbondMaxDist // =12
                , double?maxAbsSpring
                , bool b_bonds
                , bool b_angles
                , bool b_impropers
                , bool b_dihedrals
                , bool b_nonbondeds
                , bool b_nonbonded14s
                , double?sca_bonds
                , double?sca_angles
                , double?sca_impropers
                , double?sca_dihedrals
                , double?sca_nonbondeds
                , double?sca_nonbonded14s
                , Action <Universe.Atom, Vector, Universe.Atom, Vector, double> collectorBond
                , Action <Universe.Atom, Vector, Universe.Atom, Vector, Universe.Atom, Vector, double, double> collectorAngle
                , Action <Universe.Atom, Vector, Universe.Atom, Vector, Universe.Atom, Vector, Universe.Atom, Vector, double, double> collectorImproper
                , Action <Universe.Atom, Vector, Universe.Atom, Vector, Universe.Atom, Vector, Universe.Atom, Vector, double, double> collectorDihedral
                , Action <Universe.Atom, Vector, Universe.Atom, Vector, double> collectorNonbonded
                , Action <Universe.Atom, Vector, Universe.Atom, Vector, double> collectorNonbonded14
                , Func <HessSpr.CustomKijInfo, double> GetCustomKij = null
                , params string[] options
                )
            {
                IEnumerable <Universe.Nonbonded>   nonbondeds   = null;
                IEnumerable <Universe.Nonbonded14> nonbonded14s = univ.nonbonded14s.GetEnumerable();

                if (options.Contains("TIP3P: tetrahedral hydrogen bonds"))
                {
                    nonbondeds = EnumNonbondeds(univ.atoms, coords, univ.size, nbondMaxDist, ListTip3pTetraHBond, options);
                }
                else if (options.Contains("TIP3P: near waters"))
                {
                    nonbondeds = EnumNonbondeds(univ.atoms, coords, univ.size, nbondMaxDist, ListTip3pNears, options);
                }
                else
                {
                    nonbondeds = EnumNonbondeds(univ.atoms, coords, univ.size, nbondMaxDist);
                }

                bool   vdW       = true;                    // use vdW
                bool   elec      = false;                   // ignore electrostatic
                double D         = double.PositiveInfinity; // dielectric constant for Tinker is "1"
                bool   ignNegSpr = true;                    // ignore negative spring (do not add the spring into hessian matrix)

                double?K_r     = null;                      // null for sbNMA, and 340.00  for ssNMA
                double?K_theta = null;                      // null for sbNMA, and 45.00   for ssNMA
                double?K_ub    = null;                      // null for sbNMA, and 10.00   for ssNMA
                double?K_psi   = null;                      // null for sbNMA, and 70.00   for ssNMA
                double?K_chi   = null;                      // null for sbNMA, and 1.00    for ssNMA
                double?n       = null;                      // null for sbNMA, and 1       for ssNMA
                string K_nbnd  = null;                      // null for sbNMA, and "Unif"  for ssNMA

                if (options.Contains("TIP3P: (vdW+elec) for OH,OO,HH"))
                {
                    K_nbnd = "TIP3P: (vdW+elec) for OH,OO,HH";
                }
                if (options.Contains("TIP3P: (vdW+elec) for OH"))
                {
                    K_nbnd = "TIP3P: (vdW+elec) for OH";
                }
                if (options.Contains("vdW:L79"))
                {
                    K_nbnd = "L79";
                }
                if (options.Contains("vdW:UnifSgn"))
                {
                    K_nbnd = "UnifSgn";
                }
                if (options.Contains("K_chi:1"))
                {
                    K_chi = 1;
                }

                HessMatrix hess = null;

                if (b_bonds)
                {
                    hess = STeM.GetHessBond(coords, univ.bonds, K_r: K_r, hessian: hess, collector: collectorBond);
                }
                if (b_angles)
                {
                    hess = STeM.GetHessAngle(coords, univ.angles, true, K_theta: K_theta, K_ub: K_ub, hessian: hess, collector: collectorAngle);
                }
                if (b_impropers)
                {
                    hess = STeM.GetHessImproper(coords, univ.impropers, K_psi: K_psi, hessian: hess, useArnaud96: true, collector: collectorImproper);
                }
                if (b_dihedrals)
                {
                    hess = STeM.GetHessDihedral(coords, univ.dihedrals, K_chi: K_chi, n: n, hessian: hess, useAbsSpr: true, useArnaud96: true, collector: collectorDihedral);
                }
                if (b_nonbondeds)
                {
                    hess = HessSpr.GetHessNonbond(coords, nonbondeds, D, K_nbnd: K_nbnd, hessian: hess, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring, collector: collectorNonbonded, GetCustomKij: GetCustomKij);
                }
                if (b_nonbonded14s)
                {
                    hess = HessSpr.GetHessNonbond(coords, nonbonded14s, D, K_nbnd: K_nbnd, hessian: hess, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring, collector: collectorNonbonded14, GetCustomKij: GetCustomKij);
                }

                if (sca_bonds != null)
                {
                    if (sca_bonds.Value != 1)
                    {
                        hess += (sca_bonds.Value - 1) * STeM.GetHessBond(coords, univ.bonds, K_r: K_r, hessian: null);
                    }
                }
                if (sca_angles != null)
                {
                    if (sca_angles.Value != 1)
                    {
                        hess += (sca_angles.Value - 1) * STeM.GetHessAngle(coords, univ.angles, true, K_theta: K_theta, K_ub: K_ub, hessian: null);
                    }
                }
                if (sca_impropers != null)
                {
                    if (sca_impropers.Value != 1)
                    {
                        hess += (sca_impropers.Value - 1) * STeM.GetHessImproper(coords, univ.impropers, K_psi: K_psi, hessian: null, useArnaud96: true);
                    }
                }
                if (sca_dihedrals != null)
                {
                    if (sca_dihedrals.Value != 1)
                    {
                        hess += (sca_dihedrals.Value - 1) * STeM.GetHessDihedral(coords, univ.dihedrals, K_chi: K_chi, n: n, hessian: null, useAbsSpr: true, useArnaud96: true);
                    }
                }
                if (sca_nonbondeds != null)
                {
                    if (sca_nonbondeds.Value != 1)
                    {
                        hess += (sca_nonbondeds.Value - 1) * HessSpr.GetHessNonbond(coords, nonbondeds, D, K_nbnd: K_nbnd, hessian: null, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring);
                    }
                }
                if (sca_nonbonded14s != null)
                {
                    if (sca_nonbonded14s.Value != 1)
                    {
                        hess += (sca_nonbonded14s.Value - 1) * HessSpr.GetHessNonbond(coords, nonbonded14s, D, K_nbnd: K_nbnd, hessian: null, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring);
                    }
                }

                //Hess.UpdateHessNaN(hess, coords);
                {
                    foreach (var bc_br_bval in hess.EnumBlocks())
                    {
                        int bc   = bc_br_bval.Item1;
                        int br   = bc_br_bval.Item2;
                        var bval = bc_br_bval.Item3;

                        if (coords[bc] == null)
                        {
                            throw new HException("have hess block for null-coord");
                        }
                        if (coords[br] == null)
                        {
                            throw new HException("have hess block for null-coord");
                        }
                        if (bval == null)
                        {
                            throw new HException();
                        }
                        for (int c = 0; c < bval.ColSize; c++)
                        {
                            for (int r = 0; r < bval.RowSize; r++)
                            {
                                double val = bval[c, r];
                                if (double.IsNaN(val))
                                {
                                    throw new HException("hess has nan element");
                                }
                                if (double.IsPositiveInfinity(val))
                                {
                                    throw new HException("hess has pos-inf element");
                                }
                                if (double.IsNegativeInfinity(val))
                                {
                                    throw new HException("hess has neg-inf element");
                                }
                            }
                        }
                    }
                }

                return(new HessInfo
                {
                    hess = hess,
                    mass = univ.GetMasses(),
                    atoms = univ.atoms.ToArray(),
                    coords = coords.HCloneVectors().ToArray(),
                    numZeroEigval = 6,
                });
            }