Ejemplo n.º 1
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);
                }
            }
Ejemplo n.º 2
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);
                }
            }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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,
            });
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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,
            });
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
            }
                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);
                    }
                }
Ejemplo n.º 12
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
            }