public bool CheckModeWithHess(MatrixByArr hess, double[] masses, ILinAlg la, Mode[] modes = null, double tolerance = 0.00001) { if (modes == null) { modes = ToModes(masses); } HessMatrix ohess = new HessMatrixDense { hess = modes.GetHessian(masses, la), }; double corr = HMath.HCorr(hess.ToArray().HToArray1D(), ohess.ToArray().HToArray1D()); System.Console.Write("corr(TestHess,HessVibr:{0} ", corr); { HDebug.Assert(hess.ColSize == ohess.ColSize); HDebug.Assert(hess.RowSize == ohess.RowSize); double ltolerance = hess.ToArray().HAbs().HMax() * tolerance; ltolerance = tolerance; for (int c = 0; c < ohess.ColSize; c++) { for (int r = 0; r < ohess.RowSize; r++) { double v = hess[c, r]; double mwv = ohess[c, r]; double diff = Math.Abs(v - mwv); if (diff >= ltolerance) { return(false); } } } } //{ // Matrix vhess = hess / hess.ToArray().HToArray1D().HVar(); // Matrix vohess = ohess / ohess.ToArray().HToArray1D().HVar(); // // HDebug.Assert(hess.ColSize == ohess.ColSize); // HDebug.Assert(hess.RowSize == ohess.RowSize); // HDebug.Assert(vhess.Size == vohess.Size); // for(int c=0; c<vhess.ColSize; c++) // for(int r=0; r<vhess.RowSize; r++) // { // double v = vhess[c,r]; // double vo = vohess[c,r]; // double diff = Math.Abs(v - vo); // if(diff >= tolerance) // { // HDebug.Assert(false); // return false; // } // } //} return(true); }
public static double[] GetRotAngles(Universe univ , Vector[] coords , Vector[] dcoords , MatrixByArr J = null , Graph <Universe.Atom[], Universe.Bond> univ_flexgraph = null , List <Universe.RotableInfo> univ_rotinfos = null , Vector[] dcoordsRotated = null ) { if (J == null) { if (univ_rotinfos == null) { if (univ_flexgraph == null) { univ_flexgraph = univ.BuildFlexibilityGraph(); } univ_rotinfos = univ.GetRotableInfo(univ_flexgraph); } J = TNM.GetJ(univ, coords, univ_rotinfos); } double[] dangles; using (new Matlab.NamedLock("TEST")) { Matlab.Clear("TEST"); Matlab.PutVector("TEST.R", Vector.FromBlockvector(dcoords)); Matlab.PutMatrix("TEST.J", J.ToArray(), true); Matlab.PutVector("TEST.M", univ.GetMasses(3)); Matlab.Execute("TEST.M = diag(TEST.M);"); Matlab.Execute("TEST.invJMJ = inv(TEST.J' * TEST.M * TEST.J);"); Matlab.Execute("TEST.A = TEST.invJMJ * TEST.J' * TEST.M * TEST.R;"); // (6) of TNM paper dangles = Matlab.GetVector("TEST.A"); if (dcoordsRotated != null) { HDebug.Assert(dcoordsRotated.Length == dcoords.Length); Matlab.Execute("TEST.dR = TEST.J * TEST.A;"); Vector ldcoordsRotated = Matlab.GetVector("TEST.dR"); HDebug.Assert(ldcoordsRotated.Size == dcoordsRotated.Length * 3); for (int i = 0; i < dcoordsRotated.Length; i++) { int i3 = i * 3; dcoordsRotated[i] = new double[] { ldcoordsRotated[i3 + 0], ldcoordsRotated[i3 + 1], ldcoordsRotated[i3 + 2] }; } } Matlab.Clear("TEST"); } return(dangles); }
public static void ToFile(string filepath , IList <Atom> atoms , IList <Vector> coords = null , IList <MatrixByArr> anisous = null , double?anisouScale = null , IList <double> bfactors = null , bool append = false , IList <string> headers = null , int?modelidx = null ) { List <string> lines = new List <string>(); int size = atoms.Count; if (coords != null) { HDebug.Assert(size == coords.Count); } if (anisous != null) { HDebug.Assert(size == anisous.Count); } //if(anisouScale != null) Debug.Assert(size == anisouScale.Count); if (headers != null) { lines.AddRange(headers); } { // 1 2 3 4 5 6 7 8 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 // "MODEL 1 " string line = "MODEL 1 "; if (modelidx != null) { line.Replace("1", modelidx.Value.ToString()); } line = line.Substring(0, 80); lines.Add(line); } for (int i = 0; i < size; i++) { Atom atom = atoms[i]; if (atom == null) { continue; } { if (coords != null) { double x = coords[i][0]; double y = coords[i][1]; double z = coords[i][2]; atom = Atom.FromString(atom.GetUpdatedLine(x, y, z)); } if (bfactors != null) { atom = Atom.FromString(atom.GetUpdatedLineTempFactor(bfactors[i])); } lines.Add(atom.line); } { if (anisous != null) { MatrixByArr U = anisous[i]; if (anisouScale != null) { U = U * anisouScale.Value; } Anisou anisou = Anisou.FromAtom(atom, U.ToArray().HToInt()); string line = anisou.line; //anisou.GetUpdatedU(anisous[i]) lines.Add(line); } } } lines.Add("ENDMDL "); //int idx = 0; //foreach(Element element in elements) //{ // string line = element.line; // if(typeof(Atom).IsInstanceOfType(element)) // { // double x = coords[idx][0]; // double y = coords[idx][1]; // double z = coords[idx][2]; // Atom atom = (Atom)element; // line = atom.GetUpdatedLine(x, y, z); // idx++; // } // lines.Add(line); //} if (append == false) { HFile.WriteAllLines(filepath, lines); } else { StringBuilder text = new StringBuilder(); foreach (string line in lines) { text.AppendLine(line); } HFile.AppendAllText(filepath, text.ToString()); } }