//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)); }