public static Tuple <int[], int[][]> GetIdxKeepListRemv_ResiWise(Universe.Atom[] atoms, Vector[] coords) { List <Universe.Atom[]> resis = atoms.GroupByResidue(); var resi_ca_others = resis.HSplitByNames("CA").HToTuple(); Universe.Atom[] cas = new Universe.Atom[resi_ca_others.Length]; Universe.Atom[][] otherss = new Universe.Atom[resi_ca_others.Length][]; for (int i = 0; i < resi_ca_others.Length; i++) { var ca_others = resi_ca_others[i]; HDebug.Assert(ca_others.Item1.Length == 1); cas [i] = ca_others.Item1[0]; otherss[i] = ca_others.Item2; if (i >= 1) { HDebug.Assert(cas[i - 1].ResiduePdbId < cas[i].ResiduePdbId); } } return(new Tuple <int[], int[][]> ( cas.ListIDs(), otherss.ListIDs() )); }
public static HessMatrix GetHessElec(IList <Vector> coords, IEnumerable <Universe.Nonbonded14> nonbonded14s, HessMatrix hessian, double ee) { int size = coords.Count; if (hessian == null) { hessian = HessMatrixSparse.ZerosSparse(size * 3, size * 3); } foreach (Universe.Nonbonded14 nonbonded14 in nonbonded14s) { Universe.Atom atom0 = nonbonded14.atoms[0]; Universe.Atom atom1 = nonbonded14.atoms[1]; int idx0 = atom0.ID; if (coords[idx0] == null) { continue; } int idx1 = atom1.ID; if (coords[idx1] == null) { continue; } double pch0 = atom0.Charge; double pch1 = atom1.Charge; TermElec(coords, pch0, pch1, ee, hessian, idx0, idx1); TermElec(coords, pch0, pch1, ee, hessian, idx1, idx0); } return(hessian); }
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 virtual void Compute(Universe.Nonbonded nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; double pchij = atom1.Charge * atom2.Charge; Compute(coords, ref energy, ref forces, ref hessian, pchij, pwfrc, pwspr); }
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 static HessMatrix GetHessVdw(IList <Vector> coords, IEnumerable <Universe.Nonbonded14> nonbonded14s, double?Epsilon, string opt, HessMatrix hessian) { int size = coords.Count; if (hessian == null) { hessian = HessMatrixSparse.ZerosSparse(size * 3, size * 3); } foreach (Universe.Nonbonded14 nonbonded14 in nonbonded14s) { Universe.Atom atom0 = nonbonded14.atoms[0]; Universe.Atom atom1 = nonbonded14.atoms[1]; int idx0 = atom0.ID; if (coords[idx0] == null) { continue; } int idx1 = atom1.ID; if (coords[idx1] == null) { continue; } double lEpsilon; if (Epsilon != null) { lEpsilon = Epsilon.Value; } else { switch (opt) { case "gromacs": { var nbndpar0 = atom0.ConvertGromacsToCharmm; var nbndpar1 = atom1.ConvertGromacsToCharmm; double eps0_14 = nbndpar0.eps_14; eps0_14 = (double.IsNaN(eps0_14) == false) ? eps0_14 : nbndpar0.eps; double eps1_14 = nbndpar1.eps_14; eps1_14 = (double.IsNaN(eps1_14) == false) ? eps1_14 : nbndpar1.eps; lEpsilon = Math.Sqrt(eps0_14 * eps1_14); } break; default: { double eps0_14 = atom0.eps_14; eps0_14 = (double.IsNaN(eps0_14) == false) ? eps0_14 : atom0.epsilon; double eps1_14 = atom1.eps_14; eps1_14 = (double.IsNaN(eps1_14) == false) ? eps1_14 : atom1.epsilon; lEpsilon = Math.Sqrt(eps0_14 * eps1_14); } break; } } FourthTerm(coords, lEpsilon, hessian, idx0, idx1); FourthTerm(coords, lEpsilon, hessian, idx1, idx0); } return(hessian); }
public virtual void Compute(Universe.Nonbonded nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; double radi = atom1.Rmin2; double radj = atom2.Rmin2; double epsi = atom1.epsilon; double epsj = atom2.epsilon; Compute(nonbonded, coords, ref energy, ref forces, ref hessian, radi, radj, epsi, epsj, pwfrc, pwspr); }
// ! Wildcards used to minimize memory requirements // NONBONDED NBXMOD 5 ATOM CDIEL FSHIFT VATOM VDISTANCE VFSWITCH - // CUTNB 14.0 CTOFNB 12.0 CTONNB 10.0 EPS 1.0 E14FAC 1.0 WMIN 1.5 // ! // !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 // ! // !atom ignored epsilon Rmin/2 ignored eps,1-4 Rmin/2,1-4 // ! // HT 0.0 -0.0460 0.2245 ! TIP3P // HN1 0.0 -0.0460 0.2245 // CN7 0.0 -0.02 2.275 0.0 -0.01 1.90 !equivalent to protein CT1 // CN7B 0.0 -0.02 2.275 0.0 -0.01 1.90 !equivalent to protein CT1 // ... ///////////////////////////////////////////////////////////// public virtual void Compute(Universe.Nonbonded14 nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; double radi = atom1.Rmin2_14; radi = (double.IsNaN(radi) == false) ? radi : atom1.Rmin2; double radj = atom2.Rmin2_14; radj = (double.IsNaN(radj) == false) ? radj : atom2.Rmin2; double epsi = atom1.eps_14; epsi = (double.IsNaN(epsi) == false) ? epsi : atom1.epsilon; double epsj = atom2.eps_14; epsj = (double.IsNaN(epsj) == false) ? epsj : atom2.epsilon; Compute(nonbonded, coords, ref energy, ref forces, ref hessian, radi, radj, epsi, epsj, pwfrc, pwspr); }
public static bool GetPwEnrgFrcSprNbnd(bool vdW, bool elec , Universe.Nonbonded14 nonbonded14 , IList <Vector> coords , double D // = 80 // dielectric constant , out double Eij , out double Fij , out double Kij ) { Eij = Fij = Kij = double.NaN; Universe.Atom atom0 = nonbonded14.atoms[0]; Universe.Atom atom1 = nonbonded14.atoms[1]; int id0 = atom0.ID; if (coords[id0] == null) { return(false); } int id1 = atom1.ID; if (coords[id1] == null) { return(false); } Vector coord0 = coords[id0]; Vector coord1 = coords[id1]; double ri0 = atom0.Rmin2_14; if (double.IsNaN(ri0)) { ri0 = atom0.Rmin2; } double rj0 = atom1.Rmin2_14; if (double.IsNaN(rj0)) { rj0 = atom1.Rmin2; } double qi = atom0.Charge; double qj = atom1.Charge; double ei = atom0.eps_14; if (double.IsNaN(ei)) { ei = atom0.epsilon; } double ej = atom1.eps_14; if (double.IsNaN(ej)) { ej = atom1.epsilon; } GetPwEnrgFrcSprNbnd(vdW, elec , coord0, ri0, qi, ei , coord1, rj0, qj, ej , D , out Eij, out Fij, out Kij ); return(true); }
public static PPotential Elec(Universe.Nonbonded14 nonbonded, Vector[] coords, double ee) { Universe.Atom atom1 = nonbonded.atoms[0]; Vector coord1 = coords[atom1.ID]; Universe.Atom atom2 = nonbonded.atoms[1]; Vector coord2 = coords[atom2.ID]; //double ee = 1; // 80 double pch1 = atom1.Charge; double pch2 = atom2.Charge; return(Elec(coord1, coord2, pch1, pch2, ee)); }
public static HessMatrix GetHessVdw(IList <Vector> coords, IEnumerable <Universe.AtomPack> pairs, double?Epsilon, string opt, HessMatrix hessian) { int size = coords.Count; if (hessian == null) { hessian = HessMatrixSparse.ZerosSparse(size * 3, size * 3); } foreach (Universe.AtomPack pair in pairs) { Universe.Atom atom0 = pair.atoms.First(); Universe.Atom atom1 = pair.atoms.Last(); int idx0 = atom0.ID; if (coords[idx0] == null) { continue; } int idx1 = atom1.ID; if (coords[idx1] == null) { continue; } double lEpsilon; if (Epsilon != null) { lEpsilon = Epsilon.Value; } else { switch (opt) { case "gromacs": { double eps0 = atom0.ConvertGromacsToCharmm.eps; double eps1 = atom1.ConvertGromacsToCharmm.eps; lEpsilon = Math.Sqrt(eps0 * eps1); } break; default: { double eps0 = atom0.epsilon; double eps1 = atom1.epsilon; lEpsilon = Math.Sqrt(eps0 * eps1); } break; } } FourthTerm(coords, lEpsilon, hessian, idx0, idx1); FourthTerm(coords, lEpsilon, hessian, idx1, idx0); } return(hessian); }
// Lennard-Jones public static PPotential LJ(Universe.Nonbonded nonbonded, Vector[] coords) { Universe.Atom atom1 = nonbonded.atoms[0]; Vector coord1 = coords[atom1.ID]; Universe.Atom atom2 = nonbonded.atoms[1]; Vector coord2 = coords[atom2.ID]; double rad1 = atom1.Rmin2; double rad2 = atom2.Rmin2; double eps1 = atom1.epsilon; double eps2 = atom2.epsilon; return(LJ(coord1, coord2, rad1, rad2, eps1, eps2)); }
public static PPotential LJ(Universe.Nonbonded14 nonbonded, Vector[] coords) { Universe.Atom atom1 = nonbonded.atoms[0]; Vector coord1 = coords[atom1.ID]; Universe.Atom atom2 = nonbonded.atoms[1]; Vector coord2 = coords[atom2.ID]; double rad1 = atom1.Rmin2_14; rad1 = (double.IsNaN(rad1) == false) ? rad1 : atom1.Rmin2; double rad2 = atom2.Rmin2_14; rad2 = (double.IsNaN(rad2) == false) ? rad2 : atom2.Rmin2; double eps1 = atom1.eps_14; eps1 = (double.IsNaN(eps1) == false) ? eps1 : atom1.epsilon; double eps2 = atom2.eps_14; eps2 = (double.IsNaN(eps2) == false) ? eps2 : atom2.epsilon; return(LJ(coord1, coord2, rad1, rad2, eps1, eps2)); }
public virtual void Compute(Universe.Nonbonded14 nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { 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); return; } Compute(coords, ref energy, ref forces, ref hessian, pchij, pwfrc, pwspr); }
public virtual void Compute(Universe.Nonbonded nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; double radij = (atom1.Rmin2 + atom2.Rmin2); if (divideRadijByTwo) { radij = radij / 2; } double epsij = Math.Sqrt(atom1.epsilon * atom2.epsilon); Compute(coords, ref energy, ref forces, ref hessian, radij, epsij, pwfrc, pwspr); }
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) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; Vector pos0 = coords[0]; Vector pos1 = coords[1]; double rmin = (radi + radj); double epsij = Math.Sqrt(epsi * epsj); double lenergy, forceij, springij; Compute(coords, out lenergy, out forceij, out springij, epsij, rmin); 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] += GetHessianBlock(coords[0], coords[1], springij, forceij); hessian[1, 0] += GetHessianBlock(coords[1], coords[0], springij, forceij); } }
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); }
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); } }
public void SaveCoordsToPdb(string path, Pdb pdb, Vector[] coords) { Pdb.Atom[] pdbatoms = pdb.atoms; Vector[] pdbcoords = new Vector[pdbatoms.Length]; Dictionary <int, int> serial2idx = pdbatoms.ToDictionaryAsSerialToIndex(); for (int ia = 0; ia < size; ia++) { Universe.Atom uatom = atoms[ia]; List <Pdb.Atom> patoms = uatom.sources.HSelectByType((Pdb.Atom)null).ToList(); if (patoms.Count >= 1) { HDebug.Assert(patoms.Count == 1); int serial = patoms[0].serial; int idx = serial2idx[serial]; HDebug.Assert(pdbatoms[idx].serial == serial); HDebug.Assert(pdbcoords[idx] == null); pdbcoords[idx] = coords[ia].Clone(); } else { HDebug.Assert(); } } for (int i = 0; i < pdbcoords.Length; i++) { if (pdbcoords[i] == null) { HDebug.Assert(false); pdbcoords[i] = new double[3] { double.NaN, double.NaN, double.NaN }; } } pdb.ToFile(path, pdbcoords); }
public virtual void Compute(Universe.Nonbonded14 nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; double radi = atom1.Rmin2_14; radi = (double.IsNaN(radi) == false) ? radi : atom1.Rmin2; double radj = atom2.Rmin2_14; radj = (double.IsNaN(radj) == false) ? radj : atom2.Rmin2; double epsi = atom1.eps_14; epsi = (double.IsNaN(epsi) == false) ? epsi : atom1.epsilon; double epsj = atom2.eps_14; epsj = (double.IsNaN(epsj) == false) ? epsj : atom2.epsilon; double radij = (radi + radj); if (divideRadijByTwo) { radij = radij / 2; } double epsij = Math.Sqrt(epsi * epsj); if (double.IsNaN(radij) || double.IsNaN(epsij)) { HDebug.Assert(false); return; } Compute(coords, ref energy, ref forces, ref hessian, radij, epsij, pwfrc, pwspr); }
public static HessMatrix GetHessHydroBond(Universe univ, IList <Vector> coords, bool ignNegSpr, double?constSpr, double thres_energy) { int size = coords.Count; double[,] hbond_kij = new double[size, size]; foreach (var hbond in univ.EnumHydroBondIrback09(coords)) { Universe.Atom Ni = hbond.Ni; Universe.Atom Hi = hbond.Hi; Universe.Atom Oj = hbond.Oj; Universe.Atom Cj = hbond.Cj; double hbond_energy = hbond.energy; double hbond_spring = hbond.spring; // spring between Hi..Oj if (Math.Abs(hbond_energy) < thres_energy) { continue; } if (ignNegSpr && (hbond_spring < 0)) { continue; } if (constSpr != null) { hbond_spring = constSpr.Value; } int i = Hi.ID; int j = Oj.ID; hbond_kij[i, j] = hbond_spring; hbond_kij[j, i] = hbond_spring; } HessMatrix hess_hbond = GetHessAnm(coords, hbond_kij); return(hess_hbond); }
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); } } }
static Tuple <string, string, double, double, double, int> UnivAtomToTinkKey(Universe.Atom uatom) { Pdb.Atom pdbatom = uatom.sources.HFirstByType(null as Pdb.Atom); HDebug.Assert(pdbatom != null); Namd.Psf.Atom psfatom = uatom.sources.HFirstByType(null as Namd.Psf.Atom); HDebug.Assert(psfatom != null); Namd.Prm.Nonbonded prmnbnd = uatom.sources.HFirstByType(null as Namd.Prm.Nonbonded); HDebug.Assert(prmnbnd != null); string name = psfatom.AtomName.Trim(); string resn = psfatom.ResidueName.Trim(); string type = psfatom.AtomType.Trim(); double rmin2 = prmnbnd.Rmin2; double eps = prmnbnd.epsilon; double chrg = psfatom.Charge; int valnc = uatom.Bonds.Count; var key = new Tuple <string, string, double, double, double, int>(name + "-" + resn, type, rmin2, eps, chrg, valnc); return(key); }
public virtual void Compute(Universe.Nonbonded14 nonbonded, Vector[] coords, ref double energy, ref Vector[] forces, ref MatrixByArr[,] hessian, double[,] pwfrc = null, double[,] pwspr = null) { Universe.Atom atom1 = nonbonded.atoms[0]; Universe.Atom atom2 = nonbonded.atoms[1]; Compute(atom1, atom2, coords, ref energy, ref forces, ref hessian, pwfrc, pwspr); }