1 //
2 // BAGEL - Brilliantly Advanced General Electronic Structure Library
3 // Filename: finite.h
4 // Copyright (C) 2016 Toru Shiozaki
5 //
6 // Author: Jae Woo Park <jwpk1201@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 
26 #ifndef __SRC_GRAD_FINITE_H
27 #define __SRC_GRAD_FINITE_H
28 
29 #include <src/multi/casscf/casscf.h>
30 #include <src/smith/caspt2grad.h>
31 #include <src/grad/gradeval_base.h>
32 
33 namespace bagel {
34 
35 class FiniteGrad : public GradEval_base {
36   protected:
37     std::shared_ptr<const PTree> idata_;
38     std::shared_ptr<const Reference> ref_;
39 
40     mutable std::shared_ptr<Muffle> muffle_;
41     double energy_;
42 
43     int target_state_;
44     double dx_;
45     int nproc_;
46 
47   public:
48     // Constructor does nothing here
FiniteGrad(std::shared_ptr<const PTree> idata,std::shared_ptr<const Geometry> geom,std::shared_ptr<const Reference> ref,const int target,const double dx,const int nproc)49     FiniteGrad(std::shared_ptr<const PTree> idata, std::shared_ptr<const Geometry> geom, std::shared_ptr<const Reference> ref, const int target, const double dx, const int nproc)
50       : GradEval_base(geom), idata_(idata), ref_(ref), target_state_(target), dx_(dx), nproc_(nproc) {
51     }
52 
53     std::shared_ptr<GradFile> compute();
54 
energy()55     double energy() const { return energy_; }
56 
ref()57     std::shared_ptr<const Reference> ref() const { return ref_; }
58 };
59 
60 template<typename T>
61 class FiniteNacm : public GradEval_base {
62   protected:
63     std::shared_ptr<const PTree> idata_;
64     std::shared_ptr<const Reference> ref_;
65 
66     mutable std::shared_ptr<Muffle> muffle_;
67 
68     std::shared_ptr<T> task_;
69 
70     double energy1_;
71     double energy2_;
72 
73     int target_state1_;
74     int target_state2_;
75     double dx_;
76     int nproc_;
77 
init()78     void init() {
79       if (geom_->external())
80         throw std::logic_error("Gradients with external fields have not been implemented.");
81       auto idata_out = std::make_shared<PTree>(*idata_);
82       idata_out->put("_target", target_state1_);
83       idata_out->put("_target2", target_state2_);
84       task_ = std::make_shared<T>(idata_out, geom_, ref_);
85       task_->compute();
86       ref_  = task_->conv_to_ref();
87       energy1_ = task_->energy(target_state1_);
88       energy2_ = task_->energy(target_state2_);
89       std::cout << std::setprecision(8) << "  Energy = " << energy1_ << " and " << energy2_ << std::endl;
90       geom_ = ref_->geom();
91     }
92 
93   public:
FiniteNacm(std::shared_ptr<const PTree> idata,std::shared_ptr<const Geometry> geom,std::shared_ptr<const Reference> ref,const int target,const int target2,const double dx,const int nproc)94     FiniteNacm(std::shared_ptr<const PTree> idata, std::shared_ptr<const Geometry> geom, std::shared_ptr<const Reference> ref, const int target, const int target2, const double dx, const int nproc)
95       : GradEval_base(geom), idata_(idata), ref_(ref), target_state1_(target), target_state2_(target2), dx_(dx), nproc_(nproc) {
96       init();
97     }
98 
compute()99     std::shared_ptr<GradFile> compute() { throw std::logic_error("NACME for this method has not been implemented"); }
100 
energy1()101     double energy1 () const { return energy1_; }
energy2()102     double energy2 () const { return energy2_; }
103 
ref()104     std::shared_ptr<const Reference> ref() const { return ref_; }
105 };
106 
107 template<> void FiniteNacm<CASSCF>::init();
108 template<> std::shared_ptr<GradFile> FiniteNacm<CASSCF>::compute();
109 template<> std::shared_ptr<GradFile> FiniteNacm<CASPT2Energy>::compute();
110 
111 }
112 #endif
113