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