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));
                    }
                }
Exemple #2
0
                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,
                    });
                }