public static CTestgrad Testgrad(string testgradpath , Tinker.Xyz xyz , Tinker.Prm prm , string tempbase //=null , string[] keys , Dictionary <string, string[]> optOutSource // = null ) { var tmpdir = HDirectory.CreateTempDirectory(tempbase); string currpath = HEnvironment.CurrentDirectory; CTestgrad testgrad; { HEnvironment.CurrentDirectory = tmpdir.FullName; if (testgradpath == null) { string resbase = "HTLib2.Bioinfo.HTLib2.Bioinfo.External.Tinker.Resources.tinker_6_2_06."; HResource.CopyResourceTo <Tinker>(resbase + "testgrad.exe", "testgrad.exe"); testgradpath = "testgrad.exe"; } xyz.ToFile("test.xyz", false); prm.ToFile("test.prm"); string keypath = null; if (keys != null && keys.Length > 0) { keypath = "test.key"; HFile.WriteAllLines(keypath, keys); } testgrad = TestgradImpl(testgradpath, "test.xyz", "test.prm", keypath, optOutSource); } HEnvironment.CurrentDirectory = currpath; try{ tmpdir.Delete(true); } catch {} return(testgrad); }
public static CTesthess Testhess (string testhesspath , Tinker.Xyz xyz , Tinker.Prm prm , string tempbase //=null , string[] keys , Dictionary <string, string[]> optOutSource // =null , Func <int, int, HessMatrix> HessMatrixZeros // =null ) { var tmpdir = HDirectory.CreateTempDirectory(tempbase); string currpath = HEnvironment.CurrentDirectory; CTesthess testhess; { HEnvironment.CurrentDirectory = tmpdir.FullName; if (testhesspath == null) { string resbase = "HTLib2.Bioinfo.HTLib2.Bioinfo.External.Tinker.Resources.tinker_6_2_01."; HResource.CopyResourceTo <Tinker>(resbase + "testhess.exe", "testhess.exe"); testhesspath = "testhess.exe"; } xyz.ToFile("test.xyz", false); prm.ToFile("test.prm"); string keypath = null; if ((keys != null) && (keys.Length > 0)) { keypath = "test.key"; HFile.WriteAllLines(keypath, keys); } testhess = Testhess(testhesspath, "test.xyz", "test.prm", keypath, optOutSource, HessMatrixZeros); testhess.xyz = xyz; testhess.prm = prm; } HEnvironment.CurrentDirectory = currpath; try{ tmpdir.Delete(true); } catch {} string test_eig = "true"; if (test_eig == "false") { Vector D; using (new Matlab.NamedLock("")) { Matlab.PutSparseMatrix("testeig.H", testhess.hess.GetMatrixSparse(), 3, 3); Matlab.Execute("testeig.H = (testeig.H + testeig.H')/2;"); Matlab.Execute("[testeig.V, testeig.D] = eig(full(testeig.H));"); Matlab.Execute("testeig.D = diag(testeig.D);"); D = Matlab.GetVector("testeig.D"); Matlab.Execute("clear testeig;"); } } return(testhess); }
public static ONewton Newton(string tinkerpath , Tinker.Xyz xyz , Tinker.Xyz.Atom.Format xyz_atoms_format , Tinker.Prm prm , string tempbase , string copytemp // = null , string param //, string precondition // = "A" // Precondition via Auto/None/Diag/Block/SSOR/ICCG [A] : A //, double gradCriterion // = 0.01 // Enter RMS Gradient per Atom Criterion [0.01] : 0.001 , IList <Tinker.Xyz.Atom> atomsToFix // = null , bool pause // = false , params string[] keys ) { if (HDebug.IsDebuggerAttached && atomsToFix != null) { Dictionary <int, Tinker.Xyz.Atom> xyzatoms = xyz.atoms.ToIdDictionary(); foreach (var atom in atomsToFix) { HDebug.Assert(object.ReferenceEquals(atom, xyzatoms[atom.Id])); } } Tinker.Xyz minxyz; string[] minlog; using (var temp = new HTempDirectory(tempbase, copytemp)) { temp.EnterTemp(); if (tinkerpath == null) { string resbase = "HTLib2.Bioinfo.HTLib2.Bioinfo.External.Tinker.Resources.tinker_6_2_06."; HResource.CopyResourceTo <Tinker>(resbase + "newton.exe", "newton.exe"); tinkerpath = "newton.exe"; } xyz.ToFile("prot.xyz", false); prm.ToFile("prot.prm"); List <string> keylines = new List <string>(keys); if (atomsToFix != null) { foreach (var atom in atomsToFix) { Vector coord = atom.Coord; double force_constant = 10000; // force constant in kcal/Å2 for the harmonic restraint potential string keyline = string.Format("RESTRAIN-POSITION {0} {1} {2} {3} {4}", atom.Id, coord[0], coord[1], coord[2], force_constant); keylines.Add(keyline); } } HFile.WriteAllLines("prot.key", keylines); // Precondition via Auto/None/Diag/Block/SSOR/ICCG [A] : A // Enter RMS Gradient per Atom Criterion [0.01] : 0.001 //bool pause = false; string command = tinkerpath; command += string.Format(" prot.xyz prot.prm"); command += string.Format(" -k prot.key"); command += string.Format(" {0}", param); HProcess.StartAsBatchInConsole("newton.bat", pause , "time /t >> prot.log" , command //+" >> prot.log" , "time /t >> prot.log" ); HDebug.Assert(HFile.Exists("prot.xyz_2")); HDebug.Assert(HFile.Exists("prot.xyz_3") == false); minxyz = Tinker.Xyz.FromFile("prot.xyz_2", false, xyz_atoms_format); minlog = HFile.ReadAllLines("prot.log"); temp.QuitTemp(); } return(new ONewton { minxyz = minxyz, minlog = minlog }); }
public static OMinimize Minimize(string minimizepath , Tinker.Xyz xyz , Tinker.Xyz.Atom.Format xyz_atoms_format , Tinker.Prm prm , string tempbase , string copytemp // = null , string param , IList <Tinker.Xyz.Atom> atomsToFix // = null , bool pause // = false , params string[] keys ) { if (HDebug.IsDebuggerAttached && atomsToFix != null) { Dictionary <int, Tinker.Xyz.Atom> xyzatoms = xyz.atoms.ToIdDictionary(); foreach (var atom in atomsToFix) { HDebug.Assert(object.ReferenceEquals(atom, xyzatoms[atom.Id])); } } Tinker.Xyz minxyz; string[] minlog; using (var temp = new HTempDirectory(tempbase, copytemp)) { temp.EnterTemp(); xyz.ToFile("prot.xyz", false); prm.ToFile("prot.prm"); List <string> keylines = new List <string>(); //if(grdmin != null) //{ // string keyline = string.Format("GRDMIN {0}", grdmin.Value); // keylines.Add(keyline); //} if (atomsToFix != null) { foreach (var atom in atomsToFix) { Vector coord = atom.Coord; double force_constant = 10000; // force constant in kcal/Å2 for the harmonic restraint potential string keyline = string.Format("RESTRAIN-POSITION {0} {1} {2} {3} {4}", atom.Id, coord[0], coord[1], coord[2], force_constant); keylines.Add(keyline); } } if (keys != null) { keylines.AddRange(keys); } HFile.WriteAllLines("prot.key", keylines); // Enter RMS Gradient per Atom Criterion [0.01] : string command = minimizepath; command += " prot.xyz prot.prm"; command += " -k prot.key < param.txt"; HFile.WriteAllLines("param.txt", param.HSplit()); //command += string.Format(" >> prot.log"); HProcess.StartAsBatchInConsole("minimize.bat", pause , "time /t >> prot.log" , command , "time /t >> prot.log" ); HDebug.Assert(HFile.Exists("prot.xyz_2")); HDebug.Assert(HFile.Exists("prot.xyz_3") == false); minxyz = Tinker.Xyz.FromFile("prot.xyz_2", false, xyz.atoms_format); minlog = HFile.ReadAllLines("prot.log"); temp.QuitTemp(); } return(new OMinimize { minxyz = minxyz, minlog = minlog }); }