/// https://www.charmmtutorial.org/index.php/Full_example public static SPsfCrd Solvate (IEnumerable <string> toplines , IEnumerable <string> parlines , IEnumerable <string> psflines_prot , IEnumerable <string> crdlines_prot , IEnumerable <string> crdlines_water ) { string tempbase = @"C:\temp\"; SPsfCrd psfcrd; using (var temp = new HTempDirectory(tempbase, null)) { temp.EnterTemp(); string topname = "top.rtf"; HFile.WriteAllLines(topname, toplines); string parname = "par.prm"; HFile.WriteAllLines(parname, parlines); string psfname_prot = "prot.psf"; HFile.WriteAllLines(psfname_prot, psflines_prot); string crdname_prot = "prot.crd"; HFile.WriteAllLines(crdname_prot, crdlines_prot); string crdname_water = "water.crd"; HFile.WriteAllLines(crdname_water, crdlines_water); string psfname_protwater = "protwater.psf"; string crdname_protwater = "protwater.crd"; string conf_inp = @"* Run Segment Through CHARMM * ! read topology and parameter files read rtf card name $$topname$$ read para card name $$parname$$ ! read the psf and coordinate file read psf card name $$psfname_prot$$ read coor card name $$crdname_prot$$ ! Read in water sequence read sequence tip3 46656 ! Generate new segment for the water generate bwat noangle nodihedral ! Read the water PDB coordinates and append them to the protein read coor card append name $$crdname_water$$ ! Delete waters which overlap with protein delete atom sort - select .byres. (segid bwat .AND. type oh2 .and. - ((.not. (segid bwat .OR. hydrogen)) .around. 2.5)) end ! set headstr = rhdo with a crystal dimension of @greatervalue set headstr = test xxx ! we want to do a quick-and-dirty minimization to remove bad contacts. Therefore, we should ! set up shake and the non-bond parameters again. shake bonh param sele all end nbond inbfrq -1 elec fswitch vdw vswitch cutnb 16. ctofnb 12. ctonnb 10. mini sd nstep 100 nprint 1 tolgrd 100.0 ! use Expanded I/O format ioform extended ! since we've changed the structure by adding waters, we need to write out a new PSF write psf card name $$psfname_protwater$$ * new_1cbn-18126-1-solv.psf * solvation: @headstr * write coor card name $$crdname_protwater$$ * new_1cbn-18126-1-solv.crd * solvation: @headstr * stop ".Replace("$$topname$$", topname) .Replace("$$parname$$", parname) .Replace("$$psfname_prot$$", psfname_prot) .Replace("$$crdname_prot$$", crdname_prot) .Replace("$$crdname_water$$", crdname_water) .Replace("$$psfname_protwater$$", psfname_protwater) .Replace("$$crdname_protwater$$", crdname_protwater) ; HFile.WriteAllText("conf.inp", conf_inp); System.Console.WriteLine("Run the following command at " + temp + " :"); System.Console.WriteLine(" $ charmm < conf.inp"); System.Console.WriteLine(" or $ mpd&"); System.Console.WriteLine(" $ mpirun -n 38 charmm_M < conf.inp"); System.Console.WriteLine("Then, copy " + psfname_protwater + " and " + crdname_protwater + " to " + temp); while (true) { bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true); if (next) { if (HFile.ExistsAll(psfname_protwater, crdname_protwater)) { string[] psflines_protwater = HFile.ReadAllLines(psfname_protwater); string[] crdlines_protwater = HFile.ReadAllLines(crdname_protwater); psfcrd = new SPsfCrd { psflines = psflines_protwater, crdlines = crdlines_protwater, }; break; } System.Console.WriteLine("DO, copy " + psfname_protwater + " and " + crdname_protwater + " to " + temp); } } temp.QuitTemp(); } return(psfcrd); }
/// https://www.charmmtutorial.org/index.php/Full_example public static string[] Hessian (IEnumerable <string> toplines , IEnumerable <string> parlines , IEnumerable <string> psflines , IEnumerable <string> crdlines ) { string tempbase = @"C:\temp\"; string[] mincrdlines; using (var temp = new HTempDirectory(tempbase, null)) { temp.EnterTemp(); string topname = "top.rtf"; HFile.WriteAllLines(topname, toplines); string parname = "par.prm"; HFile.WriteAllLines(parname, parlines); string psfname = "target.psf"; HFile.WriteAllLines(psfname, psflines); string crdname = "target.crd"; HFile.WriteAllLines(crdname, crdlines); string mincrdname = "target-minimized.crd"; string conf_inp = @"* Minimize PDB * Minimize PDB * ! read topology and parameter file read rtf card name top.rtf read param card name par.prm ! read the psf and coordinate file read psf card name target.psf read coor card name target.crd ! set up shake shake bonh param sele all end ! set up electrostatics, since we're not using PME, set up switching ! electrostatics nbond inbfrq -1 elec fswitch vdw vswitch cutnb 16. ctofnb 12. ctonnb 10. energy coor copy comp ! mini sd nstep 100 ! mini abnr nstep 1000 nprint 10000 tolg 0.0000 ! ! mini abnr nstep 1000 nprint 100 tolg 0.01 ! ! mini abnr nstep 10000000 nprint 100 tolg 0.00 ! ! mini abnr nstep 1000000 nprint 100 tolg 10.00 ! target-min-step1-tolg-10_00.crd ! ! mini abnr nstep 1000000 nprint 100 tolg 1.00 ! target-min-step2-tolg-1_00.crd ! ! mini abnr nstep 1000000 nprint 100 tolg 0.10 ! ! mini sd nstep 10000 ! target-min-step3-sd10000.crd ! ! mini abnr nstep 1000000 nprint 100 tolg 0.01 ! target-min-step4-tolg-0_01.crd ! ! mini abnr nstep 10000 nprint 100 tolg 0.0001 ! target-min-step5-tolg-0_0001.crd ! ! mini abnr nstep 10000 nprint 100 tolg 0.000001 ! target-min-step6-tolg-0_000001.crd ! ! mini abnr nstep 10000 nprint 100 tolg 0.000000 ! target-min-step7-tolg-0_000000.crd ! ! ! coor rms ! ! ioform extended ! ! write coor card name target-minimized.crd ! * Initial minimization, no PME. ! * ! VIBRAN NMOD 20 ATOM FSWITCH rdie eps 4.0 VDW VSHIFT cutnb 13.0 ctofnb 12.0 CTONNB 8.0 ! ! DIMB ITERations 500 TOLErance 0.04 PARDim 200 IUNMode 21 DWIN ! ! WRITe SECOnd-derivatives card ! BOMLEV -2 ! VIBRAN ! DIAG ENTRopy ! VIBRan NMODes 500 ! DIAG ! print norm vector dipole !mini abnr nstep 100 nprint 100 tolg 0.000000 ! target-min-step7-tolg-0_000000.crd BOMLEV -2 open unit 1 write form name " + " \"second.dat\" " + @" REDUce CMPAct vibran !diag write second card unit 1 close unit 1 !calc natom3 ?NATOM *3 !vibran nmode @natom3 !diag !print norm !bomlev - 2 !VIBRan NMOD 300 !DIAGonalize !https://www.charmm.org/charmm/documentation/by-version/c42b1/params/doc/vibran/ stop "; conf_inp = conf_inp.Replace("$$topname$$", topname) .Replace("$$parname$$", parname) .Replace("$$psfname$$", psfname) .Replace("$$crdname$$", crdname) .Replace("$$mincrdname$$", mincrdname) ; HFile.WriteAllText("conf.inp", conf_inp); System.Console.WriteLine("Run the following command at " + temp + " :"); System.Console.WriteLine(" $ charmm < conf.inp"); System.Console.WriteLine(" or $ mpd&"); System.Console.WriteLine(" $ mpirun -n 38 charmm_M < conf.inp"); System.Console.WriteLine("Then, copy second.dat to " + temp); while (true) { bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true); if (next) { if (HFile.ExistsAll(mincrdname)) { mincrdlines = HFile.ReadAllLines(mincrdname); /// second.dat has the following format /// /// num-atoms /// pot-energy /// atom1-xforce atom1-yforce atom1-zforce /// atom2-xforce atom2-yforce atom2-zforce /// ... /// atomn-xforce atomn-yforce atomn-zforce /// upper- or lower-diag elem 1 /// upper- or lower-diag elem 2 /// .... /// upper- or lower-diag elem 3n*3n/2 /// atom1-xcoord atom1-ycoord atom1-zcoord /// atom2-xcoord atom2-ycoord atom2-zcoord /// ... /// atomn-xcoord atomn-ycoord atomn-zcoord /// break; } System.Console.WriteLine("DO, copy target.psf and target.crd to " + temp); } } temp.QuitTemp(); } return(mincrdlines); }
public Mode[] GetModesMassReduced(bool delhess, int?numModeReturn, Dictionary <string, object> secs) { HessMatrix mwhess_ = GetHessMassWeighted(delhess); IMatrix <double> mwhess = mwhess_; bool bsparse = (mwhess_ is HessMatrixSparse); Mode[] modes; using (new Matlab.NamedLock("")) { string msg = ""; { if (bsparse) { Matlab.PutSparseMatrix("V", mwhess_.GetMatrixSparse(), 3, 3); } else { Matlab.PutMatrix("V", ref mwhess, true, true); } } msg += Matlab.Execute("tic;"); msg += Matlab.Execute("V = (V+V')/2; "); // make symmetric { // eigen-decomposition if (bsparse) { if (numModeReturn != null) { int numeig = numModeReturn.Value; string cmd = "eigs(V," + numeig + ",'sm')"; msg += Matlab.Execute("[V,D] = " + cmd + "; "); } else { msg += Matlab.Execute("[V,D] = eig(full(V)); "); } } else { msg += Matlab.Execute("[V,D] = eig(V); "); } } msg += Matlab.Execute("tm=toc; "); if (secs != null) { int numcore = Matlab.Environment.NumCores; double tm = Matlab.GetValue("tm"); secs.Clear(); secs.Add("num cores", numcore); secs.Add("secs multi-threaded", tm); secs.Add("secs estimated single-threaded", tm * Math.Sqrt(numcore)); /// x=[]; for i=1:20; tic; H=rand(100*i); [V,D]=eig(H+H'); xx=toc; x=[x;i,xx]; fprintf('%d, %f\n',i,xx); end; x /// /// http://www.mathworks.com/help/matlab/ref/matlabwindows.html /// run matlab in single-thread: matlab -nodesktop -singleCompThread /// multi-thread: matlab -nodesktop /// /// my computer, single thread: cst1={0.0038,0.0106,0.0277,0.0606,0.1062,0.1600,0.2448,0.3483,0.4963,0.6740,0.9399,1.1530,1.4568,1.7902,2.1794,2.6387,3.0510,3.6241,4.2203,4.8914}; /// 2 cores: cst2={0.0045,0.0098,0.0252,0.0435,0.0784,0.1203,0.1734,0.2382,0.3316,0.4381,0.5544,0.6969,1.0170,1.1677,1.4386,1.7165,2.0246,2.4121,2.8124,3.2775}; /// scale: (cst1.cst2)/(cst1.cst1) = 0.663824 /// approx: (cst1.cst2)/(cst1.cst1)*Sqrt[2.2222] = 0.989566 /// my computer, single thread: cst1={0.0073,0.0158,0.0287,0.0573,0.0998,0.1580,0.2377,0.3439,0.4811,0.6612,0.8738,1.0974,1.4033,1.7649,2.1764,2.6505,3.1142,3.5791,4.1910,4.8849}; /// 2 cores: cst2={0.0085,0.0114,0.0250,0.0475,0.0719,0.1191,0.1702,0.2395,0.3179,0.4319,0.5638,0.7582,0.9454,1.1526,1.4428,1.7518,2.0291,2.4517,2.8200,3.3090}; /// scale: (cst1.cst2)/(cst1.cst1) = 0.671237 /// approx: (cst1.cst2)/(cst1.cst1)*Sqrt[2.2222] = 1.00062 /// ts4-stat , singhe thread: cst1={0.0048,0.0213,0.0641,0.1111,0.1560,0.2013,0.3307,0.3860,0.4213,0.8433,1.0184,1.3060,1.9358,2.2699,2.1718,3.0149,3.1081,4.3594,5.0356,5.5260}; /// 12 cores: cst2={0.2368,0.0614,0.0235,0.1321,0.0574,0.0829,0.1078,0.1558,0.1949,0.3229,0.4507,0.3883,0.4685,0.6249,0.6835,0.8998,0.9674,1.1851,1.3415,1.6266}; /// scale: (cst1.cst2)/(cst1.cst1) = 0.286778 /// (cst1.cst2)/(cst1.cst1)*Sqrt[12*1.1111] = 1.04716 /// ts4-stat , singhe thread: cst1={0.0138,0.0215,0.0522,0.0930,0.1783,0.2240,0.2583,0.4054,0.4603,0.9036,0.9239,1.5220,1.9443,2.1042,2.3583,3.0208,3.5507,3.8810,3.6943,6.2085}; /// 12 cores: cst2={0.1648,0.1429,0.1647,0.0358,0.0561,0.0837,0.1101,0.1525,0.2084,0.2680,0.3359,0.4525,0.4775,0.7065,0.6691,0.9564,1.0898,1.2259,1.2926,1.5879}; /// scale: (cst1.cst2)/(cst1.cst1) = 0.294706 /// (cst1.cst2)/(cst1.cst1)*Sqrt[12] = 1.02089 /// ts4-stat , singhe thread: cst1={0.0126,0.0183,0.0476,0.0890,0.1353,0.1821,0.2265,0.3079,0.4551,0.5703,1.0009,1.2175,1.5922,1.8805,2.1991,2.3096,3.7680,3.7538,3.9216,5.2899,5.6737,7.0783,8.8045,9.0091,9.9658,11.6888,12.8311,14.4933,17.2462,17.5660}; /// 12 cores: cst2={0.0690,0.0117,0.0275,0.0523,0.0819,0.1071,0.1684,0.1984,0.1974,0.2659,0.3305,0.4080,0.4951,0.7089,0.9068,0.7936,1.2632,1.0708,1.3187,1.6106,1.7216,2.1114,2.8249,2.7840,2.8259,3.3394,4.3092,4.2708,5.3358,5.7479}; /// scale: (cst1.cst2)/(cst1.cst1) = 0.311008 /// (cst1.cst2)/(cst1.cst1)*Sqrt[12] = 1.07736 /// Therefore, the speedup using multi-core could be sqrt(#core) } msg += Matlab.Execute("D = diag(D); "); if (msg.Trim() != "") { System.Console.WriteLine(); bool domanual = HConsole.ReadValue <bool>("possibly failed. Will you do ((('V = (V+V')/2;[V,D] = eig(V);D = diag(D);))) manually ?", false, null, false, true); if (domanual) { Matlab.Clear(); Matlab.PutMatrix("V", ref mwhess, true, true); System.Console.WriteLine("cleaning working-space and copying V in matlab are done."); System.Console.WriteLine("do V = (V+V')/2; [V,D]=eig(V); D=diag(D);"); while (HConsole.ReadValue <bool>("V and D are ready to use in matlab?", false, null, false, true) == false) { ; } //string path_V = HConsole.ReadValue<string>("path V.mat", @"C:\temp\V.mat", null, false, true); //Matlab.Execute("clear;"); //Matlab.PutMatrix("V", ref mwhess, true, true); //Matlab.Execute(string.Format("save('{0}', '-V7.3');", path_V)); //while(HConsole.ReadValue<bool>("ready for VD.mat containing V and D?", false, null, false, true) == false) ; //string path_VD = HConsole.ReadValue<string>("path VD.mat", @"C:\temp\VD.mat", null, false, true); //Matlab.Execute(string.Format("load '{0}';", path_V)); } } if (numModeReturn != null) { Matlab.PutValue("nmode", numModeReturn.Value); Matlab.Execute("V = V(:,1:nmode);"); Matlab.Execute("D = D(1:nmode);"); } MatrixByRowCol V = Matlab.GetMatrix("V", MatrixByRowCol.Zeros, true, true); Vector D = Matlab.GetVector("D"); HDebug.Assert(V.RowSize == D.Size); modes = new Mode[D.Size]; for (int i = 0; i < D.Size; i++) { Vector eigvec = V.GetColVector(i); double eigval = D[i]; modes[i] = new Mode { th = i, eigval = eigval, eigvec = eigvec, }; } V = null; } System.GC.Collect(); modes.UpdateMassReduced(mass.ToArray()); return(modes); }
/// https://www.charmmtutorial.org/index.php/Full_example public static string[] MinimizeCrd (IEnumerable <string> toplines , IEnumerable <string> parlines , IEnumerable <string> psflines , IEnumerable <string> crdlines , string conf_inp_mini ) { string tempbase = @"C:\temp\"; if (conf_inp_mini == null) { conf_inp_mini = @" mini sd nstep 100 mini abnr nstep 1000 nprint 10000 tolg 0.0001 ! mini abnr nstep 1000 nprint 100 tolg 0.01 ! mini abnr nstep 10000000 nprint 100 tolg 0.00 ! mini abnr nstep 1000000 nprint 100 tolg 10.00 ! target-min-step1-tolg-10_00.crd ! mini abnr nstep 1000000 nprint 100 tolg 1.00 ! target-min-step2-tolg-1_00.crd ! mini abnr nstep 1000000 nprint 100 tolg 0.10 ! mini sd nstep 10000 ! target-min-step3-sd10000.crd ! mini abnr nstep 1000000 nprint 100 tolg 0.01 ! target-min-step4-tolg-0_01.crd ! mini abnr nstep 10000 nprint 100 tolg 0.0001 ! target-min-step5-tolg-0_0001.crd ! mini abnr nstep 10000 nprint 100 tolg 0.000001 ! target-min-step6-tolg-0_000001.crd ! mini abnr nstep 10000 nprint 100 tolg 0.000000 ! target-min-step7-tolg-0_000000.crd "; } string[] mincrdlines; using (var temp = new HTempDirectory(tempbase, null)) { temp.EnterTemp(); string topname = "top.rtf"; HFile.WriteAllLines(topname, toplines); string parname = "par.prm"; HFile.WriteAllLines(parname, parlines); string psfname = "target.psf"; HFile.WriteAllLines(psfname, psflines); string crdname = "target.crd"; HFile.WriteAllLines(crdname, crdlines); string mincrdname = "target-minimized.crd"; string conf_inp = @"* Minimize PDB * ! read topology and parameter file read rtf card name $$topname$$ read param card name $$parname$$ ! read the psf and coordinate file read psf card name $$psfname$$ read coor card name $$crdname$$ ! set up shake shake bonh param sele all end ! set up electrostatics, since we're not using PME, set up switching ! electrostatics nbond inbfrq -1 elec fswitch vdw vswitch cutnb 16. ctofnb 12. ctonnb 10. energy coor copy comp " + conf_inp_mini + @" coor rms ioform extended write coor card name $$mincrdname$$ * Initial minimization, no PME. * stop "; conf_inp = conf_inp.Replace("$$topname$$", topname) .Replace("$$parname$$", parname) .Replace("$$psfname$$", psfname) .Replace("$$crdname$$", crdname) .Replace("$$mincrdname$$", mincrdname) ; HFile.WriteAllText("conf.inp", conf_inp); System.Console.WriteLine("Run the following command at " + temp + " :"); System.Console.WriteLine(" $ charmm < conf.inp"); System.Console.WriteLine(" or $ mpd&"); System.Console.WriteLine(" $ mpirun -n 38 charmm_M < conf.inp"); System.Console.WriteLine("Then, copy target-minimized.crd to " + temp); while (true) { bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true); if (next) { if (HFile.ExistsAll(mincrdname)) { mincrdlines = HFile.ReadAllLines(mincrdname); break; } System.Console.WriteLine("DO, copy target.psf and target.crd to " + temp); } } temp.QuitTemp(); } return(mincrdlines); }
public static SPsfCrd BuildPsfCrd (IEnumerable <string> toplines , IEnumerable <string> parlines , IEnumerable <string> pdblines ) { string tempbase = @"C:\temp\"; SPsfCrd psfcrd; using (var temp = new HTempDirectory(tempbase, null)) { temp.EnterTemp(); string topname = "top.rtf"; HFile.WriteAllLines(topname, toplines); string parname = "par.prm"; HFile.WriteAllLines(parname, parlines); string tgtname = "target"; HFile.WriteAllLines(tgtname + ".pdb", pdblines); string Setup_inp = @"* Run Segment Through CHARMM * ! read topology and parameter files read rtf card name $$topname$$ read para card name $$parname$$ ! Read sequence from the PDB coordinate file open unit 1 card read name $$tgtname$$.pdb read sequ pdb unit 1 ! now generate the PSF and also the IC table (SETU keyword) generate setu a-pro first NTER last CTER rewind unit 1 ! set bomlev to -1 to avois sying on lack of hydrogen coordinates bomlev -1 read coor pdb unit 1 ! them put bomlev back up to 0 bomlev 0 close unit 1 ! prints out number of atoms that still have undefined coordinates. define test select segid a-pro .and. ( .not. hydrogen ) .and. ( .not. init ) show end ic para ic fill preserve ic build hbuild sele all end ! write out the protein structure file (psf) and ! the coordinate file in pdb and crd format. write psf card name $$tgtname$$.psf * PSF * write coor card name $$tgtname$$.crd * Coords * stop " .Replace("$$topname$$", topname) .Replace("$$parname$$", parname) .Replace("$$tgtname$$", tgtname); HFile.WriteAllText("Setup.inp", Setup_inp); System.Console.WriteLine("Run the following command at " + temp + " :"); System.Console.WriteLine(" $ charmm < Setup.inp"); System.Console.WriteLine(" or $ mpd&"); System.Console.WriteLine(" $ mpirun -n 38 charmm_M < Setup.inp"); System.Console.WriteLine("Then, copy target.psf and target.crd to " + temp); while (true) { bool next = HConsole.ReadValue <bool>("Ready for next? ", false, null, false, true); if (next) { if (HFile.ExistsAll("target.crd", "target.psf")) { string[] crdlines = HFile.ReadAllLines("target.crd"); string[] psflines = HFile.ReadAllLines("target.psf"); psfcrd = new SPsfCrd { crdlines = crdlines, psflines = psflines, }; break; } System.Console.WriteLine("DO, copy target.psf and target.crd to " + temp); } } temp.QuitTemp(); } return(psfcrd); }