QMCPACK
convertpw4qmc.cpp File Reference
+ Include dependency graph for convertpw4qmc.cpp:

Go to the source code of this file.

Functions

void convertToVecStrings (int argc, char *argv[], std::vector< std::string > &vec)
 
bool file_exists (const std::string &name)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ convertToVecStrings()

void convertToVecStrings ( int  argc,
char *  argv[],
std::vector< std::string > &  vec 
)

Definition at line 24 of file convertpw4qmc.cpp.

Referenced by main().

25 {
26  for (int i = 1; i < argc; i++)
27  {
28  vec.push_back(argv[i]);
29  }
30 }

◆ file_exists()

bool file_exists ( const std::string &  name)
inline

Definition at line 33 of file convertpw4qmc.cpp.

Referenced by LCAOrbitalBuilder::createSPOSetFromXML(), and main().

34 {
35  ifstream ifile(name.c_str());
36  return (bool)ifile;
37 }

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 39 of file convertpw4qmc.cpp.

References convertToVecStrings(), file_exists(), EshdfFile::writeQboxAtoms(), EshdfFile::writeQboxBoilerPlate(), EshdfFile::writeQboxElectrons(), EshdfFile::writeQboxSupercell(), EshdfFile::writeQEAtoms(), EshdfFile::writeQEBoilerPlate(), EshdfFile::writeQEElectrons(), and EshdfFile::writeQESupercell().

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)