[0b990d] | 1 | //
|
---|
| 2 | // mp2extrap.cc
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 1998 Limit Point Systems, Inc.
|
---|
| 5 | //
|
---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
| 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 __GNUC__
|
---|
| 29 | #pragma implementation
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #include <util/misc/formio.h>
|
---|
| 33 | #include <util/state/stateio.h>
|
---|
| 34 | #include <chemistry/qc/mbpt/mbpt.h>
|
---|
| 35 | #include <chemistry/qc/mbpt/mp2extrap.h>
|
---|
| 36 |
|
---|
| 37 | using namespace std;
|
---|
| 38 | using namespace sc;
|
---|
| 39 |
|
---|
| 40 | /////////////////////////////////////////////////////////////////
|
---|
| 41 | // MP2BasisExtrap
|
---|
| 42 |
|
---|
| 43 | static ClassDesc MP2BasisExtrap_cd(
|
---|
| 44 | typeid(MP2BasisExtrap),"MP2BasisExtrap",1,"public SumMolecularEnergy",
|
---|
| 45 | 0, create<MP2BasisExtrap>, create<MP2BasisExtrap>);
|
---|
| 46 |
|
---|
| 47 | MP2BasisExtrap::MP2BasisExtrap(const Ref<KeyVal> &keyval):
|
---|
| 48 | SumMolecularEnergy(keyval)
|
---|
| 49 | {
|
---|
| 50 | if (n_ != 3) {
|
---|
| 51 | ExEnv::out0() << "ERROR: MP2BasisExtrap: require exactly 3 energies"
|
---|
| 52 | << endl;
|
---|
| 53 | abort();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | // the first row of the inverse of a gives the coefficients
|
---|
| 57 | //a = [ 1, -1/81, -1/243;
|
---|
| 58 | // 1, -1/256, -1/1024;
|
---|
| 59 | // 1, -1/625, -1/3125; ]
|
---|
| 60 | if (!keyval->exists("coef",0)
|
---|
| 61 | &&!keyval->exists("coef",1)
|
---|
| 62 | &&!keyval->exists("coef",2)) {
|
---|
| 63 | coef_[0] = 0.184090909090909;
|
---|
| 64 | coef_[1] = -1.551515151515153;
|
---|
| 65 | coef_[2] = 2.367424242424244;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | MBPT2 *mbpt[3];
|
---|
| 69 | if ((mbpt[0] = dynamic_cast<MBPT2*>(mole_[0].pointer())) == 0
|
---|
| 70 | ||(mbpt[1] = dynamic_cast<MBPT2*>(mole_[1].pointer())) == 0
|
---|
| 71 | ||(mbpt[2] = dynamic_cast<MBPT2*>(mole_[2].pointer())) == 0) {
|
---|
| 72 | ExEnv::out0() << "ERROR: MP2BasisExtrap: need MBPT2 objects"
|
---|
| 73 | << endl;
|
---|
| 74 | abort();
|
---|
| 75 | }
|
---|
| 76 | if (strcmp(mbpt[0]->basis()->name(),"cc-pVDZ")
|
---|
| 77 | ||strcmp(mbpt[1]->basis()->name(),"cc-pVTZ")
|
---|
| 78 | ||strcmp(mbpt[2]->basis()->name(),"cc-pVQZ")) {
|
---|
| 79 | ExEnv::out0() << "WARNING: MP2BasisExtrap:" << endl
|
---|
| 80 | << " given basis sets: "
|
---|
| 81 | << mbpt[0]->basis()->name() << ", "
|
---|
| 82 | << mbpt[1]->basis()->name() << ", "
|
---|
| 83 | << mbpt[2]->basis()->name() << endl
|
---|
| 84 | << " but prefer cc-pVDZ, cc-pVTZ, cc-pVQZ" << endl;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | MP2BasisExtrap::MP2BasisExtrap(StateIn&s):
|
---|
| 89 | SumMolecularEnergy(s)
|
---|
| 90 | {
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | void
|
---|
| 94 | MP2BasisExtrap::save_data_state(StateOut&s)
|
---|
| 95 | {
|
---|
| 96 | SumMolecularEnergy::save_data_state(s);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | MP2BasisExtrap::~MP2BasisExtrap()
|
---|
| 100 | {
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | void
|
---|
| 104 | MP2BasisExtrap::compute()
|
---|
| 105 | {
|
---|
| 106 | int i;
|
---|
| 107 |
|
---|
| 108 | MBPT2 *mbpt2[3];
|
---|
| 109 | mbpt2[0] = dynamic_cast<MBPT2*>(mole_[0].pointer());
|
---|
| 110 | mbpt2[1] = dynamic_cast<MBPT2*>(mole_[1].pointer());
|
---|
| 111 | mbpt2[2] = dynamic_cast<MBPT2*>(mole_[2].pointer());
|
---|
| 112 |
|
---|
| 113 | int *old_do_value = new int[n_];
|
---|
| 114 | int *old_do_gradient = new int[n_];
|
---|
| 115 | int *old_do_hessian = new int[n_];
|
---|
| 116 |
|
---|
| 117 | for (i=0; i<n_; i++)
|
---|
| 118 | old_do_value[i] = mole_[i]->do_value(value_.compute());
|
---|
| 119 | for (i=0; i<n_; i++)
|
---|
| 120 | old_do_gradient[i]=mole_[i]->do_gradient(gradient_.compute());
|
---|
| 121 | for (i=0; i<n_; i++)
|
---|
| 122 | old_do_hessian[i] = mole_[i]->do_hessian(hessian_.compute());
|
---|
| 123 |
|
---|
| 124 | ExEnv::out0() << indent
|
---|
| 125 | << "MP2BasisExtrap: compute" << endl;
|
---|
| 126 |
|
---|
| 127 | ExEnv::out0() << incindent;
|
---|
| 128 |
|
---|
| 129 | if (value_needed()) {
|
---|
| 130 | double val = 0.0;
|
---|
| 131 | double accuracy = 0.0;
|
---|
| 132 | for (i=0; i<n_; i++) {
|
---|
| 133 | val += coef_[i] * mbpt2[i]->corr_energy();
|
---|
| 134 | if (mbpt2[i]->actual_value_accuracy() > accuracy)
|
---|
| 135 | accuracy = mbpt2[i]->actual_value_accuracy();
|
---|
| 136 | }
|
---|
| 137 | val += mbpt2[2]->ref_energy();
|
---|
| 138 | ExEnv::out0() << endl << indent
|
---|
| 139 | << "MP2BasisExtrap =" << endl;
|
---|
| 140 | for (i=0; i<n_; i++) {
|
---|
| 141 | ExEnv::out0() << indent
|
---|
| 142 | << scprintf(" %c % 16.12f * % 16.12f",
|
---|
| 143 | (i==0?' ':'+'),
|
---|
| 144 | coef_[i], mbpt2[i]->corr_energy())
|
---|
| 145 | << endl;
|
---|
| 146 | }
|
---|
| 147 | ExEnv::out0() << indent
|
---|
| 148 | << scprintf(" + % 16.12f",
|
---|
| 149 | mbpt2[2]->ref_energy())
|
---|
| 150 | << endl;
|
---|
| 151 | ExEnv::out0() << indent
|
---|
| 152 | << scprintf(" = % 16.12f", val) << endl;
|
---|
| 153 | set_energy(val);
|
---|
| 154 | set_actual_value_accuracy(accuracy);
|
---|
| 155 | }
|
---|
| 156 | if (gradient_needed()) {
|
---|
| 157 | RefSCVector gradientvec = matrixkit()->vector(moldim());
|
---|
| 158 | gradientvec->assign(0.0);
|
---|
| 159 | double accuracy = 0.0;
|
---|
| 160 | for (i=0; i<n_; i++) {
|
---|
| 161 | gradientvec.accumulate(coef_[i] * mbpt2[i]->corr_energy_gradient());
|
---|
| 162 | if (mbpt2[i]->actual_gradient_accuracy() > accuracy)
|
---|
| 163 | accuracy = mbpt2[i]->actual_gradient_accuracy();
|
---|
| 164 | }
|
---|
| 165 | gradientvec.accumulate(mbpt2[2]->ref_energy_gradient());
|
---|
| 166 | print_natom_3(mbpt2[2]->gradient(),
|
---|
| 167 | "Total MP2 Gradient with Largest Basis Set");
|
---|
| 168 | print_natom_3(gradientvec,"Total Extrapolated MP2 Gradient");
|
---|
| 169 | set_gradient(gradientvec);
|
---|
| 170 | set_actual_gradient_accuracy(accuracy);
|
---|
| 171 | }
|
---|
| 172 | if (hessian_needed()) {
|
---|
| 173 | ExEnv::out0()
|
---|
| 174 | << "ERROR: MP2BasisExtrap: cannot do hessian" << endl;
|
---|
| 175 | abort();
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | ExEnv::out0() << decindent;
|
---|
| 179 |
|
---|
| 180 | for (i=0; i<n_; i++) mole_[i]->do_value(old_do_value[i]);
|
---|
| 181 | for (i=0; i<n_; i++) mole_[i]->do_gradient(old_do_gradient[i]);
|
---|
| 182 | for (i=0; i<n_; i++) mole_[i]->do_hessian(old_do_hessian[i]);
|
---|
| 183 |
|
---|
| 184 | delete[] old_do_value;
|
---|
| 185 | delete[] old_do_gradient;
|
---|
| 186 | delete[] old_do_hessian;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 190 |
|
---|
| 191 | // Local Variables:
|
---|
| 192 | // mode: c++
|
---|
| 193 | // c-file-style: "CLJ"
|
---|
| 194 | // End:
|
---|