QMCPACK
convert4qmc.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) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
12 // Anouar Benali, benali@anl.gov, Argonne National Laboratory
13 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
14 //
15 // File created by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
16 //////////////////////////////////////////////////////////////////////////////////////
17 
18 
21 #include "QMCTools/LCAOHDFParser.h"
22 #include "QMCTools/DiracParser.h"
23 #include "QMCTools/RMGParser.h"
24 #include "Message/Communicate.h"
25 #include "OhmmsData/FileUtility.h"
28 #include <sstream>
29 
30 int main(int argc, char** argv)
31 {
32 #ifdef HAVE_MPI
33  mpi3::environment env(argc, argv);
34  OHMMS::Controller = new Communicate(env.world());
35 #endif
36 
37  if (argc < 2)
38  {
39  std::cout << "Usage: convert [-gaussian|-gamess|-orbitals|-dirac|-rmg] filename " << std::endl;
40  std::cout << "[-nojastrow -hdf5 -prefix title -addCusp -production -NbImages NimageX NimageY NimageZ]" << std::endl;
41  std::cout << "[-psi_tag psi0 -ion_tag ion0 -gridtype log|log0|linear -first ri -last rf]" << std::endl;
42  std::cout << "[-size npts -multidet multidet.h5 -ci file.out -threshold cimin -TargetState state_number "
43  "-NaturalOrbitals NumToRead -optDetCoeffs]"
44  << std::endl;
45  std::cout << "Defaults : -gridtype log -first 1e-6 -last 100 -size 1001 -ci required -threshold 0.01 -TargetState "
46  "0 -prefix sample"
47  << std::endl;
48  std::cout << "When the input format is missing, the extension of filename is used to determine the format "
49  << std::endl;
50  std::cout << " *.Fchk -> gaussian; *.out -> gamess; *.h5 -> HDF5" << std::endl;
51  return 0;
52  }
53  else
54  {
55  try
56  {
57  if (OHMMS::Controller->rank() != 0)
58  {
60  }
61  Random.init(-1);
62  std::cout.setf(std::ios::scientific, std::ios::floatfield);
63  std::cout.setf(std::ios::right, std::ios::adjustfield);
64  std::cout.precision(12);
66  std::unique_ptr<QMCGaussianParserBase> parser;
67  int iargc = 0;
68  std::string in_file(argv[1]);
69 
70 
71  std::string punch_file;
72  std::string psi_tag("psi0");
73  std::string ion_tag("ion0");
74  std::string jastrow("j");
75  std::string prefix;
76 
77  int TargetState = 0;
78  bool addJastrow = true;
79  bool usehdf5 = false;
80  bool h5 = false;
81  bool useprefix = false;
82  bool debug = false;
83  bool prod = false;
84  bool ci = false, zeroCI = false, orderByExcitation = false, addCusp = false, multidet = false,
85  optDetCoeffs = false;
86  double thres = 1e-20;
87  int readNO = 0; // if > 0, read Natural Orbitals from gamess output
88  int readGuess = 0; // if > 0, read Initial Guess from gamess output
89  std::vector<int> Image;
90  while (iargc < argc)
91  {
92  std::string a(argv[iargc]);
93  if (a == "-gaussian")
94  {
95  parser = std::make_unique<GaussianFCHKParser>(argc, argv);
96  in_file = argv[++iargc];
97  }
98  else if (a == "-gamess")
99  {
100  parser = std::make_unique<GamesAsciiParser>(argc, argv);
101  in_file = argv[++iargc];
102  }
103  else if (a == "-dirac")
104  {
105  parser = std::make_unique<DiracParser>(argc, argv);
106  in_file = argv[++iargc];
107  usehdf5 = true;
108  }
109  else if (a == "-orbitals")
110  {
111  parser = std::make_unique<LCAOHDFParser>(argc, argv);
112  h5 = true;
113  in_file = argv[++iargc];
114  }
115  else if (a == "-rmg")
116  {
117  parser = std::make_unique<RMGParser>(argc, argv);
118  h5 = true;
119  in_file = argv[++iargc];
120  }
121  else if (a == "-hdf5")
122  {
123  usehdf5 = true;
124  }
125  else if (a == "-psi_tag")
126  {
127  psi_tag = argv[++iargc];
128  }
129  else if (a == "-production")
130  {
131  prod = true;
132  }
133  else if (a == "-ion_tag")
134  {
135  ion_tag = argv[++iargc];
136  }
137  else if (a == "-prefix")
138  {
139  prefix = argv[++iargc];
140  useprefix = true;
141  }
142  else if (a == "-ci")
143  {
144  ci = true;
145  punch_file = argv[++iargc];
146  }
147  else if (a == "-multidet")
148  {
149  multidet = true;
150  punch_file = argv[++iargc];
151  }
152  else if (a == "-NbImages")
153  {
154  int temp;
155  temp = atoi(argv[++iargc]);
156  temp += 1 - temp % 2;
157  Image.push_back(temp);
158  temp = atoi(argv[++iargc]);
159  temp += 1 - temp % 2;
160  Image.push_back(temp);
161  temp = atoi(argv[++iargc]);
162  temp += 1 - temp % 2;
163  Image.push_back(temp);
164  }
165  else if (a == "-addCusp")
166  {
167  addCusp = true;
168  }
169  else if (a == "-threshold")
170  {
171  thres = atof(argv[++iargc]);
172  }
173  else if (a == "-optDetCoeffs")
174  {
175  optDetCoeffs = true;
176  }
177  else if (a == "-TargetState")
178  {
179  TargetState = atoi(argv[++iargc]);
180  }
181  else if (a == "-NaturalOrbitals")
182  {
183  readNO = atoi(argv[++iargc]);
184  }
185  else if (a == "-readInitialGuess")
186  {
187  readGuess = atoi(argv[++iargc]);
188  }
189  else if (a == "-zeroCI")
190  {
191  zeroCI = true;
192  }
193  else if (a == "-orderByExcitation")
194  {
195  orderByExcitation = true;
196  }
197  else if (a == "-cutoff")
198  {
199  orderByExcitation = true;
200  }
201  else if (a == "-debug")
202  {
203  debug = true;
204  }
205  else if (a == "-nojastrow")
206  {
207  addJastrow = false;
208  jastrow = "noj";
209  }
210  ++iargc;
211  }
212  if (readNO > 0 && readGuess > 0)
213  {
214  std::cerr << "Can only use one of: -NaturalOrbitals or -readInitialGuess. \n";
215  abort();
216  }
217  //Failed to create a parser. Try with the extension
218  auto ext = getExtension(in_file);
219  if (parser == 0)
220  {
221  if (ext == "Fchk")
222  {
223  WARNMSG("Creating GaussianFCHKParser")
224  parser = std::make_unique<GaussianFCHKParser>(argc, argv);
225  }
226  else if (ext == "h5")
227  {
228  WARNMSG("Creating LCAOHDFParser")
229  parser = std::make_unique<LCAOHDFParser>(argc, argv);
230  h5 = true;
231  }
232  else if (ext == "out")
233  {
234  WARNMSG("Creating GamesAsciiParser")
235  parser = std::make_unique<GamesAsciiParser>(argc, argv);
236  }
237  else
238  {
239  std::cerr << "Unknown extension: " << ext << std::endl;
240  exit(1);
241  }
242  }
243  if (useprefix != true)
244  {
245  prefix = in_file;
246  std::string delimiter;
247  if (ext == "h5")
248  delimiter = ".h5";
249  else
250  delimiter = ".out";
251  int pos = 0;
252  std::string token;
253  pos = prefix.find(delimiter);
254  token = prefix.substr(0, pos);
255  prefix = token;
256  }
257  std::cout << "Using " << prefix << " to name output files" << std::endl;
258 
259  parser->Title = prefix;
260  parser->debug = debug;
261  parser->DoCusp = addCusp;
262  parser->UseHDF5 = usehdf5;
263  parser->singledetH5 = h5;
264  if (h5)
265  {
266  parser->UseHDF5 = false;
267  parser->h5file = in_file;
268  }
269  if (usehdf5)
270  parser->h5file = parser->Title + ".orbs.h5";
271  parser->IonSystem.setName(ion_tag);
272  if (debug)
273  {
274  parser->UseHDF5 = false;
275  parser->h5file = "";
276  }
277  parser->multideterminant = false;
278  if (ci)
279  parser->multideterminant = ci;
280  if (multidet)
281  {
282  parser->multideterminant = multidet;
283  parser->multidetH5 = multidet;
284  }
285  parser->multih5file = punch_file;
286  parser->production = prod;
287  parser->ci_threshold = thres;
288  parser->optDetCoeffs = optDetCoeffs;
289  parser->target_state = TargetState;
290  parser->readNO = readNO;
291  parser->orderByExcitation = orderByExcitation;
292  parser->zeroCI = zeroCI;
293  parser->readGuess = readGuess;
294  parser->outputFile = punch_file;
295  parser->Image = Image;
296  parser->parse(in_file);
297  if (prod)
298  {
299  parser->addJastrow = addJastrow;
300  parser->WFS_name = jastrow;
301  if (parser->PBC)
302  {
303  std::cout << "Generating Inputs for Supertwist with coordinates:" << parser->STwist_Coord[0] << " "
304  << parser->STwist_Coord[1] << " " << parser->STwist_Coord[2] << std::endl;
305  parser->dumpPBC(psi_tag, ion_tag);
306  }
307  else
308  parser->dump(psi_tag, ion_tag);
309  parser->dumpStdInputProd(psi_tag, ion_tag);
310  }
311  else
312  {
313  parser->addJastrow = addJastrow;
314  parser->WFS_name = jastrow;
315  if (parser->PBC)
316  {
317  std::cout << "Generating Inputs for Supertwist with coordinates:" << parser->STwist_Coord[0] << " "
318  << parser->STwist_Coord[1] << " " << parser->STwist_Coord[2] << std::endl;
319  parser->dumpPBC(psi_tag, ion_tag);
320  }
321  else
322  parser->dump(psi_tag, ion_tag);
323  parser->dumpStdInput(psi_tag, ion_tag);
324  }
325  }
326  catch (const std::exception& e)
327  {
328  app_error() << e.what() << std::endl;
329  APP_ABORT("Unhandled Exception");
330  }
331  }
333  return 0;
334 }
Declaration of OutputManager class.
void shutOff()
Permanently shut off all streams.
std::ostream & app_error()
Definition: OutputManager.h:67
#define Random
Communicate * Controller
Global Communicator for a process.
Definition: Communicate.cpp:35
OutputManagerClass outputManager(Verbosity::HIGH)
Wrapping information on parallelism.
Definition: Communicate.h:68
#define WARNMSG(msg)
Definition: OutputManager.h:90
std::string_view getExtension(const std::string_view str)
Definition: FileUtility.h:19
int main(int argc, char **argv)
Definition: convert4qmc.cpp:30
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void finalize()
Declare a global Random Number Generator.