Exemplo n.º 1
0
            public HessInfo GetSubHessInfoByBlockHess(IList <int> idxs, ILinAlg ila)
            {
                // GetSubHessInfoByBlockHess(idxSele, ila, "pinv")
                Vector idxmass = mass.ToArray().HSelectByIndex(idxs);

                object[]   idxatoms  = atoms.HSelectByIndex(idxs);
                Vector[]   idxcoords = coords.HSelectByIndex(idxs);
                HessMatrix idxhess   = null;

                if (ila != null)
                {
                    idxhess = Hess.GetHessCoarseBlkmat(hess, idxs, ila);
                }
                else
                {
                    idxhess = Hess.GetHessCoarseBlkmat(hess, idxs);
                }

                return(new HessInfo
                {
                    mass = idxmass,
                    atoms = idxatoms,
                    coords = idxcoords,
                    hess = idxhess,
                    numZeroEigval = numZeroEigval,
                });
            }
Exemplo n.º 2
0
            public Mode[] GetModesMassWeighted(bool delhess, ILinAlg la)
            {
                Matrix mwhess = GetHessMassWeighted(delhess);

                Mode[] mwmodes = Hess.GetModesFromHess(mwhess, la);
                return(mwmodes);
            }
Exemplo n.º 3
0
            private static void FourthTerm(IList <Vector> caArray, double Epsilon, HessMatrix hessian, int i, int j)
            {
                int[]    idx      = new int[] { i, j };
                Vector[] lcaArray = new Vector[] { caArray[idx[0]], caArray[idx[1]] };
                Matrix   lhess    = FourthTerm(lcaArray, Epsilon);

                for (int c = 0; c < 2; c++)
                {
                    for (int dc = 0; dc < 3; dc++)
                    {
                        for (int r = 0; r < 2; r++)
                        {
                            for (int dr = 0; dr < 3; dr++)
                            {
                                hessian[idx[c] * 3 + dc, idx[r] * 3 + dr] += lhess[c * 3 + dc, r *3 + dr];
                            }
                        }
                    }
                }

                if (HDebug.IsDebuggerAttachedWithProb(0.1))
                {
                    if (caArray.Count == 2)
                    {
                        // avoid stack overflow
                        return;
                    }
                    HessMatrix lhess0 = new double[6, 6];
                    FourthTerm(lcaArray, Epsilon, lhess0, 0, 1);
                    FourthTerm(lcaArray, Epsilon, lhess0, 1, 0);
                    double r2     = (lcaArray[0] - lcaArray[1]).Dist2;
                    Matrix dhess0 = (120 * Epsilon / r2) * Hess.GetHessAnm(lcaArray, double.PositiveInfinity);
                    HDebug.AssertToleranceMatrix(0.00000001, lhess0 - dhess0);
                }
            }
Exemplo n.º 4
0
            public static void FirstTerm(IList <Vector> caArray, double K_r, HessMatrix hessian, int i, int j)
            {
                int[]    idx          = new int[] { i, j };
                Vector[] lcaArray     = new Vector[] { caArray[idx[0]], caArray[idx[1]] };
                Matrix   lhess        = FirstTerm(lcaArray, K_r);
                double   maxabs_lhess = lhess.ToArray().HAbs().HMax();

                HDebug.Assert(maxabs_lhess < 10000);

                for (int c = 0; c < 2; c++)
                {
                    for (int dc = 0; dc < 3; dc++)
                    {
                        for (int r = 0; r < 2; r++)
                        {
                            for (int dr = 0; dr < 3; dr++)
                            {
                                hessian[idx[c] * 3 + dc, idx[r] * 3 + dr] += lhess[c * 3 + dc, r *3 + dr];
                            }
                        }
                    }
                }

                if (HDebug.IsDebuggerAttached)
                {
                    Matrix anm = (2 * K_r) * Hess.GetHessAnm(lcaArray, double.PositiveInfinity);
                    HDebug.AssertToleranceMatrix(0.00000001, lhess - anm);
                }
            }
Exemplo n.º 5
0
        public static bool GetModesSelftest()
        {
            if (GetModesSelftest_DoTest == false)
            {
                return(true);
            }
            GetModesSelftest_DoTest = false;

            string pdbpath = @"C:\Users\htna\htnasvn_htna\VisualStudioSolutions\Library2\HTLib2.Bioinfo\Bioinfo.Data\pdb\1MJC.pdb";

            if (HFile.Exists(pdbpath) == false)
            {
                return(false);
            }

            Pdb pdb = Pdb.FromFile(pdbpath);

            for (int i = 0; i < pdb.atoms.Length; i++)
            {
                HDebug.Assert(pdb.atoms[0].altLoc == pdb.atoms[i].altLoc);
                HDebug.Assert(pdb.atoms[0].chainID == pdb.atoms[i].chainID);
            }
            List <Vector> coords = pdb.atoms.ListCoord();
            double        cutoff = 13;
            Matrix        hess   = Hess.GetHessAnm(coords.ToArray(), cutoff).ToArray();

            Matrix modes;
            Vector freqs;

            GetModes(hess, out modes, out freqs);

            return(true);
        }
Exemplo n.º 6
0
        public static Mode[] PCA(IList <Vector[]> confs, Vector[] meanconf, Vector masses, Func <Matrix, Tuple <Matrix, Vector> > fnEig = null)
        {
            int    size  = meanconf.Length;
            int    size3 = size * 3;
            Matrix cov   = Matrix.Zeros(size3, size3);

            Vector vmeanconf = Vector.FromBlockvector(meanconf);

            foreach (Vector[] conf in confs)
            {
                Vector vconf  = Vector.FromBlockvector(conf);
                Vector dvconf = vconf - vmeanconf;
                LinAlg.AddToM.VVt(cov, dvconf); // hess += dvconf * dvcond'
            }
            cov /= confs.Count;

            Vector invmasses = new double[masses.Size]; // inverse mass

            for (int i = 0; i < masses.Size; i++)
            {
                invmasses[i] = 1 / masses[i];
            }

            Matrix mwcov = Hess.GetMassWeightedHess(cov, invmasses);        // just reuse Hess.GetMassWeightedHess(...)

            Mode[] mwmodes = PCA(mwcov, confs.Count, fnEig);
            Mode[] modes   = mwmodes.GetMassReduced(masses.ToArray()).ToArray(); // just reuse ListMode.GetMassDeweighted(...)

            return(modes);
        }
Exemplo n.º 7
0
 public Mode[] GetModes(ILinAlg la)
 {
     if (_modes == null)
     {
         _modes = Hess.GetModesFromHess(hess, la);
     }
     return(_modes);
 }
Exemplo n.º 8
0
 public static bool SelfTest()
 {
     HDebug.Verify(Hess.GetHessAnmSelfTest());
     HDebug.Verify(Hess.GetHessGnmSelfTest());
     HDebug.Verify(Hess.GetModesSelftest());
     HDebug.Verify(Hess.GetBFactorSelfTest());
     //HDebug.Verify(Hess.HessSbNMA.SelfTest());
     return(true);
 }
Exemplo n.º 9
0
        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,
            });
        }
Exemplo n.º 10
0
 public static MixHessInfo GetHessMixSbNMA(Universe univ, IList <Vector> coords, ILinAlg la
                                           , IList <ResInfo> lstResAllAtom, double nbondMaxDist, out string errmsg
                                           , bool bGetIntmInfo, string strBkbnReso
                                           )
 {
     // nbondMaxDist = double.PositiveInfinity
     MixModel.FnGetHess GetHess = delegate(Universe luniv, IList <Vector> lcoords, int[] idxAll, int[] idxBuffer, int[] idxCoarse, int[] idxBackbone)
     {
         var hessinfo = Hess.GetHessSbNMA(luniv, lcoords, nbondMaxDist);
         return(hessinfo);
     };
     return(MixModel.GetHessMixModel(univ, coords, la, lstResAllAtom, GetHess, out errmsg, bGetIntmInfo, strBkbnReso));
 }
Exemplo n.º 11
0
        public static HessMatrix GetHessApproxAnm(Vector[] coords, HessMatrix hess, string option, ILinAlg ila)
        {
            int nresi = coords.Length;

            HDebug.Assert(nresi * 3 == hess.ColSize);
            HDebug.Assert(nresi * 3 == hess.RowSize);

            double[,] Kij = new double[nresi, nresi];

            for (int c = 0; c < nresi; c++)
            {
                for (int r = c + 1; r < nresi; r++)
                {
                    HessMatrix anmCR = Hess.GetHessAnm(coords.HSelectByIndex(new int[] { c, r }));
                    //Matrix  anmCR = anm.SubMatrix(new int[] { 0, 1, 2 }, new int[] { 3, 4, 5 });
                    int[]      idxs   = new int[] { c *3 + 0, c *3 + 1, c *3 + 2, r *3 + 0, r *3 + 1, r *3 + 2 };
                    HessMatrix hessCR = new HessMatrixDense {
                        hess = hess.SubMatrix(idxs, idxs)
                    };
                    hessCR = Hess.CorrectHessDiag(hessCR);

                    Vector vecHessCR = hessCR.GetColVectorList().ToVector();
                    Vector vecAnmCR  = anmCR.GetColVectorList().ToVector();

                    double Kcr;
                    switch (option)
                    {
                    case "match magnitude": Kcr = vecHessCR.Dist / vecAnmCR.Dist; break;

                    case "least-mean square": Kcr = LinAlg.VtV(vecAnmCR, vecHessCR) / LinAlg.VtV(vecAnmCR, vecAnmCR); break;

                    default: throw new NotImplementedException();
                    }

                    if (Kcr < 0)
                    {
                        HDebug.Assert(false);
                    }
                    HDebug.Assert(Kcr >= 0);
                    double mag2cahessCR = vecAnmCR.Dist;
                    double mag2caAnmCR  = vecHessCR.Dist;
                    double mag2caAnmCRx = (Kcr * anmCR).GetColVectorList().ToVector().Dist;
                    Kij[c, r] = Kij[r, c] = Kcr;
                }
            }

            //return Kij;
            return(Hess.GetHessAnm(coords, Kij));

            throw new NotImplementedException();
        }
Exemplo n.º 12
0
        public HessMatrix SubMatrixByAtomsImpl(bool ignNegIdx, IList <int> idxAtoms)
        {
            if (SubMatrixByAtomsImpl_selftest)
            {
                SubMatrixByAtomsImpl_selftest = false;
                Vector[] tcoords = new Vector[] {
                    new Vector(1, 2, 3),
                    new Vector(1, 3, 2),
                    new Vector(1, 2, 9),
                };
                HessMatrix thess0  = Hess.GetHessAnm(tcoords);
                int[]      tidxs   = new int[] { 0, 2 };
                HessMatrix thess1a = thess0.SubMatrixByAtoms(false, tidxs);
                HessMatrix thess1b = new double[, ]
                {
                    { thess0[0, 0], thess0[0, 1], thess0[0, 2], thess0[0, 6], thess0[0, 7], thess0[0, 8] },
                    { thess0[1, 0], thess0[1, 1], thess0[1, 2], thess0[1, 6], thess0[1, 7], thess0[1, 8] },
                    { thess0[2, 0], thess0[2, 1], thess0[2, 2], thess0[2, 6], thess0[2, 7], thess0[2, 8] },
                    { thess0[6, 0], thess0[6, 1], thess0[6, 2], thess0[6, 6], thess0[6, 7], thess0[6, 8] },
                    { thess0[7, 0], thess0[7, 1], thess0[7, 2], thess0[7, 6], thess0[7, 7], thess0[7, 8] },
                    { thess0[8, 0], thess0[8, 1], thess0[8, 2], thess0[8, 6], thess0[8, 7], thess0[8, 8] },
                };

//                           thess1a = Hess.CorrectHessDiag(thess1a);                     // diagonal of original matrix contains the interaction between 0-1 and 1-2 also,
//                HessMatrix thess1b = Hess.GetHessAnm(tcoords.HSelectByIndex(tidxs));    // while new generated hessian matrix does not.
                Matrix tdiffhess     = thess1a - thess1b;
                double max_tdiffhess = tdiffhess.ToArray().HAbs().HMax();
                HDebug.Exception(0 == max_tdiffhess);
            }

            HessMatrix nhess = SubMatrixByAtomsImpl(ignNegIdx, idxAtoms, idxAtoms, true);

            if (HDebug.IsDebuggerAttached && idxAtoms.Count < 1000)
            {
                List <int> idx3Atoms = new List <int>();
                foreach (int idx in idxAtoms)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        idx3Atoms.Add(idx * 3 + i);
                    }
                }
                Matrix tnhess         = this.SubMatrix(idx3Atoms, idx3Atoms);
                double max2_tdiffhess = (nhess - tnhess).ToArray().HAbs().HMax();
                HDebug.AssertTolerance(0.00000001, max2_tdiffhess);
            }
            return(nhess);
        }
Exemplo n.º 13
0
        public static HessInfo GetHessSsNMA
            (Universe univ
            , IList <Vector> coords
            , IEnumerable <Universe.Bond> bonds
            , IEnumerable <Universe.Angle> angles
            , IEnumerable <Universe.Improper> impropers
            , IEnumerable <Universe.Dihedral> dihedrals
            , IEnumerable <Universe.Nonbonded> nonbondeds
            , IEnumerable <Universe.Nonbonded14> nonbonded14s
            , double?maxAbsSpring = null
            , double?K_r          = 340.00
            , double?K_theta      = 45.00
            , double?K_ub         = 10.00
            , double?K_psi        = 70.00
            , double?K_chi        = 1.00
            , double?n            = 1
            , string k_vdW        = "Unif"
            //, bool setNanForEmptyAtom                         // =true
            )
        {
            bool   vdW       = true;                    // use vdW
            bool   elec      = false;                   // ignore electrostatic
            double D         = double.PositiveInfinity; // dielectric constant for Tinker is "1"
            bool   ignNegSpr = true;                    // ignore negative spring (do not add the spring into hessian matrix)

            //maxAbsSpring = Math.Pow(10, 9);
            HessMatrix hess = null;

            hess = STeM.GetHessBond(coords, bonds, K_r, hessian: hess);
            hess = STeM.GetHessAngle(coords, angles, true, K_theta, K_ub, hessian: hess);
            hess = STeM.GetHessImproper(coords, impropers, K_psi, hessian: hess, useArnaud96: true);
            hess = STeM.GetHessDihedral(coords, dihedrals, K_chi, n, hessian: hess, useAbsSpr: true, useArnaud96: true);
            hess = HessSpr.GetHessNonbond(coords, nonbondeds, D, k_vdW, hessian: hess, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring);
            hess = HessSpr.GetHessNonbond(coords, nonbonded14s, D, k_vdW, hessian: hess, vdW: vdW, elec: elec, ignNegSpr: ignNegSpr, maxAbsSpring: maxAbsSpring);

            //if(setNanForEmptyAtom)
            Hess.UpdateHessNaN(hess, coords);

            return(new HessInfo
            {
                hess = hess,
                mass = univ.GetMasses(),
                atoms = univ.atoms.ToArray(),
                coords = coords.HCloneVectors().ToArray(),
                numZeroEigval = 6,
            });
        }
Exemplo n.º 14
0
        public static HessInfo GetHessEAnm
            (Universe univ
            , IList <Vector> coords
            , IEnumerable <Tuple <int, int, double> > enumKij
            , bool b_bonds
            , bool b_angles
            , bool b_impropers
            , bool b_dihedrals
            )
        {
            //bool vdW  = true;       // use vdW
            //bool elec = false;      // ignore electrostatic
            //double D = double.PositiveInfinity; // dielectric constant for Tinker is "1"
            //bool ignNegSpr = true;  // ignore negative spring (do not add the spring into hessian matrix)

            HessMatrix hess = null;

            hess = Hess.GetHessAnm(coords, enumKij);
            if (b_bonds)
            {
                hess = STeM.GetHessBond(coords, univ.bonds, 340.00, hessian: hess);
            }
            if (b_angles)
            {
                hess = STeM.GetHessAngle(coords, univ.angles, true, 45.00, 10.00, hessian: hess);
            }
            if (b_impropers)
            {
                hess = STeM.GetHessImproper(coords, univ.impropers, 70.00, hessian: hess, useArnaud96: true);
            }
            if (b_dihedrals)
            {
                hess = STeM.GetHessDihedral(coords, univ.dihedrals, 1.00, 1, hessian: hess, useAbsSpr: true, useArnaud96: true);
            }

            Hess.UpdateHessNaN(hess, coords);

            return(new HessInfo
            {
                hess = hess,
                mass = univ.GetMasses(),
                atoms = univ.atoms.ToArray(),
                coords = coords.HCloneVectors().ToArray(),
                numZeroEigval = 6,
            });
        }
Exemplo n.º 15
0
            public static double[] GetBFactor(Mode[] modes, double[] mass = null)
            {
                if (HDebug.Selftest())
                #region selftest
                {
                    using (new Matlab.NamedLock("SELFTEST"))
                    {
                        Matlab.Clear("SELFTEST");
                        Matlab.Execute("SELFTEST.hess = rand(30);");
                        Matlab.Execute("SELFTEST.hess = SELFTEST.hess + SELFTEST.hess';");
                        Matlab.Execute("SELFTEST.invhess = inv(SELFTEST.hess);");
                        Matlab.Execute("SELFTEST.bfactor3 = diag(SELFTEST.invhess);");
                        Matlab.Execute("SELFTEST.bfactor = SELFTEST.bfactor3(1:3:end) + SELFTEST.bfactor3(2:3:end) + SELFTEST.bfactor3(3:3:end);");
                        MatrixByArr selftest_hess    = Matlab.GetMatrix("SELFTEST.hess");
                        Mode[]      selftest_mode    = Hess.GetModesFromHess(selftest_hess);
                        Vector      selftest_bfactor = BFactor.GetBFactor(selftest_mode);
                        Vector      selftest_check   = Matlab.GetVector("SELFTEST.bfactor");
                        Vector      selftest_diff    = selftest_bfactor - selftest_check;
                        HDebug.AssertTolerance(0.00000001, selftest_diff);
                        Matlab.Clear("SELFTEST");
                    }
                }
                #endregion

                int size = modes[0].size;
                if (mass != null)
                {
                    HDebug.Assert(size == mass.Length);
                }
                double[] bfactor = new double[size];
                for (int i = 0; i < size; i++)
                {
                    foreach (Mode mode in modes)
                    {
                        bfactor[i] += mode.eigvec[i * 3 + 0] * mode.eigvec[i * 3 + 0] / mode.eigval;
                        bfactor[i] += mode.eigvec[i * 3 + 1] * mode.eigvec[i * 3 + 1] / mode.eigval;
                        bfactor[i] += mode.eigvec[i * 3 + 2] * mode.eigvec[i * 3 + 2] / mode.eigval;
                    }
                    if (mass != null)
                    {
                        bfactor[i] /= mass[i];
                    }
                }
                return(bfactor);
            }
                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);
                    }
                }
Exemplo n.º 17
0
        //public static IEnumerable<Tuple<int, int, double>> EnumHessAnmSpr_obsolete(IList<Vector> coords, double cutoff, double sprcst)
        //{
        //    int size = coords.Count;
        //    double cutoff2 = cutoff*cutoff;
        //    //Matrix Kij = Matrix.Zeros(size, size);
        //    int num_springs = 0;
        //    for(int c=0; c<size; c++)
        //    {
        //        if(coords[c] == null) continue;
        //        for(int r=c+1; r<size; r++)
        //        {
        //            if(coords[r] == null) continue;
        //            double dist2 = (coords[c] - coords[r]).Dist2;
        //            if(dist2 <= cutoff2)
        //            {
        //                yield return new Tuple<int, int, double>(c, r, sprcst);  //Kij[c, r] = sprcst;
        //                yield return new Tuple<int, int, double>(r, c, sprcst);  //Kij[r, c] = sprcst;
        //                num_springs += 2;
        //            }
        //        }
        //    }
        //    double ratio_springs = ((double)num_springs) / (size*size);
        //    //return Kij;
        //}
        public static MatrixSparse <double> GetHessAnmBmat(IList <Vector> coords, double cutoff)
        {
            if (HDebug.Selftest())
            {
                var    _coords = Pdb._smallest_protein_cacoords;
                Matrix _Bmat   = Hess.GetHessAnmBmat(_coords, 13).ToArray();
                Matrix _BB     = _Bmat * _Bmat.Tr();
                Matrix _ANM    = Hess.GetHessAnm(_coords, 13);
                double _err    = (_BB - _ANM).HAbsMax();
                HDebug.Assert(_err < 0.00000001);
            }

            List <Tuple <int, int, double> > sprs = EnumHessAnmSpr(coords, cutoff, 1).ToList();
            MatrixSparse <double>            Bmat = new MatrixSparse <double>(3 * coords.Count, sprs.Count);
            int spr_count = 0;

            for (int ij = 0; ij < sprs.Count; ij++)
            {
                var spr = sprs[ij];
                int ai  = spr.Item1;
                int aj  = spr.Item2;
                if (ai >= aj)
                {
                    continue;
                }
                double kij    = spr.Item3;
                Vector coordi = coords[ai];
                Vector coordj = coords[aj];
                double sij    = (coordi - coordj).Dist;
                double xij    = (coordj[0] - coordi[0]) / sij;
                double yij    = (coordj[1] - coordi[1]) / sij;
                double zij    = (coordj[2] - coordi[2]) / sij;
                Bmat[(ai * 3 + 0), spr_count] = xij;
                Bmat[(ai * 3 + 1), spr_count] = yij;
                Bmat[(ai * 3 + 2), spr_count] = zij;
                Bmat[(aj * 3 + 0), spr_count] = -xij;
                Bmat[(aj * 3 + 1), spr_count] = -yij;
                Bmat[(aj * 3 + 2), spr_count] = -zij;
                spr_count++;
            }
            return(Bmat.GetSubMatrix(3 * coords.Count, spr_count));
        }
Exemplo n.º 18
0
        public static bool GetBFactorSelfTest(string pdbpath, double cutoff, double corr, int round, InfoPack extra)
        {
            if (HFile.Exists(pdbpath) == false)
            {
                return(false);
            }

            Pdb pdb = Pdb.FromFile(pdbpath);

            for (int i = 0; i < pdb.atoms.Length; i++)
            {
                HDebug.Assert(pdb.atoms[0].altLoc == pdb.atoms[i].altLoc);
                HDebug.Assert(pdb.atoms[0].chainID == pdb.atoms[i].chainID);
            }
            List <Pdb.Atom> atoms = new List <Pdb.Atom>();

            for (int i = 0; i < pdb.atoms.Length; i++)
            {
                Pdb.Atom atom = pdb.atoms[i];
                if (atom.name.Trim().ToUpper() == "CA")
                {
                    atoms.Add(atom);
                }
            }
            List <Vector> coords  = atoms.ListCoord();
            Matrix        hess    = Hess.GetHessAnm(coords, cutoff);
            InfoPack      lextra  = new InfoPack();
            Vector        bfactor = GetBFactor(hess, 0.00000001, null, lextra);

            if (extra != null)
            {
                extra["num_zero_eigvals"] = lextra["num_zero_eigvals"];
                extra["eigenvalues"]      = lextra["eigenvalues"];
            }

            double corr_comp = pdb.CorrBFactor(atoms.ListName(), atoms.ListResSeq(), bfactor.ToArray());

            corr_comp = Math.Round(corr_comp, round);
            HDebug.Assert(corr == corr_comp);
            return(corr == corr_comp);
        }
Exemplo n.º 19
0
        /// Lei Zhou and Steven A. Siegelbaum,
        /// Effects of Surface Water on Protein Dynamics Studied by a Novel Coarse-Grained Normal Mode Approach
        /// Biophysical Journal, Volume 94, May 2008
        /// http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2292380/pdf/3461.pdf
        ///
        /// Divide Hessian matrix into heavy atoms and others:
        ///   Hess = [ HH HL ]
        ///          [ LH LL ],
        /// where H and L imply heavy and light atoms, respectively.
        ///
        /// Using block inverse matrix
        ///   [A B]-1 = [ (A-B D^-1 C)^-1  ... ]
        ///   [C D]     [ ...              ... ],
        /// find the HH coarse-grain block of Hessian matrix:
        ///   Hess_HH = HH - HL * LL^-1 * LH

        public static HessMatrix GetHessCoarseBlkmat(Matrix hess, IList <int> idx_heavy, ILinAlg ila, double?chkDiagToler, string invtype, params object[] invopt)
        {
            List <int> idxhess = new List <int>();

            foreach (int idx in idx_heavy)
            {
                idxhess.Add(idx * 3 + 0);
                idxhess.Add(idx * 3 + 1);
                idxhess.Add(idx * 3 + 2);
            }

            HessMatrix hess_HH = new HessMatrixDense {
                hess = hess.InvOfSubMatrixOfInv(idxhess, ila, invtype, invopt)
            };

            if (chkDiagToler == null)
            {
                chkDiagToler = 0.000001;
            }
            HDebug.Assert(Hess.CheckHessDiag(hess_HH, chkDiagToler.Value));
            return(hess_HH);
        }
Exemplo n.º 20
0
            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);
            }
Exemplo n.º 21
0
            public HessMatrix GetHessMassWeighted(bool delhess)
            {
                HessMatrix mwhess;

                if (delhess)
                {
                    mwhess = hess;
                    hess   = null;
                }
                else
                {
                    mwhess = hess.CloneHess();
                }

                double[] mass3 = new double[mass.Size * 3];
                for (int i = 0; i < mass3.Length; i++)
                {
                    mass3[i] = mass[i / 3];
                }

                Hess.UpdateMassWeightedHess(mwhess, mass3);
                return(mwhess);
            }
Exemplo n.º 22
0
        public static double GetSprTensor(Vector[] coords, HessMatrix hess, int atm1, int atm2, IList <int> atms, ILinAlg ila)
        {
            HDebug.Assert(atms.Count == atms.HUnion().Length);

            int[] idxs = atms.HUnion();
            idxs = idxs.HRemoveAll(atm1);
            idxs = idxs.HRemoveAll(atm2);
            idxs = idxs.HInsert(0, atm2);
            idxs = idxs.HInsert(0, atm1);
            HDebug.Assert(idxs.HExcept(atms).HExcept(atm1, atm2).Length == 0);
            HDebug.Assert(idxs[0] == atm1);
            HDebug.Assert(idxs[1] == atm2);

            HessMatrix H = hess.ReshapeByAtom(idxs);

            H = Hess.GetHessFixDiag(H);
            HDebug.Assert(H.ColSize == H.RowSize, H.RowSize == idxs.Length * 3);
            // H should have 6 zero eigenvalues !!
            // since it is the original hessian matrix.

            Vector u12 = (coords[atm2] - coords[atm1]).UnitVector();
            Matrix S12 = Matrix.Zeros(idxs.Length * 3, 6);

            for (int i = 0; i < 6; i++)
            {
                S12[i, i] = 1;
            }

            Matrix invkij = GetInvSprTensorSymm(H, S12, ila);

            HDebug.Assert(invkij.ColSize == 1, invkij.RowSize == 1);
            HDebug.Assert(invkij[0, 0] > 0);

            double kij = 1 / invkij[0, 0];

            return(kij);
        }
Exemplo n.º 23
0
            public static Vector[] GetRotTran(Vector[] coords, double[] masses)
            {
                #region source rtbProjection.m
                /// rtbProjection.m
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                /// function [P, xyz] = rtbProjection(xyz, mass)
                /// % the approach is to find the inertia. compute the principal axes. and then use them to determine directly translation or rotation.
                ///
                /// n = size(xyz, 1); % n: the number of atoms
                /// if nargin == 1
                ///     mass = ones(n,1);
                /// end
                ///
                /// M = sum(mass);
                /// % find the mass center.
                /// m3 = repmat(mass, 1, 3);
                /// center = sum (xyz.*m3)/M;
                /// xyz = xyz - center(ones(n, 1), :);
                ///
                /// mwX = sqrt (m3).*xyz;
                /// inertia = sum(sum(mwX.^2))*eye(3) - mwX'*mwX;
                /// [V,D] = eig(inertia);
                /// tV = V'; % tV: transpose of V. Columns of V are principal axes.
                /// for i=1:3
                ///     trans{i} = tV(ones(n,1)*i, :); % the 3 translations are along principal axes
                /// end
                /// P = zeros(n*3, 6);
                /// for i=1:3
                ///     rotate{i} = cross(trans{i}, xyz);
                ///     temp = mat2vec(trans{i});
                ///     P(:,i) = temp/norm(temp);
                ///     temp = mat2vec(rotate{i});
                ///     P(:,i+3) = temp/norm(temp);
                /// end
                /// m3 = mat2vec(sqrt(m3));
                /// P = repmat (m3(:),1,size(P,2)).*P;
                /// % now normalize columns of P
                /// P = P*diag(1./normMat(P,1));
                ///
                /// function vec = mat2vec(mat)
                /// % convert a matrix to a vector, extracting data *row-wise*.
                /// vec = reshape(mat',1,prod(size(mat)));
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                #endregion

                if (HDebug.Selftest())
                #region selftest
                {
                    // get test coords and masses
                    Vector[] tcoords = Pdb.FromLines(SelftestData.lines_1EVC_pdb).atoms.ListCoord().ToArray();
                    double[] tmasses = new double[tcoords.Length];
                    for (int i = 0; i < tmasses.Length; i++)
                    {
                        tmasses[i] = 1;
                    }
                    // get test rot/trans RTB vectors
                    Vector[] trottra = GetRotTran(tcoords, tmasses);
                    HDebug.Assert(trottra.Length == 6);
                    // get test ANM
                    var tanm = Hess.GetHessAnm(tcoords);
                    // size of vec_i == 1
                    for (int i = 0; i < trottra.Length; i++)
                    {
                        double dist = trottra[i].Dist;
                        HDebug.Assert(Math.Abs(dist - 1) < 0.00000001);
                    }
                    // vec_i and vec_j must be orthogonal
                    for (int i = 0; i < trottra.Length; i++)
                    {
                        for (int j = i + 1; j < trottra.Length; j++)
                        {
                            double dot = LinAlg.VtV(trottra[i], trottra[j]);
                            HDebug.Assert(Math.Abs(dot) < 0.00000001);
                        }
                    }
                    // vec_i' * ANM * vec_i == 0
                    for (int i = 0; i < trottra.Length; i++)
                    {
                        double eigi = LinAlg.VtMV(trottra[i], tanm, trottra[i]);
                        HDebug.Assert(Math.Abs(eigi) < 0.00000001);
                        Vector tvecx = trottra[i].Clone();
                        tvecx[1] += (1.0 / tvecx.Size) * Math.Sign(tvecx[1]);
                        tvecx     = tvecx.UnitVector();
                        double eigix = LinAlg.VtMV(tvecx, tanm, tvecx);
                        HDebug.Assert(Math.Abs(eigix) > 0.00000001);
                    }
                }
                #endregion

                Vector[] rottran;
                using (new Matlab.NamedLock(""))
                {
                    Matlab.PutMatrix("xyz", coords.ToMatrix(), true);
                    Matlab.Execute("xyz = xyz';");
                    Matlab.PutVector("mass", masses);
                    //Matlab.Execute("function [P, xyz] = rtbProjection(xyz, mass)                                                                                        ");
                    //Matlab.Execute("% the approach is to find the inertia. compute the principal axes. and then use them to determine directly translation or rotation. ");
                    Matlab.Execute("                                                                                 ");
                    Matlab.Execute("n = size(xyz, 1); % n: the number of atoms                                       ");
                    //Matlab.Execute("if nargin == 1;                                                                  ");
                    //Matlab.Execute("    mass = ones(n,1);                                                            ");
                    //Matlab.Execute("end                                                                              ");
                    Matlab.Execute("                                                                                 ");
                    Matlab.Execute("M = sum(mass);                                                                   ");
                    Matlab.Execute("% find the mass center.                                                          ");
                    Matlab.Execute("m3 = repmat(mass, 1, 3);                                                         ");
                    Matlab.Execute("center = sum (xyz.*m3)/M;                                                        ");
                    Matlab.Execute("xyz = xyz - center(ones(n, 1), :);                                               ");
                    Matlab.Execute("                                                                                 ");
                    Matlab.Execute("mwX = sqrt (m3).*xyz;                                                            ");
                    Matlab.Execute("inertia = sum(sum(mwX.^2))*eye(3) - mwX'*mwX;                                    ");
                    Matlab.Execute("[V,D] = eig(inertia);                                                            ");
                    Matlab.Execute("tV = V'; % tV: transpose of V. Columns of V are principal axes.                  ");
                    Matlab.Execute("for i=1:3                                                                        \n"
                                   + "    trans{i} = tV(ones(n,1)*i, :); % the 3 translations are along principal axes \n"
                                   + "end                                                                              \n");
                    Matlab.Execute("P = zeros(n*3, 6);                                                               ");
                    Matlab.Execute("mat2vec = @(mat) reshape(mat',1,prod(size(mat)));                                ");
                    Matlab.Execute("for i=1:3                                                                        \n"
                                   + "    rotate{i} = cross(trans{i}, xyz);                                            \n"
                                   + "    temp = mat2vec(trans{i});                                                    \n"
                                   + "    P(:,i) = temp/norm(temp);                                                    \n"
                                   + "    temp = mat2vec(rotate{i});                                                   \n"
                                   + "    P(:,i+3) = temp/norm(temp);                                                  \n"
                                   + "end                                                                              ");
                    Matlab.Execute("m3 = mat2vec(sqrt(m3));                                                          ");
                    Matlab.Execute("P = repmat (m3(:),1,size(P,2)).*P;                                               ");
                    //Matlab.Execute("% now normalize columns of P                                                     "); // already normalized
                    //Matlab.Execute("normMat = @(x) sqrt(sum(x.^2,2));                                                "); // already normalized
                    //Matlab.Execute("P = P*diag(1./normMat(P,1));                                                     "); // already normalized
                    //Matlab.Execute("                                                                                 "); // already normalized
                    //////////////////////////////////////////////////////////////////////////////////////////////////////
                    //Matlab.Execute("function vec = mat2vec(mat)                                                      ");
                    //Matlab.Execute("% convert a matrix to a vector, extracting data *row-wise*.                      ");
                    //Matlab.Execute("vec = reshape(mat',1,prod(size(mat)));                                           ");
                    //////////////////////////////////////////////////////////////////////////////////////////////////////
                    //Matlab.Execute("function amp = normMat(x)                                                        ");
                    //Matlab.Execute("amp = sqrt(sum(x.^2,2));                                                         ");

                    Matrix xyz = Matlab.GetMatrix("xyz", true);
                    Matrix P   = Matlab.GetMatrix("P", true);
                    rottran = P.GetColVectorList();
                }
                return(rottran);
            }
Exemplo n.º 24
0
            public static CTesthess ReadHess
                (Xyz xyz
                , string outputpath
                , Dictionary <string, string[]> optOutSource  // =null
                , Func <int, int, HessMatrix> HessMatrixZeros // =null
                )
            {
                int size = xyz.atoms.Length;

                #region format: output.txt
                ///      ######################################################################
                ///    ##########################################################################
                ///   ###                                                                      ###
                ///  ###            TINKER  ---  Software Tools for Molecular Design            ###
                ///  ##                                                                          ##
                ///  ##                        Version 6.2  February 2013                        ##
                ///  ##                                                                          ##
                ///  ##               Copyright (c)  Jay William Ponder  1990-2013               ##
                ///  ###                           All Rights Reserved                          ###
                ///   ###                                                                      ###
                ///    ##########################################################################
                ///      ######################################################################
                ///
                ///
                ///  Atoms with an Unusual Number of Attached Atoms :
                ///
                ///  Type           Atom Name      Atom Type       Expected    Found
                ///
                ///  Valence        1496-NR2           69              2         3
                ///  Valence        2438-FE           107              6         5
                ///
                ///  Diagonal Hessian Elements for Each Atom :
                ///
                ///       Atom                 X               Y               Z
                ///
                ///          1            1445.9830       1358.3447       1484.8642
                ///          2             212.9895        294.4584        604.5062
                ///          3             187.1986        751.6727        125.0336
                ///          4             813.4799        132.1743        151.5707
                ///        ...
                ///       2507             178.7277        479.7434        243.4103
                ///       2508             969.8813        977.2507       1845.6726
                ///       2509             390.1648        232.0577       1029.6844
                ///       2510             322.3674        337.8749        996.8230
                ///
                ///  Sum of Diagonal Hessian Elements :          5209042.9060
                ///
                ///  Hessian Matrix written to File :  test.hes
                #endregion
                Tuple <int, double, double, double>[] outDiagHessElems = new Tuple <int, double, double, double> [size];
                double?outSumDiagHessElem = null;
                string outHessMatFile     = null;
                string outHessFormat      = null;
                {
                    string step = "";
                    foreach (string _line in HFile.ReadLines(outputpath))
                    {
                        string line = _line.Trim();
                        if (line.Length == 0)
                        {
                            continue;
                        }
                        if (line.Trim().StartsWith("#"))
                        {
                            continue;
                        }
                        if (line.Contains(" :"))
                        {
                            if (line.Contains("Atoms with an Unusual Number of Attached Atoms"))
                            {
                                step = "";                  continue;
                            }
                            else if (line.Contains("Diagonal Hessian Elements for Each Atom"))
                            {
                                step = "hess diagonal";     continue;
                            }
                            else if (line.Contains("Sum of Diagonal Hessian Elements"))
                            {
                                step = "sum hess diagonal";
                            }
                            else if (line.Contains("Hessian Matrix written to File"))
                            {
                                step = "full hess file";
                            }
                            else if (line.Contains("Hessian Sparse Matrix written to File"))
                            {
                                step = "sparse hess file";
                            }
                            else if (line.Contains("Select Smaller Size for Sparse Hessian Matrix"))
                            {
                                continue;
                            }
                            else
                            {
                                HDebug.Assert(false);
                                continue;
                            }
                        }
                        switch (step)
                        {
                        case "":
                            continue;

                        case "hess diagonal":
                        {
                            string[] tokens = line.Split().HRemoveAll("");
                            if (tokens[0] == "Atom")
                            {
                                continue;
                            }
                            int    Atom = int.Parse(tokens[0]);         // ; if(   int.TryParse(tokens[0], out Atom) == false) continue;
                            double X    = double.Parse(tokens[1]);      // ; if(double.TryParse(tokens[1], out    X) == false) continue;
                            double Y    = double.Parse(tokens[2]);      // ; if(double.TryParse(tokens[2], out    Y) == false) continue;
                            double Z    = double.Parse(tokens[3]);      // ; if(double.TryParse(tokens[3], out    Z) == false) continue;
                            HDebug.Assert(outDiagHessElems[Atom - 1] == null);
                            outDiagHessElems[Atom - 1] = new Tuple <int, double, double, double>(Atom, X, Y, Z);
                        }
                            continue;

                        case "sum hess diagonal":
                        {
                            string[] tokens = line.Split().HRemoveAll("");
                            double   sum    = double.Parse(tokens.Last());    // if(double.TryParse(tokens.Last(), out sum) == false) continue;
                            outSumDiagHessElem = sum;
                        }
                            step = "";
                            continue;

                        case   "full hess file": outHessFormat = "full matrix"; goto case "hess file";

                        case "sparse hess file": outHessFormat = "sparse matrix"; goto case "hess file";

                        case "hess file":
                        {
                            string[] tokens         = line.Split().HRemoveAll("");
                            string   outputpath_dir = HFile.GetFileInfo(outputpath).Directory.FullName;
                            outHessMatFile = outputpath_dir + "\\" + tokens.Last();
                        }
                            step = "";
                            continue;

                        default:
                            HDebug.Assert(false);
                            step = "";
                            continue;
                        }
                    }
                }
                #region Format: test.hes
                /// Diagonal Hessian Elements  (3 per Atom)
                ///
                ///   1445.9830   1358.3447   1484.8642    212.9895    294.4584    604.5062
                ///    187.1986    751.6727    125.0336    813.4799    132.1743    151.5707
                ///   1167.7472   1188.3459   1162.5475    268.8291    498.0188    143.2438
                ///   ...
                /// Off-diagonal Hessian Elements for Atom     1 X
                ///     23.0878     14.6380   -214.0545     96.9308   -186.7740   -205.1460
                ///   -208.7035    -28.9630   -788.9124     39.6748    126.4491   -190.5074
                ///   ...
                /// Off-diagonal Hessian Elements for Atom     1 Y
                ///    -64.1616     97.2697   -292.3813    264.1922   -184.4701   -728.8687
                ///   -109.9103     15.4168   -152.5717    -11.7733     18.8369   -188.4875
                ///   ...
                /// Off-diagonal Hessian Elements for Atom     1 Z
                ///   -155.9409    219.8782   -610.0622    -10.0041    -62.8209   -156.1112
                ///     77.0829    -14.2127   -166.0525     53.1834    -97.4207   -347.9315
                ///   ...
                /// Off-diagonal Hessian Elements for Atom     2 X
                ///   -106.5166    185.8395     19.7546    -10.0094     25.8072     -8.1335
                ///     35.8501    -64.8320      3.8761    -13.8893      9.4266      0.1312
                ///   ...
                ///
                ///   ...
                ///
                /// Off-diagonal Hessian Elements for Atom  2508 X
                ///    488.4590    -69.2721   -338.4824   -155.1656    253.3732   -297.4214
                ///   -164.8301   -191.3769
                /// Off-diagonal Hessian Elements for Atom  2508 Y
                ///     74.0161   -149.1060   -273.4863    176.4975   -170.6527   -341.1639
                ///   -263.6141
                /// Off-diagonal Hessian Elements for Atom  2508 Z
                ///    304.9942    223.7496   -851.3028   -242.9481   -310.7953   -821.2532
                /// Off-diagonal Hessian Elements for Atom  2509 X
                ///    198.4498   -331.6530     78.8172     17.3909    -30.0512
                /// Off-diagonal Hessian Elements for Atom  2509 Y
                ///   -227.5916     25.7235     74.5131    -53.2690
                /// Off-diagonal Hessian Elements for Atom  2509 Z
                ///     46.7873     20.7615   -168.0704
                /// Off-diagonal Hessian Elements for Atom  2510 X
                ///    252.6853    247.2963
                /// Off-diagonal Hessian Elements for Atom  2510 Y
                ///    343.6797
                #endregion
                HessMatrix hess;
                {
                    if (HessMatrixZeros != null)
                    {
                        hess = HessMatrixZeros(size * 3, size * 3);
                    }
                    else
                    {
                        switch (outHessFormat)
                        {
                        case "full matrix": hess = HessMatrixDense.ZerosDense(size * 3, size * 3); break;

                        case "sparse matrix": hess = HessMatrixSparse.ZerosSparse(size * 3, size * 3); break;

                        default:              hess = null;                                             break;
                        }
                    }
                    //HDebug.SetEpsilon(hess);
                    string step    = "";
                    int    diagidx = -1;
                    int    offidx1 = -1;
                    int    offidx2 = -1;

                    /// string[] lines = HFile.ReadAllLines(outHessMatFile);
                    /// GC.WaitForFullGCComplete();
                    /// object[] tokenss = new object[lines.Length];
                    ///
                    /// Parallel.For(0, lines.Length, delegate(int i)
                    /// //for(int i=0; i<lines.Length; i++)
                    /// {
                    ///     string line = lines[i];
                    ///     string[] stokens = line.Trim().Split().RemoveAll("");
                    ///     if(stokens.Length != 0)
                    ///     {
                    ///         double[] dtokens = new double[stokens.Length];
                    ///         for(int j=0; j<stokens.Length; j++)
                    ///             if(double.TryParse(stokens[j], out dtokens[j]) == false)
                    ///             {
                    ///                 tokenss[i] = stokens;
                    ///                 goto endfor;
                    ///             }
                    ///         tokenss[i] = dtokens;
                    ///     }
                    /// endfor: ;
                    /// });

                    /// System.IO.StreamReader matreader = HFile.OpenText(outHessMatFile);
                    /// while(matreader.EndOfStream == false)
                    /// for(int i=0; i<lines.Length; i++)
                    /// foreach(string line in lines)
                    foreach (string line in HFile.HEnumAllLines(outHessMatFile))
                    {
                        ///     string line = lines[i];
                        ///     string line = matreader.ReadLine();
                        string[] tokens = line.Trim().Split().HRemoveAll("");
                        if (tokens.Length == 0)
                        {
                            continue;
                        }
                        ///     if(tokenss[i] == null)
                        ///         continue;
                        ///     string[] stokens = (tokenss[i] as string[]);
                        if (tokens[0] == "Diagonal" && tokens[1] == "Hessian" && tokens[2] == "Elements")
                        {
                            step = "Diagonal"; diagidx = 0; continue;
                        }
                        if (tokens[0] == "Off-diagonal" && tokens[1] == "Hessian" && tokens[2] == "Elements")
                        {
                            step = "Off-diagonal"; offidx1++; offidx2 = offidx1 + 1; continue;
                        }
                        if (tokens[0] == "Off-diagonal" && tokens[1] == "sparse" && tokens[2] == "Hessian" &&
                            tokens[3] == "Indexes/Elements" && tokens[4] == "for" && tokens[5] == "Atom")
                        {
                            step    = "Off-diagonal sparse";
                            offidx1 = (int.Parse(tokens[6]) - 1) * 3;
                            switch (tokens[7])
                            {
                            case "X": break;

                            case "Y": offidx1 += 1; break;

                            case "Z": offidx1 += 2; break;

                            default: throw new HException();
                            }
                            continue;
                        }

                        ///     double[] dtokens = (tokenss[i] as double[]);
                        ///     tokens = new string[20];
                        ///     for(int i=0; i*12<line.Length; i++)
                        ///         tokens[i] = line.Substring(i*12, 12).Trim();
                        ///     tokens = tokens.HRemoveAll("").ToArray();
                        ///     tokens = tokens.HRemoveAll(null).ToArray();

                        switch (step)
                        {
                        case "Diagonal":
                        {
                            ///                 foreach(double val in dtokens)
                            foreach (string token in tokens)
                            {
                                HDebug.Assert(token.Last() != ' ');
                                double val = double.Parse(token);
                                HDebug.Assert(hess[diagidx, diagidx] == 0);
                                hess[diagidx, diagidx] = val;
                                diagidx++;
                            }
                        }
                            continue;

                        case "Off-diagonal":
                        {
                            ///                 foreach(double val in dtokens)
                            foreach (string token in tokens)
                            {
                                HDebug.Assert(token.Last() != ' ');
                                //double val = double.Parse(token);
                                double val;
                                bool   succ = double.TryParse(token, out val);
                                if (succ == false)
                                {
                                    HDebug.Assert(false);
                                    goto case "exception 0";
                                }
                                if (size < 3000)
                                {
                                    HDebug.Assert(hess[offidx1, offidx2] == 0);
                                    HDebug.Assert(hess[offidx2, offidx1] == 0);
                                }
                                if (val != 0)
                                {
                                    hess[offidx1, offidx2] = val;
                                    hess[offidx2, offidx1] = val;
                                }
                                offidx2++;
                            }
                        }
                            continue;

                        case "Off-diagonal sparse":
                        {
                            HDebug.Assert(tokens.Length % 2 == 0);
                            for (int i = 0; i < tokens.Length; i += 2)
                            {
                                HDebug.Assert(tokens[i].Last() != ' ');
                                HDebug.Assert(tokens[i + 1].Last() != ' ');
                                //double val = double.Parse(token);
                                double val;
                                bool   succ = true;
                                succ &= int.TryParse(tokens[i], out offidx2); offidx2--;
                                succ &= double.TryParse(tokens[i + 1], out val);
                                if (succ == false)
                                {
                                    HDebug.Assert(false);
                                    goto case "exception 0";
                                }
                                if (size < 3000)
                                {
                                    HDebug.Assert(hess[offidx1, offidx2] == 0);
                                    HDebug.Assert(hess[offidx2, offidx1] == 0);
                                }
                                if (val != 0)
                                {
                                    hess[offidx1, offidx2] = val;
                                    hess[offidx2, offidx1] = val;
                                }
                            }
                        }
                            continue;

                        default:
                            HDebug.Assert(false);
                            goto case "exception 1";

                        case "exception 0":
                            throw new HException("incomplete hessian file (0)");

                        case "exception 1":
                            throw new HException("incomplete hessian file (1)");
                        }
                        throw new HException("incomplete hessian file (2)");
                    }
                    /// matreader.Close();

                    if (HDebug.IsDebuggerAttached && size < 3000)
                    {
                        //for(int c=0; c<size*3; c++)
                        //    for(int r=0; r<size*3; r++)
                        //        if(hess[c, r] == double.Epsilon)
                        //            throw new Exception("incomplete hessian file (3)");
                        //
                        //for(int c=0; c<size*3; c++)
                        //{
                        //    double sum = 0;
                        //    double max = double.NegativeInfinity;
                        //    for(int r=0; r<size*3; r++)
                        //    {
                        //        max = Math.Max(max, hess[c, r]);
                        //        sum += hess[c, r];
                        //        HDebug.Assert(hess[c, r] != double.Epsilon);
                        //    }
                        //    HDebug.Assert(Math.Abs(sum) < max/1000);
                        //    HDebug.AssertTolerance(0.1, sum);
                        //}

                        Hess.CheckHessDiag(hess, 0.1, null);

                        for (int i = 0; i < size; i++)
                        {
                            HDebug.Assert(outDiagHessElems[i].Item1 == i + 1);
                            HDebug.AssertTolerance(0.000001, outDiagHessElems[i].Item2 - hess[i * 3 + 0, i * 3 + 0]);
                            HDebug.AssertTolerance(0.000001, outDiagHessElems[i].Item3 - hess[i * 3 + 1, i * 3 + 1]);
                            HDebug.AssertTolerance(0.000001, outDiagHessElems[i].Item4 - hess[i * 3 + 2, i * 3 + 2]);
                        }
                    }
                }

                if (optOutSource != null)
                {
                    optOutSource.Add("test.hes", HFile.HEnumAllLines(outHessMatFile).ToArray());
                }

                return(new CTesthess
                {
                    hess = hess,
                    xyz = xyz,
                });
            }
Exemplo n.º 25
0
 public HessMatrix CorrectHessDiag()
 {
     return(Hess.CorrectHessDiag(this));
 }
Exemplo n.º 26
0
        public static double GetSprScalar(Vector[] coords, HessMatrix hess, int atm1, int atm2, IList <int> atms, ILinAlg ila)
        {
            HDebug.Assert(atms.Count == atms.HUnion().Length);

            int[] idxs = atms.HUnion();
            idxs = idxs.HRemoveAll(atm1);
            idxs = idxs.HRemoveAll(atm2);
            idxs = idxs.HInsert(0, atm2);
            idxs = idxs.HInsert(0, atm1);
            HDebug.Assert(idxs.HExcept(atms).HExcept(atm1, atm2).Length == 0);
            HDebug.Assert(idxs[0] == atm1);
            HDebug.Assert(idxs[1] == atm2);

            HessMatrix H = hess.ReshapeByAtom(idxs);

            H = Hess.GetHessFixDiag(H);
            HDebug.Assert(H.ColSize == H.RowSize, H.RowSize == idxs.Length * 3);
            // H should have 6 zero eigenvalues !!
            // since it is the original hessian matrix.

            // return "0" spring if there is no connect between atm1 and atm2
            {
                Graph <int, object> g = new Graph <int, object>();
                for (int i = 0; i < H.ColBlockSize; i++)
                {
                    g.AddNode(i);
                }
                foreach (var bc_br_bval in H.EnumBlocks())
                {
                    int bc = bc_br_bval.Item1;
                    int br = bc_br_bval.Item2;
                    if (bc > br)
                    {
                        continue;
                    }
                    g.AddEdge(bc, br, new object());
                    //g.AddEdge(br, bc, new object()); // g is bi-directional graph
                }
                var paths = g.FindPathShortest(g.GetNode(0), new Graph <int, object> .Node[] { g.GetNode(1) });
                if (paths == null)
                {
                    // if there is no path between 0 <-> 1, then there is no spring
                    return(0);
                }
            }

            Vector u12 = (coords[atm2] - coords[atm1]).UnitVector();
            Matrix S12 = new double[idxs.Length * 3, 1];

            S12[0, 0] = u12[0];    S12[1, 0] = u12[1];    S12[2, 0] = u12[2];
            S12[3, 0] = -u12[0];    S12[4, 0] = -u12[1];    S12[5, 0] = -u12[2];

            Matrix invkij = GetInvSprTensorSymm(H, S12, ila);

            HDebug.Assert(invkij.ColSize == 1, invkij.RowSize == 1);
            HDebug.Assert(invkij[0, 0] > 0);

            double kij = 1 / invkij[0, 0];

            return(kij);
        }
Exemplo n.º 27
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,
                    });
                }
Exemplo n.º 28
0
            public static void TestTuLiangDataSet()
            {
                System.Console.WriteLine("pdbid : ANM(TuLiang -> mine), STeM(TuLiang -> mine)");
                foreach (STeM.DataSet data in STeM.TuLiangDataSet)
                {
                    Pdb pdb      = PdbDatabase.GetPdb(data.pdbid);
                    int numChain = pdb.atoms.ListChainID().HListCommonT().Count;
                    HDebug.Assert(numChain == 1);
                    //List<Pdb.Atom> atoms = pdb.atoms.SelectByName("CA");
                    List <Pdb.Atom> atoms = pdb.atoms.SelectByAltLoc().SelectByName("CA");
                    //List<Pdb.Atom> atoms = pdb.atoms.SelectByDefault().SelectByName("CA");
                    List <Vector> coords   = atoms.ListCoord();
                    Vector        bfactors = atoms.ListTempFactor().ToArray();

                    Matrix hessANM = Hess.GetHessAnm(coords, 12);
                    Mode[] modeANM = Hess.GetModesFromHess(hessANM);
                    modeANM = modeANM.SelectExceptSmallSix();
                    Vector bfactorANM = modeANM.GetBFactor().ToArray();
                    double corrANM    = HBioinfo.BFactor.Corr(bfactors, bfactorANM);

                    //Matrix hessGNM = ENM.GnmHessian(coords, 12);
                    //Mode[] modeGNM = Hess.GetModes(hessGNM);
                    //Vector bfactorGNM = modeGNM.GetBFactor().ToArray();
                    //double corrGNM = BFactor.Corr(bfactors, bfactorGNM);

                    HessMatrix hessSTeM = STeM.GetHessCa_matlab(coords);
                    //Matrix hessSTeM = STeM.GetHessCa(coords);
                    Mode[] modeSTeM = Hess.GetModesFromHess(hessSTeM);
                    modeSTeM = modeSTeM.SelectExceptSmallSix();
                    Vector bfactorSTeM = modeSTeM.GetBFactor().ToArray();
                    double corrSTeM    = HBioinfo.BFactor.Corr(bfactors, bfactorSTeM);

                    System.Console.Write(data.pdbid);
                    System.Console.Write(" : ANM({0:0.00}) -> {1:0.0000})", data.ANM, corrANM);
                    System.Console.Write(" : STeM({0:0.00}) -> {1:0.0000})", data.STeM, corrSTeM);
                    System.Console.WriteLine();
                }
                /// Capture of result...
                ///
                /// pdbid : ANM(TuLiang -> mine), STeM(TuLiang -> mine)
                /// 1AAC : ANM(0.70) -> 0.6918) : STeM(0.76) -> 0.7538)
                /// 1ADS : ANM(0.77) -> 0.7807) : STeM(0.71) -> 0.7142)
                /// 1AHC : ANM(0.79) -> 0.7953) : STeM(0.61) -> 0.6117)
                /// 1AKY : ANM(0.56) -> 0.5675) : STeM(0.60) -> 0.6023)
                /// 1AMM : ANM(0.56) -> 0.5951) : STeM(0.55) -> 0.5304)
                #region ...
                /// 1AMP : ANM(0.62) -> 0.5643) : STeM(0.68) -> 0.6739)
                /// 1ARB : ANM(0.78) -> 0.7526) : STeM(0.83) -> 0.8253)
                /// 1ARS : ANM(0.14) -> 0.1343) : STeM(0.41) -> 0.3646)
                /// 1ARU : ANM(0.70) -> 0.7358) : STeM(0.79) -> 0.7921)
                /// 1BKF : ANM(0.52) -> 0.4695) : STeM(0.50) -> 0.4940)
                /// 1BPI : ANM(0.43) -> 0.4225) : STeM(0.57) -> 0.5588)
                /// 1CDG : ANM(0.65) -> 0.6586) : STeM(0.71) -> 0.7068)
                /// 1CEM : ANM(0.51) -> 0.5232) : STeM(0.76) -> 0.6735)
                /// 1CNR : ANM(0.34) -> 0.3445) : STeM(0.42) -> 0.4190)
                /// 1CNV : ANM(0.69) -> 0.6748) : STeM(0.68) -> 0.6775)
                /// 1CPN : ANM(0.51) -> 0.5607) : STeM(0.56) -> 0.5535)
                /// 1CSH : ANM(0.44) -> 0.4257) : STeM(0.57) -> 0.5755)
                /// 1CTJ : ANM(0.47) -> 0.4889) : STeM(0.62) -> 0.6256)
                /// 1CUS : ANM(0.74) -> 0.7416) : STeM(0.76) -> 0.7992)
                /// 1DAD : ANM(0.28) -> 0.3461) : STeM(0.42) -> 0.4155)
                /// 1DDT : ANM(0.21) -> 0.1899) : STeM(0.49) -> 0.4869)
                /// 1EDE : ANM(0.67) -> 0.7044) : STeM(0.75) -> 0.7439)
                /// 1EZM : ANM(0.56) -> 0.5609) : STeM(0.58) -> 0.5842)
                /// 1FNC : ANM(0.29) -> 0.2663) : STeM(0.61) -> 0.6109)
                /// 1FRD : ANM(0.54) -> 0.5933) : STeM(0.77) -> 0.7579)
                /// 1FUS : ANM(0.40) -> 0.3935) : STeM(0.61) -> 0.6084)
                /// 1FXD : ANM(0.58) -> 0.6291) : STeM(0.70) -> 0.6793)
                /// 1GIA : ANM(0.68) -> 0.6655) : STeM(0.69) -> 0.6856)
                /// 1GKY : ANM(0.36) -> 0.3833) : STeM(0.44) -> 0.4257)
                /// 1GOF : ANM(0.75) -> 0.7614) : STeM(0.78) -> 0.7736)
                /// 1GPR : ANM(0.65) -> 0.5689) : STeM(0.66) -> 0.6534)
                /// 1HFC : ANM(0.63) -> 0.6313) : STeM(0.35) -> 0.7303)
                /// 1IAB : ANM(0.36) -> 0.3262) : STeM(0.53) -> 0.5232)
                /// 1IAG : ANM(0.34) -> 0.3464) : STeM(0.44) -> 0.4344)
                /// 1IFC : ANM(0.61) -> 0.5054) : STeM(0.53) -> 0.5395)
                /// 1IGD : ANM(0.18) -> 0.1874) : STeM(0.27) -> 0.2660)
                /// 1IRO : ANM(0.82) -> 0.7949) : STeM(0.85) -> 0.8461)
                /// 1JBC : ANM(0.72) -> 0.7380) : STeM(0.73) -> 0.7326)
                /// 1KNB : ANM(0.63) -> 0.6615) : STeM(0.54) -> 0.5389)
                /// 1LAM : ANM(0.53) -> 0.5324) : STeM(0.71) -> 0.7102)
                /// 1LCT : ANM(0.52) -> 0.5488) : STeM(0.61) -> 0.6115)
                /// 1LIS : ANM(0.16) -> 0.1674) : STeM(0.30) -> 0.2959)
                /// 1LIT : ANM(0.65) -> 0.5715) : STeM(0.76) -> 0.7575)
                /// 1LST : ANM(0.39) -> 0.3860) : STeM(0.73) -> 0.7283)
                /// 1MJC : ANM(0.67) -> 0.6470) : STeM(0.61) -> 0.6164)
                /// 1MLA : ANM(0.59) -> 0.5686) : STeM(0.54) -> 0.5404)
                /// 1MRJ : ANM(0.66) -> 0.6708) : STeM(0.50) -> 0.4923)
                /// 1NAR : ANM(0.62) -> 0.6257) : STeM(0.74) -> 0.7332)
                /// 1NFP : ANM(0.23) -> 0.2561) : STeM(0.41) -> 0.4053)
                /// 1NIF : ANM(0.42) -> 0.4139) : STeM(0.61) -> 0.6112)
                /// 1NPK : ANM(0.53) -> 0.5654) : STeM(0.64) -> 0.5983)
                /// 1OMP : ANM(0.61) -> 0.5857) : STeM(0.65) -> 0.6499)
                /// 1ONC : ANM(0.55) -> 0.5789) : STeM(0.58) -> 0.5736)
                /// 1OSA : ANM(0.36) -> 0.3596) : STeM(0.55) -> 0.5465)
                /// 1OYC : ANM(0.78) -> 0.7708) : STeM(0.77) -> 0.7757)
                /// 1PBE : ANM(0.53) -> 0.5341) : STeM(0.63) -> 0.6290)
                /// 1PDA : ANM(0.60) -> 0.6240) : STeM(0.58) -> 0.5697)
                /// 1PHB : ANM(0.56) -> 0.5919) : STeM(0.59) -> 0.5866)
                /// 1PHP : ANM(0.59) -> 0.5852) : STeM(0.65) -> 0.6470)
                /// 1PII : ANM(0.19) -> 0.2429) : STeM(0.28) -> 0.2871)
                /// 1PLC : ANM(0.41) -> 0.3411) : STeM(0.42) -> 0.4239)
                /// 1POA : ANM(0.54) -> 0.5944) : STeM(0.42) -> 0.4290)
                /// 1POC : ANM(0.46) -> 0.4341) : STeM(0.39) -> 0.3878)
                /// 1PPN : ANM(0.61) -> 0.5655) : STeM(0.67) -> 0.6757)
                /// 1PTF : ANM(0.47) -> 0.4669) : STeM(0.54) -> 0.5349)
                /// 1PTX : ANM(0.65) -> 0.5949) : STeM(0.62) -> 0.6167)
                /// 1RA9 : ANM(0.48) -> 0.5029) : STeM(0.53) -> 0.5267)
                /// 1RCF : ANM(0.59) -> 0.5629) : STeM(0.58) -> 0.5937)
                /// 1REC : ANM(0.34) -> 0.3352) : STeM(0.49) -> 0.4884)
                /// 1RIE : ANM(0.71) -> 0.7440) : STeM(0.52) -> 0.6806)
                /// 1RIS : ANM(0.25) -> 0.2199) : STeM(0.47) -> 0.4779)
                /// 1RRO : ANM(0.08) -> 0.1192) : STeM(0.36) -> 0.3266)
                /// 1SBP : ANM(0.69) -> 0.6955) : STeM(0.67) -> 0.6668)
                /// 1SMD : ANM(0.50) -> 0.5193) : STeM(0.67) -> 0.6713)
                /// 1SNC : ANM(0.68) -> 0.6860) : STeM(0.72) -> 0.7275)
                /// 1THG : ANM(0.50) -> 0.4982) : STeM(0.50) -> 0.4934)
                /// 1TML : ANM(0.64) -> 0.6266) : STeM(0.58) -> 0.5728)
                /// 1UBI : ANM(0.56) -> 0.5610) : STeM(0.61) -> 0.6235)
                /// 1WHI : ANM(0.12) -> 0.1223) : STeM(0.38) -> 0.3713)
                /// 1XIC : ANM(0.29) -> 0.2942) : STeM(0.47) -> 0.4624)
                /// 2AYH : ANM(0.63) -> 0.6453) : STeM(0.82) -> 0.8157)
                /// 2CBA : ANM(0.67) -> 0.6562) : STeM(0.80) -> 0.8054)
                /// 2CMD : ANM(0.68) -> 0.6630) : STeM(0.62) -> 0.6106)
                /// 2CPL : ANM(0.61) -> 0.6379) : STeM(0.72) -> 0.7131)
                /// 2CTC : ANM(0.63) -> 0.6220) : STeM(0.75) -> 0.7495)
                /// 2CY3 : ANM(0.51) -> 0.5150) : STeM(0.67) -> 0.6614)
                /// 2END : ANM(0.63) -> 0.6307) : STeM(0.68) -> 0.6841)
                /// 2ERL : ANM(0.74) -> 0.7400) : STeM(0.85) -> 0.8445)
                /// 2HFT : ANM(0.63) -> 0.5503) : STeM(0.72) -> 0.7228)
                /// 2IHL : ANM(0.62) -> 0.6632) : STeM(0.72) -> 0.7083)
                /// 2MCM : ANM(0.78) -> 0.7774) : STeM(0.79) -> 0.7886)
                /// 2MHR : ANM(0.65) -> 0.6117) : STeM(0.64) -> 0.6341)
                /// 2MNR : ANM(0.46) -> 0.4762) : STeM(0.47) -> 0.4688)
                /// 2PHY : ANM(0.54) -> 0.5160) : STeM(0.68) -> 0.6831)
                /// 2RAN : ANM(0.43) -> 0.4072) : STeM(0.31) -> 0.3138)
                /// 2RHE : ANM(0.28) -> 0.2074) : STeM(0.33) -> 0.3317)
                /// 2RN2 : ANM(0.68) -> 0.6555) : STeM(0.75) -> 0.7478)
                /// 2SIL : ANM(0.43) -> 0.4203) : STeM(0.51) -> 0.5127)
                /// 2TGI : ANM(0.69) -> 0.6787) : STeM(0.73) -> 0.7391)
                /// 3CHY : ANM(0.61) -> 0.5572) : STeM(0.68) -> 0.6885)
                /// 3COX : ANM(0.71) -> 0.6925) : STeM(0.72) -> 0.7179)
                /// 3EBX : ANM(0.22) -> 0.1913) : STeM(0.40) -> 0.3871)
                /// 3GRS : ANM(0.44) -> 0.4431) : STeM(0.59) -> 0.5910)
                /// 3LZM : ANM(0.60) -> 0.5867) : STeM(0.66) -> 0.6567)
                /// 3PTE : ANM(0.68) -> 0.6788) : STeM(0.77) -> 0.7688)
                /// 4FGF : ANM(0.41) -> 0.3695) : STeM(0.43) -> 0.4166)
                /// 4GCR : ANM(0.73) -> 0.7077) : STeM(0.75) -> 0.7258)
                /// 4MT2 : ANM(0.42) -> 0.3117) : STeM(0.46) -> 0.4547)
                /// 5P21 : ANM(0.40) -> 0.3540) : STeM(0.45) -> 0.4521)
                /// 7RSA : ANM(0.42) -> 0.4663) : STeM(0.59) -> 0.5938)
                /// 8ABP : ANM(0.61) -> 0.6265) : STeM(0.62) -> 0.6182)
                #endregion
            }
Exemplo n.º 29
0
            public static bool SelfTest_1AAC()
            {
                Pdb.Atom[] atoms_ca = new Pdb.Atom[]
                {
                    #region 1AAC text of CA atoms
                    Pdb.Atom.FromString("ATOM      2  CA  ASP A   1      25.378 -18.141  21.012  1.00 23.28           C  "),
                    Pdb.Atom.FromString("ATOM     10  CA  LYS A   2      24.390 -18.799  17.407  1.00 12.32           C  "),
                    Pdb.Atom.FromString("ATOM     19  CA  ALA A   3      25.772 -15.617  15.840  1.00 10.31           C  "),
                    Pdb.Atom.FromString("ATOM     24  CA  THR A   4      28.837 -13.442  16.439  1.00  9.47           C  "),
                    Pdb.Atom.FromString("ATOM     31  CA  ILE A   5      28.913  -9.665  15.865  1.00  7.94           C  "),
                    Pdb.Atom.FromString("ATOM     39  CA  PRO A   6      31.906  -8.243  13.886  1.00  8.02           C  "),
                    Pdb.Atom.FromString("ATOM     46  CA  SER A   7      31.049  -4.632  14.810  1.00  7.70           C  "),
                    Pdb.Atom.FromString("ATOM     52  CA  GLU A   8      28.768  -3.589  17.658  1.00 10.01           C  "),
                    Pdb.Atom.FromString("ATOM     73  CA  PRO A  10      26.932   0.412  12.498  1.00  7.09           C  "),
                    Pdb.Atom.FromString("ATOM     80  CA  PHE A  11      29.488   1.217   9.844  1.00  6.81           C  "),
                    Pdb.Atom.FromString("ATOM     91  CA  ALA A  12      29.431   2.815   6.390  1.00  6.76           C  "),
                    Pdb.Atom.FromString("ATOM     96  CA  ALA A  13      28.012   1.036   3.320  1.00  8.60           C  "),
                    Pdb.Atom.FromString("ATOM    101  CA  ALA A  14      31.392   1.654   1.659  1.00 11.18           C  "),
                    Pdb.Atom.FromString("ATOM    106  CA  GLU A  15      33.092  -0.407   4.404  1.00  9.76           C  "),
                    Pdb.Atom.FromString("ATOM    115  CA  VAL A  16      31.115  -3.590   3.763  1.00 12.85           C  "),
                    Pdb.Atom.FromString("ATOM    122  CA  ALA A  17      33.429  -6.584   3.205  1.00 20.32           C  "),
                    Pdb.Atom.FromString("ATOM    127  CA  ASP A  18      34.080  -7.894  -0.306  1.00 27.64           C  "),
                    Pdb.Atom.FromString("ATOM    135  CA  GLY A  19      31.708 -10.634  -1.313  1.00 26.92           C  "),
                    Pdb.Atom.FromString("ATOM    139  CA  ALA A  20      29.393  -9.683   1.528  1.00 19.57           C  "),
                    Pdb.Atom.FromString("ATOM    144  CA  ILE A  21      25.881 -11.238   1.583  1.00 11.70           C  "),
                    Pdb.Atom.FromString("ATOM    152  CA  VAL A  22      23.847  -8.061   1.553  1.00  7.77           C  "),
                    Pdb.Atom.FromString("ATOM    159  CA  VAL A  23      20.196  -7.501   2.410  1.00  6.37           C  "),
                    Pdb.Atom.FromString("ATOM    166  CA  ASP A  24      19.093  -3.982   1.466  1.00  6.66           C  "),
                    Pdb.Atom.FromString("ATOM    174  CA  ILE A  25      16.500  -2.121   3.513  1.00  7.21           C  "),
                    Pdb.Atom.FromString("ATOM    182  CA  ALA A  26      14.398   0.375   1.556  1.00  8.41           C  "),
                    Pdb.Atom.FromString("ATOM    187  CA  LYS A  27      10.724   1.489   1.214  1.00  9.80           C  "),
                    Pdb.Atom.FromString("ATOM    201  CA  MET A  28      10.147   0.295   4.838  1.00  8.69           C  "),
                    Pdb.Atom.FromString("ATOM    209  CA  LYS A  29      10.882  -3.362   4.004  1.00  9.09           C  "),
                    Pdb.Atom.FromString("ATOM    223  CA  TYR A  30      13.753  -5.845   4.132  1.00  6.32           C  "),
                    Pdb.Atom.FromString("ATOM    235  CA  GLU A  31      14.275  -6.364   0.381  1.00  9.00           C  "),
                    Pdb.Atom.FromString("ATOM    244  CA  THR A  32      15.144 -10.026   0.769  1.00  7.30           C  "),
                    Pdb.Atom.FromString("ATOM    251  CA  PRO A  33      12.722 -11.107   3.546  1.00  8.68           C  "),
                    Pdb.Atom.FromString("ATOM    258  CA  GLU A  34      13.757 -14.780   3.406  1.00  9.28           C  "),
                    Pdb.Atom.FromString("ATOM    267  CA  LEU A  35      17.468 -15.255   2.972  1.00  7.34           C  "),
                    Pdb.Atom.FromString("ATOM    275  CA  HIS A  36      19.181 -18.672   2.822  1.00  6.97           C  "),
                    Pdb.Atom.FromString("ATOM    285  CA  VAL A  37      22.841 -18.828   3.840  1.00  7.29           C  "),
                    Pdb.Atom.FromString("ATOM    292  CA  LYS A  38      25.361 -21.456   5.044  1.00  9.55           C  "),
                    Pdb.Atom.FromString("ATOM    306  CA  VAL A  39      26.828 -21.965   8.529  1.00  9.09           C  "),
                    Pdb.Atom.FromString("ATOM    313  CA  GLY A  40      29.717 -19.533   8.887  1.00  8.81           C  "),
                    Pdb.Atom.FromString("ATOM    317  CA  ASP A  41      28.343 -16.891   6.520  1.00  8.19           C  "),
                    Pdb.Atom.FromString("ATOM    325  CA  THR A  42      28.196 -13.227   7.468  1.00  7.95           C  "),
                    Pdb.Atom.FromString("ATOM    332  CA  VAL A  43      24.989 -11.395   6.512  1.00  6.02           C  "),
                    Pdb.Atom.FromString("ATOM    339  CA  THR A  44      25.158  -7.607   6.224  1.00  5.34           C  "),
                    Pdb.Atom.FromString("ATOM    346  CA  TRP A  45      22.054  -5.421   6.244  1.00  4.51           C  "),
                    Pdb.Atom.FromString("ATOM    360  CA  ILE A  46      22.453  -1.974   4.623  1.00  5.55           C  "),
                    Pdb.Atom.FromString("ATOM    368  CA  ASN A  47      19.890   0.774   5.248  1.00  6.52           C  "),
                    Pdb.Atom.FromString("ATOM    376  CA  ARG A  48      19.350   2.559   1.939  1.00 10.21           C  "),
                    Pdb.Atom.FromString("ATOM    387  CA  GLU A  49      16.823   5.111   3.196  1.00 12.44           C  "),
                    Pdb.Atom.FromString("ATOM    396  CA  ALA A  50      16.764   8.058   5.564  1.00 13.39           C  "),
                    Pdb.Atom.FromString("ATOM    401  CA  MET A  51      14.386   6.508   8.133  1.00 12.52           C  "),
                    Pdb.Atom.FromString("ATOM    409  CA  PRO A  52      16.509   4.566  10.725  1.00  9.20           C  "),
                    Pdb.Atom.FromString("ATOM    416  CA  HIS A  53      16.032   0.778  10.889  1.00  6.43           C  "),
                    Pdb.Atom.FromString("ATOM    426  CA  ASN A  54      17.658  -2.107  12.766  1.00  5.06           C  "),
                    Pdb.Atom.FromString("ATOM    434  CA  VAL A  55      17.296  -5.891  13.052  1.00  5.44           C  "),
                    Pdb.Atom.FromString("ATOM    441  CA  HIS A  56      15.979  -7.379  16.316  1.00  4.53           C  "),
                    Pdb.Atom.FromString("ATOM    451  CA  PHE A  57      15.920 -11.061  17.243  1.00  5.94           C  "),
                    Pdb.Atom.FromString("ATOM    462  CA  VAL A  58      13.932 -11.794  20.435  1.00  7.60           C  "),
                    Pdb.Atom.FromString("ATOM    469  CA  ALA A  59      15.316 -13.765  23.405  1.00  7.37           C  "),
                    Pdb.Atom.FromString("ATOM    474  CA  GLY A  60      16.074 -17.393  22.787  1.00  9.00           C  "),
                    Pdb.Atom.FromString("ATOM    478  CA  VAL A  61      16.521 -17.029  18.997  1.00  8.51           C  "),
                    Pdb.Atom.FromString("ATOM    485  CA  LEU A  62      20.244 -16.290  18.543  1.00  9.65           C  "),
                    Pdb.Atom.FromString("ATOM    493  CA  GLY A  63      21.156 -16.644  22.197  1.00 10.26           C  "),
                    Pdb.Atom.FromString("ATOM    497  CA  GLU A  64      19.729 -16.413  25.651  1.00  9.18           C  "),
                    Pdb.Atom.FromString("ATOM    506  CA  ALA A  65      19.129 -12.671  25.468  1.00  8.86           C  "),
                    Pdb.Atom.FromString("ATOM    511  CA  ALA A  66      17.408 -10.687  22.723  1.00  7.22           C  "),
                    Pdb.Atom.FromString("ATOM    516  CA  LEU A  67      19.808  -9.283  20.128  1.00  9.01           C  "),
                    Pdb.Atom.FromString("ATOM    524  CA  LYS A  68      18.504  -5.777  19.473  1.00 10.06           C  "),
                    Pdb.Atom.FromString("ATOM    533  CA  GLY A  69      20.805  -4.416  16.788  1.00  8.06           C  "),
                    Pdb.Atom.FromString("ATOM    537  CA  PRO A  70      21.868  -0.715  16.656  1.00  8.23           C  "),
                    Pdb.Atom.FromString("ATOM    544  CA  MET A  71      19.807   1.769  14.640  1.00  8.56           C  "),
                    Pdb.Atom.FromString("ATOM    552  CA  MET A  72      21.337   2.189  11.156  1.00  8.26           C  "),
                    Pdb.Atom.FromString("ATOM    560  CA  LYS A  73      21.086   5.638   9.601  1.00  9.59           C  "),
                    Pdb.Atom.FromString("ATOM    574  CA  LYS A  74      21.097   6.084   5.777  1.00  9.46           C  "),
                    Pdb.Atom.FromString("ATOM    588  CA  GLU A  75      23.892   4.149   4.097  1.00  9.45           C  "),
                    Pdb.Atom.FromString("ATOM    602  CA  GLN A  76      24.997   2.451   7.267  1.00  6.02           C  "),
                    Pdb.Atom.FromString("ATOM    611  CA  ALA A  77      25.416  -1.310   7.631  1.00  5.75           C  "),
                    Pdb.Atom.FromString("ATOM    616  CA  TYR A  78      25.448  -3.978  10.318  1.00  4.90           C  "),
                    Pdb.Atom.FromString("ATOM    628  CA  SER A  79      26.700  -7.612  10.117  1.00  5.13           C  "),
                    Pdb.Atom.FromString("ATOM    634  CA  LEU A  80      26.024 -10.884  11.899  1.00  5.65           C  "),
                    Pdb.Atom.FromString("ATOM    642  CA  THR A  81      27.969 -14.123  11.320  1.00  6.53           C  "),
                    Pdb.Atom.FromString("ATOM    649  CA  PHE A  82      25.693 -17.171  11.780  1.00  5.24           C  "),
                    Pdb.Atom.FromString("ATOM    660  CA  THR A  83      27.363 -20.163  13.449  1.00  6.79           C  "),
                    Pdb.Atom.FromString("ATOM    667  CA  GLU A  84      24.599 -22.785  13.726  1.00  6.27           C  "),
                    Pdb.Atom.FromString("ATOM    676  CA  ALA A  85      21.975 -24.045  11.260  1.00  7.61           C  "),
                    Pdb.Atom.FromString("ATOM    681  CA  GLY A  86      18.324 -23.142  11.886  1.00  7.35           C  "),
                    Pdb.Atom.FromString("ATOM    685  CA  THR A  87      15.680 -20.519  11.055  1.00  8.50           C  "),
                    Pdb.Atom.FromString("ATOM    692  CA  TYR A  88      16.009 -17.145  12.731  1.00  7.35           C  "),
                    Pdb.Atom.FromString("ATOM    704  CA  ASP A  89      13.191 -14.620  12.557  1.00  7.28           C  "),
                    Pdb.Atom.FromString("ATOM    712  CA  TYR A  90      13.740 -10.922  13.122  1.00  5.26           C  "),
                    Pdb.Atom.FromString("ATOM    724  CA  HIS A  91      11.902  -7.619  12.935  1.00  4.80           C  "),
                    Pdb.Atom.FromString("ATOM    734  CA  CYS A  92      12.663  -3.894  13.049  1.00  5.44           C  "),
                    Pdb.Atom.FromString("ATOM    740  CA  THR A  93      12.228  -2.579  16.647  1.00  6.60           C  "),
                    Pdb.Atom.FromString("ATOM    747  CA  PRO A  94      10.460   0.815  15.821  1.00  7.51           C  "),
                    Pdb.Atom.FromString("ATOM    754  CA  HIS A  95       8.594  -0.728  12.857  1.00  7.46           C  "),
                    Pdb.Atom.FromString("ATOM    764  CA  PRO A  96       7.518  -4.286  13.932  1.00  7.59           C  "),
                    Pdb.Atom.FromString("ATOM    771  CA  PHE A  97       5.480  -4.778  10.739  1.00  7.30           C  "),
                    Pdb.Atom.FromString("ATOM    782  CA  MET A  98       8.923  -5.104   8.994  1.00  6.57           C  "),
                    Pdb.Atom.FromString("ATOM    790  CA  ARG A  99       9.707  -8.821   9.391  1.00  7.91           C  "),
                    Pdb.Atom.FromString("ATOM    808  CA  GLY A 100      12.343 -11.105   7.827  1.00  6.39           C  "),
                    Pdb.Atom.FromString("ATOM    812  CA  LYS A 101      14.085 -14.438   8.459  1.00  7.31           C  "),
                    Pdb.Atom.FromString("ATOM    826  CA  VAL A 102      17.523 -15.900   7.870  1.00  6.58           C  "),
                    Pdb.Atom.FromString("ATOM    833  CA  VAL A 103      17.552 -19.658   7.157  1.00  7.20           C  "),
                    Pdb.Atom.FromString("ATOM    840  CA  VAL A 104      21.061 -21.012   7.897  1.00  7.28           C  "),
                    Pdb.Atom.FromString("ATOM    847  CA  GLU A 105      21.699 -24.347   6.221  1.00 13.74           C  "),
                    #endregion
                };
                Pdb.Atom[] atoms_r6 = new Pdb.Atom[]
                {
                    Pdb.Atom.FromString("ATOM     42  CB  PRO A   6      31.929  -8.271  12.386  1.00  7.98           C  "),
                    Pdb.Atom.FromString("ATOM     43  CG  PRO A   6      30.972  -9.378  12.022  1.00  9.48           C  "),
                    Pdb.Atom.FromString("ATOM     44  CD  PRO A   6      29.880  -9.313  13.099  1.00  8.27           C  "),
                };

                {
                    HessMatrix hess = GetHessCa(atoms_ca.ListCoord());

                    InfoPack extra = new InfoPack();
                    //Vector bfactors = ENM.BFactorFromHessian(hess, null, 6, extra);
                    Vector bfactors          = Hess.GetBFactor(hess, null, 6, extra);
                    Vector eigvals           = (double[])extra["eigenvalues"];
                    int[]  idxsorted_eigvals = eigvals.ToArray().HAbs().HIdxSorted();
                    for (int i = 0; i < 6; i++)
                    {
                        eigvals[idxsorted_eigvals[i]] = 0;
                    }
                    for (int i = 0; i < eigvals.Size; i++)
                    {
                        if (eigvals[i] < 0)
                        {
                            // return false, if there exists negative eigenvalue
                            HDebug.Assert(false);
                            return(false);
                        }
                    }
                }
                {
                    List <Pdb.Atom> atoms = new List <Pdb.Atom>();
                    atoms.AddRange(atoms_ca);
                    atoms.AddRange(atoms_r6);
                    HDebug.Assert(atoms[5].resSeq == 6);

                    List <int> idxs_ca = new List <int>(); for (int i = 0; i < atoms_ca.Length; i++)
                    {
                        idxs_ca.Add(i);
                    }
                    List <int> idxs_r6 = new List <int>(); for (int i = atoms_ca.Length; i < atoms.Count; i++)
                    {
                        idxs_r6.Add(i);
                    }
                    idxs_r6.InsertRange(0, new int[] { 3, 4, 5 });

                    List <Tuple <int, int> > list12 = new List <Tuple <int, int> >();
                    for (int i = 1; i < idxs_ca.Count; i++)
                    {
                        list12.Add(new Tuple <int, int>(idxs_ca[i - 1], idxs_ca[i]));
                    }
                    for (int i = 3; i < idxs_r6.Count; i++)
                    {
                        list12.Add(new Tuple <int, int>(idxs_r6[i - 1], idxs_r6[i]));
                    }

                    List <Tuple <int, int, int> > list123 = new List <Tuple <int, int, int> >();
                    for (int i = 2; i < idxs_ca.Count; i++)
                    {
                        list123.Add(new Tuple <int, int, int>(idxs_ca[i - 2], idxs_ca[i - 1], idxs_ca[i]));
                    }
                    for (int i = 3; i < idxs_r6.Count; i++)
                    {
                        list123.Add(new Tuple <int, int, int>(idxs_r6[i - 2], idxs_r6[i - 1], idxs_r6[i]));
                    }

                    List <Tuple <int, int, int, int> > list1234 = new List <Tuple <int, int, int, int> >();
                    for (int i = 3; i < idxs_ca.Count; i++)
                    {
                        list1234.Add(new Tuple <int, int, int, int>(idxs_ca[i - 3], idxs_ca[i - 2], idxs_ca[i - 1], idxs_ca[i]));
                    }
                    for (int i = 3; i < idxs_r6.Count; i++)
                    {
                        list1234.Add(new Tuple <int, int, int, int>(idxs_r6[i - 3], idxs_r6[i - 2], idxs_r6[i - 1], idxs_r6[i]));
                    }

                    List <Tuple <int, int> > listNonbond = new List <Tuple <int, int> >();
                    for (int i = 0; i < idxs_ca.Count; i++)
                    {
                        for (int j = i + 4; j < idxs_ca.Count; j++)
                        {
                            listNonbond.Add(new Tuple <int, int>(idxs_ca[i], idxs_ca[j]));
                        }
                    }
                    for (int i = 0; i < idxs_r6.Count; i++)
                    {
                        for (int j = i + 4; j < idxs_r6.Count; j++)
                        {
                            listNonbond.Add(new Tuple <int, int>(idxs_r6[i], idxs_r6[j]));
                        }
                    }

                    List <Vector> coords  = atoms.ListCoord();
                    HessMatrix    hessian = HessMatrixSparse.ZerosSparse(atoms.Count * 3, atoms.Count * 3);

                    double Epsilon = 0.36;
                    double K_r     = 100 * Epsilon;
                    double K_theta = 20 * Epsilon;
                    double K_phi1  = 1 * Epsilon;
                    double K_phi3  = 0.5 * Epsilon;
                    for (int i = 0; i < list12.Count; i++)
                    {
                        FirstTerm(coords, K_r, hessian, list12[i].Item1, list12[i].Item2);
                    }
                    for (int i = 0; i < list123.Count; i++)
                    {
                        SecondTerm(coords, K_theta, hessian, list123[i].Item1, list123[i].Item2, list123[i].Item3);
                    }
                    for (int i = 0; i < list1234.Count; i++)
                    {
                        ThirdTerm(coords, K_phi1, K_phi3, hessian, list1234[i].Item1, list1234[i].Item2, list1234[i].Item3, list1234[i].Item4);
                    }
                    for (int i = 0; i < listNonbond.Count; i++)
                    {
                        FourthTerm(coords, Epsilon, hessian, listNonbond[i].Item1, listNonbond[i].Item2);
                    }

                    InfoPack extra = new InfoPack();
                    //Vector bfactors = ENM.BFactorFromHessian(hessian, null, 6, extra);
                    Vector bfactors          = Hess.GetBFactor(hessian, null, 6, extra);
                    Vector eigvals           = (double[])extra["eigenvalues"];
                    int[]  idxsorted_eigvals = eigvals.ToArray().HAbs().HIdxSorted();
                    for (int i = 0; i < 6; i++)
                    {
                        eigvals[idxsorted_eigvals[i]] = 0;
                    }
                    for (int i = 0; i < eigvals.Size; i++)
                    {
                        if (eigvals[i] < 0)
                        {
                            // return false, if there exists negative eigenvalue
                            HDebug.Assert(false);
                            return(false);
                        }
                    }
                }
                //{
                //    Debug.Assert(atoms_ca[5].resSeq == 6);
                //    Pdb.Atom[] atoms_resi6 = new Pdb.Atom[]
                //        {
                //            atoms_ca[5],
                //            Pdb.Atom.FromString("ATOM     42  CB  PRO A   6      31.929  -8.271  12.386  1.00  7.98           C  "),
                //            Pdb.Atom.FromString("ATOM     43  CG  PRO A   6      30.972  -9.378  12.022  1.00  9.48           C  "),
                //            Pdb.Atom.FromString("ATOM     44  CD  PRO A   6      29.880  -9.313  13.099  1.00  8.27           C  "),
                //        };
                //    Matrix hess_ca = GetHessCa(atoms_ca.ListCoord());
                //    Matrix hess_resi6 = GetHessCa(atoms_resi6.ListCoord());
                //
                //    int size_ca = atoms_ca.Length;
                //    int size_r6 = atoms_resi6.Length - 1;
                //    Matrix hess = new double[(size_ca+size_r6)*3,(size_ca+size_r6)*3];
                //    for(int c = 0; c < hess.ColSize; c++)
                //        for(int r = 0; r < hess.RowSize; r++)
                //            hess[c, r] = double.NaN;
                //    for(int c = 0; c < hess_ca.ColSize; c++)
                //        for(int r = 0; r < hess_ca.RowSize; r++)
                //            hess[c, r] = hess_ca[c, r];
                //    for(int c = 0; c < hess_resi6.ColSize; c++)
                //        for(int r = 0; r < hess_resi6.RowSize; r++)
                //        {
                //                 if(c <  3 && r <  3) { int c0=5      *3+ c   ; int r0=5      *3+ r   ; Debug.Assert(double.IsNaN(hess[c0, r0]) ==false); hess[c0, r0] = hess_resi6[c, r]; }
                //            else if(c <  3 && r >= 3) { int c0=5      *3+ c   ; int r0=size_ca*3+(r-3); Debug.Assert(double.IsNaN(hess[c0, r0]) == true); hess[c0, r0] = hess_resi6[c, r]; }
                //            else if(c >= 3 && r <  3) { int c0=size_ca*3+(c-3); int r0=5      *3+ r   ; Debug.Assert(double.IsNaN(hess[c0, r0]) == true); hess[c0, r0] = hess_resi6[c, r]; }
                //            else if(c >= 3 && r >= 3) { int c0=size_ca*3+(c-3); int r0=size_ca*3+(r-3); Debug.Assert(double.IsNaN(hess[c0, r0]) == true); hess[c0, r0] = hess_resi6[c, r]; }
                //            else Debug.Assert(false);
                //        }
                //    for(int j = size_ca * 3; j < (size_ca + size_r6) * 3; j++)
                //    {
                //        for(int i = 0; i < 5*3; i++)
                //        {
                //            Debug.Assert(double.IsNaN(hess[i, j]) == true); hess[i, j] = 0;
                //            Debug.Assert(double.IsNaN(hess[j, i]) == true); hess[j, i] = 0;
                //        }
                //        for(int i = 6*3; i < size_ca * 3; i++)
                //        {
                //            Debug.Assert(double.IsNaN(hess[i, j]) == true); hess[i, j] = 0;
                //            Debug.Assert(double.IsNaN(hess[j, i]) == true); hess[j, i] = 0;
                //        }
                //    }
                //    for(int c = 0; c < hess.ColSize; c++)
                //        for(int r = 0; r < hess.RowSize; r++)
                //            Debug.Assert(double.IsNaN(hess[c, r]) == false);
                //
                //    InfoPack extra = new InfoPack();
                //    Vector bfactors = ENM.BFactorFromHessian(hess, null, 6, extra);
                //    Vector eigvals = (double[])extra["eigenvalues"];
                //    int[] idxsorted_eigvals = eigvals.ToArray().Abs().IdxSorted();
                //    for(int i = 0; i < 6; i++) eigvals[idxsorted_eigvals[i]] = 0;
                //    for(int i = 0; i < eigvals.Size; i++)
                //        if(eigvals[i] < 0)
                //        {
                //            // return false, if there exists negative eigenvalue
                //            Debug.Assert(false);
                //            return false;
                //        }
                //}

                return(true);
            }
                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));
                    }
                }