source: ThirdParty/mpqc_open/src/bin/mpqc/mpqc.cc@ 1ca493a

Candidate_v1.7.0 stable
Last change on this file since 1ca493a was ffeb81, checked in by Frederik Heber <frederik.heber@…>, 5 years ago

FIX: mpqc included boost bind and function unnecessarily.

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