コード例 #1
0
        public MatrixByArr[,] GetHess4PwIntrAct(List <ForceField.IForceField> frcflds, double frcfactor)
        {
            if (GetHess4PwIntrAct_doselftest)
            {
                GetHess4PwIntrAct_doselftest = false;
                HDebug.Assert(GetHess4PwIntrAct_selftest(frcflds, frcfactor));
            }

            Vector[] coords = GetCoords();
            Dictionary <Pair <int, int>, ForceField.PwIntrActInfo> pwintractinfos = new Dictionary <Pair <int, int>, ForceField.PwIntrActInfo>();

            for (int i = 0; i < size - 1; i++)
            {
                for (int j = i + 1; j < size; j++)
                {
                    pwintractinfos.Add(new Pair <int, int>(i, j), new ForceField.PwIntrActInfo());
                }
            }
            GetHess4PwIntrActBonds(frcflds, coords, pwintractinfos);
            GetHess4PwIntrActAngles(frcflds, coords, pwintractinfos);
            GetHess4PwIntrActImpropers(frcflds, coords, pwintractinfos);
            GetHess4PwIntrActNonbondeds(frcflds, coords, pwintractinfos);

            MatrixByArr[,] hessblk = new MatrixByArr[size, size];
            Vector[] frcs = new Vector[size];
            for (int i = 0; i < size; i++)
            {
                hessblk[i, i] = new double[3, 3];
                frcs[i]       = new double[3];
            }
            foreach (Pair <int, int> key in pwintractinfos.Keys)
            {
                int i = key.Item1;
                int j = key.Item2;
                ForceField.PwIntrActInfo pwintractinfo = pwintractinfos[key];
                double fij = pwintractinfo.Fij * frcfactor;
                double kij = pwintractinfo.Kij;
                hessblk[i, j]  = ForceField.GetHessianBlock(coords[i], coords[j], kij, fij);
                hessblk[j, i]  = ForceField.GetHessianBlock(coords[i], coords[j], kij, fij);
                hessblk[i, i] -= hessblk[i, j];
                hessblk[j, j] -= hessblk[j, i];
                /////////////////////////////////////////
                Vector uvec_ij = (coords[j] - coords[i]).UnitVector();
                frcs[i] += uvec_ij * fij;
                frcs[j] += -uvec_ij * fij;
            }

            double[] frcmags = new double[size];
            for (int i = 0; i < size; i++)
            {
                frcmags[i] = frcs[i].Dist;
            }
            double frcmag_max = frcmags.Max();
            double frcmag_avg = frcmags.Average();
            double frcmag_med = frcmags.Median();

            return(hessblk);
        }
コード例 #2
0
            public virtual void Compute(Universe.Atom atom1, Universe.Atom atom2, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null)
            {
                HDebug.Depreciated("check idx1 and idx2");
                int idx1 = 0; // nonbonded.atoms[0].ID;
                int idx2 = 1; // nonbonded.atoms[1].ID;

                Vector diff = (coords[idx2] - coords[idx1]);
                double dx   = diff[0];
                double dy   = diff[1];
                double dz   = diff[2];
                double pchi = atom1.Charge;
                double pchj = atom2.Charge;
                double ee   = 80;

                ///////////////////////////////////////////////////////////////////////////////
                // energy
                double lenergy = EnergyEs(dx, dy, dz, pchi, pchj, ee);

                energy += lenergy;
                ///////////////////////////////////////////////////////////////////////////////
                // force
                if (forces != null)
                {
                    Vector f12 = ForceEs(dx, dy, dz, pchi, pchj, ee);
                    forces[idx1] += f12;
                    forces[idx2] += -f12;
                }
                ///////////////////////////////////////////////////////////////////////////////
                // hessian
                if (hessian != null)
                {
                    //string option = "Spring+Force";
                    //Vector diff01 = (coords[1] - coords[0]);
                    //Vector diff10 = (coords[0] - coords[1]);
                    //hessian[0, 1] += SprngEs(diff01, pchi, pchj, ee, option);
                    //hessian[1, 0] += SprngEs(diff10, pchi, pchj, ee, option);
                    {
                        // !V(Lennard-Jones) = Eps,i,j[(Rmin,i,j/ri,j)**12 - 2(Rmin,i,j/ri,j)**6]
                        // !epsilon: kcal/mole, Eps,i,j = sqrt(eps,i * eps,j)
                        // !Rmin/2: A, Rmin,i,j = Rmin/2,i + Rmin/2,j
                        //
                        // V(rij) =           (332 * pchij / ee) * rij^-1
                        // F(rij) = (   -1) * (332 * pchij / ee) * rij^-2
                        // K(rij) = (-2*-1) * (332 * pchij / ee) * rij^-3
                        double pchij = pchi * pchj;
                        double rij2  = dx * dx + dy * dy + dz * dz;
                        double rij   = Math.Sqrt(rij2);
                        double rij3  = rij2 * rij;
                        double fij   = (-1) * (332 * pchij / ee) / rij2;
                        double kij   = (-2 * -1) * (332 * pchij / ee) / rij3;
                        fij *= optHessianForceFactor;
                        //Matrix Hij = ForceField.GetHessianBlock(coords[0], coords[1], kij, fij);
                        hessian[0, 1] += ForceField.GetHessianBlock(coords[0], coords[1], kij, fij);
                        hessian[1, 0] += ForceField.GetHessianBlock(coords[1], coords[0], kij, fij);
                    }
                }
            }
コード例 #3
0
ファイル: ForceField.PwElec.cs プロジェクト: htna/explsolv
            public virtual void Compute(Universe.Atom atom1, Universe.Atom atom2, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null)
            {
                Vector pos0 = coords[0];
                Vector pos1 = coords[1];
                double pchi = atom1.Charge;
                double pchj = atom2.Charge;
                double ee   = 80;

                double pchij = pchi * pchj;

                double lenergy, forceij, springij;

                Compute(coords, out lenergy, out forceij, out springij, pchij, ee);
                double abs_forceij = Math.Abs(forceij);

                if (pwfrc != null)
                {
                    pwfrc[0, 1] = pwfrc[1, 0] = forceij;
                }
                if (pwspr != null)
                {
                    pwspr[0, 1] = pwspr[1, 0] = springij;
                }
                ///////////////////////////////////////////////////////////////////////////////
                // energy
                energy += lenergy;
                ///////////////////////////////////////////////////////////////////////////////
                // force
                if (forces != null)
                {
                    Vector frc0, frc1;
                    GetForceVector(pos0, pos1, forceij, out frc0, out frc1);
                    forces[0] += frc0;
                    forces[1] += frc1;
                }
                ///////////////////////////////////////////////////////////////////////////////
                // hessian
                if (hessian != null)
                {
                    hessian[0, 1] += ForceField.GetHessianBlock(coords[0], coords[1], springij, forceij);
                    hessian[1, 0] += ForceField.GetHessianBlock(coords[1], coords[0], springij, forceij);
                }
            }
コード例 #4
0
            public virtual void Compute(Universe.AtomPack nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian
                                        , double radi, double radj, double epsi, double epsj, double[,] pwfrc = null, double[,] pwspr = null)
            {
                HDebug.Depreciated("check idx1 and idx2");
                int idx1 = 0; // nonbonded.atoms[0].ID;
                int idx2 = 1; // nonbonded.atoms[1].ID;

                Universe.Atom atom1 = nonbonded.atoms[0];
                Universe.Atom atom2 = nonbonded.atoms[1];

                Vector diff = (coords[idx2] - coords[idx1]);
                double dx   = diff[0];
                double dy   = diff[1];
                double dz   = diff[2];

                //double radi = atom1.Rmin2;
                //double radj = atom2.Rmin2;
                //double epsi = atom1.epsilon;
                //double epsj = atom2.epsilon;

                ///////////////////////////////////////////////////////////////////////////////
                // energy
                energy += EnergyVdw(dx, dy, dz, radi, radj, epsi, epsj);
                ///////////////////////////////////////////////////////////////////////////////
                // force
                if (forces != null)
                {
                    Vector f12 = ForceVdw(dx, dy, dz, radi, radj, epsi, epsj);
                    forces[idx1] += f12;
                    forces[idx2] += -f12;
                }
                ///////////////////////////////////////////////////////////////////////////////
                // hessian
                if (hessian != null)
                {
                    //string option = "Spring+Force";
                    //Vector diff01 = (coords[1] - coords[0]);
                    //Vector diff10 = (coords[0] - coords[1]);
                    //hessian[0, 1] += SprngVdw(diff01, radi, radj, epsi, epsj, option);
                    //hessian[1, 0] += SprngVdw(diff10, radi, radj, epsi, epsj, option);
                    {
                        // !V(Lennard-Jones) = Eps,i,j[(Rmin,i,j/ri,j)**12 - 2(Rmin,i,j/ri,j)**6]
                        // !epsilon: kcal/mole, Eps,i,j = sqrt(eps,i * eps,j)
                        // !Rmin/2: A, Rmin,i,j = Rmin/2,i + Rmin/2,j
                        //
                        // V(r) =           epsij * r0^12 * rij^-12  -        2 * epsij * r0^6 * rij^-6
                        // F(r) =     -12 * epsij * r0^12 * rij^-13  -     -6*2 * epsij * r0^6 * rij^-7
                        // K(r) = -13*-12 * epsij * r0^12 * rij^-14  -  -7*-6*2 * epsij * r0^6 * rij^-8
                        double r     = (radi + radj);
                        double r6    = Math.Pow(r, 6);
                        double r12   = Math.Pow(r, 12);
                        double rij2  = (dx * dx + dy * dy + dz * dz);
                        double rij   = Math.Sqrt(rij2);
                        double rij7  = Math.Pow(rij2, 3) * rij;
                        double rij8  = Math.Pow(rij2, 4);
                        double rij13 = Math.Pow(rij2, 6) * rij;
                        double rij14 = Math.Pow(rij2, 7);
                        double epsij = epsi * epsj;
                        double fij   = (-12) * epsij * r12 / rij13 - (-6 * 2) * epsij * r6 / rij7;
                        double kij   = (-13 * -12) * epsij * r12 / rij14 - (-7 * -6 * 2) * epsij * r6 / rij8;
                        fij *= optHessianForceFactor;
                        //Matrix Hij = ForceField.GetHessianBlock(coords[0], coords[1], kij, fij);
                        hessian[0, 1] += ForceField.GetHessianBlock(coords[0], coords[1], kij, fij);
                        hessian[1, 0] += ForceField.GetHessianBlock(coords[1], coords[0], kij, fij);
                    }
                }
            }