public static Mode[] GetModeCoarseBlkmat(Matrix hess, IList <int> idx_heavy, ILinAlg ila) { HDebug.Depreciated("use GetHessCoarseBlkmat() and GetModesFromHess() separately"); Matrix hess_HH = GetHessCoarseBlkmat(hess, idx_heavy, ila); //{ // Matlab.PutMatrix("H", hess); // Matlab.Execute("H = (H + H')/2;"); // // Matlab.PutVector("idx0", idx_heavy.ToArray()); // Matlab.Execute("idx0 = sort([idx0*3+1; idx0*3+2; idx0*3+3]);"); // Matlab.PutValue("idx1", hess.ColSize); // Matlab.Execute("idx1 = setdiff(1:idx1, idx0)';"); // HDebug.Assert(Matlab.GetValueInt("length(union(idx0,idx1))") == hess.ColSize*3); // // Matlab.Execute("A = full(H(idx0,idx0));"); // Matlab.Execute("B = H(idx0,idx1) ;"); // Matlab.Execute("C = H(idx1,idx0) ;"); // Matlab.Execute("D = full(H(idx1,idx1));"); // Matlab.Execute("clear H;"); // // Matlab.Execute("bhess = A - B * inv(D) * C;"); // Matlab.Execute("bhess = (bhess + bhess')/2;"); //} Mode[] modes = GetModesFromHess(hess_HH, ila); return(modes); }
public static void GetModes(Matrix hess, out Matrix modes, out Vector freqs) { HDebug.Depreciated("use others"); HDebug.Assert(GetModesSelftest()); HDebug.Assert(hess.RowSize == hess.ColSize); Matrix eigvec; Vector eigval; NumericSolver.Eig(hess.ToArray(), out eigvec, out eigval); int n = hess.RowSize; modes = new double[n, n - 6]; freqs = new double[n - 6]; for (int r = 0; r < 6; r++) { HDebug.AssertTolerance(0.00000001, eigval[r]); } for (int r = 6; r < n; r++) { int rr = r - 6; freqs[rr] = eigval[r]; for (int c = 0; c < n; c++) { modes[c, rr] = eigvec[c, r]; } } }
public void BuildHess4PwIntrAct(Universe.AtomPack info, Vector[] coords, out Pair <int, int>[] pwidxs, out PwIntrActInfo[] pwhessinfos) { HDebug.Depreciated("check idx1 and idx2"); int idx1 = 0; // nonbonded.atoms[0].ID; int idx2 = 1; // nonbonded.atoms[1].ID; Universe.Atom atom1 = info.atoms[0]; Universe.Atom atom2 = info.atoms[1]; Vector diff = (coords[idx2] - coords[idx1]); double dx = diff[0]; double dy = diff[1]; double dz = diff[2]; double radi = double.NaN; double radj = double.NaN; double epsi = double.NaN; double epsj = double.NaN; if (typeof(Universe.Nonbonded14).IsInstanceOfType(info)) { radi = atom1.Rmin2_14; radi = (double.IsNaN(radi) == false) ? radi : atom1.Rmin2; radj = atom2.Rmin2_14; radj = (double.IsNaN(radj) == false) ? radj : atom2.Rmin2; epsi = atom1.eps_14; epsi = (double.IsNaN(epsi) == false) ? epsi : atom1.epsilon; epsj = atom2.eps_14; epsj = (double.IsNaN(epsj) == false) ? epsj : atom2.epsilon; } if (typeof(Universe.Nonbonded).IsInstanceOfType(info)) { radi = atom1.Rmin2; radj = atom2.Rmin2; epsi = atom1.epsilon; epsj = atom2.epsilon; } HDebug.Assert(double.IsNaN(radi) == false, double.IsNaN(radj) == false, double.IsNaN(epsi) == false, double.IsNaN(epsj) == false); // !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; pwidxs = new Pair <int, int> [1]; pwidxs[0] = new Pair <int, int>(0, 1); pwhessinfos = new PwIntrActInfo[1]; pwhessinfos[0] = new PwIntrActInfo(kij, fij); }
public static Mode[] GetModeCoarseBlkmat(HessMatrix hess, IList <int> idx_heavy, ILinAlg ila) { HDebug.Depreciated("use GetHessCoarseBlkmat() and GetModesFromHess() separately"); Matrix hess_HH = GetHessCoarseBlkmat(hess, idx_heavy); Mode[] modes = GetModesFromHess(hess_HH, ila); return(modes); }
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); } } }
public void BuildHess4PwIntrAct(Universe.AtomPack info, Vector[] coords, out Pair <int, int>[] pwidxs, out PwIntrActInfo[] pwhessinfos) { Universe.Nonbonded nonbonded = (Universe.Nonbonded)info; 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]; double pchij = atom1.Charge * atom2.Charge; if (double.IsNaN(pchij)) { HDebug.Assert(false); pwidxs = null; pwhessinfos = null; return; } 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; // !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; pwidxs = new Pair <int, int> [1]; pwidxs[0] = new Pair <int, int>(0, 1); pwhessinfos = new PwIntrActInfo[1]; pwhessinfos[0] = new PwIntrActInfo(kij, fij); }
Dictionary <Atom, CachedPotential>[] nonbondeds = null; // (atom, (potential, force)) public Nonbondeds_v1(Atoms atoms , int size , double maxdist // = 12 ) { HDebug.Depreciated("use class Universe.Nonbondeds, instead of this"); // length this.size = size; // maxdist this.maxdist = maxdist; this.maxdist2 = maxdist * maxdist; // atoms & coords HDebug.Assert(size == atoms.Count); this.atoms = new Atom[size]; foreach (Atom atom in atoms) { int id = atom.ID; HDebug.Assert(this.atoms[id] == null); this.atoms[id] = atom; } // assign memory for this.coords and this.nonbondeds this.coords = new Vector[size]; this.nonbondeds = new Dictionary <Atom, CachedPotential> [size]; }
//public static Mode[] GetModes(Matrix hess) //{ // return GetModesFromHess(hess); //} public static Mode[] GetModesFromHess(Matrix hess) { //string cachepath = null; HDebug.Depreciated("use Mode[] GetModesFromHess(Matrix hess, ILinAlg la)"); Vector[] eigvec; double[] eigval; //if(cachepath != null && HFile.Exists(cachepath)) //{ // HSerialize.Deserialize(cachepath, null, out eigval, out eigvec); //} //else //{ HDebug.Verify(NumericSolver.Eig(hess.ToArray(), out eigvec, out eigval)); // if(cachepath != null) // HSerialize.SerializeDepreciated(cachepath, null, eigval, eigvec); //} List <Mode> modes; { // sort by eigenvalues int[] idx = eigval.HAbs().HIdxSorted(); modes = new List <Mode>(idx.Length); for (int i = 0; i < eigval.Length; i++) { Mode mode = new Mode { eigval = eigval[idx[i]], eigvec = eigvec[idx[i]] }; modes.Add(mode); } } return(modes.ToArray()); }
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); } } }