forked from CrawfordGroup/ugacc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ugacc.cc
236 lines (195 loc) · 8.82 KB
/
ugacc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* @BEGIN LICENSE
*
* ugacc by T. Daniel Crawford, a plugin to:
*
* Psi4: an open-source quantum chemistry software package
*
* Copyright (c) 2007-2016 The Psi4 Developers.
*
* The copyrights for code used from other parties are included in
* the corresponding files.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @END LICENSE
*/
#include "psi4/psi4-dec.h"
#include "psi4/libparallel/parallel.h"
#include "psi4/liboptions/liboptions.h"
#include "psi4/libpsio/psio.hpp"
#include "psi4/libmints/mintshelper.h"
#include "psi4/libtrans/integraltransform.h"
#include <map>
#include "hamiltonian.h"
#include "ccwfn.h"
#include "hbar.h"
#include "cclambda.h"
#include "ccdensity.h"
#include "perturbation.h"
#include "ccpert.h"
#include "ccresp.h"
#include "array.h"
using namespace std;
namespace psi { namespace ugacc {
extern "C"
int read_options(std::string name, Options& options)
{
if(name == "UGACC" || options.read_globals()) {
options.add_int("PRINT", 1);
options.add_str("REFERENCE", "RHF");
options.add_str("WFN", "CCSD");
options.add_str("DERTYPE", "NONE");
options.add_str("MYHAND", "RIGHT");
options.add_int("MAXITER", 100);
options.add_bool("DIIS", true);
options.add_double("R_CONVERGENCE", 1e-7);
options.add_double("MY_OMEGA", 0.00);
options.add_bool("OOC", false);
}
return true;
}
extern "C"
SharedWavefunction ugacc(SharedWavefunction ref, Options& options)
{
outfile->Printf("\n");
outfile->Printf("\t\t\t**************************\n");
outfile->Printf("\t\t\t* *\n");
outfile->Printf("\t\t\t* UGA-CC *\n");
outfile->Printf("\t\t\t* *\n");
outfile->Printf("\t\t\t**************************\n");
outfile->Printf("\n");
outfile->Printf("\tWave function = %s\n", options.get_str("WFN").c_str());
outfile->Printf("\tMaxiter = %d\n", options.get_int("MAXITER"));
outfile->Printf("\tConvergence = %3.1e\n", options.get_double("R_CONVERGENCE"));
outfile->Printf("\tDIIS = %s\n", options.get_bool("DIIS") ? "Yes" : "No");
outfile->Printf("\tOut-of-core = %s\n", options.get_bool("OOC") ? "Yes" : "No");
outfile->Printf("\tDertype = %s\n", options.get_str("DERTYPE").c_str());
outfile->Printf("\tOMEGA = %3.1e\n", options.get_double("MY_OMEGA"));
outfile->Printf("\tHAND = %s\n", options.get_str("MYHAND").c_str());
const char * rol = options.get_str("MYHAND").c_str() ;
// Error trapping – need closed-shell SCF in place
if(!ref) throw PSIEXCEPTION("SCF has not been run yet!");
if(options.get_str("REFERENCE") != "RHF")
throw PSIEXCEPTION("Only for use with RHF references.");
for(int h=0; h < ref->nirrep(); h++)
if(ref->soccpi()[h]) throw PSIEXCEPTION("UGACC is for closed-shell systems only.");
shared_ptr<PSIO> psio(_default_psio_lib_);
std::vector<shared_ptr<MOSpace> > spaces;
spaces.push_back(MOSpace::all);
shared_ptr<Hamiltonian> H(new Hamiltonian(psio, ref, spaces));
shared_ptr<CCWfn> cc(new CCWfn(ref, H, options));
double ecc = cc->compute_energy();
if(options.get_str("DERTYPE") == "NONE") return ref;
shared_ptr<HBAR> hbar(new HBAR(H, cc));
shared_ptr<CCLambda> cclambda(new CCLambda(cc, hbar));
cclambda->compute_lambda();
shared_ptr<CCDensity> ccdensity(new CCDensity(cc, cclambda));
double eone = ccdensity->onepdm();
double etwo = ccdensity->twopdm();
double eref = cc->reference_energy();
outfile->Printf("\tOne-Electron Energy = %20.14f\n", eone);
outfile->Printf("\tTwo-Electron Energy = %20.14f\n", etwo);
std::string wfn = options.get_str("WFN") == "CCSD_T" ? "CCSD(T)" : options.get_str("WFN");
outfile->Printf("\t%s Correlation Energy = %20.14f (from density)\n", wfn.c_str(), eone+etwo);
outfile->Printf("\t%s Correlation Energy = %20.14f (from ccwfn)\n", wfn.c_str(), ecc);
outfile->Printf("\t%s Total Energy = %20.14f (from density)\n", wfn.c_str(), eone+etwo+eref);
outfile->Printf("\t%s Total Energy = %20.14f (from ccwfn)\n", wfn.c_str(), ecc + eref);
Process::environment.globals["CURRENT ENERGY"] = ecc + eref;
// Prepare property integrals for perturbed wave functions
shared_ptr<MintsHelper> mints(new MintsHelper(ref->basisset(), options, 0));
shared_ptr<Perturbation> mu(new Perturbation("Mu", ref, mints, false));
shared_ptr<Perturbation> am(new Perturbation("L", ref, mints, false));
// Solve perturbed wave function equations for given perturbation and +/- field frequency
map<string, shared_ptr<CCPert> > cc_perts;
map<string, double > polars;
map<string, double > rots;
double polar;
double rotation;
double omega = options.get_double("MY_OMEGA");
vector<string> cart(3); cart[0] = "X"; cart[1] = "Y"; cart[2] = "Z";
hand my_hand ;
if (!strcmp(rol,"RIGHT"))
my_hand = right;
else
my_hand = left;
/* Below is the recipe for calculating length gauge optical rotation and polarizability*/
outfile->Printf("\n\tSolving right hand perturbed CC amplitudes\n");
for(vector<string>::size_type iter = 0; iter != cart.size(); iter++) {
string entry = "Mu" + cart[iter] + std::to_string(omega);
string entry_1 = "L" + cart[iter] + std::to_string(omega);
outfile->Printf("\n\tCC RH Perturbed Wavefunction: %s\n", entry.c_str());
cc_perts[entry] = shared_ptr<CCPert>(new CCPert(mu->prop_p((int) iter), omega, cc, hbar, cclambda));
cc_perts[entry]->solve(right);
outfile->Printf("\n\tCC RH Perturbed Wavefunction: %s\n", entry_1.c_str());
cc_perts[entry_1] = shared_ptr<CCPert>(new CCPert(am->prop_p((int) iter), omega, cc, hbar, cclambda));
cc_perts[entry_1]->solve(right);
if(omega != 0.0 && my_hand == right) {
entry = "Mu" + cart[iter] + std::to_string(-omega);
outfile->Printf("\n\tCC RH Perturbed Wavefunction: %s\n", entry.c_str());
cc_perts[entry] = shared_ptr<CCPert>(new CCPert(mu->prop_p((int) iter), -omega, cc, hbar, cclambda));
cc_perts[entry]->solve(right);
}
if (my_hand == left){
outfile->Printf("\n\tSolving left hand perturbed CC amplitudes\n");
outfile->Printf("\n\tCC LH Perturbed Wavefunction: %s\n", entry.c_str());
cc_perts[entry]->solve(left);
outfile->Printf("\n\tCC LH Perturbed Wavefunction: %s\n", entry_1.c_str());
cc_perts[entry_1]->solve(left);
}
}
/* Dipole polarizabilities */
for(vector<string>::size_type p = 0; p != cart.size(); p++){
for(vector<string>::size_type q = 0 ; q <= p; q++) {
string pert_p = "Mu" + cart[p] + std::to_string(omega);
string pert_q = "Mu" + cart[q] + std::to_string(omega);
shared_ptr<CCResp> ccpolar(new CCResp(cc_perts[pert_p], cc_perts[pert_q]));
if (p == q)
polar = ccpolar->linresp(cc_perts[pert_p], cc_perts[pert_q]);
else {
polar = 0.5 * ccpolar->linresp(cc_perts[pert_p], cc_perts[pert_q]);
polar += 0.5 * ccpolar->linresp(cc_perts[pert_q], cc_perts[pert_p]);
}
string label = "<<Mu_" + cart[p] + ";" "Mu_" + cart[q] + ">>";
polars[label] = polar;
label = "<<Mu_" + cart[q] + ";" "Mu_" + cart[p] + ">>";
polars[label] = polar;
}
}
/* Length gauge optical rotation */
for(vector<string>::size_type p = 0; p != cart.size(); p++){
for(vector<string>::size_type q = 0 ; q != cart.size(); q++) {
string pert_p = "Mu" + cart[p] + std::to_string(omega);
string pert_q = "L" + cart[q] + std::to_string(omega);
shared_ptr<CCResp> ccrot(new CCResp(cc_perts[pert_p], cc_perts[pert_q]));
rotation = 0.5 * ccrot->linresp(cc_perts[pert_p], cc_perts[pert_q]);
rotation -= 0.5 * ccrot->linresp(cc_perts[pert_q], cc_perts[pert_p]);
string label = "<<Mu_" + cart[p] + ";" "L_" + cart[q] + ">>";
rots[label] = -1.0 * rotation;
}
}
outfile->Printf("\n\tDipole Polarizabilities (au)\n\n");
for(auto elem : polars){
outfile->Printf("\t%s : %20.14lf ", elem.first.c_str(), elem.second);
outfile->Printf("\n\n");
}
outfile->Printf("\n\tOptical rotation (length gauge) (a.u)\n\n");
for(auto elem : rots){
outfile->Printf("\t%s : %20.14lf ", elem.first.c_str(), elem.second);
outfile->Printf("\n\n");
}
return cc;
}
}} // End namespaces