[0b990d] | 1 | //
|
---|
| 2 | // mbpttest.cc
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
| 5 | //
|
---|
| 6 | // Author: Ida Nielsen <ida@kemi.aau.dk>
|
---|
| 7 | // Maintainer: LPS
|
---|
| 8 | //
|
---|
| 9 | // This file is part of the SC Toolkit.
|
---|
| 10 | //
|
---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
| 12 | // it under the terms of the GNU Library General Public License as published by
|
---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
| 14 | // any later version.
|
---|
| 15 | //
|
---|
| 16 | // The SC Toolkit 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 Library General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU Library General Public License
|
---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB. 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 | #ifdef HAVE_CONFIG_H
|
---|
| 29 | #include <scconfig.h>
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #include <string.h>
|
---|
| 33 |
|
---|
| 34 | #include <sys/stat.h>
|
---|
| 35 | #include <unistd.h>
|
---|
| 36 | #include <new>
|
---|
| 37 |
|
---|
| 38 | #include <util/keyval/keyval.h>
|
---|
| 39 | #include <util/group/message.h>
|
---|
| 40 | #include <util/group/pregtime.h>
|
---|
| 41 | #include <util/misc/bug.h>
|
---|
| 42 | #include <util/misc/formio.h>
|
---|
| 43 | #include <util/state/stateio.h>
|
---|
| 44 | #include <util/state/state_bin.h>
|
---|
| 45 |
|
---|
| 46 | #include <math/scmat/repl.h>
|
---|
| 47 | #include <math/scmat/dist.h>
|
---|
| 48 |
|
---|
| 49 | #include <math/optimize/qnewton.h>
|
---|
| 50 | #include <math/optimize/gdiis.h>
|
---|
| 51 | #include <math/optimize/efc.h>
|
---|
| 52 | #include <math/optimize/update.h>
|
---|
| 53 |
|
---|
| 54 | #include <chemistry/molecule/coor.h>
|
---|
| 55 | #include <chemistry/molecule/energy.h>
|
---|
| 56 |
|
---|
| 57 | #include <chemistry/qc/scf/clhf.h>
|
---|
| 58 | #include <chemistry/qc/scf/hsoshf.h>
|
---|
| 59 |
|
---|
| 60 | #include <chemistry/qc/mbpt/mbpt.h>
|
---|
| 61 |
|
---|
| 62 | using namespace std;
|
---|
| 63 | using namespace sc;
|
---|
| 64 |
|
---|
| 65 | // Force linkages:
|
---|
| 66 | #ifndef __PIC__
|
---|
| 67 | static ForceLink<CLHF> fl0a;
|
---|
| 68 | static ForceLink<HSOSHF> fl0b;
|
---|
| 69 |
|
---|
| 70 | static ForceLink<MBPT2> fl0e;
|
---|
| 71 |
|
---|
| 72 | static ForceLink<RedundMolecularCoor> fl1a;
|
---|
| 73 | static ForceLink<CartMolecularCoor> fl1b;
|
---|
| 74 | static ForceLink<SymmMolecularCoor> fl1c;
|
---|
| 75 |
|
---|
| 76 | static ForceLink<QNewtonOpt> fl2;
|
---|
| 77 | static ForceLink<GDIISOpt> fl3;
|
---|
| 78 | static ForceLink<EFCOpt> fl4;
|
---|
| 79 | static ForceLink<BFGSUpdate> fl5;
|
---|
| 80 |
|
---|
| 81 | static ForceLink<ReplSCMatrixKit> fl6;
|
---|
| 82 | static ForceLink<DistSCMatrixKit> fl7;
|
---|
| 83 |
|
---|
| 84 | # ifdef HAVE_SYSV_IPC
|
---|
| 85 | # include <util/group/messshm.h>
|
---|
| 86 | static ForceLink<ShmMessageGrp> fl8;
|
---|
| 87 | # endif
|
---|
| 88 | static ForceLink<ProcMessageGrp> fl9;
|
---|
| 89 | # ifdef HAVE_NX_H
|
---|
| 90 | # include <util/group/messpgon.h>
|
---|
| 91 | static ForceLink<ParagonMessageGrp> fl10;
|
---|
| 92 | # endif
|
---|
| 93 | #endif
|
---|
| 94 |
|
---|
| 95 | Ref<RegionTimer> tim;
|
---|
| 96 | Ref<MessageGrp> grp;
|
---|
| 97 |
|
---|
| 98 | static Ref<MessageGrp>
|
---|
| 99 | init_mp(const Ref<KeyVal>& keyval, int &argc, char **&argv)
|
---|
| 100 | {
|
---|
| 101 | grp << keyval->describedclassvalue("message");
|
---|
| 102 |
|
---|
| 103 | if (grp.null()) grp = MessageGrp::initial_messagegrp(argc, argv);
|
---|
| 104 |
|
---|
| 105 | if (grp.null()) {
|
---|
| 106 | grp << keyval->describedclassvalue("messagegrp");
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | if (grp.null()) grp = MessageGrp::get_default_messagegrp();
|
---|
| 110 |
|
---|
| 111 | if (grp.null()) {
|
---|
| 112 | std::cerr << indent << "Couldn't initialize MessageGrp\n";
|
---|
| 113 | abort();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | MessageGrp::set_default_messagegrp(grp);
|
---|
| 117 |
|
---|
| 118 | Ref<Debugger> debugger; debugger << keyval->describedclassvalue(":debug");
|
---|
| 119 | // Let the debugger know the name of the executable and the node
|
---|
| 120 | if (debugger.nonnull()) {
|
---|
| 121 | debugger->set_exec("mbpttest");
|
---|
| 122 | debugger->set_prefix(grp->me());
|
---|
| 123 | debugger->debug("curt is a hog");
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | tim = new ParallelRegionTimer(grp,"mbpttest",1,0);
|
---|
| 127 | RegionTimer::set_default_regiontimer(tim);
|
---|
| 128 |
|
---|
| 129 | SCFormIO::set_printnode(0);
|
---|
| 130 | SCFormIO::init_mp(grp->me());
|
---|
| 131 | //SCFormIO::set_debug(1);
|
---|
| 132 |
|
---|
| 133 | SCFormIO::setindent(ExEnv::outn(), 2);
|
---|
| 134 | SCFormIO::setindent(cerr, 2);
|
---|
| 135 |
|
---|
| 136 | return grp;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | main(int argc, char**argv)
|
---|
| 140 | {
|
---|
| 141 | const char *input = (argc > 1)? argv[1] : SRCDIR "/mbpttest.in";
|
---|
| 142 | const char *keyword = (argc > 2)? argv[2] : "mole";
|
---|
| 143 | const char *optkeyword = (argc > 3)? argv[3] : "opt";
|
---|
| 144 |
|
---|
| 145 | // open keyval input
|
---|
| 146 | Ref<KeyVal> rpkv(new ParsedKeyVal(input));
|
---|
| 147 |
|
---|
| 148 | init_mp(rpkv, argc, argv);
|
---|
| 149 |
|
---|
| 150 | tim->enter("input");
|
---|
| 151 |
|
---|
| 152 | int do_gradient = rpkv->booleanvalue("gradient");
|
---|
| 153 |
|
---|
| 154 | if (rpkv->exists("matrixkit")) {
|
---|
| 155 | Ref<SCMatrixKit> kit; kit << rpkv->describedclassvalue("matrixkit");
|
---|
| 156 | SCMatrixKit::set_default_matrixkit(kit);
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | struct stat sb;
|
---|
| 160 | Ref<MolecularEnergy> mole;
|
---|
| 161 | Ref<Optimize> opt;
|
---|
| 162 |
|
---|
| 163 | if (stat("mbpttest.ckpt",&sb)==0 && sb.st_size) {
|
---|
| 164 | StateInBin si("mbpttest.ckpt");
|
---|
| 165 | opt << SavableState::restore_state(si);
|
---|
| 166 | mole << opt->function();
|
---|
| 167 | } else {
|
---|
| 168 | mole << rpkv->describedclassvalue(keyword);
|
---|
| 169 | opt << rpkv->describedclassvalue(optkeyword);
|
---|
| 170 | if (opt.nonnull()) {
|
---|
| 171 | opt->set_checkpoint();
|
---|
| 172 | opt->set_checkpoint_file("mbpttest.ckpt");
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | tim->exit("input");
|
---|
| 177 |
|
---|
| 178 | if (mole.nonnull()) {
|
---|
| 179 | ExEnv::out0() << indent << "energy: " << mole->energy() << endl;
|
---|
| 180 | if (do_gradient && mole->gradient_implemented()) {
|
---|
| 181 | if (opt.nonnull()) {
|
---|
| 182 | opt->optimize();
|
---|
| 183 | } else {
|
---|
| 184 | mole->gradient().print("gradient");
|
---|
| 185 | }
|
---|
| 186 | } else if (mole->value_implemented()) {
|
---|
| 187 | ExEnv::out0() << indent
|
---|
| 188 | << scprintf("value of mole is %20.15f\n\n", mole->energy());
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | mole->print(ExEnv::out0());
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | StateOutBin so("mbpttest.wfn");
|
---|
| 195 | SavableState::save_state(mole.pointer(),so);
|
---|
| 196 |
|
---|
| 197 | tim->print(ExEnv::out0());
|
---|
| 198 |
|
---|
| 199 | tim = 0;
|
---|
| 200 | grp = 0;
|
---|
| 201 | RegionTimer::set_default_regiontimer(0);
|
---|
| 202 | MessageGrp::set_default_messagegrp(0);
|
---|
| 203 | return 0;
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 207 |
|
---|
| 208 | // Local Variables:
|
---|
| 209 | // mode: c++
|
---|
| 210 | // c-file-style: "CLJ-CONDENSED"
|
---|
| 211 | // End:
|
---|