1 // 2 // BAGEL - Brilliantly Advanced General Electronic Structure Library 3 // Filename: scf_base.h 4 // Copyright (C) 2009 Toru Shiozaki 5 // 6 // Author: Toru Shiozaki <shiozaki@northwestern.edu> 7 // Maintainer: Shiozaki group 8 // 9 // This file is part of the BAGEL package. 10 // 11 // This program 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 3 of the License, or 14 // (at your option) any later version. 15 // 16 // This program 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 this program. If not, see <http://www.gnu.org/licenses/>. 23 // 24 25 #ifndef __SCF_SCF_BASE_H 26 #define __SCF_SCF_BASE_H 27 28 #include <src/mat1e/overlap.h> 29 #include <src/mat1e/giao/zoverlap.h> 30 #include <src/mat1e/hcore.h> 31 #include <src/mat1e/giao/zhcore.h> 32 #include <src/wfn/method.h> 33 #include <src/scf/fmm/fmm.h> 34 35 namespace bagel { 36 37 template <typename MatType = Matrix, typename OvlType = Overlap, typename HcType = Hcore, 38 class Enable = typename std::enable_if<((std::is_same<MatType, Matrix>::value && std::is_same<OvlType, Overlap>::value && std::is_same<HcType, Hcore>::value) 39 || (std::is_same<MatType, ZMatrix>::value && std::is_same<OvlType, ZOverlap>::value && std::is_same<HcType, ZHcore>::value))>::type> 40 class SCF_base_ : public Method { 41 protected: 42 std::shared_ptr<const MatType> tildex_; 43 std::shared_ptr<const OvlType> overlap_; 44 std::shared_ptr<const HcType> hcore_; 45 std::shared_ptr<const Coeff_<MatType>> coeff_; 46 47 int max_iter_; 48 49 int diis_start_; 50 int diis_size_; 51 52 double thresh_overlap_; 53 double thresh_scf_; 54 int multipole_print_; 55 int dma_print_; 56 57 std::vector<double> schwarz_; 58 void init_schwarz(); 59 60 VectorB eig_; 61 double energy_; 62 std::vector<double> scf_dipole_; 63 64 int nocc_; 65 int noccB_; 66 67 const std::string indent = " "; 68 69 // when gradient is requested, we store half-transformed integrals 70 // TODO so far only implemented in closed-shell SCF 71 bool do_grad_; 72 std::shared_ptr<DFHalfDist> half_; 73 74 // FMM 75 bool dofmm_; 76 std::shared_ptr<const FMM> fmm_; 77 std::shared_ptr<const FMM> fmmK_; 78 79 bool restart_; 80 get_coeff(const std::shared_ptr<const Reference> ref)81 void get_coeff(const std::shared_ptr<const Reference> ref) { coeff_ = ref->coeff(); } 82 83 private: 84 // serialization 85 friend class boost::serialization::access; 86 template<class Archive> serialize(Archive & ar,const unsigned int)87 void serialize(Archive& ar, const unsigned int) { 88 ar & boost::serialization::base_object<Method>(*this); 89 ar & tildex_ & overlap_ & hcore_ & coeff_ & max_iter_ & diis_start_ & diis_size_ 90 & thresh_overlap_ & thresh_scf_ & multipole_print_ & dma_print_ & schwarz_ & eig_ & energy_ 91 & nocc_ & noccB_ & do_grad_ & restart_ & dofmm_ & fmm_ & fmmK_; 92 } 93 94 public: SCF_base_()95 SCF_base_() { } 96 SCF_base_(std::shared_ptr<const PTree> idata_, std::shared_ptr<const Geometry>, std::shared_ptr<const Reference>, const bool need_schwarz = false); ~SCF_base_()97 virtual ~SCF_base_() { } 98 99 virtual void compute() override = 0; 100 coeff()101 const std::shared_ptr<const Coeff_<MatType>> coeff() const { return coeff_; } set_coeff(const std::shared_ptr<Coeff_<MatType>> o)102 void set_coeff(const std::shared_ptr<Coeff_<MatType>> o) { coeff_ = o; } 103 hcore()104 const std::shared_ptr<const HcType> hcore() const { return hcore_; } schwarz()105 const std::vector<double>& schwarz() const { return schwarz_; } 106 nocc()107 int nocc() const { return nocc_; } noccB()108 int noccB() const { return noccB_; } energy()109 double energy() const { return energy_; } scf_dipole()110 const std::vector<double>& scf_dipole() const { return scf_dipole_; } 111 thresh_overlap()112 double thresh_overlap() const { return thresh_overlap_; } thresh_scf()113 double thresh_scf() const { return thresh_scf_; } 114 115 virtual std::shared_ptr<const Reference> conv_to_ref() const override = 0; 116 eig()117 VectorB& eig() { return eig_; } 118 half()119 std::shared_ptr<DFHalfDist> half() const { return half_; } discard_half()120 void discard_half() { half_.reset(); } 121 }; 122 123 // specialized for GIAO cases 124 template <> 125 void SCF_base_<ZMatrix, ZOverlap, ZHcore, std::enable_if<true>::type>::get_coeff(const std::shared_ptr<const Reference> ref); 126 127 using SCF_base = SCF_base_<Matrix, Overlap, Hcore>; 128 using SCF_base_London = SCF_base_<ZMatrix, ZOverlap, ZHcore>; 129 130 } 131 132 extern template class bagel::SCF_base_<bagel::Matrix, bagel::Overlap, bagel::Hcore>; 133 extern template class bagel::SCF_base_<bagel::ZMatrix, bagel::ZOverlap, bagel::ZHcore>; 134 135 #include <src/util/archive.h> 136 BOOST_CLASS_EXPORT_KEY(bagel::SCF_base) 137 BOOST_CLASS_EXPORT_KEY(bagel::SCF_base_London) 138 139 #endif 140