public Xyz CloneByRemoveHeader() { List <Element> nelements = new List <Element>(); foreach (Element element in elements) { Element nelement = null; switch (element.type) { case "Header": nelement = Header.FromData((element as Header).NumAtoms); break; case "Atom": nelement = element; break; default: HDebug.ToDo("donot list " + element.type + " in Tinker.Xyz.CloneByRemoveHeader()"); break; } nelements.Add(nelement); } Xyz nxyz = new Xyz { elements = nelements.ToArray() }; return(nxyz); }
public static PFSM GetHessFSM(IList <Vector> coords, Matrix pwspring, Matrix pwforce, ILinAlg la) { HDebug.ToDo("check!!"); int size = coords.Count; Matrix khess = Hess.GetHessAnm(coords, pwspring.ToArray()); Matrix invkhess; { var HH = la.ToILMat(khess); HDebug.Assert(false); // try to use eig, instead of pinv var invHH = la.PInv(HH); HH.Dispose(); //var VVDD = la.EigSymm(HH); invkhess = invHH.ToArray(); invHH.Dispose(); } Matrix npwforce = Hess.GetHessFSM_GetEqlibForc(coords, khess, invkhess, pwforce); Matrix pwdist = coords.Pwdist(); Matrix anm = Hess.GetHessAnm(coords, double.PositiveInfinity); MatrixBySparseMatrix fhess = MatrixBySparseMatrix.Zeros(size * 3, size * 3, 3); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i == j) { continue; } int[] idxi = new int[] { i *3 + 0, i *3 + 1, i *3 + 2 }; int[] idxj = new int[] { j *3 + 0, j *3 + 1, j *3 + 2 }; // ANM_ij MatrixByArr fhess_ij = anm.SubMatrix(idxi, idxj).ToArray(); // ANM_ij - GNM_ij = ANM_ij - I_33 fhess_ij[0, 0] += 1; fhess_ij[1, 1] += 1; fhess_ij[2, 2] += 1; // fij/rij * (ANM_ij - GNM_ij) fhess_ij *= (npwforce[i, j] / pwdist[i, j]); fhess.SetBlock(i, j, fhess_ij); fhess.SetBlock(i, i, fhess.GetBlock(i, i) - fhess_ij); } } return(new PFSM { KHess = khess, FHess = fhess, }); }
public Int CloneByReindex(Tuple <int, int>[] idFromTo) { HDebug.ToDo("check!!"); List <Element> nelements = new List <Element>(); Dictionary <int, int> from2to = idFromTo.HToDictionaryWithKey1Value2(); foreach (Element element in elements) { Element nelement = null; if (element.type == "Header") { Header header = element as Header; string name = header.Name; int numatoms = from2to.Values.Max(); nelement = Header.FromData(numatoms, name); } else { Atom atom = element as Atom; if (atom.Ids.Length < 4) { if (from2to[atom.Id] != atom.Id) { throw new Exception("indexes of first three should not change"); } nelement = new Atom(element.line); } else { int Id = from2to[atom.Id]; int IdBond = from2to[atom.IdBond]; int IdAngle = from2to[atom.IdAngle]; int IdDihedral = from2to[atom.IdDihedral]; nelement = Atom.FromData(Id, atom.AtomType, atom.AtomId , IdBond, atom.Leng , IdAngle, atom.Angle , IdDihedral, atom.Dihedral, atom.Chirality ); } } if (nelement == null) { throw new NotImplementedException(); } nelements.Add(nelement); } Int intrnl = new Int { elements = nelements.ToArray() }; return(intrnl); }
public static HessMatrix GetMassWeightedHess(HessMatrix hess, Vector mass) { HessMatrix mwhess = hess.CloneHess(); HDebug.ToDo("check: mass -> mass3"); double[] mass3 = new double[mass.Size * 3]; for (int i = 0; i < mass3.Length; i++) { mass3[i] = mass[i / 3]; } UpdateMassWeightedHess(mwhess, mass3); return(mwhess); }
public static int Exec(string command, params string[] parameters) { HDebug.ToDo(); command = GetProgramPath(command); foreach (string parameter in parameters) { command += " " + parameter; } //int exitcode = HtProcess.StartAsBatchSilent(null, null, null, command); int exitcode = HProcess.StartAsBatchInConsole(null, true, command); HDebug.Assert(false); return(-1); }
public static void PCA(string pdbpath, string outpathroot, double scaleAnimation) { HDebug.ToDo(); Pdb.Atom[] meanconf; Matrix modes; Vector freq; PCA(pdbpath, out meanconf, out modes, out freq); for (int i = 0; i < freq.Size; i++) { string outpath = outpathroot + i.ToString("00") + ".pdb"; Vector[] mode = (modes.GetColVector(i) * scaleAnimation / freq[i]).ToVectors(3); Pdb.ToFileAnimated(outpath, meanconf, mode); } }
public static void PCA(string pdbpath, out Pdb.Atom[] meanconf, out Matrix modes, out Vector freq) { HDebug.ToDo(); meanconf = null; modes = null; freq = null; //Pdb[] pdbs; //Pdb.FromFile(pdbpath, out pdbs); // //List<Vector>[] confs = new List<Vector>[pdbs.Length]; //for(int i=0; i<confs.Length; i++) // confs[i] = pdbs[i].atoms.ListCoord(); // //List<Vector> lmeanconf; //Do(confs, out lmeanconf, out modes, out freq); //meanconf = pdbs[0].atoms.UpdateCoord(lmeanconf).ToArray(); }
public static MatrixByArr d2PI_dR2(IList <Vector> coords) { Vector ri = coords[0]; Vector rj = coords[1]; Vector rk = coords[2]; Vector rl = coords[3]; Vector F = ri - rj; Vector G = rj - rk; double G2 = G.Dist2; double G1 = Math.Sqrt(G2); double G3 = G1 * G2; Vector H = rl - rk; Vector A = LinAlg.CrossProd(F, G); double A2 = A.Dist2; double A4 = A2 * A2; Vector B = LinAlg.CrossProd(H, G); double B2 = B.Dist2; double B4 = B2 * B2; double FG = DotProd(H, G); Vector G_A = CrossProd(G, A); Vector F_A = CrossProd(F, A); Vector G_B = CrossProd(G, B); Vector H_B = CrossProd(H, B); Vector one3 = new double[3] { 1, 1, 1 }; Vector dF_di = one3; Vector dF_dj = -one3; Vector dG_dj = one3; Vector dG_dk = -one3; Vector dH_dk = -one3; Vector dH_dl = one3; MatrixByArr d2pi_dF2 = (G1 / A4) * (TensrProd(A, CrossProd(G, A)) + TensrProd(CrossProd(G, A), A)); /// (32) MatrixByArr d2pi_dH2 = (-G1 / B4) * (TensrProd(B, CrossProd(G, B)) + TensrProd(CrossProd(G, B), B)); /// (33) MatrixByArr d2pi_dG2 = (1 / (2 * G3 * A2)) * (TensrProd(G_A, A) + TensrProd(A, G_A)) /// (44) + (1 / (G1 * A4)) * (TensrProd(A, F_A) + TensrProd(F_A, A)) - (1 / (2 * G3 * B2)) * (TensrProd(G_B, B) + TensrProd(B, G_B)) - (1 / (G1 * B4)) * (TensrProd(B, H_B) + TensrProd(H_B, B)); HDebug.ToDo(); //Matrix d2pi_dFdG = /// (38) //Matrix d2pi_dGdH = /// (39) MatrixByArr d2pi_dFdH = new double[3, 3]; /// (40) return(null); }
public static List <Mode> SelectExceptSmallSix(this List <Mode> modes) { HDebug.ToDo("use SeparateTolerants(...) instead"); /// example: /// Tuple<Mode[], Mode[]> nzmodes_zeromodes = modes.SeparateTolerants(); /// Mode[] modesNonzero = nzmodes_zeromodes.Item1; /// Mode[] modesZero = nzmodes_zeromodes.Item2; /// { /// Debug.Assert(modesZero.Length == 6); /// if(modesNonzero.ListEigval().SelectLess(0).Length > 0) /// { /// message = "existance of the negative eigenvalues for "+hessopt; /// } /// } double[] eigvals = modes.ListEigval().ToArray(); double[] abs_eigvals = eigvals.HAbs(); int[] idx_sort_abs_eigvals = abs_eigvals.HIdxSorted(); int[] idx_zeroeigval = idx_sort_abs_eigvals.HSelectCount(6).ToArray(); modes = modes.HRemoveIndexe(idx_zeroeigval); return(modes); }
public Mode[] ToModes_wrong() { HDebug.ToDo("call ToModes() instead since this is incorrect"); List <Mode> modes = new List <Mode>(); foreach (int idx in idx2freq_mode.Keys) { double eigval = idx2eigval[idx]; Tuple <int, Vector>[] lst_atm_vec = idx2freq_mode[idx].Item2; Vector eigvec = new double[lst_atm_vec.Length * 3]; for (int i = 0; i < eigvec.Size; i++) { eigvec[i] = double.NaN; } foreach (Tuple <int, Vector> atm_vec in lst_atm_vec) { int atm = atm_vec.Item1; Vector vec = atm_vec.Item2; HDebug.Assert(vec.Size == 3); HDebug.Assert(double.IsNaN(eigvec[(atm - 1) * 3 + 0])); eigvec[(atm - 1) * 3 + 0] = vec[0]; HDebug.Assert(double.IsNaN(eigvec[(atm - 1) * 3 + 1])); eigvec[(atm - 1) * 3 + 1] = vec[1]; HDebug.Assert(double.IsNaN(eigvec[(atm - 1) * 3 + 2])); eigvec[(atm - 1) * 3 + 2] = vec[2]; } for (int i = 0; i < eigvec.Size; i++) { HDebug.Assert(double.IsNaN(eigvec[i]) == false); } Mode mode = new Mode(); mode.eigval = eigval; mode.eigvec = eigvec; modes.Add(mode); } return(modes.ToArray()); }
public static HessMatrix GetHessAnm(IList <Vector> coords, IList <double> cutoffs, string options = "") { if (coords.Count > 10000) { HDebug.ToDo("System size is too big. Use EnumHessAnmSpr() and other GetHessAnm()"); } //Debug.Assert(AnmHessianSelfTest()); HDebug.Assert(coords.Count == cutoffs.Count); double[] cutoffs2 = new double[cutoffs.Count]; for (int i = 0; i < cutoffs.Count; i++) { cutoffs2[i] = cutoffs[i] * cutoffs[i]; } double Epsilon = 0;// double.Epsilon; int n = coords.Count; HessMatrix hess = null; if (n < 100) { hess = HessMatrixDense.ZerosDense(n * 3, n * 3); } else { hess = HessMatrixSparse.ZerosSparse(n * 3, n * 3); } Action <int> comp_hess_i = delegate(int i) { if (coords[i] == null) { return; } //continue; for (int j = 0; j < n; j++) { if (i == j) { continue; } if (coords[j] == null) { continue; } Vector vec_ij = coords[j] - coords[i]; double dist2 = vec_ij.Dist2; double cutoff2 = Math.Max(cutoffs2[i], cutoffs2[j]); if (dist2 > cutoff2) { if (Epsilon == 0) { continue; } HDebug.Assert(hess[i * 3 + 0, j * 3 + 0] == 0); hess[i * 3 + 0, j *3 + 0] = Epsilon; HDebug.Assert(hess[i * 3 + 0, j * 3 + 1] == 0); hess[i * 3 + 0, j *3 + 1] = Epsilon; HDebug.Assert(hess[i * 3 + 0, j * 3 + 2] == 0); hess[i * 3 + 0, j *3 + 2] = Epsilon; HDebug.Assert(hess[i * 3 + 1, j * 3 + 0] == 0); hess[i * 3 + 1, j *3 + 0] = Epsilon; HDebug.Assert(hess[i * 3 + 1, j * 3 + 1] == 0); hess[i * 3 + 1, j *3 + 1] = Epsilon; HDebug.Assert(hess[i * 3 + 1, j * 3 + 2] == 0); hess[i * 3 + 1, j *3 + 2] = Epsilon; HDebug.Assert(hess[i * 3 + 2, j * 3 + 0] == 0); hess[i * 3 + 2, j *3 + 0] = Epsilon; HDebug.Assert(hess[i * 3 + 2, j * 3 + 1] == 0); hess[i * 3 + 2, j *3 + 1] = Epsilon; HDebug.Assert(hess[i * 3 + 2, j * 3 + 2] == 0); hess[i * 3 + 2, j *3 + 2] = Epsilon; continue; } Vector unit_ij = vec_ij.UnitVector(); double k_ij = 1; double val; val = k_ij * unit_ij[0] * unit_ij[0]; hess[i * 3 + 0, j *3 + 0] = Epsilon - val; hess[i * 3 + 0, i *3 + 0] += val; // hess[i*3+0, j*3+0] = Epsilon - k_ij * unit_ij[0]*unit_ij[0]; hess[i*3+0, i*3+0] += k_ij * unit_ij[0]*unit_ij[0]; val = k_ij * unit_ij[0] * unit_ij[1]; hess[i * 3 + 0, j *3 + 1] = Epsilon - val; hess[i * 3 + 0, i *3 + 1] += val; // hess[i*3+0, j*3+1] = Epsilon - k_ij * unit_ij[0]*unit_ij[1]; hess[i*3+0, i*3+1] += k_ij * unit_ij[0]*unit_ij[1]; val = k_ij * unit_ij[0] * unit_ij[2]; hess[i * 3 + 0, j *3 + 2] = Epsilon - val; hess[i * 3 + 0, i *3 + 2] += val; // hess[i*3+0, j*3+2] = Epsilon - k_ij * unit_ij[0]*unit_ij[2]; hess[i*3+0, i*3+2] += k_ij * unit_ij[0]*unit_ij[2]; val = k_ij * unit_ij[1] * unit_ij[0]; hess[i * 3 + 1, j *3 + 0] = Epsilon - val; hess[i * 3 + 1, i *3 + 0] += val; // hess[i*3+1, j*3+0] = Epsilon - k_ij * unit_ij[1]*unit_ij[0]; hess[i*3+1, i*3+0] += k_ij * unit_ij[1]*unit_ij[0]; val = k_ij * unit_ij[1] * unit_ij[1]; hess[i * 3 + 1, j *3 + 1] = Epsilon - val; hess[i * 3 + 1, i *3 + 1] += val; // hess[i*3+1, j*3+1] = Epsilon - k_ij * unit_ij[1]*unit_ij[1]; hess[i*3+1, i*3+1] += k_ij * unit_ij[1]*unit_ij[1]; val = k_ij * unit_ij[1] * unit_ij[2]; hess[i * 3 + 1, j *3 + 2] = Epsilon - val; hess[i * 3 + 1, i *3 + 2] += val; // hess[i*3+1, j*3+2] = Epsilon - k_ij * unit_ij[1]*unit_ij[2]; hess[i*3+1, i*3+2] += k_ij * unit_ij[1]*unit_ij[2]; val = k_ij * unit_ij[2] * unit_ij[0]; hess[i * 3 + 2, j *3 + 0] = Epsilon - val; hess[i * 3 + 2, i *3 + 0] += val; // hess[i*3+2, j*3+0] = Epsilon - k_ij * unit_ij[2]*unit_ij[0]; hess[i*3+2, i*3+0] += k_ij * unit_ij[2]*unit_ij[0]; val = k_ij * unit_ij[2] * unit_ij[1]; hess[i * 3 + 2, j *3 + 1] = Epsilon - val; hess[i * 3 + 2, i *3 + 1] += val; // hess[i*3+2, j*3+1] = Epsilon - k_ij * unit_ij[2]*unit_ij[1]; hess[i*3+2, i*3+1] += k_ij * unit_ij[2]*unit_ij[1]; val = k_ij * unit_ij[2] * unit_ij[2]; hess[i * 3 + 2, j *3 + 2] = Epsilon - val; hess[i * 3 + 2, i *3 + 2] += val; // hess[i*3+2, j*3+2] = Epsilon - k_ij * unit_ij[2]*unit_ij[2]; hess[i*3+2, i*3+2] += k_ij * unit_ij[2]*unit_ij[2]; } }; if (options.Split(';').Contains("parallel")) { System.Threading.Tasks.Parallel.For(0, n, comp_hess_i); } else { for (int i = 0; i < n; i++) { comp_hess_i(i); } } return(hess); }
public static Pdb FromPdbidChainAltlocResis(string pdbIdChain, bool removeSymbolAltloc) { /// "pdbid:chains:altlocs:residues" /// ex: "1A6G:A::1-151" string[] tokens = pdbIdChain.Split(':'); Pdb.Atom[] atoms; { string pdbid = tokens[0]; Pdb pdb = FromPdbid(pdbid); atoms = pdb.atoms; } if (tokens.Length >= 2) { char[] chains = tokens[1].ToCharArray(); atoms = atoms.SelectByChainID(chains).ToArray(); } if ((tokens.Length >= 3) && (tokens[2].Trim().Length >= 1)) { char[] altlocs = tokens[2].ToCharArray(); HDebug.Assert(altlocs.Length >= 1); HDebug.ToDo(); } else { atoms = atoms.SelectByAltLoc().ToArray(); } if ((tokens.Length >= 4) && (tokens[3].Trim().Length >= 1)) { /// "1,2,5,10,15-100,113,115-160" List <int> resis = new List <int>(); string resis0 = tokens[3].Trim(); string[] resis1 = resis0.Split(','); foreach (string resis2 in resis1) { string[] resis3 = resis2.Trim().Split('-').HTrim().HRemoveAll(""); int[] resis4 = resis3.HParseInt(); if (resis4.Length == 1) { int resi = resis4[0]; HDebug.Assert(resis.Contains(resi) == false); resis.Add(resi); continue; } HDebug.Assert(resis4.Length == 2); //if(resis4.Length == 2) { HDebug.Assert(resis4[0] <= resis4[1]); for (int resi = resis4[0]; resi <= resis4[1]; resi++) { HDebug.Assert(resis.Contains(resi) == false); resis.Add(resi); } continue; } } atoms = atoms.SelectByResSeq(resis.ToArray()).ToArray(); } if (removeSymbolAltloc) { atoms = atoms.CloneByRemoveSymbolAltLoc().ToArray(); } return(Pdb.FromAtoms(atoms)); }
static HessMatrix GetMulImpl(HessMatrix left, HessMatrix right, ILinAlg ila, bool warning) { if (HDebug.Selftest()) { Matrix h1 = new double[, ] { { 0, 1, 2, 3, 4, 5 } , { 1, 2, 3, 4, 5, 6 } , { 2, 3, 4, 5, 6, 7 } , { 3, 4, 5, 6, 7, 8 } , { 4, 5, 6, 7, 8, 9 } , { 5, 6, 7, 8, 9, 0 } }; HessMatrix h2 = HessMatrixSparse.FromMatrix(h1); Matrix h11 = Matrix.GetMul(h1, h1); HessMatrix h22 = HessMatrix.GetMulImpl(h2, h2, null, false); Matrix hdiff = h11 - h22; HDebug.AssertToleranceMatrix(0, hdiff); } if ((left is HessMatrixDense) && (right is HessMatrixDense)) { if (ila != null) { return(new HessMatrixDense { hess = ila.Mul(left, right) }); } if (warning) { HDebug.ToDo("Check (HessMatrixDense * HessMatrixDense) !!!"); } } Dictionary <int, Dictionary <int, Tuple <int, int, MatrixByArr> > > left_ic_rows = new Dictionary <int, Dictionary <int, Tuple <int, int, MatrixByArr> > >(); foreach (var ic_row in left.EnumRowBlocksAll()) { left_ic_rows.Add(ic_row.Item1, ic_row.Item2.HToDictionaryWithKeyItem2()); } Dictionary <int, Dictionary <int, Tuple <int, int, MatrixByArr> > > right_ir_cols = new Dictionary <int, Dictionary <int, Tuple <int, int, MatrixByArr> > >(); foreach (var ir_col in right.EnumColBlocksAll()) { right_ir_cols.Add(ir_col.Item1, ir_col.Item2.HToDictionaryWithKeyItem1()); } HessMatrix mul = null; if ((left is HessMatrixDense) && (right is HessMatrixDense)) { mul = HessMatrixDense.ZerosDense(left.ColSize, right.RowSize); } else { mul = HessMatrixSparse.ZerosSparse(left.ColSize, right.RowSize); } for (int ic = 0; ic < left.ColBlockSize; ic++) { var left_row = left_ic_rows[ic]; if (left_row.Count == 0) { continue; } for (int ir = 0; ir < right.RowBlockSize; ir++) { var right_col = right_ir_cols[ir]; if (right_col.Count == 0) { continue; } foreach (var left_ck in left_row) { int ik = left_ck.Key; HDebug.Assert(ic == left_ck.Value.Item1); HDebug.Assert(ik == left_ck.Value.Item2); if (right_col.ContainsKey(ik)) { var right_kr = right_col[ik]; HDebug.Assert(ik == right_kr.Item1); HDebug.Assert(ir == right_kr.Item2); MatrixByArr mul_ckr = mul.GetBlock(ic, ir) + left_ck.Value.Item3 * right_kr.Item3; mul.SetBlock(ic, ir, mul_ckr); } } } } return(mul); }
public double Rmin2_14 = double.NaN; // { get { return PrmNonbonded.Rmin2_14; } } public bool IsHydrogen() { HDebug.ToDo(); // check //return ((AtomType[0] == 'H') || (AtomType[0] == 'h')); return((AtomElem == "H") || (AtomElem == "h")); }
public void _SaveCoordsToPdb(string path, Vector[] coords) { System.Console.Error.WriteLine("Check if 'Universe._SaveCoordsToPdb(string path, Vector[] coords)' is correct"); HDebug.ToDo(); pdb.ToFile(path, coords); }