public static void GetEnergies(AlignData data1, IList <Vector> coords2 , out double pot_rmsd, out double pot_enrg, out double pot_enrg_full, out double pot_enrg_anisou , Pdb pdb2 = null , string pdb2outpath = null ) { Anisou[] anisous1;// = data1.GetAnisous(); double[] bfactor1; { List <Mode> modes = new List <Mode>(data1.GetModes()); for (int i = 0; i < 6; i++) { modes.RemoveAt(0); } bfactor1 = HBioinfo.GetBFactor(modes.ToArray(), data1.masses); HDebug.Assert(data1.size == bfactor1.Length); anisous1 = Anisou.FromBFactor(bfactor1, scale: 10000 * 1000); } //Trans3 trans = MinAnisou.GetTrans(data1.coords, anisous1, coords2); Trans3 trans = GetTrans(data1.coords, bfactor1, coords2); List <Vector> coords2trans = new List <Vector>(trans.GetTransformed(coords2)); if (pdb2 != null && pdb2outpath != null) { data1.pdb.ToFile(pdb2outpath, coords2trans, anisous: anisous1.GetUs()); } pot_rmsd = data1.GetRmsdFrom(coords2trans); pot_enrg = data1.GetEnergyFromDiag(coords2trans); pot_enrg_full = data1.GetEnergyFromFull(coords2trans); pot_enrg_anisou = data1.GetEnergyFromAnisou(coords2trans); }
public Mode[] GetModes() { // determine eigvals and eigvecs if (_modes != null) { return(_modes.HClone <Mode>()); } MatrixByArr hess = MatrixByArr.FromMatrixArray(this.hess); _modes = HBioinfo.GetModes(hess, cachebase + "Modes.data"); return(_modes.HClone <Mode>()); }
public static (List <(double freq, double dovlp)> freq1_dovlp, List <(double freq, double dovlp)> freq2_dovlp) DegeneratcyOverlap (IList <Mode> modes1, double[] mass1, double[] mass2, IList <Mode> modes2 , ILinAlg ila, bool bResetUnitVector , double degeneracy_tolerance // 3.0 , Matrix overlapsigned = null ) { if (overlapsigned == null) { overlapsigned = HBioinfo.OverlapSigned(modes1, mass1, mass2, modes2, ila, bResetUnitVector); } double[] freqs1 = modes1.ListFreq(); double[] freqs2 = modes2.ListFreq(); bool isfreqssorted = true; { for (int i = 1; i < freqs1.Length; i++) { isfreqssorted = isfreqssorted && (freqs1[i - 1] <= freqs1[i]); // ( sorted ) or ( freqs1[i-1] is close to zero ) } for (int i = 1; i < freqs2.Length; i++) { isfreqssorted = isfreqssorted && (freqs2[i - 1] <= freqs2[i]); // ( sorted ) or ( freqs2[i-1] is close to zero ) } } int[] idx1sorted = null; int[] idx2sorted = null; if (isfreqssorted == false) { idx1sorted = freqs1.HIdxSorted(); idx2sorted = freqs2.HIdxSorted(); modes1 = modes1.HSelectByIndex(idx1sorted); modes2 = modes2.HSelectByIndex(idx2sorted); if (mass1 != null) { HDebug.Assert(mass1.Length == idx1sorted.Length); mass1 = mass1.HSelectByIndex(idx1sorted); } if (mass2 != null) { HDebug.Assert(mass2.Length == idx2sorted.Length); mass2 = mass2.HSelectByIndex(idx2sorted); } freqs1 = modes1.ListFreq(); freqs2 = modes2.ListFreq(); overlapsigned = HBioinfo.OverlapSigned(modes1, mass1, mass2, modes2, ila, bResetUnitVector); } if (HDebug.IsDebuggerAttached) { for (int i = 1; i < freqs1.Length; i++) { HDebug.Assert(freqs1[i - 1] <= freqs1[i]); } for (int i = 1; i < freqs2.Length; i++) { HDebug.Assert(freqs2[i - 1] <= freqs2[i]); } } List <(double freq, double dovlp)> freq1_dovlp = new List <(double, double)>(); for (int i1 = 0; i1 < freqs1.Length; i1++) { double freq = freqs1[i1]; int i2a = Array.BinarySearch(freqs2, freq - degeneracy_tolerance); int i2b = Array.BinarySearch(freqs2, freq + degeneracy_tolerance); if (i2a == i2b) { freq1_dovlp.Add((freqs1[i1], 0)); continue; } if (i2a < 0) { i2a = ~i2a; } if (i2b < 0) { i2b = ~i2b; } HDebug.Assert(i2a < i2b); double dovlp = 0; for (int i2 = i2a; i2 < i2b; i2++) { dovlp += overlapsigned[i1, i2] * overlapsigned[i1, i2]; } freq1_dovlp.Add((freqs1[i1], dovlp)); } List <(double freq, double dovlp)> freq2_dovlp = new List <(double, double)>(); for (int i2 = 0; i2 < freqs2.Length; i2++) { double freq = freqs2[i2]; int i1a = Array.BinarySearch(freqs1, freq - degeneracy_tolerance); int i1b = Array.BinarySearch(freqs1, freq + degeneracy_tolerance); if (i1a == i1b) { freq2_dovlp.Add((freqs2[i2], 0)); continue; } if (i1a < 0) { i1a = ~i1a; } if (i1b < 0) { i1b = ~i1b; } HDebug.Assert(i1a < i1b); double dovlp = 0; for (int i1 = i1a; i1 < i1b; i1++) { dovlp += overlapsigned[i1, i2] * overlapsigned[i1, i2]; } freq2_dovlp.Add((freqs2[i2], dovlp)); } if (HDebug.IsDebuggerAttached) { HDebug.Assert(freqs1.Length == freq1_dovlp.Count); HDebug.Assert(freqs2.Length == freq2_dovlp.Count); for (int i = 0; i < freqs1.Length; i++) { HDebug.Assert(freqs1[i] == freq1_dovlp[i].freq); } for (int i = 0; i < freqs2.Length; i++) { HDebug.Assert(freqs2[i] == freq2_dovlp[i].freq); } } return(freq1_dovlp, freq2_dovlp); }
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 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, }); }