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