public static Universe Build(string xyzpath, bool loadxyzLatest, string prmpath, string pdbpath) { Tinker.Xyz xyz = Tinker.Xyz.FromFile(xyzpath, false); Tinker.Xyz xyz1 = Tinker.Xyz.FromFile(xyzpath, loadxyzLatest); Tinker.Prm prm = Tinker.Prm.FromFile(prmpath); Pdb pdb = Pdb.FromFile(pdbpath); Universe univ = Build(xyz, prm, pdb, 0.002); if (HDebug.IsDebuggerAttached) { HDebug.Assert(xyz.atoms.Length == univ.size); Vector[] xyzcoords = xyz.atoms.HListCoords(); Vector[] unvcoords = univ.GetCoords(); for (int i = 0; i < univ.size; i++) { Vector dcoord = xyzcoords[i] - unvcoords[i]; HDebug.AssertTolerance(0.00000001, dcoord); } } univ.SetCoords(xyz1.atoms.HListCoords()); return(univ); }
public static HessMatrix GetHess(Universe univ) { Vector[] coords = univ.GetCoords(); HessMatrix hessian_spr = HessMatrixSparse.ZerosSparse(univ.size * 3, univ.size * 3); Universe.Nonbondeds_v1 nonbondeds = new Universe.Nonbondeds_v1(univ.atoms, univ.size, 12); nonbondeds.UpdateNonbondeds(coords, 0); hessian_spr = STeM.GetHessBond(coords, univ.bonds, null, hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with bond")); hessian_spr = STeM.GetHessAngle(coords, univ.angles, true, null, null, hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with angle")); hessian_spr = STeM.GetHessImproper(coords, univ.impropers, null, hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with improper")); hessian_spr = STeM.GetHessDihedral(coords, univ.dihedrals, null, null, hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with dihedral")); hessian_spr = STeM.GetHessVdw(coords, univ.nonbonded14s.GetEnumerable(), null, null, hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with vdw14")); hessian_spr = STeM.GetHessElec(coords, univ.nonbonded14s.GetEnumerable(), hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with elec14")); hessian_spr = STeM.GetHessVdw(coords, nonbondeds.GetEnumerable(), null, null, hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with vdw")); hessian_spr = STeM.GetHessElec(coords, nonbondeds.GetEnumerable(), hessian: hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr with elec")); //hessian_spr = GetHessSprElec(coords, nonbondeds , hessian: hessian_spr); Debug.Verify(Hess.CheckHessDiag(hessian_spr)); //hessian_spr = GetHessSprVdw(coords, nonbondeds , hessian: hessian_spr); Debug.Verify(Hess.CheckHessDiag(hessian_spr)); hessian_spr = Hess.CorrectHessDiag(hessian_spr); HDebug.Verify(Hess.CheckHessDiag(hessian_spr, 0.000001, "non-computable exception while generating STeM hess_spr")); return(hessian_spr); }
public static Mode[] GetModeByTorsional(Universe univ , HessMatrix hessian , List <Universe.RotableInfo> univ_rotinfos = null , Matrix J = null , Vector[] coords = null , HPack <Matrix> optoutJMJ = null // J' M J , HPack <Matrix> optoutJM = null // J' M , Func <Matrix, Tuple <Matrix, Vector> > fnEigSymm = null , Func <Matrix, Matrix, Matrix, Matrix> fnMul = null ) { if (univ_rotinfos == null) { Graph <Universe.Atom[], Universe.Bond> univ_flexgraph = univ.BuildFlexibilityGraph(null as IList <Bond>); if (univ_flexgraph.FindLoops().Count > 0) { // loop should not exist in the flexibility-graph; no-global loop in backbone return(null); } univ_rotinfos = univ.GetRotableInfo(univ_flexgraph); } if (coords == null) { coords = univ.GetCoords(); } if (J == null) { J = TNM.GetJ(univ, coords, univ_rotinfos); } Vector masses = univ.GetMasses(); Mode[] modes = GetModeByTorsional(hessian, masses, J , optoutJMJ: optoutJMJ, optoutJM: optoutJM , fnEigSymm: fnEigSymm, fnMul: fnMul ); return(modes); }
public static Tuple <double, double, double[]> GetQuality (string pathcache , Universe univ , Func <Hess.HessInfo> GetHessInfo , double GetHessCoarseResiIter_thres_zeroblk ) { if (HFile.Exists(pathcache) == false) { double corr = double.NaN; double wovlp = double.NaN; double[] ovlps = new double[] { double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, }; try { Hess.HessInfo hessinfo = GetHessInfo(); Mode[] camodes_orig; { int[] idxca = (hessinfo.atoms as Universe.Atom[]).ListPdbAtomName(true).HIdxEqual("CA"); Matrix cahess = Hess.GetHessCoarseBlkmat(hessinfo.hess, idxca, "inv"); Mode[] lcamodes = Hess.GetModesFromHess(cahess, la); var camodes_nzero_zero = lcamodes.SeparateTolerants(); if (bool.Parse("false")) { camodes_nzero_zero = lcamodes.SeparateTolerantsByCountSigned(6); } /// manually fix 3LKY, 4EDL if (camodes_nzero_zero.Item2.Length != 6) { throw new HException("# zero-eigval != 6"); } camodes_orig = camodes_nzero_zero.Item1; } GC.Collect(); Vector cabfactor_orig = camodes_orig.GetBFactor().ToArray(); Mode[] camodes_iter; { var cahess = Hess.GetHessCoarseResiIter_BlockWise(hessinfo, univ.GetCoords(), la, 18, 500, GetHessCoarseResiIter_thres_zeroblk); Mode[] lcamodes = Hess.GetModesFromHess(cahess.hess, la); var camodes_nzero_zero = lcamodes.SeparateTolerantsByCountSigned(6); if (camodes_nzero_zero.Item2.Length != 6) { throw new HException("# zero-eigval != 6"); } camodes_iter = camodes_nzero_zero.Item1; } GC.Collect(); Vector cabfactor_iter = camodes_iter.GetBFactor().ToArray(); corr = HBioinfo.BFactor.Corr(cabfactor_orig, cabfactor_iter); var lwovlp = HBioinfo.OverlapWeightedByEigval(camodes_orig, camodes_iter, la, false, "corresponding index"); wovlp = lwovlp.woverlap; ovlps = new double[] { lwovlp.overlaps[0], lwovlp.overlaps[1], lwovlp.overlaps[2], lwovlp.overlaps[3], lwovlp.overlaps[4], lwovlp.overlaps[5], lwovlp.overlaps[6], lwovlp.overlaps[7], lwovlp.overlaps[8], lwovlp.overlaps[9], }; } catch (Exception e) { if (e.Message != "# zero-eigval != 6") { throw; } } HSerialize.SerializeText(pathcache, new double[] { corr, wovlp, ovlps[0], ovlps[1], ovlps[2], ovlps[3], ovlps[4], ovlps[5], ovlps[6], ovlps[7], ovlps[8], ovlps[9], }); } { double[] buff; HSerialize.DeserializeText(pathcache, out buff); double corr = buff[0]; double wovlp = buff[1]; double[] ovlps = new double[] { buff[2], buff[3], buff[4], buff[5], buff[6] , buff[7], buff[8], buff[9], buff[10], buff[11] }; if (double.IsNaN(corr)) { HDebug.Assert(false); } return(new Tuple <double, double, double[]>(corr, wovlp, ovlps)); } }
public static Tuple <double, double, double[]> GetQuality (string pathbase , Universe univ , Universe univ_scrn , string hesstype , double GetHessCoarseResiIter_thres_zeroblk ) { Universe luniv; Func <Hess.HessInfo> GetHessInfo; switch (hesstype) { case "NMA": luniv = univ; GetHessInfo = delegate() { return(Hess.GetHessNMA(luniv, luniv.GetCoords(), tempbase, 16)); }; break; case "scrnNMA": luniv = univ_scrn; GetHessInfo = delegate() { return(Hess.GetHessNMA(luniv, luniv.GetCoords(), tempbase, 16, "CUTOFF 9", "TAPER")); }; break; case "sbNMA": luniv = univ; GetHessInfo = delegate() { return(Hess.GetHessSbNMA(luniv, luniv.GetCoords(), double.PositiveInfinity)); }; break; case "ssNMA": luniv = univ; GetHessInfo = delegate() { return(Hess.GetHessSsNMA(luniv, luniv.GetCoords(), double.PositiveInfinity)); }; break; case "eANM": luniv = univ; GetHessInfo = delegate() { return(Hess.GetHessEAnm(luniv, luniv.GetCoords())); }; break; case "AA-ANM": luniv = univ; GetHessInfo = delegate() { return(Hess.GetHessAnm(luniv, luniv.GetCoords(), 4.5)); }; break; default: throw new HException(); } string pathcache = pathbase + string.Format("{0}.{1}.txt", hesstype, GetHessCoarseResiIter_thres_zeroblk); Tuple <double, double, double[]> corr_wovlp_ovlps; try { corr_wovlp_ovlps = GetQuality(pathcache, luniv, GetHessInfo, GetHessCoarseResiIter_thres_zeroblk); return(corr_wovlp_ovlps); } catch { return(null); } }
public static Quality GetQuality (string pathcache , Universe univ , Func <Hess.HessInfo> GetHessInfo , double GetHessCoarseResiIter_thres_zeroblk ) { double corr = double.NaN; double wovlp = double.NaN; double sparsityall = double.NaN; double sparsityca = double.NaN; double[] ovlps = new double[] { double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, }; double[] eigvals = new double[] { double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, double.NaN, }; try { Hess.HessInfo hessinfo = GetHessInfo(); double lsparsityall = 1 - hessinfo.hess.RatioUsedBlocks; Mode[] camodes_orig; { int[] idxca = (hessinfo.atoms as Universe.Atom[]).ListPdbAtomName(true).HIdxEqual("CA"); HessMatrix cahess = Hess.GetHessCoarseBlkmat(hessinfo.hess, idxca, "inv"); Mode[] lcamodes = Hess.GetModesFromHess(cahess, la); var camodes_nzero_zero = lcamodes.SeparateTolerants(); if (bool.Parse("false")) { camodes_nzero_zero = lcamodes.SeparateTolerantsByCountSigned(6); } /// manually fix 3LKY, 4EDL if (camodes_nzero_zero.Item2.Length != 6) { throw new HException("# zero-eigval != 6"); } camodes_orig = camodes_nzero_zero.Item1; } GC.Collect(); Vector cabfactor_orig = camodes_orig.GetBFactor().ToArray(); double lsparsityca; Mode[] camodes_iter; Mode[] camodes; { var coords = univ.GetCoords(); var cahess = Hess.GetHessCoarseResiIter_BlockWise(hessinfo, coords, la, 18, 500, GetHessCoarseResiIter_thres_zeroblk); lsparsityca = 1 - cahess.hess.RatioUsedBlocks; camodes = Hess.GetModesFromHess(cahess.hess, la); var camodes_nzero_zero = camodes.SeparateTolerantsByCountSigned(6); if (camodes_nzero_zero.Item2.Length != 6) { throw new HException("# zero-eigval != 6"); } camodes_iter = camodes_nzero_zero.Item1; } GC.Collect(); Vector cabfactor_iter = camodes_iter.GetBFactor().ToArray(); corr = HBioinfo.BFactor.Corr(cabfactor_orig, cabfactor_iter); var lwovlp = HBioinfo.OverlapWeightedByEigval(camodes_orig, camodes_iter, la, false, "corresponding index"); wovlp = lwovlp.woverlap; sparsityall = lsparsityall; sparsityca = lsparsityca; ovlps = new double[] { lwovlp.overlaps[0], lwovlp.overlaps[1], lwovlp.overlaps[2], lwovlp.overlaps[3], lwovlp.overlaps[4], lwovlp.overlaps[5], lwovlp.overlaps[6], lwovlp.overlaps[7], lwovlp.overlaps[8], lwovlp.overlaps[9], }; eigvals = new double[] { camodes[0].eigval, camodes[1].eigval, camodes[2].eigval, camodes[3].eigval, camodes[4].eigval, camodes[5].eigval, camodes[6].eigval, camodes[7].eigval, camodes[8].eigval, camodes[9].eigval, }; } catch (Exception e) { if (e.Message != "# zero-eigval != 6") { throw; } } return(new Quality { corr = corr, wovlp = wovlp, sparsity_all = sparsityall, sparsity_ca = sparsityca, ovlps = ovlps, eigvals = eigvals, }); }