public static CTestgrad TestgradImpl (string testgradpath , string xyzpath , string prmpath , string keypath //=null , Dictionary <string, string[]> optOutSource // = null ) { { bool ComputeAnalyticalGradientVector = true; bool ComputeNumericalGradientVector = false; bool OutputBreakdownByGradientComponent = false; string command = ""; command += testgradpath; //command += GetProgramPath("testgrad.exe"); command += " " + xyzpath; //command += " " + prmpath; command += " " + (ComputeAnalyticalGradientVector ? "Y" : "N"); command += " " + (ComputeNumericalGradientVector ? "Y" : "N"); command += " " + (OutputBreakdownByGradientComponent ? "Y" : "N"); if (keypath != null) { command += " -k " + keypath; } command += " > output.txt"; bool pause = false; HProcess.StartAsBatchInConsole(null, pause, command); //int exitcode = HProcess.StartAsBatchSilent(null, null, null, command); } return(ReadGrad("output.txt", optOutSource)); }
public static int Exec(string command, params string[] parameters) { HDebug.ToDo(); command = GetProgramPath(command); foreach (string parameter in parameters) { command += " " + parameter; } //int exitcode = HtProcess.StartAsBatchSilent(null, null, null, command); int exitcode = HProcess.StartAsBatchInConsole(null, true, command); HDebug.Assert(false); return(-1); }
public static int Run(string command , string[] commandsNext = null , List <string> lineStderr = null , List <string> lineStdout = null , bool silent_run = true , bool?pause = null //, string batPathToCopy = null ) { List <string> lines = new List <string>(); { lines.Add(@"set GMXLIB=C:\Program Files (x86)\Gromacs\share\gromacs\top"); lines.Add(@"set GMXBIN=C:\Program Files (x86)\Gromacs\bin"); lines.Add(@"set GMXDATA=C:\Program Files (x86)\Gromacs\share"); lines.Add(@"set GMXLDLIB=C:\Program Files (x86)\Gromacs\lib"); lines.Add(@"set GMXMAN=C:\Program Files (x86)\Gromacs\share\man"); lines.Add(command); if (commandsNext != null) { lines.AddRange(commandsNext); } } int exitcode; //bool silent_run = true; if (silent_run) { // int StartAsBatchSilent(string batpath, List<string> lineStdout, List<string> lineStderr, params string[] commands) //exitcode = HProcess.StartAsBatchSilent(batPathToCopy, lineStdout, lineStderr, lines.ToArray()); exitcode = HProcess.StartAsBatchSilent(null, lineStdout, lineStderr, lines.ToArray()); } else { // int StartAsBatchInConsole(string batpath, bool pause=false, params string[] commands) //exitcode = HProcess.StartAsBatchInConsole(batPathToCopy, (pause == null || pause == true), lines.ToArray()); exitcode = HProcess.StartAsBatchInConsole(null, (pause == null || pause == true), lines.ToArray()); } return(exitcode); }
public static CTesthess Testhess (string testhesspath , string xyzpath , string prmpath , string keypath //=null , Dictionary <string, string[]> optOutSource // =null , Func <int, int, HessMatrix> HessMatrixZeros // =null ) { int size; { size = Tinker.Xyz.FromFile(xyzpath, false).atoms.Length; } { //bool ComputeAnalyticalHessianMatrix = true; string command = ""; command += testhesspath; //command += GetProgramPath("testhess.exe"); command += " " + xyzpath; command += " " + prmpath; if (keypath != null) { command += " -k " + keypath; } //command += " " + (ComputeAnalyticalHessianMatrix ? "Y" : "N"); command += " > output.txt"; bool pause = false; HProcess.StartAsBatchInConsole(null, pause, command); //int exitcode = HProcess.StartAsBatchSilent(null, null, null, command); } var testhess = ReadHess(xyzpath, "output.txt", optOutSource, HessMatrixZeros); testhess.prm = Prm.FromFile(prmpath); if (optOutSource != null) { optOutSource.Add("output.txt", HFile.ReadAllLines("output.txt")); } return(testhess); }
public static CPsfgen Psfgen (IList <Tuple <string, string, Pdb.IAtom[]> > lstSegFileAtoms // segname, filename, pdbatoms , string tempbase //=null , string parameters //=null , string namdversion //="2.8" , IList <string> infiles , IList <string> outfiles , string topology , IList <string> psfgen_lines = null , string psfgen_workdir = null , HOptions options = null ) { if (options == null) { options = new HOptions((string)null); } Dictionary <System.IO.FileInfo, string[]> infile_lines = new Dictionary <System.IO.FileInfo, string[]>(); foreach (string infile in infiles) { infile_lines.Add(HFile.GetFileInfo(infile), HFile.ReadAllLines(infile)); } string currpath = HEnvironment.CurrentDirectory; System.IO.DirectoryInfo tmpdir = null; if (psfgen_workdir != null) { HEnvironment.CurrentDirectory = psfgen_workdir; } else { tmpdir = HDirectory.CreateTempDirectory(tempbase); HEnvironment.CurrentDirectory = tmpdir.FullName; } string[] lines = null; if ((psfgen_lines != null) && (psfgen_lines.Count > 0)) { lines = psfgen_lines.ToArray(); } else { lines = GetPsfgenLines (custom_pdbalias: null , custom_patches: null ); } if (topology != null) { lines = lines.ToArray().HReplace("$topology$", topology); } List <string> psf_lines; List <string> pdb_lines; { { //foreach(var respath_filename in GetResourcePaths("2.8", "psfgen")) foreach (var respath_filename in GetResourcePaths(namdversion, "psfgen")) { string respath = respath_filename.Item1; string filename = respath_filename.Item2; HResource.CopyResourceTo <Tinker>(respath, filename); } } // Dictionary<string, Tuple<string, Pdb.IAtom[]>> segname_filename_pdbatoms = new Dictionary<string, Tuple<string, Pdb.IAtom[]>>(); // //if(pdbs.Length != 1) throw new ArgumentException(); // for(int i=0; i<lstSegFilePdb.Count; i++) // { // string segnameprefix = lstSegFilePdb[i].Item1; if( segnameprefix == null) segnameprefix = string.Format("{0:00}", i); // string filenameprefix = lstSegFilePdb[i].Item2; if(filenameprefix == null) filenameprefix = string.Format("{0:00}", i); // Pdb pdb = lstSegFilePdb[i].Item3; // List<Pdb.IAtom> pdb_atoms = new List<Pdb.IAtom>(); // pdb_atoms.AddRange(pdb.atoms); // pdb_atoms.AddRange(pdb.hetatms); // char[] chains = pdb_atoms.ListChainID().HToHashSet().ToArray(); // // HDebug.AssertIf(chains.Length> 1, segnameprefix.Length <= 5); // HDebug.AssertIf(chains.Length<=1, segnameprefix.Length <= 6); // foreach(char chain in chains) // { // Pdb.IAtom[] chain_atoms = pdb_atoms.SelectByChainID(chain).SelectByAltLoc().ToArray(); // string suffix = null; // if(('a' <= chain) && (chain <= 'z')) suffix = string.Format("L{0}", chain); // if(('A' <= chain) && (chain <= 'Z')) suffix = string.Format("U{0}", chain); // if(('0' <= chain) && (chain <= '9')) suffix = string.Format("N{0}", chain); // string segname = segnameprefix + ((chains.Length <= 1) ? "" : suffix); // string filename = filenameprefix + ((chains.Length <= 1) ? "" : suffix); // segname_filename_pdbatoms.Add(segname, new Tuple<string,Pdb.IAtom[]>(filename, chain_atoms)); // } // } foreach (var finfo_line in infile_lines) { string inname = finfo_line.Key.Name; string[] inlines = finfo_line.Value; HFile.WriteAllLines(inname, inlines); } HashSet <string> segnames = new HashSet <string>(); int segindex = 0; foreach (var seg_file_atoms in lstSegFileAtoms) { string segname = seg_file_atoms.Item1; string filename = seg_file_atoms.Item2; Pdb.IAtom[] chain_atoms = seg_file_atoms.Item3.SelectByAltLoc().ToArray(); HDebug.Exception(chain_atoms.ListChainID().HToHashSet().Count == 1); if (segname == null) { while (segindex <= 9999) { if (segnames.Contains(segindex.ToString()) == false) { segname = segindex.ToString(); segnames.Add(segname); break; } segindex++; } } if (filename == null) { filename = segname; } Pdb.ToFile (filename + ".pdb" , chain_atoms.HToType <Pdb.IAtom, Pdb.Element>() , false ); for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains("$segname$")) { string insert = lines[i]; insert = insert.Replace("$segname$", segname); insert = insert.Replace("$segfilename$", filename); lines = lines.HInsert(i, insert); i++; } } } lines = lines.HRemoveAllContains("$segname$"); HFile.WriteAllLines("prot.inp", lines); string command0 = string.Format("psfgen < prot.inp"); bool pause = options.Contains("psfgen pause"); HProcess.StartAsBatchInConsole(null, pause, command0); psf_lines = System.IO.File.ReadLines("prot.psf").ToList(); pdb_lines = System.IO.File.ReadLines("prot.pdb").ToList(); } HEnvironment.CurrentDirectory = currpath; if (tmpdir != null) { try{ tmpdir.Delete(true); } catch {} } return(new CPsfgen { psf_lines = psf_lines, pdb_lines = pdb_lines, }); }
public static CNamd2 Namd2 (IList <string> pdb_lines , IList <string> psf_lines , IList <string> prm_lines , string tempbase // = null , string namd2version // = "2.8" , string option // = "+p3" , IList <string> infiles = null , IList <string> outfiles = null , IList <string> conf_lines = null ) { string[] lines = null; if ((conf_lines != null) && (conf_lines.Count > 0)) { lines = conf_lines.ToArray(); } else { // http://www.msg.ucsf.edu/local/programs/Vega/pages/tu_namdmin.htm lines = new string[] { "numsteps 10000 " // minimization steps //{ "numsteps 1000 " // minimization steps , "minimization on " , "dielectric 1.0 " , "coordinates prot.pdb " // coordinate file , "outputname output " // output file: prot.coor , "outputEnergies 1000 " , "binaryoutput no " , "DCDFreq 1000 " , "restartFreq 1000 " , "structure prot.psf " // psf file , "paraTypeCharmm on " , "parameters prot.prm " // parameter file //, "parameters par_all22_vega.inp " , "exclude scaled1-4 " , "1-4scaling 1.0 " , "switching on " , "switchdist 8.0 " , "cutoff 22.0 " //, "cutoff 12.0 " , "pairlistdist 23.5 " //, "pairlistdist 13.5 " , "margin 0.0 " , "stepspercycle 20 " , "fixedAtoms on " // fix atoms , "fixedAtomsCol O " // select fixing atoms from O }; } var tmpdir = HDirectory.CreateTempDirectory(tempbase); string currpath = HEnvironment.CurrentDirectory; HEnvironment.CurrentDirectory = tmpdir.FullName; string[] coor_lines = null; double coor_rmsd = double.NaN; { { //foreach(var respath_filename in GetResourcePaths("2.8", "psfgen")) foreach (var respath_filename in GetResourcePaths(namd2version, "namd2")) { string respath = respath_filename.Item1; string filename = respath_filename.Item2; HResource.CopyResourceTo <Tinker>(respath, filename); } } Vector[] coords0 = Pdb.FromLines(pdb_lines).atoms.ListCoord().ToArray(); System.IO.File.WriteAllLines("prot.pdb", pdb_lines); System.IO.File.WriteAllLines("prot.psf", psf_lines); System.IO.File.WriteAllLines("prot.prm", prm_lines); System.IO.File.WriteAllLines("prot.conf", lines); if (option == null) { option = ""; } string command = string.Format("namd2 {0} prot.conf", option); HProcess.StartAsBatchInConsole(null, false, command); if (HFile.Exists("output.coor")) { coor_lines = HFile.ReadAllLines("output.coor"); Vector[] coords1 = Pdb.FromLines(coor_lines).atoms.ListCoord().ToArray(); Vector[] coords1x = Align.MinRMSD.Align(coords0, coords1); coor_rmsd = Align.MinRMSD.GetRMSD(coords0, coords1x); } } HEnvironment.CurrentDirectory = currpath; try{ tmpdir.Delete(true); } catch {} if (coor_lines == null) { return(null); } return(new CNamd2 { coor_lines = coor_lines, coor_rmsd = coor_rmsd, }); }
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 }); }