| 1 | //
|
|---|
| 2 | // vxb_eval_info.cc
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2003 Edward Valeev
|
|---|
| 5 | //
|
|---|
| 6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu>
|
|---|
| 7 | // Maintainer: EV
|
|---|
| 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 __GNUG__
|
|---|
| 29 | #pragma implementation
|
|---|
| 30 | #endif
|
|---|
| 31 |
|
|---|
| 32 | #include <stdexcept>
|
|---|
| 33 | #include <stdlib.h>
|
|---|
| 34 | #include <util/misc/formio.h>
|
|---|
| 35 | #include <util/ref/ref.h>
|
|---|
| 36 | #include <util/misc/string.h>
|
|---|
| 37 | #include <chemistry/qc/basis/basis.h>
|
|---|
| 38 | #include <chemistry/qc/basis/petite.h>
|
|---|
| 39 | #include <chemistry/qc/mbptr12/mbptr12.h>
|
|---|
| 40 | #include <chemistry/qc/mbptr12/vxb_eval_info.h>
|
|---|
| 41 | #include <chemistry/qc/mbptr12/moindexspace.h>
|
|---|
| 42 |
|
|---|
| 43 | using namespace std;
|
|---|
| 44 | using namespace sc;
|
|---|
| 45 |
|
|---|
| 46 | inline int max(int a,int b) { return (a > b) ? a : b;}
|
|---|
| 47 |
|
|---|
| 48 | /*---------------
|
|---|
| 49 | R12IntEvalInfo
|
|---|
| 50 | ---------------*/
|
|---|
| 51 | static ClassDesc R12IntEvalInfo_cd(
|
|---|
| 52 | typeid(R12IntEvalInfo),"R12IntEvalInfo",4,"virtual public SavableState",
|
|---|
| 53 | 0, 0, create<R12IntEvalInfo>);
|
|---|
| 54 |
|
|---|
| 55 | R12IntEvalInfo::R12IntEvalInfo(MBPT2_R12* mbptr12)
|
|---|
| 56 | {
|
|---|
| 57 | // Default values
|
|---|
| 58 | memory_ = DEFAULT_SC_MEMORY;
|
|---|
| 59 | debug_ = 0;
|
|---|
| 60 | dynamic_ = false;
|
|---|
| 61 | print_percent_ = 10.0;
|
|---|
| 62 |
|
|---|
| 63 | wfn_ = mbptr12;
|
|---|
| 64 | ref_ = mbptr12->ref();
|
|---|
| 65 | integral_ = mbptr12->integral();
|
|---|
| 66 | bs_ = mbptr12->basis();
|
|---|
| 67 | bs_aux_ = mbptr12->aux_basis();
|
|---|
| 68 | bs_vir_ = mbptr12->vir_basis();
|
|---|
| 69 |
|
|---|
| 70 | matrixkit_ = SCMatrixKit::default_matrixkit();
|
|---|
| 71 | mem_ = MemoryGrp::get_default_memorygrp();
|
|---|
| 72 | msg_ = MessageGrp::get_default_messagegrp();
|
|---|
| 73 | thr_ = ThreadGrp::get_default_threadgrp();
|
|---|
| 74 |
|
|---|
| 75 | integral_->set_basis(bs_);
|
|---|
| 76 | Ref<PetiteList> plist = integral_->petite_list();
|
|---|
| 77 | RefSCDimension oso_dim = plist->SO_basisdim();
|
|---|
| 78 | nocc_ = 0;
|
|---|
| 79 | for (int i=0; i<oso_dim->n(); i++) {
|
|---|
| 80 | if (ref_->occupation(i) == 2.0) nocc_++;
|
|---|
| 81 | }
|
|---|
| 82 | nfzc_ = mbptr12->nfzcore();
|
|---|
| 83 | nfzv_ = mbptr12->nfzvirt();
|
|---|
| 84 |
|
|---|
| 85 | ints_method_ = mbptr12->r12ints_method();
|
|---|
| 86 | ints_file_ = mbptr12->r12ints_file();
|
|---|
| 87 |
|
|---|
| 88 | eigen2_();
|
|---|
| 89 |
|
|---|
| 90 | abs_method_ = mbptr12->abs_method();
|
|---|
| 91 | construct_ri_basis_(false);
|
|---|
| 92 | construct_orthog_vir_();
|
|---|
| 93 |
|
|---|
| 94 | tfactory_ = new MOIntsTransformFactory(integral_,obs_space_);
|
|---|
| 95 | tfactory_->set_memory(memory_);
|
|---|
| 96 | tfactory_->set_file_prefix(ints_file_);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | R12IntEvalInfo::R12IntEvalInfo(StateIn& si) : SavableState(si)
|
|---|
| 100 | {
|
|---|
| 101 | wfn_ = require_dynamic_cast<Wavefunction*>(SavableState::restore_state(si),
|
|---|
| 102 | "R12IntEvalInfo::R12IntEvalInfo");
|
|---|
| 103 | ref_ << SavableState::restore_state(si);
|
|---|
| 104 | integral_ << SavableState::restore_state(si);
|
|---|
| 105 | bs_ << SavableState::restore_state(si);
|
|---|
| 106 | bs_aux_ << SavableState::restore_state(si);
|
|---|
| 107 | bs_vir_ << SavableState::restore_state(si);
|
|---|
| 108 | bs_ri_ << SavableState::restore_state(si);
|
|---|
| 109 |
|
|---|
| 110 | matrixkit_ = SCMatrixKit::default_matrixkit();
|
|---|
| 111 | mem_ = MemoryGrp::get_default_memorygrp();
|
|---|
| 112 | msg_ = MessageGrp::get_default_messagegrp();
|
|---|
| 113 | thr_ = ThreadGrp::get_default_threadgrp();
|
|---|
| 114 |
|
|---|
| 115 | si.get(nocc_);
|
|---|
| 116 | si.get(nfzc_);
|
|---|
| 117 | si.get(nfzv_);
|
|---|
| 118 |
|
|---|
| 119 | int ints_method; si.get(ints_method); ints_method_ = (StoreMethod) ints_method;
|
|---|
| 120 | si.get(ints_file_);
|
|---|
| 121 |
|
|---|
| 122 | double memory; si.get(memory); memory_ = (size_t) memory;
|
|---|
| 123 | si.get(debug_);
|
|---|
| 124 | int dynamic; si.get(dynamic); dynamic_ = (bool) dynamic;
|
|---|
| 125 |
|
|---|
| 126 | if (si.version(::class_desc<R12IntEvalInfo>()) >= 2) {
|
|---|
| 127 | si.get(print_percent_);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | if (si.version(::class_desc<R12IntEvalInfo>()) >= 3) {
|
|---|
| 131 | int absmethod; si.get(absmethod); abs_method_ = (LinearR12::ABSMethod) absmethod;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | if (si.version(::class_desc<R12IntEvalInfo>()) >= 4) {
|
|---|
| 135 | obs_space_ << SavableState::restore_state(si);
|
|---|
| 136 | abs_space_ << SavableState::restore_state(si);
|
|---|
| 137 | ribs_space_ << SavableState::restore_state(si);
|
|---|
| 138 | act_occ_space_ << SavableState::restore_state(si);
|
|---|
| 139 | occ_space_ << SavableState::restore_state(si);
|
|---|
| 140 | occ_space_symblk_ << SavableState::restore_state(si);
|
|---|
| 141 | act_vir_space_ << SavableState::restore_state(si);
|
|---|
| 142 | vir_space_ << SavableState::restore_state(si);
|
|---|
| 143 | vir_space_symblk_ << SavableState::restore_state(si);
|
|---|
| 144 | tfactory_ << SavableState::restore_state(si);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | eigen2_();
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | R12IntEvalInfo::~R12IntEvalInfo()
|
|---|
| 151 | {
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | void R12IntEvalInfo::save_data_state(StateOut& so)
|
|---|
| 155 | {
|
|---|
| 156 | SavableState::save_state(wfn_,so);
|
|---|
| 157 | SavableState::save_state(ref_.pointer(),so);
|
|---|
| 158 | SavableState::save_state(integral_.pointer(),so);
|
|---|
| 159 | SavableState::save_state(bs_.pointer(),so);
|
|---|
| 160 | SavableState::save_state(bs_aux_.pointer(),so);
|
|---|
| 161 | SavableState::save_state(bs_vir_.pointer(),so);
|
|---|
| 162 | SavableState::save_state(bs_ri_.pointer(),so);
|
|---|
| 163 |
|
|---|
| 164 | so.put(nocc_);
|
|---|
| 165 | so.put(nfzc_);
|
|---|
| 166 | so.put(nfzv_);
|
|---|
| 167 |
|
|---|
| 168 | so.put((int)ints_method_);
|
|---|
| 169 | so.put(ints_file_);
|
|---|
| 170 |
|
|---|
| 171 | so.put((double)memory_);
|
|---|
| 172 | so.put(debug_);
|
|---|
| 173 | so.put((int)dynamic_);
|
|---|
| 174 | so.put(print_percent_);
|
|---|
| 175 | so.put((int)abs_method_);
|
|---|
| 176 |
|
|---|
| 177 | SavableState::save_state(obs_space_.pointer(),so);
|
|---|
| 178 | SavableState::save_state(abs_space_.pointer(),so);
|
|---|
| 179 | SavableState::save_state(ribs_space_.pointer(),so);
|
|---|
| 180 | SavableState::save_state(act_occ_space_.pointer(),so);
|
|---|
| 181 | SavableState::save_state(occ_space_.pointer(),so);
|
|---|
| 182 | SavableState::save_state(occ_space_symblk_.pointer(),so);
|
|---|
| 183 | SavableState::save_state(act_vir_space_.pointer(),so);
|
|---|
| 184 | SavableState::save_state(vir_space_.pointer(),so);
|
|---|
| 185 | SavableState::save_state(vir_space_symblk_.pointer(),so);
|
|---|
| 186 | SavableState::save_state(tfactory_.pointer(),so);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | const std::string& R12IntEvalInfo::ints_file() const
|
|---|
| 190 | {
|
|---|
| 191 | return ints_file_;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | void
|
|---|
| 195 | R12IntEvalInfo::set_memory(const size_t memory)
|
|---|
| 196 | {
|
|---|
| 197 | if (memory > 0)
|
|---|
| 198 | memory_ = memory;
|
|---|
| 199 | tfactory_->set_memory(memory_);
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 | void
|
|---|
| 204 | R12IntEvalInfo::set_absmethod(LinearR12::ABSMethod abs_method)
|
|---|
| 205 | {
|
|---|
| 206 | if (abs_method != abs_method_) {
|
|---|
| 207 | abs_method = abs_method_;
|
|---|
| 208 | construct_ri_basis_(false);
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 | void R12IntEvalInfo::eigen2_()
|
|---|
| 214 | {
|
|---|
| 215 | Ref<Molecule> molecule = bs_->molecule();
|
|---|
| 216 | Ref<SCMatrixKit> so_matrixkit = bs_->so_matrixkit();
|
|---|
| 217 | Ref<PetiteList> plist = ref_->integral()->petite_list();
|
|---|
| 218 | RefSCDimension oso_dim = plist->SO_basisdim();
|
|---|
| 219 |
|
|---|
| 220 | if (debug_) ExEnv::out0() << indent << "R12IntEvalInfo: eigen_" << endl;
|
|---|
| 221 | if (debug_) ExEnv::out0() << indent << "getting fock matrix" << endl;
|
|---|
| 222 | // get the closed shell AO fock matrices -- this is where SCF is computed
|
|---|
| 223 | RefSymmSCMatrix fock_c_so = ref_->fock(0);
|
|---|
| 224 | ExEnv::out0() << endl;
|
|---|
| 225 |
|
|---|
| 226 | // transform the AO fock matrices to the MO basis
|
|---|
| 227 | RefSymmSCMatrix fock_c_mo1 = so_matrixkit->symmmatrix(oso_dim);
|
|---|
| 228 | RefSCMatrix vecs_so_mo1 = ref_->eigenvectors();
|
|---|
| 229 |
|
|---|
| 230 | fock_c_mo1.assign(0.0);
|
|---|
| 231 | fock_c_mo1.accumulate_transform(vecs_so_mo1.t(), fock_c_so);
|
|---|
| 232 | fock_c_so = 0;
|
|---|
| 233 |
|
|---|
| 234 | if (debug_) ExEnv::out0() << indent << "diagonalizing" << endl;
|
|---|
| 235 | // diagonalize the fock matrix
|
|---|
| 236 | RefDiagSCMatrix vals = fock_c_mo1.eigvals();
|
|---|
| 237 |
|
|---|
| 238 | // compute the AO to new MO scf vector
|
|---|
| 239 | if (debug_) ExEnv::out0() << indent << "AO to MO" << endl;
|
|---|
| 240 | RefSCMatrix so_ao = plist->sotoao();
|
|---|
| 241 | RefSCMatrix vecs = so_ao.t() * vecs_so_mo1;
|
|---|
| 242 |
|
|---|
| 243 | mo_space_ = new MOIndexSpace("symmetry-blocked MOs", vecs, bs_, integral(),
|
|---|
| 244 | vals, 0, 0, MOIndexSpace::symmetry);
|
|---|
| 245 | obs_space_ = new MOIndexSpace("MOs sorted by energy", vecs, bs_, integral(),
|
|---|
| 246 | vals, 0, 0);
|
|---|
| 247 | occ_space_ = new MOIndexSpace("occupied MOs sorted by energy", vecs, bs_,
|
|---|
| 248 | integral(), vals, 0, mo_space_->rank() - nocc_);
|
|---|
| 249 | occ_space_symblk_ = new MOIndexSpace("occupied MOs symmetry-blocked", vecs, bs_,
|
|---|
| 250 | integral(), vals, 0, mo_space_->rank() - nocc_,
|
|---|
| 251 | MOIndexSpace::symmetry);
|
|---|
| 252 |
|
|---|
| 253 | if (nfzc_ == 0)
|
|---|
| 254 | act_occ_space_ = occ_space_;
|
|---|
| 255 | else
|
|---|
| 256 | act_occ_space_ = new MOIndexSpace("active occupied MOs sorted by energy", vecs,
|
|---|
| 257 | bs_, integral(), vals, nfzc_,
|
|---|
| 258 | mo_space_->rank() - nocc_);
|
|---|
| 259 |
|
|---|
| 260 | if (debug_) ExEnv::out0() << indent << "R12IntEvalInfo: eigen2_ done" << endl;
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 264 |
|
|---|
| 265 | // Local Variables:
|
|---|
| 266 | // mode: c++
|
|---|
| 267 | // c-file-style: "CLJ-CONDENSED"
|
|---|
| 268 | // End:
|
|---|