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
19 #include "QMCTools/CasinoParser.h"
20 #include "QMCTools/GaussianFCHKParser.h"
21 #include "QMCTools/GamesAsciiParser.h"
22 #include "QMCTools/LCAOHDFParser.h"
23 #include "QMCTools/BParser.h"
24 #include "Message/Communicate.h"
25 #include "OhmmsData/FileUtility.h"
26 #include "Utilities/RandomGenerator.h"
27 #include "Platforms/Host/OutputManager.h"
28 #include <sstream>
29
main(int argc,char ** argv)30 int main(int argc, char** argv)
31 {
32 if (argc < 2)
33 {
34 std::cout << "Usage: convert [-gaussian|-casino|-gamess|-orbitals] filename " << std::endl;
35 std::cout << "[-nojastrow -hdf5 -prefix title -addCusp -production -NbImages NimageX NimageY NimageZ]" << std::endl;
36 std::cout << "[-psi_tag psi0 -ion_tag ion0 -gridtype log|log0|linear -first ri -last rf]" << std::endl;
37 std::cout << "[-size npts -multidet multidet.h5 -ci file.out -threshold cimin -TargetState state_number "
38 "-NaturalOrbitals NumToRead -optDetCoeffs]"
39 << std::endl;
40 std::cout << "Defaults : -gridtype log -first 1e-6 -last 100 -size 1001 -ci required -threshold 0.01 -TargetState "
41 "0 -prefix sample"
42 << std::endl;
43 std::cout << "When the input format is missing, the extension of filename is used to determine the format "
44 << std::endl;
45 std::cout << " *.Fchk -> gaussian; *.out -> gamess; *.data -> casino; *.h5 -> HDF5" << std::endl;
46 return 1;
47 }
48 #ifdef HAVE_MPI
49 mpi3::environment env(argc, argv);
50 OHMMS::Controller->initialize(env);
51 #endif
52 try
53 {
54 if (OHMMS::Controller->rank() != 0)
55 {
56 outputManager.shutOff();
57 }
58 Random.init(0, 1, -1);
59 std::cout.setf(std::ios::scientific, std::ios::floatfield);
60 std::cout.setf(std::ios::right, std::ios::adjustfield);
61 std::cout.precision(12);
62 QMCGaussianParserBase::init();
63 QMCGaussianParserBase* parser = 0;
64 int iargc = 0;
65 std::string in_file(argv[1]);
66
67
68 std::string punch_file;
69 std::string psi_tag("psi0");
70 std::string ion_tag("ion0");
71 std::string jastrow("j");
72 std::string prefix;
73
74
75 int TargetState = 0;
76 bool addJastrow = true;
77 bool usehdf5 = false;
78 bool h5 = false;
79 bool useprefix = false;
80 bool debug = false;
81 bool prod = false;
82 bool ci = false, zeroCI = false, orderByExcitation = false, addCusp = false, multidet = false, optDetCoeffs = false;
83 double thres = 1e-20;
84 int readNO = 0; // if > 0, read Natural Orbitals from gamess output
85 int readGuess = 0; // if > 0, read Initial Guess from gamess output
86 std::vector<int> Image;
87 while (iargc < argc)
88 {
89 std::string a(argv[iargc]);
90 if (a == "-gaussian")
91 {
92 parser = new GaussianFCHKParser(argc, argv);
93 in_file = argv[++iargc];
94 }
95 else if (a == "-gamess")
96 {
97 parser = new GamesAsciiParser(argc, argv);
98 in_file = argv[++iargc];
99 }
100 else if (a == "-orbitals")
101 {
102 parser = new LCAOHDFParser(argc, argv);
103 h5 = true;
104 in_file = argv[++iargc];
105 }
106 else if (a == "-casino")
107 {
108 parser = new CasinoParser(argc, argv);
109 in_file = argv[++iargc];
110 }
111 else if (a == "-b")
112 {
113 parser = new BParser(argc, argv);
114 in_file = argv[++iargc];
115 }
116 else if (a == "-hdf5")
117 {
118 usehdf5 = true;
119 }
120 else if (a == "-psi_tag")
121 {
122 psi_tag = argv[++iargc];
123 }
124 else if (a == "-production")
125 {
126 prod = true;
127 }
128 else if (a == "-ion_tag")
129 {
130 ion_tag = argv[++iargc];
131 }
132 else if (a == "-prefix")
133 {
134 prefix = argv[++iargc];
135 useprefix = true;
136 }
137 else if (a == "-ci")
138 {
139 ci = true;
140 punch_file = argv[++iargc];
141 }
142 else if (a == "-multidet")
143 {
144 multidet = true;
145 punch_file = argv[++iargc];
146 }
147 else if (a == "-NbImages")
148 {
149 int temp;
150 temp = atoi(argv[++iargc]);
151 temp += 1 - temp % 2;
152 Image.push_back(temp);
153 temp = atoi(argv[++iargc]);
154 temp += 1 - temp % 2;
155 Image.push_back(temp);
156 temp = atoi(argv[++iargc]);
157 temp += 1 - temp % 2;
158 Image.push_back(temp);
159 }
160 else if (a == "-addCusp")
161 {
162 addCusp = true;
163 }
164 else if (a == "-threshold")
165 {
166 thres = atof(argv[++iargc]);
167 }
168 else if (a == "-optDetCoeffs")
169 {
170 optDetCoeffs = true;
171 }
172 else if (a == "-TargetState")
173 {
174 TargetState = atoi(argv[++iargc]);
175 }
176 else if (a == "-NaturalOrbitals")
177 {
178 readNO = atoi(argv[++iargc]);
179 }
180 else if (a == "-readInitialGuess")
181 {
182 readGuess = atoi(argv[++iargc]);
183 }
184 else if (a == "-zeroCI")
185 {
186 zeroCI = true;
187 }
188 else if (a == "-orderByExcitation")
189 {
190 orderByExcitation = true;
191 }
192 else if (a == "-cutoff")
193 {
194 orderByExcitation = true;
195 }
196 else if (a == "-debug")
197 {
198 debug = true;
199 }
200 else if (a == "-nojastrow")
201 {
202 addJastrow = false;
203 jastrow = "noj";
204 }
205 ++iargc;
206 }
207 if (readNO > 0 && readGuess > 0)
208 {
209 std::cerr << "Can only use one of: -NaturalOrbitals or -readInitialGuess. \n";
210 abort();
211 }
212 //Failed to create a parser. Try with the extension
213 std::string ext = getExtension(in_file);
214 if (parser == 0)
215 {
216 if (ext == "data")
217 {
218 WARNMSG("Creating CasinoParser")
219 parser = new CasinoParser(argc, argv);
220 }
221 else if (ext == "Fchk")
222 {
223 WARNMSG("Creating GaussianFCHKParser")
224 parser = new GaussianFCHKParser(argc, argv);
225 }
226 else if (ext == "h5")
227 {
228 WARNMSG("Creating LCAOHDFParser")
229 parser = new LCAOHDFParser(argc, argv);
230 }
231 else if (ext == "10")
232 {
233 WARNMSG("Creating BParser")
234 parser = new BParser(argc, argv);
235 }
236 else if (ext == "out")
237 {
238 WARNMSG("Creating GamesAsciiParser")
239 parser = new GamesAsciiParser(argc, argv);
240 }
241 else
242 {
243 std::cerr << "Unknown extension: " << ext << std::endl;
244 exit(1);
245 }
246 }
247 if (useprefix != true)
248 {
249 prefix = in_file;
250 std::string delimiter;
251 if (ext == "h5")
252 delimiter = ".h5";
253 else
254 delimiter = ".out";
255 int pos = 0;
256 std::string token;
257 pos = prefix.find(delimiter);
258 token = prefix.substr(0, pos);
259 prefix.erase(0, pos + delimiter.length());
260 prefix = token;
261 }
262 std::cout << "Using " << prefix << " to name output files" << std::endl;
263
264 parser->Title = prefix;
265 parser->debug = debug;
266 parser->DoCusp = addCusp;
267 parser->UseHDF5 = usehdf5;
268 parser->singledetH5 = h5;
269 if (h5)
270 {
271 parser->UseHDF5 = false;
272 parser->h5file = in_file;
273 }
274 if (usehdf5)
275 parser->h5file = parser->Title + ".orbs.h5";
276 parser->IonSystem.setName(ion_tag);
277 if (debug)
278 {
279 parser->UseHDF5 = false;
280 parser->h5file = "";
281 }
282 parser->multideterminant = false;
283 if (ci)
284 parser->multideterminant = ci;
285 if (multidet)
286 {
287 parser->multideterminant = multidet;
288 parser->multidetH5 = multidet;
289 }
290 parser->multih5file = punch_file;
291 parser->production = prod;
292 parser->ci_threshold = thres;
293 parser->optDetCoeffs = optDetCoeffs;
294 parser->target_state = TargetState;
295 parser->readNO = readNO;
296 parser->orderByExcitation = orderByExcitation;
297 parser->zeroCI = zeroCI;
298 parser->readGuess = readGuess;
299 parser->outputFile = punch_file;
300 parser->Image = Image;
301 parser->parse(in_file);
302 if (prod)
303 {
304 parser->addJastrow = addJastrow;
305 parser->WFS_name = jastrow;
306 if (parser->PBC)
307 {
308 std::cout << "Generating Inputs for Supertwist with coordinates:" << parser->STwist_Coord[0] << " "
309 << parser->STwist_Coord[1] << " " << parser->STwist_Coord[2] << std::endl;
310 parser->dumpPBC(psi_tag, ion_tag);
311 }
312 else
313 parser->dump(psi_tag, ion_tag);
314 parser->dumpStdInputProd(psi_tag, ion_tag);
315 }
316 else
317 {
318 parser->addJastrow = false;
319 jastrow = "noj";
320 parser->WFS_name = jastrow;
321 if (parser->PBC)
322 {
323 std::cout << "Generating Inputs for Supertwist with coordinates:" << parser->STwist_Coord[0] << " "
324 << parser->STwist_Coord[1] << " " << parser->STwist_Coord[2] << std::endl;
325 parser->dumpPBC(psi_tag, ion_tag);
326 }
327 else
328 parser->dump(psi_tag, ion_tag);
329 parser->dumpStdInput(psi_tag, ion_tag);
330
331 parser->addJastrow = true;
332 jastrow = "j";
333 parser->WFS_name = jastrow;
334 if (parser->PBC)
335 {
336 std::cout << "Generating Inputs for Supertwist with coordinates:" << parser->STwist_Coord[0] << " "
337 << parser->STwist_Coord[1] << " " << parser->STwist_Coord[2] << std::endl;
338 parser->dumpPBC(psi_tag, ion_tag);
339 }
340 else
341 parser->dump(psi_tag, ion_tag);
342 parser->dumpStdInput(psi_tag, ion_tag);
343 }
344 }
345 catch (const std::exception& e)
346 {
347 app_error() << e.what() << std::endl;
348 APP_ABORT("Unhandled Exception");
349 }
350
351 OHMMS::Controller->finalize();
352 return 0;
353 }
354