source: ThirdParty/mpqc_open/src/bin/mpqc/mpqc.cc@ e9f307

Candidate_v1.7.0 stable
Last change on this file since e9f307 was e9f307, checked in by Frederik Heber <frederik.heber@…>, 6 weeks ago

MPQC_OPEN: fix validation testsuite after output muting.

  • our muting of the mpqc_open output broke the validation test cases as they diff against the output.
  • added "vv" as command-line option for mpqc to enforce output printing.
  • FIX: Since perl 5.30 matching an unescaped "{" is deprecated.
  • Property mode set to 100644
File size: 43.9 KB
Line 
1//
2// mpqc.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Edward Seidl <seidl@janed.com>
7// Maintainer: LPS
8//
9// This file is part of MPQC.
10//
11// MPQC is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// MPQC is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with the MPQC; see the file COPYING. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28// This is needed to make GNU extensions available, such as
29// feenableexcept and fedisableexcept.
30#ifndef _GNU_SOURCE
31# define _GNU_SOURCE
32#endif
33
34#ifdef HAVE_CONFIG_H
35#include <scconfig.h>
36#endif
37
38#ifdef HAVE_TIME_H
39#include <time.h>
40#endif
41
42#include <scdirlist.h>
43
44#include <new>
45#include <stdexcept>
46#include <string.h>
47#include <unistd.h>
48#include <sys/stat.h>
49#include <fstream>
50
51#include <scconfig.h>
52#ifdef HAVE_SSTREAM
53# include <sstream>
54#else
55# include <strstream.h>
56#endif
57
58#ifdef HAVE_SYS_RESOURCE_H
59# include <sys/resource.h>
60#endif
61#ifdef HAVE_SYS_TIME_H
62# include <sys/time.h>
63#endif
64
65#include <util/options/GetLongOpt.h>
66#include <util/class/scexception.h>
67#include <util/misc/newstring.h>
68#include <util/keyval/keyval.h>
69#include <util/state/state_bin.h>
70#include <util/group/message.h>
71#include <util/group/memory.h>
72#include <util/group/mstate.h>
73#include <util/group/thread.h>
74#include <util/group/pregtime.h>
75#include <util/misc/bug.h>
76#include <util/misc/formio.h>
77#include <util/misc/exenv.h>
78#ifdef HAVE_CHEMISTRY_CCA
79 #include <util/misc/ccaenv.h>
80#endif
81#include <util/render/render.h>
82
83#include <math/optimize/opt.h>
84
85#include <chemistry/molecule/coor.h>
86#include <chemistry/molecule/energy.h>
87#include <chemistry/molecule/molfreq.h>
88#include <chemistry/molecule/fdhess.h>
89#include <chemistry/molecule/formula.h>
90#include <chemistry/qc/wfn/wfn.h>
91
92// Force linkages:
93#include <util/group/linkage.h>
94#include <chemistry/qc/wfn/linkage.h>
95#include <chemistry/qc/scf/linkage.h>
96#include <chemistry/qc/dft/linkage.h>
97#include <chemistry/qc/mbpt/linkage.h>
98#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_MBPTR12
99# include <chemistry/qc/mbptr12/linkage.h>
100#endif
101#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_CINTS
102# include <chemistry/qc/cints/linkage.h>
103#endif
104//#include <chemistry/qc/psi/linkage.h>
105#include <util/state/linkage.h>
106#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_CC
107# include <chemistry/qc/cc/linkage.h>
108#endif
109#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_PSI
110# include <chemistry/qc/psi/linkage.h>
111#endif
112#ifdef HAVE_SC_SRC_LIB_CHEMISTRY_QC_INTCCA
113# include <chemistry/qc/intcca/linkage.h>
114#endif
115
116#ifdef HAVE_MPI
117#define MPICH_SKIP_MPICXX
118#include <mpi.h>
119#include <util/group/messmpi.h>
120#endif
121
122using namespace std;
123using namespace sc;
124
125#include "mpqcin.h"
126#include "mpqc.h"
127#include "mpqc_extract.h"
128
129//////////////////////////////////////////////////////////////////////////
130
131const KeyValValueboolean truevalue(1), falsevalue(0);
132const char *devnull = "/dev/null";
133
134
135static void
136trash_stack_b(int &i, char *&ichar)
137{
138 char stack;
139 ichar = &stack;
140 ichar -= 10;
141 for (i=0; i<1000; i++) {
142 *ichar-- = 0xfe;
143 }
144}
145
146static void
147trash_stack()
148{
149 int i;
150 char *ichar;
151 trash_stack_b(i,ichar);
152}
153
154namespace detail {
155
156 void
157 clean_up(void)
158 {
159 ::MemoryGrp::set_default_memorygrp(0);
160 ::ThreadGrp::set_default_threadgrp(0);
161 ::SCMatrixKit::set_default_matrixkit(0);
162 ::Integral::set_default_integral(0);
163 ::RegionTimer::set_default_regiontimer(0);
164 }
165
166} /* namespace detail */
167
168static void
169final_clean_up(void)
170{
171 MessageGrp::set_default_messagegrp(0);
172}
173
174#include <signal.h>
175
176#ifdef HAVE_FENV_H
177# include <fenv.h>
178#endif
179
180static void
181print_unseen(const Ref<ParsedKeyVal> &parsedkv,
182 const char *input)
183{
184 if (parsedkv->have_unseen()) {
185 ExEnv::out0() << endl;
186 ExEnv::out0() << indent
187 << "The following keywords in \"" << input << "\" were ignored:"
188 << endl;
189 ExEnv::out0() << incindent;
190 parsedkv->print_unseen(ExEnv::out0());
191 ExEnv::out0() << decindent;
192 }
193}
194
195double EvaluateDensity(
196 SCVector3 &r,
197 Ref<Integral> &intgrl,
198 GaussianBasisSet::ValueData &vdat,
199 Ref<Wavefunction> &wfn);
200
201/** Places all known options into \a options and parses them from argc,argv.
202 *
203 * \param options options structure
204 * \param argc argument count
205 * \param argv argument array
206 * \return return value by GetLongOpt::parse() function
207 */
208int ParseOptions(
209 GetLongOpt &options,
210 int argc,
211 char **argv)
212{
213 options.usage("[options] [filename]");
214 options.enroll("f", GetLongOpt::MandatoryValue,
215 "the name of an object format input file", 0);
216 options.enroll("o", GetLongOpt::MandatoryValue,
217 "the name of the output file", 0);
218 options.enroll("n", GetLongOpt::MandatoryValue,
219 "listen for incoming object format input files", 0);
220 options.enroll("messagegrp", GetLongOpt::MandatoryValue,
221 "which message group to use", 0);
222 options.enroll("threadgrp", GetLongOpt::MandatoryValue,
223 "which thread group to use", 0);
224 options.enroll("memorygrp", GetLongOpt::MandatoryValue,
225 "which memory group to use", 0);
226 options.enroll("integral", GetLongOpt::MandatoryValue,
227 "which integral evaluator to use", 0);
228 options.enroll("l", GetLongOpt::MandatoryValue, "basis set limit", "0");
229 options.enroll("W", GetLongOpt::MandatoryValue,
230 "set the working directory", ".");
231 options.enroll("c", GetLongOpt::NoValue, "check input then exit", 0);
232 options.enroll("v", GetLongOpt::NoValue, "print the version number", 0);
233 options.enroll("w", GetLongOpt::NoValue, "print the warranty", 0);
234 options.enroll("L", GetLongOpt::NoValue, "print the license", 0);
235 options.enroll("k", GetLongOpt::NoValue, "print key/value assignments", 0);
236 options.enroll("vv", GetLongOpt::NoValue, "print the output", 0);
237 options.enroll("i", GetLongOpt::NoValue, "convert simple to OO input", 0);
238 options.enroll("d", GetLongOpt::NoValue, "debug", 0);
239 options.enroll("h", GetLongOpt::NoValue, "print this message", 0);
240 options.enroll("cca-path", GetLongOpt::OptionalValue,
241 "cca component path", "");
242 options.enroll("cca-load", GetLongOpt::OptionalValue,
243 "cca components to load", "");
244
245 int optind = options.parse(argc, argv);
246
247 return optind;
248}
249
250/** Checks for each known option and acts accordingly.
251 *
252 * \param options option structure
253 * \param *output name of outputfile on return
254 * \param *outstream open output stream on return
255 */
256void ComputeOptions(
257 GetLongOpt &options,
258 const char *&output,
259 ostream *&outstream)
260{
261 output = options.retrieve("o");
262 outstream = 0;
263 if (output != 0) {
264 outstream = new ofstream(output);
265 ExEnv::set_out(outstream);
266 }
267
268 if (options.retrieve("h")) {
269 ExEnv::out0()
270 << indent << "MPQC version " << SC_VERSION << endl
271 << indent << "compiled for " << TARGET_ARCH << endl
272 << SCFormIO::copyright << endl;
273 options.usage(ExEnv::out0());
274 exit(0);
275 }
276
277 if (options.retrieve("v")) {
278 ExEnv::out0()
279 << indent << "MPQC version " << SC_VERSION << endl
280 << indent << "compiled for " << TARGET_ARCH << endl
281 << SCFormIO::copyright;
282 exit(0);
283 }
284
285 if (options.retrieve("w")) {
286 ExEnv::out0()
287 << indent << "MPQC version " << SC_VERSION << endl
288 << indent << "compiled for " << TARGET_ARCH << endl
289 << SCFormIO::copyright << endl
290 << SCFormIO::warranty;
291 exit(0);
292 }
293
294 if (options.retrieve("L")) {
295 ExEnv::out0()
296 << indent << "MPQC version " << SC_VERSION << endl
297 << indent << "compiled for " << TARGET_ARCH << endl
298 << SCFormIO::copyright << endl
299 << SCFormIO::license;
300 exit(0);
301 }
302
303 if (options.retrieve("d"))
304 SCFormIO::set_debug(1);
305
306 // set the working dir
307 if (strcmp(options.retrieve("W"),"."))
308 int retval = chdir(options.retrieve("W"));
309
310 // check that n and f/o are not given at the same time
311 if ((options.retrieve("n")) && ((options.retrieve("f")) || (options.retrieve("o")))) {
312 throw invalid_argument("-n must not be given with -f or -o");
313 }
314}
315
316/** Parse remainder options not treated by ComputeOptions() into temporary storage.
317 *
318 * \param options option structure to obtain values from
319 * \param values remaining option values which are processed later and now
320 * stored in a temporary structure
321 */
322void parseRemainderOptions(
323 GetLongOpt &options,
324 detail::OptionValues &values,
325 int argc,
326 char **argv)
327{
328 values.keyvalue = options.retrieve("k");
329 values.debug = options.retrieve("d");
330 values.limit = atoi(options.retrieve("l"));
331 values.check = options.retrieve("c");
332 values.simple_input = options.retrieve("i");
333 values.executablename = argv[0];
334
335#ifdef HAVE_CHEMISTRY_CCA
336 values.cca_load = options.retrieve("cca-load");
337 values.cca_path = options.retrieve("cca-path");
338#endif
339}
340
341/** Sets object and generic input file names.
342 *
343 * \param object_input filename of object-oriented input
344 * \param generic_input filename of generic input
345 * \param options (command-line)option structure
346 * \param argc argument count
347 * \param argv argument array
348 */
349void getInputFileNames(
350 const char *&object_input,
351 const char *&generic_input,
352 GetLongOpt &options,
353 int optind,
354 int argc,
355 char **argv)
356{
357 // initialize keyval input
358 object_input = options.retrieve("f");
359 generic_input = 0;
360 if (argc - optind == 0) {
361 generic_input = 0;
362 }
363 else if (argc - optind == 1) {
364 generic_input = argv[optind];
365 }
366 else if (!options.retrieve("n")) {
367 options.usage();
368 throw invalid_argument("extra arguments given");
369 }
370
371 if (object_input == 0 && generic_input == 0) {
372 generic_input = "mpqc.in";
373 }
374 else if (object_input && !options.retrieve("n") && generic_input) {
375 options.usage();
376 throw invalid_argument("only one of -f and a file argument can be given");
377 }
378}
379
380/** Gets the MPI Message group.
381 *
382 * \param grp reference to obtained group
383 * \param argc argument count
384 * \param argv argument array
385 */
386void getMessageGroup(
387 Ref<MessageGrp> &grp,
388 int argc,
389 char **argv)
390{
391#if defined(HAVE_MPI) && defined(ALWAYS_USE_MPI)
392 grp = new MPIMessageGrp(&argc, &argv);
393#endif
394 if (grp.null()) grp = MessageGrp::initial_messagegrp(argc, argv);
395 if (grp.nonnull())
396 MessageGrp::set_default_messagegrp(grp);
397 else
398 grp = MessageGrp::get_default_messagegrp();
399}
400
401/** Sets the base name of output files.
402 *
403 * \param input input file name
404 * \param output output file name
405 */
406void setOutputBaseName(const char *input, const char *output)
407{
408 const char *basename_source;
409 if (output) basename_source = output;
410 else basename_source = input;
411 const char *baseprefix = ::strrchr(basename_source, '.');
412 int nfilebase = 1;
413 if (baseprefix == NULL) {
414 std::cerr << "setOutputBaseName() - ERROR: basename_source "
415 << basename_source << " contains no dot (.)." << std::endl;
416 nfilebase = ::strlen(basename_source);
417 } else
418 nfilebase = (int) (baseprefix - basename_source);
419 char *basename = new char[nfilebase + 1];
420 strncpy(basename, basename_source, nfilebase);
421 basename[nfilebase] = '\0';
422 SCFormIO::set_default_basename(basename);
423 delete[] basename;
424}
425
426/** Prints current key values.
427 *
428 * \param keyval key value structure
429 * \param opt optimization structure
430 * \param molname name of molecule
431 * \param restartfile name of restartfile
432 */
433void printOptions(
434 Ref<KeyVal> &keyval,
435 Ref<Optimize> &opt,
436 const char *molname,
437 const char *restartfile)
438{
439 int restart = keyval->booleanvalue("restart",truevalue);
440
441 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
442
443 int savestate = keyval->booleanvalue("savestate",truevalue);
444
445 int do_energy = keyval->booleanvalue("do_energy",truevalue);
446
447 int do_grad = keyval->booleanvalue("do_gradient",falsevalue);
448
449 int do_opt = keyval->booleanvalue("optimize",truevalue);
450
451 int do_pdb = keyval->booleanvalue("write_pdb",falsevalue);
452
453 int print_mole = keyval->booleanvalue("print_mole",truevalue);
454
455 int print_timings = keyval->booleanvalue("print_timings",truevalue);
456
457 // sanity checks for the benefit of reasonable looking output
458 if (opt.null()) do_opt=0;
459
460 ExEnv::out0() << endl << indent
461 << "MPQC options:" << endl << incindent
462 << indent << "matrixkit = <"
463 << SCMatrixKit::default_matrixkit()->class_name() << ">" << endl
464 << indent << "filename = " << molname << endl
465 << indent << "restart_file = " << restartfile << endl
466 << indent << "restart = " << (restart ? "yes" : "no") << endl
467 << indent << "checkpoint = " << (checkpoint ? "yes" : "no") << endl
468 << indent << "savestate = " << (savestate ? "yes" : "no") << endl
469 << indent << "do_energy = " << (do_energy ? "yes" : "no") << endl
470 << indent << "do_gradient = " << (do_grad ? "yes" : "no") << endl
471 << indent << "optimize = " << (do_opt ? "yes" : "no") << endl
472 << indent << "write_pdb = " << (do_pdb ? "yes" : "no") << endl
473 << indent << "print_mole = " << (print_mole ? "yes" : "no") << endl
474 << indent << "print_timings = " << (print_timings ? "yes" : "no")
475 << endl << decindent;
476
477}
478
479/** Saves the current state to checkpoint file.
480 *
481 * \param keyval key value structure
482 * \param opt optimization structure
483 * \param grp message group
484 * \param mole MolecularEnergy object
485 * \param molname name of molecule
486 * \param ckptfile name of check point file
487 */
488void saveState(
489 char *wfn_file,
490 int savestate,
491 Ref<Optimize> &opt,
492 Ref<MessageGrp> &grp,
493 Ref<MolecularEnergy> &mole,
494 char *&molname,
495 char *&ckptfile)
496{
497 // function stuff
498 if (savestate) {
499 if (opt.nonnull()) {
500 if (grp->me() == 0) {
501 ckptfile = new char[strlen(molname)+6];
502 sprintf(ckptfile,"%s.ckpt",molname);
503 }
504 else {
505 ckptfile = new char[strlen(devnull)+1];
506 strcpy(ckptfile, devnull);
507 }
508
509 StateOutBin so(ckptfile);
510 SavableState::save_state(opt.pointer(),so);
511 so.close();
512
513 delete[] ckptfile;
514 }
515
516 if (mole.nonnull()) {
517 if (grp->me() == 0) {
518 if (wfn_file == 0) {
519 wfn_file = new char[strlen(molname)+6];
520 sprintf(wfn_file,"%s.wfn",molname);
521 }
522 }
523 else {
524 delete[] wfn_file;
525 wfn_file = new char[strlen(devnull)+1];
526 strcpy(wfn_file, devnull);
527 }
528
529 StateOutBin so(wfn_file);
530 SavableState::save_state(mole.pointer(),so);
531 so.close();
532
533 }
534 }
535 delete[] wfn_file;
536}
537
538/** Sets up indentation and output modes.
539 *
540 * \param grp message group
541 */
542void setupSCFormIO(
543 Ref<MessageGrp> &grp
544 )
545{
546 SCFormIO::setindent(ExEnv::outn(), 2);
547 SCFormIO::setindent(ExEnv::errn(), 2);
548 SCFormIO::setindent(cout, 2);
549 SCFormIO::setindent(cerr, 2);
550
551 SCFormIO::set_printnode(0);
552 if (grp->n() > 1)
553 SCFormIO::init_mp(grp->me());
554}
555
556/** Initialises the timer.
557 *
558 * \param grp message group
559 * \param keyval key value structure
560 * \param tim timing structure
561 */
562void initTimings(
563 Ref<MessageGrp> &grp,
564 Ref<KeyVal> &keyval,
565 Ref<RegionTimer> &tim
566 )
567{
568 grp->sync(); // make sure nodes are sync'ed before starting timings
569 if (keyval->exists("timer")) tim << keyval->describedclassvalue("timer");
570 else tim = new ParallelRegionTimer(grp,"mpqc",1,1);
571 RegionTimer::set_default_regiontimer(tim);
572
573 if (tim.nonnull()) tim->enter("input");
574}
575
576/** Prints the header of the output.
577 *
578 * \param tim timing structure
579 */
580void makeAnnouncement(
581 Ref<RegionTimer> &tim
582 )
583{
584 const char title1[] = "MPQC: Massively Parallel Quantum Chemistry";
585 int ntitle1 = sizeof(title1);
586 const char title2[] = "Version " SC_VERSION;
587 int ntitle2 = sizeof(title2);
588 ExEnv::out0() << endl;
589 ExEnv::out0() << indent;
590 for (int i=0; i<(80-ntitle1)/2; i++) ExEnv::out0() << ' ';
591 ExEnv::out0() << title1 << endl;
592 ExEnv::out0() << indent;
593 for (int i=0; i<(80-ntitle2)/2; i++) ExEnv::out0() << ' ';
594 ExEnv::out0() << title2 << endl << endl;
595
596 const char *tstr = 0;
597#if defined(HAVE_TIME) && defined(HAVE_CTIME)
598 time_t t;
599 time(&t);
600 tstr = ctime(&t);
601#endif
602 if (!tstr) {
603 tstr = "UNKNOWN";
604 }
605
606 ExEnv::out0()
607 << indent << scprintf("Machine: %s", TARGET_ARCH) << endl
608 << indent << scprintf("User: %s@%s",
609 ExEnv::username(), ExEnv::hostname()) << endl
610 << indent << scprintf("Start Time: %s", tstr) << endl;
611}
612
613/** Parse the input configuration from char array into keyvalue container.
614 *
615 * \param parsedkv key value container to fill
616 * \param values temporary options value structure
617 * \param in_char_array char array with input file
618 * \param use_simple_input whether the format in \a in_char_array is simple (1)
619 * or object-oriented (0)
620 */
621void parseIntoKeyValue(
622 Ref<ParsedKeyVal> &parsedkv,
623 detail::OptionValues &values,
624 char *&in_char_array,
625 int use_simple_input)
626{
627 if (use_simple_input) {
628 MPQCIn mpqcin;
629 char *simple_input_text = mpqcin.parse_string(in_char_array);
630 if (values.simple_input) {
631 ExEnv::out0() << "Generated object-oriented input file:" << endl
632 << simple_input_text
633 << endl;
634 exit(0);
635 }
636 parsedkv = new ParsedKeyVal();
637 parsedkv->parse_string(simple_input_text);
638 delete[] simple_input_text;
639 } else {
640 parsedkv = new ParsedKeyVal();
641 parsedkv->parse_string(in_char_array);
642 }
643}
644
645/** Parse the input file into the key value container.
646 *
647 * \param grp message group
648 * \param parsedkev keyvalue container on return
649 * \param values (command-line) options structure
650 * \param input input file name
651 * \param generic_input filename of generic input
652 * \param in_char_array char array with input file's contents on return
653 * \param use_simple_input whether the file contents is in simple format (1)
654 * or object-oriented (0)
655 */
656void parseInputfile(
657 Ref<MessageGrp> &grp,
658 Ref<ParsedKeyVal> &parsedkv,
659 detail::OptionValues &values,
660 const char *&input,
661 const char *&generic_input,
662 char *&in_char_array,
663 int &use_simple_input
664 )
665{
666 // read the input file on only node 0
667 if (grp->me() == 0) {
668 ifstream is(input);
669#ifdef HAVE_SSTREAM
670 ostringstream ostrs;
671 is >> ostrs.rdbuf();
672 int n = 1 + strlen(ostrs.str().c_str());
673 in_char_array = strcpy(new char[n],ostrs.str().c_str());
674#else
675 ostrstream ostrs;
676 is >> ostrs.rdbuf();
677 ostrs << ends;
678 in_char_array = ostrs.str();
679 int n = ostrs.pcount();
680#endif
681 grp->bcast(n);
682 grp->bcast(in_char_array, n);
683 }
684 else {
685 int n;
686 grp->bcast(n);
687 in_char_array = new char[n];
688 grp->bcast(in_char_array, n);
689 }
690
691 if (generic_input && grp->me() == 0) {
692 MPQCIn mpqcin;
693 use_simple_input = mpqcin.check_string(in_char_array);
694 }
695 else {
696 use_simple_input = 0;
697 }
698 grp->bcast(use_simple_input);
699}
700
701/** Get the thread group.
702 *
703 * \param keyval keyvalue container
704 * \param thread thread group on return
705 * \param argc argument count
706 * \param argv argument array
707 */
708void getThreadGroup(
709 Ref<KeyVal> &keyval,
710 Ref<ThreadGrp> &thread,
711 int argc,
712 char **argv)
713{
714 //first try the commandline and environment
715 thread = ThreadGrp::initial_threadgrp(argc, argv);
716
717 // if we still don't have a group, try reading the thread group
718 // from the input
719 if (thread.null()) {
720 thread << keyval->describedclassvalue("thread");
721 }
722
723 if (thread.nonnull())
724 ThreadGrp::set_default_threadgrp(thread);
725 else
726 thread = ThreadGrp::get_default_threadgrp();
727}
728
729/** Get the memory group.
730 *
731 * \param keyval keyvalue container
732 * \param memory memory group on return
733 * \param argc argument count
734 * \param argv argument array
735 */
736void getMemoryGroup(
737 Ref<KeyVal> &keyval,
738 Ref<MemoryGrp> &memory,
739 int argc,
740 char **argv)
741{
742 // first try the commandline and environment
743 memory = MemoryGrp::initial_memorygrp(argc, argv);
744
745 // if we still don't have a group, try reading the memory group
746 // from the input
747 if (memory.null()) {
748 memory << keyval->describedclassvalue("memory");
749 }
750
751 if (memory.nonnull())
752 MemoryGrp::set_default_memorygrp(memory);
753 else
754 memory = MemoryGrp::get_default_memorygrp();
755}
756
757/** Prepares CCA component if available.
758 *
759 * \param keyval keyvalue container
760 * \param values parsed (command-line) options
761 */
762void prepareCCA(
763 Ref<KeyVal> &keyval,
764 detail::OptionValues &values
765 )
766{
767#ifdef HAVE_CHEMISTRY_CCA
768 // initialize cca framework
769 KeyValValuestring emptystring("");
770 bool do_cca = keyval->booleanvalue("do_cca",falsevalue);
771
772 string cca_path(values.cca_path);
773 string cca_load(values.cca_load);
774 if(cca_path.size()==0)
775 cca_path = keyval->stringvalue("cca_path",emptystring);
776 if(cca_load.size()==0)
777 cca_load = keyval->stringvalue("cca_load",emptystring);
778
779 if( !do_cca && (cca_load.size() > 0 || cca_path.size() > 0) )
780 do_cca = true;
781
782 if(cca_path.size()==0) {
783 #ifdef CCA_PATH
784 cca_path = CCA_PATH;
785 #endif
786 }
787 if(cca_load.size()==0) {
788 cca_load += "MPQC.IntegralEvaluatorFactory";
789 }
790
791 if( cca_load.size() > 0 && cca_path.size() > 0 && do_cca ) {
792 string cca_args = "--path " + cca_path + " --load " + cca_load;
793 ExEnv::out0() << endl << indent << "Initializing CCA framework with args: "
794 << endl << indent << cca_args << endl;
795 CCAEnv::init( cca_args );
796 }
797#endif
798}
799
800/** Setup debugger.
801 *
802 * \param keyval keyvalue container
803 * \param grp message group
804 * \param debugger debugger structure
805 * \param options parsed command line options
806 */
807void setupDebugger(
808 Ref<KeyVal> &keyval,
809 Ref<MessageGrp> &grp,
810 Ref<Debugger> &debugger,
811 detail::OptionValues &values)
812{
813 debugger << keyval->describedclassvalue("debug");
814 if (debugger.nonnull()) {
815 Debugger::set_default_debugger(debugger);
816 debugger->set_exec(values.executablename.c_str());
817 debugger->set_prefix(grp->me());
818 if (values.debug)
819 debugger->debug("Starting debugger because -d given on command line.");
820 }
821}
822
823/** Get integral factory.
824 *
825 * \param keyval keyvalue container
826 * \param integral integral group on return
827 * \param argc argument count
828 * \param argv argument array
829 */
830void getIntegralFactory(
831 Ref<KeyVal> &keyval,
832 Ref<Integral> &integral,
833 int argc,
834 char **argv)
835{
836 // first try commandline and environment
837 integral = Integral::initial_integral(argc, argv);
838
839 // if we still don't have a integral, try reading the integral
840 // from the input
841 if (integral.null()) {
842 integral << keyval->describedclassvalue("integrals");
843 }
844
845 if (integral.nonnull())
846 Integral::set_default_integral(integral);
847 else
848 integral = Integral::get_default_integral();
849
850}
851
852void performRestart(
853 Ref<KeyVal> &keyval,
854 Ref<MessageGrp> &grp,
855 Ref<Optimize> &opt,
856 Ref<MolecularEnergy> &mole,
857 char *&restartfile
858 )
859{
860 int restart = keyval->booleanvalue("restart",truevalue);
861 struct stat sb;
862 int statresult, statsize;
863 if (restart) {
864 if (grp->me() == 0) {
865 statresult = stat(restartfile,&sb);
866 statsize = (statresult==0) ? sb.st_size : 0;
867 }
868 grp->bcast(statresult);
869 grp->bcast(statsize);
870 }
871 if (restart && statresult==0 && statsize) {
872 BcastStateInBin si(grp,restartfile);
873 if (keyval->exists("override")) {
874 si.set_override(new PrefixKeyVal(keyval,"override"));
875 }
876 char *suf = strrchr(restartfile,'.');
877 if (!strcmp(suf,".wfn")) {
878 mole << SavableState::key_restore_state(si,"mole");
879 ExEnv::out0() << endl
880 << indent << "Restored <" << mole->class_name()
881 << "> from " << restartfile << endl;
882
883 opt << keyval->describedclassvalue("opt");
884 if (opt.nonnull())
885 opt->set_function(mole.pointer());
886 }
887 else {
888 opt << SavableState::key_restore_state(si,"opt");
889 if (opt.nonnull()) {
890 mole << opt->function();
891 ExEnv::out0() << endl << indent
892 << "Restored <Optimize> from " << restartfile << endl;
893 }
894 }
895 } else {
896 mole << keyval->describedclassvalue("mole");
897 opt << keyval->describedclassvalue("opt");
898 }
899}
900
901char *setMolecularCheckpointFile(
902 Ref<KeyVal> &keyval,
903 Ref<MessageGrp> &grp,
904 Ref<MolecularEnergy> &mole,
905 char *mole_ckpt_file
906 )
907{
908 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
909 int checkpoint_freq = keyval->intvalue("checkpoint_freq",KeyValValueint(1));
910 if (mole.nonnull()) {
911 MolecularFormula mf(mole->molecule());
912 ExEnv::out0() << endl << indent
913 << "Molecular formula " << mf.formula() << endl;
914 if (checkpoint) {
915 mole->set_checkpoint();
916 if (grp->me() == 0) mole->set_checkpoint_file(mole_ckpt_file);
917 else mole->set_checkpoint_file(devnull);
918 mole->set_checkpoint_freq(checkpoint_freq);
919 }
920 }
921}
922
923/** Checks whether limit on command-line exceeds the basis functions.
924 *
925 * \param mole molecular energy object
926 * \param values temporarily storage for (command-line) options
927 * \return 0 - not exceeded, 1 - exceeded
928 */
929int checkBasisSetLimit(
930 Ref<MolecularEnergy> &mole,
931 detail::OptionValues &values
932 )
933{
934 int check = (values.check != (const char *)0);
935 int limit = values.limit;
936 if (limit) {
937 Ref<Wavefunction> wfn; wfn << mole;
938 if (wfn.nonnull() && wfn->ao_dimension()->n() > limit) {
939 ExEnv::out0() << endl << indent
940 << "The limit of " << limit << " basis functions has been exceeded."
941 << endl;
942 check = 1;
943 }
944 }
945 return check;
946}
947
948/** Performs the energy optimization.
949 *
950 * \param opt optimization object
951 * \param mole molecular energy object
952 * \return 0 - not read for frequency calculation, 1 - ready
953 */
954int performEnergyOptimization(
955 Ref<Optimize> &opt,
956 Ref<MolecularEnergy> &mole
957 )
958{
959 int ready_for_freq = 0;
960 int result = opt->optimize();
961 if (result) {
962 ExEnv::out0() << indent
963 << "The optimization has converged." << endl << endl;
964 ExEnv::out0() << indent
965 << scprintf("Value of the MolecularEnergy: %15.10f",
966 mole->energy())
967 << endl << endl;
968 ready_for_freq = 1;
969 } else {
970 ExEnv::out0() << indent
971 << "The optimization has NOT converged." << endl << endl;
972 ready_for_freq = 0;
973 }
974 return ready_for_freq;
975}
976
977/** Performs gradient calculation.
978 *
979 * \param mole molecular energy object
980 */
981void performGradientCalculation(
982 Ref<MolecularEnergy> &mole
983 )
984{
985 mole->do_gradient(1);
986 ExEnv::out0() << endl << indent
987 << scprintf("Value of the MolecularEnergy: %15.10f",
988 mole->energy())
989 << endl;
990 if (mole->value_result().actual_accuracy()
991 > mole->value_result().desired_accuracy()) {
992 ExEnv::out0() << indent
993 << "WARNING: desired accuracy not achieved in energy" << endl;
994 }
995 ExEnv::out0() << endl;
996 // Use result_noupdate since the energy might not have converged
997 // to the desired accuracy in which case grabbing the result will
998 // start up the calculation again. However the gradient might
999 // not have been computed (if we are restarting and the gradient
1000 // isn't in the save file for example).
1001 RefSCVector grad;
1002 if (mole->gradient_result().computed()) {
1003 grad = mole->gradient_result().result_noupdate();
1004 }
1005 else {
1006 grad = mole->gradient();
1007 }
1008 if (grad.nonnull()) {
1009 grad.print("Gradient of the MolecularEnergy:");
1010 if (mole->gradient_result().actual_accuracy()
1011 > mole->gradient_result().desired_accuracy()) {
1012 ExEnv::out0() << indent
1013 << "WARNING: desired accuracy not achieved in gradient" << endl;
1014 }
1015 }
1016}
1017
1018/** Performs frequency calculation.
1019 *
1020 * \param mole molecular energy object
1021 * \param molhess molecular hessian object
1022 * \param molfreq molecular frequency object
1023 */
1024void performFrequencyCalculation(
1025 Ref<MolecularEnergy> &mole,
1026 Ref<MolecularHessian> &molhess,
1027 Ref<MolecularFrequencies> &molfreq
1028
1029 )
1030{
1031 RefSymmSCMatrix xhessian;
1032 if (molhess.nonnull()) {
1033 // if "hess" input was given, use it to compute the hessian
1034 xhessian = molhess->cartesian_hessian();
1035 }
1036 else if (mole->hessian_implemented()) {
1037 // if mole can compute the hessian, use that hessian
1038 xhessian = mole->get_cartesian_hessian();
1039 }
1040 else if (mole->gradient_implemented()) {
1041 // if mole can compute gradients, use gradients at finite
1042 // displacements to compute the hessian
1043 molhess = new FinDispMolecularHessian(mole);
1044 xhessian = molhess->cartesian_hessian();
1045 }
1046 else {
1047 ExEnv::out0() << "mpqc: WARNING: Frequencies cannot be computed" << endl;
1048 }
1049
1050 if (xhessian.nonnull()) {
1051 char *hessfile = SCFormIO::fileext_to_filename(".hess");
1052 MolecularHessian::write_cartesian_hessian(hessfile,
1053 mole->molecule(), xhessian);
1054 delete[] hessfile;
1055
1056 molfreq->compute_frequencies(xhessian);
1057 // DEGENERACY IS NOT CORRECT FOR NON-SINGLET CASES:
1058 molfreq->thermochemistry(1);
1059 }
1060}
1061
1062/** Renders some objects.
1063 *
1064 * \param renderer renderer object
1065 * \param keyval keyvalue container
1066 * \param tim timing object
1067 * \param grp message group
1068 */
1069void renderObjects(
1070 Ref<Render> &renderer,
1071 Ref<KeyVal> &keyval,
1072 Ref<RegionTimer> &tim,
1073 Ref<MessageGrp> &grp
1074 )
1075{
1076 Ref<RenderedObject> rendered;
1077 rendered << keyval->describedclassvalue("rendered");
1078 Ref<AnimatedObject> animated;
1079 animated << keyval->describedclassvalue("rendered");
1080 if (rendered.nonnull()) {
1081 if (tim.nonnull()) tim->enter("render");
1082 if (grp->me() == 0) renderer->render(rendered);
1083 if (tim.nonnull()) tim->exit("render");
1084 }
1085 else if (animated.nonnull()) {
1086 if (tim.nonnull()) tim->enter("render");
1087 if (grp->me() == 0) renderer->animate(animated);
1088 if (tim.nonnull()) tim->exit("render");
1089 }
1090 else {
1091 if (tim.nonnull()) tim->enter("render");
1092 int n = keyval->count("rendered");
1093 for (int i=0; i<n; i++) {
1094 rendered << keyval->describedclassvalue("rendered",i);
1095 animated << keyval->describedclassvalue("rendered",i);
1096 if (rendered.nonnull()) {
1097 // make sure the object has a name so we don't overwrite its file
1098 if (rendered->name() == 0) {
1099 char ic[64];
1100 sprintf(ic,"%02d",i);
1101 rendered->set_name(ic);
1102 }
1103 if (grp->me() == 0) renderer->render(rendered);
1104 }
1105 else if (animated.nonnull()) {
1106 // make sure the object has a name so we don't overwrite its file
1107 if (animated->name() == 0) {
1108 char ic[64];
1109 sprintf(ic,"%02d",i);
1110 animated->set_name(ic);
1111 }
1112 if (grp->me() == 0) renderer->animate(animated);
1113 }
1114 }
1115 if (tim.nonnull()) tim->exit("render");
1116 }
1117}
1118
1119/** Save the molecule to PDB file.
1120 *
1121 * \param do_pdb whether to save as pdb (1) or not (0)
1122 * \param grp message group
1123 * \param mole molecular energy object
1124 * \param molname name of output file
1125 */
1126void saveToPdb(
1127 int do_pdb,
1128 Ref<MessageGrp> &grp,
1129 Ref<MolecularEnergy> &mole,
1130 const char *molname
1131 )
1132{
1133 if (do_pdb && grp->me() == 0) {
1134 char *ckptfile = new char[strlen(molname)+5];
1135 sprintf(ckptfile, "%s.pdb", molname);
1136 ofstream pdbfile(ckptfile);
1137 mole->molecule()->print_pdb(pdbfile);
1138 delete[] ckptfile;
1139 }
1140}
1141
1142void init()
1143{
1144 //trash_stack();
1145
1146 int i;
1147 atexit(detail::clean_up);
1148
1149#ifdef HAVE_FEENABLEEXCEPT
1150 // this uses a glibc extension to trap on individual exceptions
1151# ifdef FE_DIVBYZERO
1152 feenableexcept(FE_DIVBYZERO);
1153# endif
1154# ifdef FE_INVALID
1155 feenableexcept(FE_INVALID);
1156# endif
1157# ifdef FE_OVERFLOW
1158 feenableexcept(FE_OVERFLOW);
1159# endif
1160#endif
1161
1162#ifdef HAVE_FEDISABLEEXCEPT
1163 // this uses a glibc extension to not trap on individual exceptions
1164# ifdef FE_UNDERFLOW
1165 fedisableexcept(FE_UNDERFLOW);
1166# endif
1167# ifdef FE_INEXACT
1168 fedisableexcept(FE_INEXACT);
1169# endif
1170#endif
1171
1172#if defined(HAVE_SETRLIMIT)
1173 struct rlimit rlim;
1174 rlim.rlim_cur = 0;
1175 rlim.rlim_max = 0;
1176 setrlimit(RLIMIT_CORE,&rlim);
1177#endif
1178}
1179
1180//!> this is backup for the old ExEnv::out0 stream when we override using /dev/null
1181ostream *oldstream = NULL;
1182
1183/** Performs the main work to calculate the ground state energies, gradients, etc.
1184 *
1185 * @param _initvalues struct with all state variables
1186 * @param argc argument count
1187 * @param argv argument array
1188 * @param data void ptr to extract structure
1189 */
1190void mpqc::mainFunction(
1191 mpqc::InitValues &_initvalues,
1192 int argc,
1193 char **argv,
1194 void *data
1195 )
1196{
1197 // get the basename for output files
1198 setOutputBaseName(_initvalues.input, _initvalues.output);
1199
1200 // Based on verbose flag in InitValues, out ExEnv::set_out to nullstream (see out0()) to mute info
1201 ofstream nullofstream;
1202 if (( _initvalues.output == 0 ) && ( _initvalues.options.retrieve("vv") == 0 )) {
1203 // only change out0 when oldstream is unset, yet
1204 if (oldstream == NULL) {
1205 ExEnv::out0() << "Muting mpqc's output due to verbosity level of 0." << endl;
1206 nullofstream.open("/dev/null");
1207 oldstream = &ExEnv::out0();
1208 ExEnv::set_out(&nullofstream);
1209 }
1210 } else {
1211 // only revert out0 if oldstream is set, i.e., when it has been changed
1212 if (oldstream != NULL) {
1213 ExEnv::out0() << "Unmuting mpqc's output due to verbosity level of 1 or larger." << endl;
1214 ExEnv::set_out(oldstream);
1215 oldstream = NULL;
1216 }
1217 }
1218
1219 // parse input into keyvalue container
1220 Ref<ParsedKeyVal> parsedkv;
1221 int use_simple_input = 0; // default is object-oriented if in_char_array is given
1222 if (!_initvalues.in_char_array) // obtain from file
1223 parseInputfile(
1224 _initvalues.grp,
1225 parsedkv,
1226 _initvalues.values,
1227 _initvalues.input,
1228 _initvalues.generic_input,
1229 _initvalues.in_char_array,
1230 use_simple_input);
1231 parseIntoKeyValue(
1232 parsedkv,
1233 _initvalues.values,
1234 _initvalues.in_char_array,
1235 use_simple_input);
1236// delete[] in_char_array;
1237
1238 // prefix parsed values wit "mpqc"
1239 if (_initvalues.values.keyvalue) parsedkv->verbose(1);
1240 Ref<KeyVal> keyval = new PrefixKeyVal(parsedkv.pointer(),"mpqc");
1241
1242 // set up output classes
1243 setupSCFormIO(_initvalues.grp);
1244
1245 // initialize timing for mpqc
1246 Ref<RegionTimer> tim;
1247 initTimings(_initvalues.grp, keyval, tim);
1248
1249 // announce ourselves
1250 makeAnnouncement(tim);
1251
1252 // get the thread group.
1253 Ref<ThreadGrp> thread;
1254 getThreadGroup(keyval, thread, argc, argv);
1255
1256 // get the memory group.
1257 Ref<MemoryGrp> memory;
1258 getMemoryGroup(keyval, memory, argc, argv);
1259
1260 ExEnv::out0() << indent
1261 << "Using " << _initvalues.grp->class_name()
1262 << " for message passing (number of nodes = " << _initvalues.grp->n() << ")." << endl
1263 << indent
1264 << "Using " << thread->class_name()
1265 << " for threading (number of threads = " << thread->nthread() << ")." << endl
1266 << indent
1267 << "Using " << memory->class_name()
1268 << " for distributed shared memory." << endl
1269 << indent
1270 << "Total number of processors = " << _initvalues.grp->n() * thread->nthread() << endl;
1271
1272 // prepare CCA if available
1273 prepareCCA(keyval, _initvalues.values);
1274
1275 // now set up the debugger
1276 Ref<Debugger> debugger;
1277 setupDebugger(keyval, _initvalues.grp, debugger, _initvalues.values);
1278
1279 // now check to see what matrix kit to use
1280 if (keyval->exists("matrixkit"))
1281 SCMatrixKit::set_default_matrixkit(
1282 dynamic_cast<SCMatrixKit*>(
1283 keyval->describedclassvalue("matrixkit").pointer()));
1284
1285 // get the integral factory.
1286 Ref<Integral> integral;
1287 getIntegralFactory(keyval, integral, argc, argv);
1288 ExEnv::out0() << endl << indent
1289 << "Using " << integral->class_name()
1290 << " by default for molecular integrals evaluation" << endl << endl;
1291
1292 // create some filenames for molecule, checkpoint, basename of output
1293 const char *basename = SCFormIO::default_basename();
1294 KeyValValueString molnamedef(basename);
1295 char * molname = keyval->pcharvalue("filename", molnamedef);
1296 if (strcmp(molname, basename))
1297 SCFormIO::set_default_basename(molname);
1298
1299 char * ckptfile = new char[strlen(molname)+6];
1300 sprintf(ckptfile,"%s.ckpt",molname);
1301
1302 KeyValValueString restartfiledef(ckptfile);
1303 char * restartfile = keyval->pcharvalue("restart_file", restartfiledef);
1304
1305 char * wfn_file = keyval->pcharvalue("wfn_file");
1306 if (wfn_file == 0) {
1307 wfn_file = new char[strlen(molname)+6];
1308 sprintf(wfn_file,"%s.wfn",molname);
1309 }
1310 char *mole_ckpt_file = new char[strlen(wfn_file)+1];
1311 sprintf(mole_ckpt_file,"%s",wfn_file);
1312
1313 int savestate = keyval->booleanvalue("savestate",truevalue);
1314
1315 // setup molecular energy and optimization instances
1316 Ref<MolecularEnergy> mole;
1317 Ref<Optimize> opt;
1318
1319 // read in restart file if we do restart
1320 performRestart(keyval, _initvalues.grp, opt, mole, restartfile);
1321
1322 // setup molecule checkpoint file
1323 setMolecularCheckpointFile(keyval, _initvalues.grp, mole, mole_ckpt_file);
1324 delete[] mole_ckpt_file;
1325
1326 int checkpoint = keyval->booleanvalue("checkpoint",truevalue);
1327 if (checkpoint && opt.nonnull()) {
1328 opt->set_checkpoint();
1329 if (_initvalues.grp->me() == 0) opt->set_checkpoint_file(ckptfile);
1330 else opt->set_checkpoint_file(devnull);
1331 }
1332
1333 // see if frequencies are wanted
1334 Ref<MolecularHessian> molhess;
1335 molhess << keyval->describedclassvalue("hess");
1336 Ref<MolecularFrequencies> molfreq;
1337 molfreq << keyval->describedclassvalue("freq");
1338
1339 // check basis set limit
1340 const int check = checkBasisSetLimit(mole, _initvalues.values);
1341 if (check) {
1342 ExEnv::out0() << endl << indent
1343 << "Exiting since the check option is on." << endl;
1344 exit(0);
1345 }
1346
1347 // from now on we time the calculations
1348 if (tim.nonnull()) tim->change("calc");
1349
1350 int do_energy = keyval->booleanvalue("do_energy",truevalue);
1351
1352 int do_grad = keyval->booleanvalue("do_gradient",falsevalue);
1353
1354 int do_opt = keyval->booleanvalue("optimize",truevalue);
1355
1356 int do_pdb = keyval->booleanvalue("write_pdb",falsevalue);
1357
1358 int print_mole = keyval->booleanvalue("print_mole",truevalue);
1359
1360 int print_timings = keyval->booleanvalue("print_timings",truevalue);
1361
1362 // print all current options (keyvalues)
1363 printOptions(keyval, opt, molname, restartfile);
1364
1365 // see if any pictures are desired
1366 Ref<Render> renderer;
1367 renderer << keyval->describedclassvalue("renderer");
1368
1369 // If we have a renderer, then we will read in some more info
1370 // below. Otherwise we can get rid of the keyval's, to eliminate
1371 // superfluous references to objects that we might otherwise be
1372 // able to delete. We cannot read in the remaining rendering
1373 // objects now, since some of their KeyVal CTOR's are heavyweight,
1374 // requiring optimized geometries, etc.
1375 if (renderer.null()) {
1376 if (parsedkv.nonnull()) print_unseen(parsedkv, _initvalues.input);
1377 keyval = 0;
1378 parsedkv = 0;
1379 }
1380
1381 delete[] restartfile;
1382 delete[] ckptfile;
1383
1384 int ready_for_freq = 1;
1385 if (mole.nonnull()) {
1386 if (((do_opt && opt.nonnull()) || do_grad)
1387 && !mole->gradient_implemented()) {
1388 ExEnv::out0() << indent
1389 << "WARNING: optimization or gradient requested but the given"
1390 << endl
1391 << " MolecularEnergy object cannot do gradients."
1392 << endl;
1393 }
1394
1395 if (do_opt && opt.nonnull() && mole->gradient_implemented()) {
1396
1397 ready_for_freq = performEnergyOptimization(opt, mole);
1398
1399 } else if (do_grad && mole->gradient_implemented()) {
1400
1401 performGradientCalculation(mole);
1402
1403 } else if (do_energy && mole->value_implemented()) {
1404 ExEnv::out0() << endl << indent
1405 << scprintf("Value of the MolecularEnergy: %15.10f",
1406 mole->energy())
1407 << endl << endl;
1408 }
1409 }
1410
1411 // stop timing of calculations
1412 if (tim.nonnull()) tim->exit("calc");
1413
1414 // save this before doing the frequency stuff since that obsoletes the
1415 saveState(wfn_file, savestate, opt, _initvalues.grp, mole, molname, ckptfile);
1416
1417 // Frequency calculation.
1418 if (ready_for_freq && molfreq.nonnull()) {
1419 performFrequencyCalculation(mole, molhess, molfreq);
1420 }
1421
1422 if (renderer.nonnull()) {
1423 renderObjects(renderer, keyval, tim, _initvalues.grp);
1424
1425 Ref<MolFreqAnimate> molfreqanim;
1426 molfreqanim << keyval->describedclassvalue("animate_modes");
1427 if (ready_for_freq && molfreq.nonnull()
1428 && molfreqanim.nonnull()) {
1429 if (tim.nonnull()) tim->enter("render");
1430 molfreq->animate(renderer, molfreqanim);
1431 if (tim.nonnull()) tim->exit("render");
1432 }
1433 }
1434
1435 if (mole.nonnull()) {
1436 if (print_mole)
1437 mole->print(ExEnv::out0());
1438
1439 saveToPdb(do_pdb, _initvalues.grp, mole, molname);
1440
1441 }
1442 else {
1443 ExEnv::out0() << "mpqc: The molecular energy object is null" << endl
1444 << " make sure \"mole\" specifies a MolecularEnergy derivative"
1445 << endl;
1446 }
1447 if (parsedkv.nonnull()) print_unseen(parsedkv, _initvalues.input);
1448
1449 // here, we may gather the results
1450 // we start to fill the MPQC_Data object
1451 if (tim.nonnull()) tim->enter("extract");
1452 extractResults(mole, data);
1453 if (tim.nonnull()) tim->exit("extract");
1454
1455 if (print_timings)
1456 if (tim.nonnull()) tim->print(ExEnv::out0());
1457
1458 extractTimings(tim, data);
1459
1460 delete[] molname;
1461 SCFormIO::set_default_basename(0);
1462
1463 renderer = 0;
1464 molfreq = 0;
1465 molhess = 0;
1466 opt = 0;
1467 mole = 0;
1468 integral = 0;
1469 debugger = 0;
1470 thread = 0;
1471 tim = 0;
1472 keyval = 0;
1473 parsedkv = 0;
1474 memory = 0;
1475 detail::clean_up();
1476
1477#if defined(HAVE_TIME) && defined(HAVE_CTIME)
1478 time_t t;
1479 time(&t);
1480 const char *tstr = ctime(&t);
1481#endif
1482 if (!tstr) {
1483 tstr = "UNKNOWN";
1484 }
1485 ExEnv::out0() << endl
1486 << indent << scprintf("End Time: %s", tstr) << endl;
1487}
1488
1489// static values object
1490detail::OptionValues values;
1491
1492
1493namespace mpqc {
1494
1495 InitValues::InitValues() :
1496 input(NULL),
1497 object_input(NULL),
1498 generic_input(NULL),
1499 output(NULL),
1500 outstream(NULL),
1501 in_char_array(NULL),
1502 values(::values),
1503 verbose(0)
1504 {};
1505
1506 void init(InitValues &_initvalues, int argc, char *argv[]) {
1507
1508#if !defined(DEFAULT_MPI) && !defined(ALWAYS_USE_MPI) && defined(HAVE_MPI)
1509 MPI_Init(&argc, &argv);
1510#endif
1511
1512 ::init();
1513
1514 ExEnv::init(argc, argv);
1515
1516 }
1517
1518 void parseOptions(InitValues &_initvalues, int argc, char *argv[])
1519 {
1520 // parse commandline options
1521 int optind = ParseOptions(_initvalues.options, argc, argv);
1522 ComputeOptions(_initvalues.options, _initvalues.output, _initvalues.outstream);
1523 parseRemainderOptions(_initvalues.options, _initvalues.values, argc, argv);
1524
1525 // get input file names, either object-oriented or generic
1526 getInputFileNames(_initvalues.object_input, _initvalues.generic_input, _initvalues.options, optind, argc, argv);
1527 if (_initvalues.object_input)
1528 _initvalues.input = _initvalues.object_input;
1529 if (_initvalues.generic_input)
1530 _initvalues.input = _initvalues.generic_input;
1531
1532 // get the message group. first try the commandline and environment
1533 getMessageGroup(_initvalues.grp, argc, argv);
1534 }
1535
1536 void cleanup(InitValues &_initvalues) {
1537 if (_initvalues.output != 0) {
1538 ExEnv::set_out(&cout);
1539 delete _initvalues.outstream;
1540 }
1541
1542 _initvalues.grp = 0;
1543 final_clean_up();
1544
1545#if !defined(DEFAULT_MPI) && !defined(ALWAYS_USE_MPI) && defined(HAVE_MPI)
1546 // there is an MPI_Finalize() hidden somewhere else
1547// MPI_Finalize();
1548#endif
1549 }
1550
1551} /* namespace mpqc */
1552
1553namespace detail {
1554
1555int
1556try_main(int argc, char *argv[])
1557{
1558 mpqc::InitValues initvalues;
1559
1560 mpqc::init(initvalues, argc, argv);
1561
1562 mpqc::parseOptions(initvalues, argc, argv);
1563
1564 // check if we got option "-n"
1565 int exitflag = 0;
1566 void *data = NULL;
1567 mpqc::mainFunction(
1568 initvalues,
1569 argc, argv,
1570 data);
1571
1572 mpqc::cleanup(initvalues);
1573
1574 return exitflag;
1575}
1576
1577} /* namespace detail */
1578
1579double EvaluateDensity(SCVector3 &r, Ref<Integral> &intgrl, GaussianBasisSet::ValueData &vdat, Ref<Wavefunction> &wfn)
1580{
1581 ExEnv::out0() << "We get the following values at " << r << "." << endl;
1582 int nbasis = wfn->basis()->nbasis();
1583 double *b_val = new double[nbasis];
1584 wfn->basis()->values(r, &vdat, b_val);
1585 double sum=0.;
1586 for (int i=0; i<nbasis; i++)
1587 sum += b_val[i];
1588 delete[] b_val;
1589 return sum;
1590}
1591
1592/////////////////////////////////////////////////////////////////////////////
1593
1594// Local Variables:
1595// mode: c++
1596// c-file-style: "ETS"
1597// End:
Note: See TracBrowser for help on using the repository browser.