QMCPACK
convertpw4qmc.cpp
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois / NCSA Open Source License.
3 // See LICENSE file in top directory for details .
4 //
5 // Copyright ( c ) 2018 QMCPACK developers
6 //
7 // File developed by : Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
8 //
9 // File created by : Luke Shulenburger, lshulen@sandia.gov, Sandia National Laboratories
10 /////////////////////////////////////////////////////////////////////////////////////////
11 
12 #include <iostream>
13 #include <string>
14 #include <fstream>
15 #include "config.h"
16 #ifdef HAVE_MPI
17 #include <mpi.h>
18 #endif
19 #include "XmlRep.h"
20 #include "WriteEshdf.h"
21 
22 using namespace std;
23 
24 void convertToVecStrings(int argc, char* argv[], std::vector<std::string>& vec)
25 {
26  for (int i = 1; i < argc; i++)
27  {
28  vec.push_back(argv[i]);
29  }
30 }
31 
32 
33 inline bool file_exists(const std::string& name)
34 {
35  ifstream ifile(name.c_str());
36  return (bool)ifile;
37 }
38 
39 int main(int argc, char* argv[])
40 {
41 #ifdef HAVE_MPI
42  int rank = 0, world_size = 1;
43  int provided;
44  MPI_Init_thread(NULL, NULL, MPI_THREAD_FUNNELED, &provided);
45  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
46  MPI_Comm_size(MPI_COMM_WORLD, &world_size);
47 #endif
48 
49  vector<string> vecParams;
50  convertToVecStrings(argc, argv, vecParams);
51  string fname;
52  string ofname = "eshdf.h5";
53  for (int i = 0; i < vecParams.size(); i++)
54  {
55  if (vecParams[i] == "--output" || vecParams[i] == "-o")
56  {
57  ofname = vecParams[i + 1];
58  i++;
59  }
60  else
61  {
62  fname = vecParams[i];
63  }
64  }
65  if (file_exists(fname) == false)
66  {
67  cerr << "must specify a valid xml file name as an argument" << endl;
68  cerr << fname << " did not work" << endl;
69  return (1);
70  }
71 
72  ifstream is(fname.c_str());
73 
74  XmlNode inFile(&is, 0, true);
75  string name = inFile.getName();
76  string directory("./");
77  const int last_slash_index = fname.find_last_of('/');
78  if (last_slash_index > -1)
79  {
80  directory = fname.substr(0, last_slash_index + 1);
81  }
82 
83  if (name == "qes:espresso")
84  {
85  // may be good to test different versions of espresso to see
86  // if this changes at all
87  cout << "xml file comes from quantum espresso" << endl;
88  EshdfFile outFile(ofname);
89  outFile.writeQEBoilerPlate(inFile);
90  outFile.writeQESupercell(inFile);
91  outFile.writeQEAtoms(inFile);
92  outFile.writeQEElectrons(inFile, directory);
93  }
94  else if (name == "fpmd:sample")
95  {
96  cout << "xml file comes from qbox" << endl;
97  EshdfFile outFile(ofname);
98  outFile.writeQboxBoilerPlate(inFile);
99  outFile.writeQboxSupercell(inFile);
100  outFile.writeQboxAtoms(inFile);
101  outFile.writeQboxElectrons(inFile);
102  }
103  else
104  {
105  cerr << "xml format is unrecognized" << endl;
106  return (1);
107  }
108 
109 #ifdef HAVE_MPI
110  MPI_Finalize();
111 #endif
112  return 0;
113 }
bool file_exists(const std::string &name)
Definition: XmlRep.h:81
void convertToVecStrings(int argc, char *argv[], std::vector< std::string > &vec)
void writeQEElectrons(const XmlNode &qeXml, const std::string &dir_name)
Definition: WriteEshdf.cpp:980
void writeQEAtoms(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:352
void writeQboxBoilerPlate(const XmlNode &qboxSample)
Definition: WriteEshdf.cpp:240
int main(int argc, char *argv[])
void writeQEBoilerPlate(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:279
void writeQboxElectrons(const XmlNode &qboxSample)
void writeQboxAtoms(const XmlNode &qboxSample)
Definition: WriteEshdf.cpp:412
void writeQESupercell(const XmlNode &qeXml)
Definition: WriteEshdf.cpp:327
void writeQboxSupercell(const XmlNode &qboxSample)
Definition: WriteEshdf.cpp:304