PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/job/src/qchemfiles.cpp

https://gitlab.com/Molcas/MolGUI
C++ | 661 lines | 470 code | 78 blank | 113 comment | 102 complexity | 5069992565a7da7f2af7fc1a3255a58a MD5 | raw file
  1. /***********************************************************************
  2. * This file is part of MolGUI. *
  3. * *
  4. * MolGUI is free software; you can redistribute it and/or modify it *
  5. * under the terms of the GNU Lesser General Public License, v. 2.1. *
  6. * MolGUI is distributed in the hope that it will be useful, but it is *
  7. * provided "as is" and without any express or implied warranties. *
  8. * For more details see the full text of the license in the file *
  9. * LICENSE or in <http://www.gnu.org/licenses/>. *
  10. ***********************************************************************/
  11. #include "qchemfiles.h"
  12. #include <wx/filename.h>
  13. #include <wx/tokenzr.h>
  14. #include "fileutil.h"
  15. #include "stringutil.h"
  16. #include "envutil.h"
  17. #include "tools.h"
  18. #include "renderingdata.h"
  19. #include "molfile.h"
  20. #include "xyzfile.h"
  21. #include "simuproject.h"
  22. #include "envsettings.h"
  23. #include "manager.h"
  24. #include "execprocess.h"
  25. #include "qchemlogreading.h"
  26. #include <wx/filename.h>
  27. #include <wx/dir.h>
  28. #include <stdio.h>
  29. #include "dlgsummary.h"
  30. #include "dlgoutput.h"
  31. #include "molglcanvas.h"
  32. #define Q_BUFFERSIZE 80
  33. #define STRINGSIZE 30
  34. #define NA_SIZE 6
  35. #define COOD_SIZE 5
  36. #define SIZE_FOUR 4
  37. #define SIZE_16 16
  38. QChemFiles::QChemFiles(SimuProject* simuProject, wxString resultDir) : AbstractProjectFiles(simuProject, resultDir) {
  39. }
  40. QChemFiles::~QChemFiles() {
  41. }
  42. bool QChemFiles::CreateInputFile(void) {
  43. wxString molFile = ProjectTreeItemData::GetFileName(m_pSimuProject, wxEmptyString, ITEM_MOLECULE);
  44. // wxString jobFile = ProjectTreeItemData::GetFileName(m_pSimuProject, wxEmptyString, ITEM_JOB_INFO);
  45. wxString quifile=m_pSimuProject->GetResultFileName(m_name) + wxT(".xyz");
  46. wxString quiproc=wxEmptyString;
  47. wxString execOutputDir=wxEmptyString;
  48. if(wxFileExists(molFile)) {
  49. RenderingData tmpData(NULL);
  50. MolFile::LoadFile(molFile, &tmpData);
  51. XYZFile::SaveCoord(quifile, tmpData.GetAtomBondArray(), false);
  52. if(!wxFileExists(quifile)){
  53. Tools::ShowError(quifile + wxT(" does not exist!"));
  54. return false;
  55. }
  56. wxString execDir = EnvSettingsData::Get()->GetChemSoftDir(PROJECT_QCHEM);
  57. //wxMessageBox(execDir);
  58. wxString conspath=execDir+platform::PathSep();
  59. execDir += platform::PathSep() + EnvUtil::GetProgramName(wxT("qui"));
  60. //wxMessageBox(execDir);
  61. if(!wxFileExists(execDir)) {
  62. Tools::ShowError(execDir + wxT(" does not exist!"));
  63. return false;
  64. }
  65. execOutputDir = m_pSimuProject->GetResultFileName(m_name) + wxT(".in");
  66. if(!wxFileExists(execOutputDir))
  67. SaveQuiCons(conspath);
  68. //wxMessageBox(execOutputDir);
  69. quiproc=execDir+wxT(" \"")+quifile+wxT("\" \"")+execOutputDir+wxT("\"");
  70. //wxMessageBox(quiproc);
  71. // long processId = wxExecute(quiproc, wxEXEC_SYNC);
  72. wxExecute(quiproc, wxEXEC_SYNC);
  73. // std::cout << "QChemFiles::CreateInputFile: " << quiproc << ";" << std::endl;
  74. if(wxFileExists(quifile))
  75. wxRemoveFile(quifile);
  76. wxString fileName=conspath + wxT("aaa.click");
  77. if(wxFileExists(fileName)){
  78. wxString strLine;
  79. long lok;
  80. wxFileInputStream fis(fileName);
  81. wxTextInputStream tis(fis);
  82. strLine=tis.ReadLine();
  83. strLine.ToLong(&lok);
  84. if(lok==1)
  85. return true;
  86. else
  87. return false;
  88. }
  89. return false;
  90. }
  91. return false;
  92. }
  93. wxString QChemFiles::GetExecPara(void) {
  94. wxString qchempara=wxEmptyString;
  95. wxString rcfile= EnvSettingsData::Get()->GetChemSoftDir(PROJECT_QCHEM);
  96. rcfile += platform::PathSep() + wxT("qchem.rc");
  97. qchempara=wxT("\"")+m_pSimuProject->GetResultFileName(m_name) + wxT(".in\" \"")+m_pSimuProject->GetResultFileName(m_name)+wxT(".out\" \"")+rcfile+wxT("\"");
  98. return qchempara;
  99. }
  100. wxString QChemFiles::GetExecCommand(void){
  101. wxString execProcName = wxEmptyString;
  102. if(platform::windows) {
  103. execProcName= wxT("qc.bat");
  104. }else{
  105. execProcName= wxT("qc.sh");
  106. }
  107. return execProcName;
  108. }
  109. /*
  110. void QChemFiles::BuildResultTree(wxTreeCtrl* pTree, wxTreeItemId& jobResultNode) {
  111. ProjectTreeItemData* itemData = NULL;
  112. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_SUMMARY);
  113. pTree->AppendItem(jobResultNode, wxT("Summary"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  114. if(HasSurfaceData()) {
  115. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_DENSITY);
  116. pTree->AppendItem(jobResultNode, wxT("Density"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  117. }
  118. if(HasVibrationData()) {
  119. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_VIBRATION);
  120. pTree->AppendItem(jobResultNode, wxT("Vibration"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  121. InitVibrationData();
  122. }
  123. }
  124. */
  125. bool QChemFiles::PostJobTerminated(bool isFinal) {
  126. wxString outFile = GetOutputFileName();
  127. // wxMessageBox(outFile);
  128. if(!wxFileExists(outFile)) {
  129. return true; // when the job file does not exist, terminate the processing
  130. }
  131. GetSummary();
  132. if(!HasSummary()) //SONG add it, if the first line of sum file is 1, then won't do the surface Cal.
  133. {
  134. Tools::ShowError(wxT("Sorry, Q-Chem Job Failed!"));
  135. return true;
  136. }
  137. /* if(HasSummary())
  138. {
  139. wxMessageBox("Hello Hassummary is true");
  140. return true;
  141. }*/
  142. GetXYZ();
  143. if(!isFinal){
  144. ConvertVib();
  145. if (wxNO == wxMessageBox(wxString(wxT("Do you want to calculate surfaces?")),
  146. wxString(wxT("Calculate Setting")), wxYES_NO | wxICON_QUESTION)) {
  147. SetNeedSurface(false);
  148. }else{
  149. SetNeedSurface(true);
  150. }
  151. if(GetNeedSurface()){
  152. ConvertDens();
  153. return DoCalcSurface();
  154. }
  155. }
  156. // if(GetNeedSurface())SaveSurfaces();
  157. // Tools::ShowStatus(wxT("Job Finished!"));
  158. return true;
  159. }
  160. bool QChemFiles::ConvertVib()
  161. {
  162. FILE *fpin, *fpout;
  163. char buffer[Q_BUFFERSIZE];
  164. char string1[STRINGSIZE];
  165. char string2[STRINGSIZE];
  166. char string3[STRINGSIZE];
  167. char string4[STRINGSIZE];
  168. char string_f1[STRINGSIZE];
  169. char string_f2[STRINGSIZE];
  170. char string_f3[STRINGSIZE];
  171. char string_i1[STRINGSIZE];
  172. char string_i2[STRINGSIZE];
  173. char string_i3[STRINGSIZE];
  174. char *string_Stand = const_cast<char*>("Standard");
  175. char *string_Nucle =const_cast<char*>( "Nuclear");
  176. char *string_Orien = const_cast<char*>("Orientation");
  177. char *string_Mode =const_cast<char*>( "Mode:");
  178. char *string_Begin_IRS =const_cast<char*>( "$BEGIN IRS");
  179. char *string_End_IRS =const_cast<char*>( "$END IRS");
  180. char *string_Begin_IR = const_cast<char*>("$BEGIN IR");
  181. char *string_End_IR = const_cast<char*>("$END IR");
  182. int index, i;
  183. int tempI;
  184. char stringES[3];
  185. int NofAtoms=0;
  186. int count=0;
  187. struct vib_part {
  188. char vx[STRINGSIZE];
  189. char vy[STRINGSIZE];
  190. char vz[STRINGSIZE];
  191. } *vib1, *vib2;
  192. // wxMessageBox(GetOutputFileName());
  193. // wxMessageBox(GetVibOutputFileName());
  194. char *charOutputName=NULL,*charVibName=NULL;
  195. StringUtil::String2CharPointer(&charOutputName, GetOutputFileName());
  196. StringUtil::String2CharPointer(&charVibName, GetVibOutputFileName());
  197. if ((fpin = fopen(charOutputName, "r")) == NULL) {
  198. printf( "Can't open input file %s. \n", charOutputName);
  199. return false;
  200. }
  201. if ((fpout = fopen(charVibName, "w")) == NULL) {
  202. printf( "Can't open output file %s. \n", charVibName);
  203. return false;
  204. }
  205. // Get number of atoms
  206. while (fgets(buffer, Q_BUFFERSIZE, fpin) != NULL) {
  207. sscanf(buffer, "%s %s %s", string1, string2, string3);
  208. if (!strcmp(string1, string_Stand) &&
  209. !strcmp(string2, string_Nucle) &&
  210. !strcmp(string3, string_Orien) ) {
  211. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  212. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  213. index = 0;
  214. while (1) {
  215. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  216. if (buffer[1] == 45 && buffer[2] == 45)
  217. break;
  218. index++;
  219. }
  220. NofAtoms = index;
  221. fprintf(fpout, "%d\n", NofAtoms);
  222. fprintf(fpout, "#Generated with SimuGUI from Q-Chem output\n");
  223. rewind(fpin);
  224. break;
  225. }
  226. }
  227. //
  228. vib1 = (struct vib_part *) malloc(sizeof(struct vib_part)*NofAtoms +1);
  229. vib2 = (struct vib_part *) malloc(sizeof(struct vib_part)*NofAtoms +1);
  230. while (fgets(buffer, Q_BUFFERSIZE, fpin) != NULL) {
  231. // Get coordinate
  232. sscanf(buffer, "%s %s %s %s", string1, string2, string3, string4);
  233. if (!strcmp(string1, string_Stand) &&
  234. !strcmp(string2, string_Nucle) &&
  235. !strcmp(string3, string_Orien) ) {
  236. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  237. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  238. for (i=0; i<NofAtoms; i++) {
  239. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  240. sscanf(buffer, "%d %2s %s %s %s", &tempI, stringES, string1, string2, string3);
  241. fprintf(fpout, "%2s %12s %12s %12s\n", stringES, string1, string2, string3);
  242. }
  243. fprintf(fpout, " \n");
  244. fprintf(fpout, "%s\n", string_Begin_IRS);
  245. }
  246. // Get vib info
  247. if (!strcmp(string1,string_Mode) ) {
  248. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  249. string_f1[0] = '\0';
  250. string_f2[0] = '\0';
  251. string_f3[0] = '\0';
  252. sscanf(buffer, "%s %s %s %s", string1, string_f1, string_f2, string_f3);
  253. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  254. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  255. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  256. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  257. string_i1[0] = '\0';
  258. string_i2[0] = '\0';
  259. string_i3[0] = '\0';
  260. sscanf(buffer, "%s %s %s %s %s", string1, string1, string_i1, string_i2, string_i3);
  261. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  262. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  263. fprintf(fpout, "%s\n", string_Begin_IR);
  264. fprintf(fpout, "%s %s\n", string_f1, string_i1);
  265. fprintf(fpout, "A \n");
  266. for (i=0; i<NofAtoms; i++) {
  267. if(fgets(buffer, Q_BUFFERSIZE, fpin) == NULL) return false;
  268. sscanf(buffer, "%s %s %s %s %s %s %s %s %s %s",
  269. stringES, string1, string2, string3,
  270. vib1[i].vx, vib1[i].vy, vib1[i].vz,
  271. vib2[i].vx, vib2[i].vy, vib2[i].vz);
  272. fprintf(fpout, " %7s %7s %7s\n", string1, string2, string3);
  273. }
  274. fprintf(fpout, "%s\n", string_End_IR);
  275. // fprintf(fpout, " \n");
  276. count++;
  277. // second
  278. if (string_f2[0] != '\0') {
  279. fprintf(fpout, "%s\n", string_Begin_IR);
  280. fprintf(fpout, "%s %s\n", string_f2, string_i2);
  281. fprintf(fpout, "A \n");
  282. for (i=0; i<NofAtoms; i++) {
  283. fprintf(fpout, " %7s %7s %7s\n", vib1[i].vx, vib1[i].vy, vib1[i].vz);
  284. }
  285. fprintf(fpout, "%s\n", string_End_IR);
  286. // fprintf(fpout, " \n");
  287. count++;
  288. }
  289. // third
  290. if (string_f3[0] != '\0') {
  291. fprintf(fpout, "%s\n", string_Begin_IR);
  292. fprintf(fpout, "%s %s\n", string_f3, string_i3);
  293. fprintf(fpout, "A \n");
  294. for (i=0; i<NofAtoms; i++) {
  295. fprintf(fpout, " %7s %7s %7s\n", vib2[i].vx, vib2[i].vy, vib2[i].vz);
  296. }
  297. fprintf(fpout, "%s\n", string_End_IR);
  298. count++;
  299. }
  300. }
  301. }
  302. fprintf(fpout, "%s\n", string_End_IRS);
  303. free ( (void *) vib1);
  304. free ( (void *) vib2);
  305. fclose (fpout);
  306. fclose (fpin);
  307. if (count==0)
  308. {
  309. if(wxFileExists(GetVibOutputFileName()))
  310. wxRemoveFile(GetVibOutputFileName());
  311. }
  312. return true;
  313. }
  314. wxString QChemFiles::GetInputFileName()
  315. {
  316. return m_pSimuProject->GetResultFileName(m_name) + wxT(".in");
  317. }
  318. wxString QChemFiles::GetOutputFileName()
  319. {
  320. return m_pSimuProject->GetResultFileName(m_name) + wxT(".out");
  321. }
  322. wxString QChemFiles::GetSurfaceFileName()
  323. {
  324. return m_pSimuProject->GetResultDir(m_name) + platform::PathSep() + wxT("surface.info");
  325. }
  326. bool QChemFiles::ConvertDens()
  327. {
  328. wxString execDir = EnvSettingsData::Get()->GetChemSoftDir(PROJECT_QCHEM);
  329. execDir += platform::PathSep() + EnvUtil::GetProgramName(wxT("surfaceinfo"));
  330. if(!wxFileExists(execDir)) {
  331. Tools::ShowError(execDir + wxT(" does not exist!"));
  332. return false;
  333. }
  334. wxString fchkFile=m_pSimuProject->GetResultDir(m_name)+platform::PathSep()+wxT("Test.FChk");
  335. wxString surfacefile=GetSurfaceFileName();
  336. wxString quiproc=execDir+wxT(" ")+fchkFile+wxT(" ")+surfacefile;
  337. // long processId = wxExecute(quiproc, wxEXEC_SYNC);
  338. wxExecute(quiproc, wxEXEC_SYNC);
  339. // std::cout << "QChemFiles::ConvertDens: " << quiproc << ";" << std::endl;
  340. //wxCopyFile(jobFile, m_pSimuProject->GetResultFileName(m_name) + wxT(".input"));
  341. return true;
  342. }
  343. /*
  344. wxArrayString QChemFiles::GetSurfaceDataFiles()
  345. {
  346. wxArrayString fileArray;
  347. wxString fileName = m_pSimuProject->GetResultFileName(m_name);;
  348. if(wxFileExists(fileName + wxT(".dens"))){
  349. fileArray.Add(fileName + wxT(".dens"));
  350. }else {
  351. if(wxFileExists(fileName + wxT("_a.dens")) ){
  352. fileArray.Add(fileName + wxT("_a.dens"));
  353. }
  354. if(wxFileExists(fileName + wxT("_b.dens")) ){
  355. fileArray.Add(fileName + wxT("_b.dens"));
  356. }
  357. }
  358. return fileArray;
  359. }
  360. */
  361. bool QChemFiles::GetSummary()
  362. {
  363. wxString execDir = EnvSettingsData::Get()->GetChemSoftDir(PROJECT_QCHEM);
  364. execDir += platform::PathSep() + EnvUtil::GetProgramName(wxT("getsum"));
  365. if(!wxFileExists(execDir)) {
  366. Tools::ShowError(execDir + wxT(" does not exist!"));
  367. return false;
  368. }
  369. wxString infile = GetOutputFileName();
  370. wxString sumfile=GetSummaryFileName();
  371. wxString quiproc=execDir+wxT(" \"")+infile+wxT("\" \"")+sumfile+wxT("\"");
  372. // std::cout << "QChemFiles::GetSummary: " << quiproc << ";" << std::endl;
  373. // long processId = wxExecute(quiproc, wxEXEC_SYNC);
  374. wxExecute(quiproc, wxEXEC_SYNC);
  375. //wxCopyFile(jobFile, m_pSimuProject->GetResultFileName(m_name) + wxT(".input"));
  376. return true;
  377. }
  378. /* for(i = 0; i < atomNumber; i++) {
  379. strLine = tis.ReadLine(); // read one line
  380. wxStringTokenizer tzk(strLine);
  381. AtomBond atomBond = AtomBond();
  382. atomSymbol = tzk.GetNextToken();
  383. if(atomSymbol.ToLong(&lAtomIndex)) {
  384. atomId = (int)lAtomIndex;
  385. }else {
  386. atomId = GetElemId(atomSymbol);
  387. }
  388. tzk.GetNextToken().ToDouble(&x);
  389. tzk.GetNextToken().ToDouble(&y);
  390. tzk.GetNextToken().ToDouble(&z);
  391. atomBond.atom.elemId = (int)atomId;
  392. if(atomBond.atom.elemId == ELEM_H) {
  393. atomBond.atom.elemId = (ElemId)DEFAULT_HYDROGEN_ID;
  394. }
  395. atomBond.atom.pos.x = x;
  396. atomBond.atom.pos.y = y;
  397. atomBond.atom.pos.z = z;
  398. appendAtomBondArray.Add(atomBond);
  399. }
  400. */
  401. void QChemFiles::GetXYZ()
  402. {
  403. wxString inputDir= GetOutputFileName();
  404. wxString xyzDir=m_pSimuProject->GetResultFileName(m_name) + wxT(".Opt.xyz");
  405. char * inputDirchar = NULL;
  406. char * xyzDirchar = NULL;
  407. StringUtil::String2CharPointer(&inputDirchar,inputDir); //convert from wxString to char*
  408. StringUtil::String2CharPointer(&xyzDirchar,xyzDir);
  409. QchemLogReading (inputDirchar, xyzDirchar);
  410. return;
  411. }
  412. void QChemFiles::BuildResultTree(wxTreeCtrl* pTree, wxTreeItemId& jobResultNode){
  413. ProjectTreeItemData* itemData = NULL;
  414. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_INPUT);
  415. pTree->AppendItem(jobResultNode, wxT("Input"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  416. if(HasSummary()){
  417. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_SUMMARY);
  418. pTree->AppendItem(jobResultNode, wxT("Summary"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  419. }
  420. // else //SONG add it
  421. // {
  422. // Tools::ShowError(wxT("Sorry, Q-Chem Job Failed!"));
  423. // }
  424. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_OUTPUT);
  425. pTree->AppendItem(jobResultNode, wxT("Output"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  426. // if(!HasSummary()) //SONG add it
  427. // return ;
  428. if(HasSurfaceData()) {
  429. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_DENSITY);
  430. pTree->AppendItem(jobResultNode, wxT("Density"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  431. }
  432. if(HasVibrationData()) {
  433. itemData = new ProjectTreeItemData(m_pSimuProject, m_name, ITEM_JOB_RESULT_FREQUENCE);
  434. pTree->AppendItem(jobResultNode, wxT("Vibration"), TREE_IMAGE_JOB_RESULT_EXIST, TREE_IMAGE_JOB_RESULT_EXIST, itemData);
  435. InitVibrationData();
  436. }
  437. }
  438. void QChemFiles::ShowResultItem(ProjectTreeItemData *item)
  439. {
  440. ProjectTreeItemType itemType=item->GetType();
  441. wxString jtitle =wxEmptyString;
  442. jtitle=jtitle+item->GetTitle();
  443. //wxMessageBox(wxT("QChemFiles::ShowResultItem:")+jtitle);
  444. if(itemType==ITEM_MOPACOUTPUT){
  445. wxString outfile=m_pSimuProject->GetMopacOutFilePath(jtitle);
  446. DlgOutput* pdlg=new DlgOutput(Manager::Get()->GetAppWindow(),wxID_ANY);
  447. //wxMessageBox(outfile);
  448. pdlg->AppendFile(outfile,wxT("Mopac OutputFile"));
  449. pdlg->Show(true);
  450. return;
  451. }else if(itemType == ITEM_JOB_RESULT_SUMMARY)
  452. {
  453. // wxMessageBox(wxT("before new dlg"));
  454. DlgSummary *dlgsummary=new DlgSummary(Manager::Get()->GetAppWindow(),wxID_ANY);
  455. // wxMessageBox(wxT("before getsummaryfile"));
  456. wxString sumfile=m_pSimuProject->GetFiles(jtitle)->GetSummaryFileName();
  457. // wxMessageBox(sumfile);
  458. dlgsummary->AppendSummary(sumfile);
  459. dlgsummary->ShowModal();
  460. // free(dlgsummary);
  461. dlgsummary=NULL;
  462. }
  463. else if(itemType== ITEM_JOB_RESULT_INPUT)
  464. {
  465. DlgOutput *dlgOutput=new DlgOutput(Manager::Get()->GetAppWindow(),wxID_ANY);
  466. wxString infile=m_pSimuProject->GetFiles(jtitle)->GetInputFileName();
  467. // wxMessageBox(infile);
  468. dlgOutput->AppendFile(infile,wxT("InPut"));
  469. dlgOutput->Show(true);
  470. }
  471. else if(itemType == ITEM_JOB_RESULT_OUTPUT)
  472. {
  473. DlgOutput *dlgOutput=new DlgOutput(Manager::Get()->GetAppWindow(),wxID_ANY);
  474. wxString outfile=m_pSimuProject->GetFiles(jtitle)->GetOutputFileName();
  475. // wxMessageBox(outfile);
  476. dlgOutput->AppendFile(outfile,wxT("OutPut"));
  477. dlgOutput->Show(true);
  478. }else{
  479. Manager::Get()->GetViewManager()->ShowMolView(item, wxEmptyString, true);//show return;
  480. }
  481. }
  482. bool QChemFiles::HasInput()
  483. {
  484. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".in");
  485. if(wxFileExists(tmpFileName))
  486. return true;
  487. else
  488. return false;
  489. }
  490. bool QChemFiles::HasOutput()
  491. {
  492. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".output");
  493. if(wxFileExists(tmpFileName))
  494. return true;
  495. else
  496. return false;
  497. }
  498. bool QChemFiles::HasError_Info(){
  499. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".error");
  500. if(wxFileExists(tmpFileName))
  501. return true;
  502. else
  503. return false;
  504. }
  505. bool QChemFiles::HasOptimization(){
  506. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".geo.molden");
  507. if(wxFileExists(tmpFileName))
  508. return true;
  509. else
  510. return false;
  511. }
  512. bool QChemFiles::HasGssOrb()
  513. {
  514. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".GssOrb");
  515. if(wxFileExists(tmpFileName))
  516. return true;
  517. else
  518. return false;
  519. }
  520. bool QChemFiles::HasScfOrb()
  521. {
  522. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".ScfOrb");
  523. if(wxFileExists(tmpFileName))
  524. return true;
  525. else
  526. return false;
  527. }
  528. bool QChemFiles::HasDump()
  529. {
  530. wxString tmpFileName= m_pSimuProject->GetResultFileName(m_name)+wxT(".xmldump.xml");
  531. if(wxFileExists(tmpFileName))
  532. return true;
  533. tmpFileName=tmpFileName.BeforeLast(platform::PathSep().GetChar(0))+platform::PathSep()+wxT("xmldump.xml");
  534. if(wxFileExists(tmpFileName)){
  535. wxRenameFile(tmpFileName,m_pSimuProject->GetResultFileName(m_name)+wxT(".xmldump.xml"));
  536. return true;
  537. }
  538. return false;
  539. }
  540. void QChemFiles::SaveQuiCons(wxString QuiConsPath) { //QuiConsPath specify the path file of a.cons . should be end of '/'
  541. Manager::Get()->GetProjectManager()->GetActiveProject()->Save();
  542. wxString name;
  543. name =Manager::Get()->GetProjectManager()->GetActiveProject()->GetResultDir(name);
  544. name.RemoveLast();
  545. wxString simName = name + platform::PathSep() + name.AfterLast(platform::PathSep().GetChar(0)) + wxT(".sim");
  546. ifstream in(simName.ToAscii());
  547. vector<string> vec;
  548. string s;
  549. while(getline(in, s)) {
  550. if (0 == s.compare("$BEGIN CONSTRAINTS")) {
  551. while (getline(in, s)){
  552. if (0 != s.compare("$END CONSTRAINTS")) {
  553. string::size_type pos=0;
  554. if( (pos=s.find("L", pos)) != string::npos){
  555. s.erase(pos, 1);
  556. s.insert(pos, "stre");
  557. }
  558. pos=0;
  559. if( (pos=s.find("A", pos)) != string::npos){
  560. s.erase(pos, 1);
  561. s.insert(pos, "bend");
  562. }
  563. pos=0;
  564. if( (pos=s.find("D", pos)) != string::npos){
  565. s.erase(pos, 1);
  566. s.insert(pos, "tors");
  567. }
  568. vec.push_back(s);
  569. } else {
  570. break;
  571. }
  572. }
  573. }
  574. }
  575. in.close();
  576. QuiConsPath = QuiConsPath + wxT("a.cons");
  577. ofstream out( QuiConsPath.ToAscii() );
  578. for (unsigned int i=0; i<vec.size(); ++i) {
  579. out << vec[i] << endl;
  580. }
  581. out.close();
  582. }