[0b990d] | 1 | //
|
---|
| 2 | // mbpt.h
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
| 5 | //
|
---|
| 6 | // Author: Ida Nielsen <ibniels@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 | #ifndef _chemistry_qc_mbpt_mbpt_h
|
---|
| 29 | #define _chemistry_qc_mbpt_mbpt_h
|
---|
| 30 |
|
---|
| 31 | #ifdef __GNUC__
|
---|
| 32 | #pragma interface
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include <util/group/memory.h>
|
---|
| 36 | #include <util/group/message.h>
|
---|
| 37 | #include <util/group/thread.h>
|
---|
| 38 | #include <chemistry/qc/basis/obint.h>
|
---|
| 39 | #include <chemistry/qc/basis/tbint.h>
|
---|
| 40 | #include <chemistry/qc/scf/scf.h>
|
---|
| 41 |
|
---|
| 42 | namespace sc {
|
---|
| 43 |
|
---|
| 44 | // //////////////////////////////////////////////////////////////////////////
|
---|
| 45 |
|
---|
| 46 | /** The MBPT2 class implements several second-order perturbation theory
|
---|
| 47 | methods. */
|
---|
| 48 | class MBPT2: public Wavefunction {
|
---|
| 49 | protected:
|
---|
| 50 | #define ref_to_mp2_acc 100.0
|
---|
| 51 |
|
---|
| 52 | Ref<SCF> reference_;
|
---|
| 53 | Ref<MemoryGrp> mem;
|
---|
| 54 | int nfzc, nfzv;
|
---|
| 55 | size_t mem_alloc;
|
---|
| 56 |
|
---|
| 57 | double cphf_epsilon_;
|
---|
| 58 | int eliminate_in_gmat_;
|
---|
| 59 | const double *intbuf_;
|
---|
| 60 | Ref<TwoBodyInt> tbint_;
|
---|
| 61 | Ref<TwoBodyInt> *tbints_;
|
---|
| 62 | Ref<TwoBodyDerivInt> *tbintder_;
|
---|
| 63 | int nbasis;
|
---|
| 64 | int noso;
|
---|
| 65 | Ref<MessageGrp> msg_;
|
---|
| 66 | int nvir, nocc, nsocc;
|
---|
| 67 |
|
---|
| 68 | Ref<ThreadGrp> thr_;
|
---|
| 69 |
|
---|
| 70 | // use a dynamic load balance algorithm if possible if true
|
---|
| 71 | // (will not work if messagegrp not thread safe and
|
---|
| 72 | // memorygrp needs catchup to work)
|
---|
| 73 | int dynamic_;
|
---|
| 74 |
|
---|
| 75 | // control how frequently progress is printed
|
---|
| 76 | double print_percent_;
|
---|
| 77 |
|
---|
| 78 | // The maximum number of orbitals in a pass.
|
---|
| 79 | int max_norb_;
|
---|
| 80 |
|
---|
| 81 | // the irreps of the orbitals and the offset within the irrep
|
---|
| 82 | int *symorb_irrep_;
|
---|
| 83 | int *symorb_num_;
|
---|
| 84 |
|
---|
| 85 | char *method_;
|
---|
| 86 | char *algorithm_;
|
---|
| 87 | // if do_d1_ is true, D1(MP2) will be computed even if the gradient is not
|
---|
| 88 | int do_d1_;
|
---|
| 89 | // if do_d2_ is true, D2(MP1) will be computed
|
---|
| 90 | int do_d2_;
|
---|
| 91 |
|
---|
| 92 | int nfuncmax;
|
---|
| 93 |
|
---|
| 94 | double hf_energy_;
|
---|
| 95 | RefSCVector hf_gradient_;
|
---|
| 96 |
|
---|
| 97 | double restart_ecorr_;
|
---|
| 98 | int restart_orbital_v1_;
|
---|
| 99 | int restart_orbital_memgrp_;
|
---|
| 100 |
|
---|
| 101 | protected:
|
---|
| 102 | void init_variables();
|
---|
| 103 |
|
---|
| 104 | // implement the Compute::compute() function
|
---|
| 105 | void compute();
|
---|
| 106 |
|
---|
| 107 | // Fill in the eigenvectors and eigenvalues (Guest & Saunders general
|
---|
| 108 | // form is used for the Fock matrix in the open shell case).
|
---|
| 109 | void eigen(RefDiagSCMatrix &vals, RefSCMatrix &vecs,
|
---|
| 110 | RefDiagSCMatrix &occs);
|
---|
| 111 |
|
---|
| 112 | // calculate the opt2 energy using algorithm v1
|
---|
| 113 | void compute_hsos_v1();
|
---|
| 114 |
|
---|
| 115 | // calculate the opt2 energy using algorithm v2
|
---|
| 116 | distsize_t compute_v2_memory(int ni,
|
---|
| 117 | int nfuncmax, int nbfme, int nshell,
|
---|
| 118 | int ndocc, int nsocc, int nvir, int nproc);
|
---|
| 119 | void compute_hsos_v2();
|
---|
| 120 |
|
---|
| 121 | // calculate the opt2 energy using the load balanced version of v2
|
---|
| 122 | void compute_hsos_v2_lb();
|
---|
| 123 |
|
---|
| 124 | // calculate the closed shell mp2 energy and gradient
|
---|
| 125 | int compute_cs_batchsize(size_t mem_static, int nocc_act);
|
---|
| 126 | // distsize_t is used to allow memory requirements to be
|
---|
| 127 | // estimated by starting the calculation on a single processor
|
---|
| 128 | distsize_t compute_cs_dynamic_memory(int ni, int nocc_act);
|
---|
| 129 | int make_cs_gmat(RefSymmSCMatrix& Gmat, double *DPmat);
|
---|
| 130 | int make_cs_gmat_new(RefSymmSCMatrix& Gmat, const RefSymmSCMatrix& DPmat);
|
---|
| 131 | void form_max_dens(double *DPmat, signed char *maxp);
|
---|
| 132 | int init_cs_gmat();
|
---|
| 133 | void done_cs_gmat();
|
---|
| 134 | int make_g_d_nor(RefSymmSCMatrix& Gmat,
|
---|
| 135 | double *DPmat, const double *mgdbuff);
|
---|
| 136 | void cs_cphf(double **scf_vector,
|
---|
| 137 | double *Laj, double *eigval, RefSCMatrix& P2aj);
|
---|
| 138 | void s2pdm_contrib(const double *intderbuf, double *PHF,
|
---|
| 139 | double *P2AO, double **hf_ginter, double **ginter);
|
---|
| 140 | void hcore_cs_grad(double *PHF, double *PMP2,
|
---|
| 141 | double **hf_ginter, double **ginter);
|
---|
| 142 | void overlap_cs_grad(double *WHF, double *WMP2,
|
---|
| 143 | double **hf_ginter, double **ginter);
|
---|
| 144 | void compute_cs_grad();
|
---|
| 145 | public:
|
---|
| 146 | MBPT2(StateIn&);
|
---|
| 147 | /** The KeyVal constructor.
|
---|
| 148 | <dl>
|
---|
| 149 |
|
---|
| 150 | <dt><tt>reference</tt><dd> This gives the reference wavefunction.
|
---|
| 151 | It must be an object of type CLSCF for closed-shell molecules and
|
---|
| 152 | HSOSSCF for open-shell molecules. The is no default.
|
---|
| 153 |
|
---|
| 154 | <dt><tt>nfzc</tt><dd> The number of frozen core orbitals. The
|
---|
| 155 | default is 0. If no atoms have an atomic number greater than 30,
|
---|
| 156 | then the number of orbitals to be frozen can be automatically
|
---|
| 157 | determined by specifying nfzc = auto.
|
---|
| 158 |
|
---|
| 159 | <dt><tt>nfzv</tt><dd> The number of frozen virtual orbitals. The
|
---|
| 160 | default is 0.
|
---|
| 161 |
|
---|
| 162 | <dt><tt>memory</tt><dd> The amount of memory, in bytes, that each
|
---|
| 163 | processor may use.
|
---|
| 164 |
|
---|
| 165 | <dt><tt>method</tt><dd> This gives a string that must take on one
|
---|
| 166 | of the values below. The default is mp for closed-shell systems
|
---|
| 167 | and zapt for open-shell systems.
|
---|
| 168 |
|
---|
| 169 | <dl>
|
---|
| 170 |
|
---|
| 171 | <dt><tt>mp</tt><dd> Use Møller-Plesset perturbation theory.
|
---|
| 172 | This is only valid for closed-shell systems. Energies and
|
---|
| 173 | gradients can be computed with this method.
|
---|
| 174 |
|
---|
| 175 | <dt><tt>opt1</tt><dd> Use the OPT1 variant of open-shell
|
---|
| 176 | perturbation theory. Only energies can be computed for
|
---|
| 177 | open-shell systems.
|
---|
| 178 |
|
---|
| 179 | <dt><tt>opt2</tt><dd> Use the OPT2 variant of open-shell
|
---|
| 180 | perturbation theory. Only energies can be computed for
|
---|
| 181 | open-shell systems.
|
---|
| 182 |
|
---|
| 183 | <dt><tt>zapt</tt><dd> Use the ZAPT variant of open-shell
|
---|
| 184 | perturbation theory. Only energies can be computed for
|
---|
| 185 | open-shell systems.
|
---|
| 186 |
|
---|
| 187 | </dl>
|
---|
| 188 |
|
---|
| 189 | <dt><tt>algorithm</tt><dd> This gives a string that must take on
|
---|
| 190 | one of the values given below. The default is memgrp for
|
---|
| 191 | closed-shell systems. For open-shell systems v1 is used for a
|
---|
| 192 | small number of processors and v2 is used otherwise.
|
---|
| 193 |
|
---|
| 194 | <dl>
|
---|
| 195 |
|
---|
| 196 | <dt><tt>memgrp</tt><dd> Use the distributed shared memory
|
---|
| 197 | algorithm (which uses a MemoryGrp object). This is only valid
|
---|
| 198 | for MP2 energies and gradients.
|
---|
| 199 |
|
---|
| 200 | <dt><tt>v1</tt><dd> Use algorithm V1. Only energies can be
|
---|
| 201 | computed. The maximum number of processors that can be utilized
|
---|
| 202 | is the number of virtual orbitals. This algorithm computes few
|
---|
| 203 | integrals than the others, but has higher communication
|
---|
| 204 | requirements.
|
---|
| 205 |
|
---|
| 206 | <dt><tt>v2</tt><dd> Use algorithm V2. Only energies can be
|
---|
| 207 | computed. The maximum number of processors that can be utilized
|
---|
| 208 | is the number of shells.
|
---|
| 209 |
|
---|
| 210 | <dt><tt>v2lb</tt><dd> Use a modified V2 algorithm that may
|
---|
| 211 | compute more two electron integrals, but may get better load
|
---|
| 212 | balance on the \f$O(n_\mathrm{basis}^5)\f$ part of the
|
---|
| 213 | calculation. Only energies can be computed. This is recommended
|
---|
| 214 | only for computations involving large molecules (where the
|
---|
| 215 | transformation is dominant) on very many processors (approaching
|
---|
| 216 | the number of shells).
|
---|
| 217 |
|
---|
| 218 | </dl>
|
---|
| 219 |
|
---|
| 220 | The v1 and v2 algorithms are discussed in Ida M. B. Nielsen and
|
---|
| 221 | Edward T. Seidl, J. Comp. Chem. 16, 1301 (1995). The memgrp
|
---|
| 222 | algorithm is discussed in Ida M. B. Nielsen, Chem. Phys. Lett. 255,
|
---|
| 223 | 210 (1996).
|
---|
| 224 |
|
---|
| 225 | <dt><tt>memorygrp</tt><dd> A MemoryGrp object is used by the memgrp
|
---|
| 226 | algorithm. If this is not given the program will try to find an
|
---|
| 227 | appropriate default.
|
---|
| 228 |
|
---|
| 229 | </dl> */
|
---|
| 230 | MBPT2(const Ref<KeyVal>&);
|
---|
| 231 | ~MBPT2();
|
---|
| 232 |
|
---|
| 233 | void save_data_state(StateOut&);
|
---|
| 234 |
|
---|
| 235 | Ref<SCF> ref() { return reference_; }
|
---|
| 236 | double ref_energy();
|
---|
| 237 | double corr_energy();
|
---|
| 238 | RefSCVector ref_energy_gradient();
|
---|
| 239 | RefSCVector corr_energy_gradient();
|
---|
| 240 |
|
---|
| 241 | int nelectron();
|
---|
| 242 |
|
---|
| 243 | int nfzcore() const { return nfzc; };
|
---|
| 244 | int nfzvirt() const { return nfzv; };
|
---|
| 245 |
|
---|
| 246 | RefSymmSCMatrix density();
|
---|
| 247 | int spin_polarized();
|
---|
| 248 |
|
---|
| 249 | int gradient_implemented() const;
|
---|
| 250 | int value_implemented() const;
|
---|
| 251 |
|
---|
| 252 | void symmetry_changed();
|
---|
| 253 |
|
---|
| 254 | // override compute's obsolete so we can call the reference's obsolete
|
---|
| 255 | void obsolete();
|
---|
| 256 |
|
---|
| 257 | void print(std::ostream&o=ExEnv::out0()) const;
|
---|
| 258 | };
|
---|
| 259 |
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | #endif
|
---|
| 263 |
|
---|
| 264 | // Local Variables:
|
---|
| 265 | // mode: c++
|
---|
| 266 | // c-file-style: "CLJ"
|
---|
| 267 | // End:
|
---|