source: ThirdParty/mpqc_open/src/lib/chemistry/qc/scf/hsoshf.cc@ bbc982

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since bbc982 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 8.6 KB
Line 
1//
2// hsoshf.cc --- implementation of the high-spin open shell Hartree-Fock SCF class
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Edward Seidl <seidl@janed.com>
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#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <math.h>
33
34#include <util/misc/timer.h>
35#include <util/misc/formio.h>
36#include <util/state/stateio.h>
37
38#include <chemistry/qc/basis/petite.h>
39
40#include <chemistry/qc/scf/hsoshf.h>
41#include <chemistry/qc/scf/lgbuild.h>
42#include <chemistry/qc/scf/hsoshftmpl.h>
43
44using namespace std;
45using namespace sc;
46
47///////////////////////////////////////////////////////////////////////////
48// HSOSHF
49
50static ClassDesc HSOSHF_cd(
51 typeid(HSOSHF),"HSOSHF",1,"public HSOSSCF",
52 0, create<HSOSHF>, create<HSOSHF>);
53
54HSOSHF::HSOSHF(StateIn& s) :
55 SavableState(s),
56 HSOSSCF(s)
57{
58}
59
60HSOSHF::HSOSHF(const Ref<KeyVal>& keyval) :
61 HSOSSCF(keyval)
62{
63}
64
65HSOSHF::~HSOSHF()
66{
67}
68
69void
70HSOSHF::save_data_state(StateOut& s)
71{
72 HSOSSCF::save_data_state(s);
73}
74
75int
76HSOSHF::value_implemented() const
77{
78 return 1;
79}
80
81int
82HSOSHF::gradient_implemented() const
83{
84 return 1;
85}
86
87void
88HSOSHF::print(ostream&o) const
89{
90 HSOSSCF::print(o);
91}
92
93//////////////////////////////////////////////////////////////////////////////
94
95void
96HSOSHF::two_body_energy(double &ec, double &ex)
97{
98 tim_enter("hsoshf e2");
99 ec = 0.0;
100 ex = 0.0;
101 if (local_ || local_dens_) {
102 // grab the data pointers from the G and P matrices
103 double *dpmat;
104 double *spmat;
105 tim_enter("local data");
106 RefSymmSCMatrix ddens = beta_ao_density();
107 RefSymmSCMatrix sdens = alpha_ao_density() - ddens;
108 ddens->scale(2.0);
109 ddens->accumulate(sdens);
110 ddens->scale(2.0);
111 ddens->scale_diagonal(0.5);
112 sdens->scale(2.0);
113 sdens->scale_diagonal(0.5);
114 RefSymmSCMatrix dptmp = get_local_data(ddens, dpmat, SCF::Read);
115 RefSymmSCMatrix sptmp = get_local_data(sdens, spmat, SCF::Read);
116 tim_exit("local data");
117
118 // initialize the two electron integral classes
119 Ref<TwoBodyInt> tbi = integral()->electron_repulsion();
120 tbi->set_integral_storage(0);
121
122 signed char * pmax = init_pmax(dpmat);
123
124 LocalHSOSEnergyContribution lclc(dpmat, spmat);
125 Ref<PetiteList> pl = integral()->petite_list();
126 LocalGBuild<LocalHSOSEnergyContribution>
127 gb(lclc, tbi, pl, basis(), scf_grp_, pmax,
128 desired_value_accuracy()/100.0);
129 gb.run();
130
131 delete[] pmax;
132
133 ec = lclc.ec;
134 ex = lclc.ex;
135 }
136 else {
137 ExEnv::err0() << indent << "Cannot yet use anything but Local matrices\n";
138 abort();
139 }
140 tim_exit("hsoshf e2");
141}
142
143//////////////////////////////////////////////////////////////////////////////
144
145void
146HSOSHF::ao_fock(double accuracy)
147{
148 Ref<PetiteList> pl = integral()->petite_list(basis());
149
150 // calculate G. First transform cl_dens_diff_ to the AO basis, then
151 // scale the off-diagonal elements by 2.0
152 RefSymmSCMatrix dd = cl_dens_diff_;
153 cl_dens_diff_ = pl->to_AO_basis(dd);
154 cl_dens_diff_->scale(2.0);
155 cl_dens_diff_->scale_diagonal(0.5);
156
157 RefSymmSCMatrix ddo = op_dens_diff_;
158 op_dens_diff_ = pl->to_AO_basis(ddo);
159 op_dens_diff_->scale(2.0);
160 op_dens_diff_->scale_diagonal(0.5);
161
162 // now try to figure out the matrix specialization we're dealing with
163 // if we're using Local matrices, then there's just one subblock, or
164 // see if we can convert G and P to local matrices
165 if (local_ || local_dens_) {
166 double *gmat, *gmato, *pmat, *pmato;
167
168 // grab the data pointers from the G and P matrices
169 RefSymmSCMatrix gtmp = get_local_data(cl_gmat_, gmat, SCF::Accum);
170 RefSymmSCMatrix ptmp = get_local_data(cl_dens_diff_, pmat, SCF::Read);
171 RefSymmSCMatrix gotmp = get_local_data(op_gmat_, gmato, SCF::Accum);
172 RefSymmSCMatrix potmp = get_local_data(op_dens_diff_, pmato, SCF::Read);
173
174 signed char * pmax = init_pmax(pmat);
175
176// LocalHSOSContribution lclc(gmat, pmat, gmato, pmato);
177// LocalGBuild<LocalHSOSContribution>
178// gb(lclc, tbi_, pl, basis(), scf_grp_, pmax,
179// desired_value_accuracy()/100.0);
180// gb.run();
181 int i;
182 int nthread = threadgrp_->nthread();
183 LocalGBuild<LocalHSOSContribution> **gblds =
184 new LocalGBuild<LocalHSOSContribution>*[nthread];
185 LocalHSOSContribution **conts = new LocalHSOSContribution*[nthread];
186
187 double **gmats = new double*[nthread];
188 gmats[0] = gmat;
189 double **gmatos = new double*[nthread];
190 gmatos[0] = gmato;
191
192 Ref<GaussianBasisSet> bs = basis();
193 int ntri = i_offset(bs->nbasis());
194
195 double gmat_accuracy = accuracy;
196 if (min_orthog_res() < 1.0) { gmat_accuracy *= min_orthog_res(); }
197
198 for (i=0; i < nthread; i++) {
199 if (i) {
200 gmats[i] = new double[ntri];
201 memset(gmats[i], 0, sizeof(double)*ntri);
202 gmatos[i] = new double[ntri];
203 memset(gmatos[i], 0, sizeof(double)*ntri);
204 }
205 conts[i] = new LocalHSOSContribution(gmats[i], pmat, gmatos[i], pmato);
206 gblds[i] = new LocalGBuild<LocalHSOSContribution>(*conts[i], tbis_[i],
207 pl, bs, scf_grp_, pmax, gmat_accuracy, nthread, i
208 );
209
210 threadgrp_->add_thread(i, gblds[i]);
211 }
212
213 tim_enter("start thread");
214 if (threadgrp_->start_threads() < 0) {
215 ExEnv::err0() << indent
216 << "HSOSHF: error starting threads" << endl;
217 abort();
218 }
219 tim_exit("start thread");
220
221 tim_enter("stop thread");
222 if (threadgrp_->wait_threads() < 0) {
223 ExEnv::err0() << indent
224 << "HSOSHF: error waiting for threads" << endl;
225 abort();
226 }
227 tim_exit("stop thread");
228
229 double tnint=0;
230 for (i=0; i < nthread; i++) {
231 tnint += gblds[i]->tnint;
232
233 if (i) {
234 for (int j=0; j < ntri; j++) {
235 gmat[j] += gmats[i][j];
236 gmato[j] += gmatos[i][j];
237 }
238 delete[] gmats[i];
239 delete[] gmatos[i];
240 }
241
242 delete gblds[i];
243 delete conts[i];
244 }
245
246 delete[] gmats;
247 delete[] gmatos;
248 delete[] gblds;
249 delete[] conts;
250
251 delete[] pmax;
252
253 scf_grp_->sum(&tnint, 1, 0, 0);
254 ExEnv::out0() << indent << scprintf("%20.0f integrals\n", tnint);
255
256 // if we're running on multiple processors, then sum the G matrices
257 if (scf_grp_->n() > 1) {
258 scf_grp_->sum(gmat, i_offset(basis()->nbasis()));
259 scf_grp_->sum(gmato, i_offset(basis()->nbasis()));
260 }
261
262 // if we're running on multiple processors, or we don't have local
263 // matrices, then accumulate gtmp back into G
264 if (!local_ || scf_grp_->n() > 1) {
265 cl_gmat_->convert_accumulate(gtmp);
266 op_gmat_->convert_accumulate(gotmp);
267 }
268 }
269
270 // for now quit
271 else {
272 ExEnv::err0() << indent << "Cannot yet use anything but Local matrices\n";
273 abort();
274 }
275
276 // get rid of AO delta P
277 cl_dens_diff_ = dd;
278 dd = cl_dens_diff_.clone();
279
280 op_dens_diff_ = ddo;
281 ddo = op_dens_diff_.clone();
282
283 // now symmetrize the skeleton G matrix, placing the result in dd
284 RefSymmSCMatrix skel_gmat = cl_gmat_.copy();
285 skel_gmat.scale(1.0/(double)pl->order());
286 pl->symmetrize(skel_gmat,dd);
287
288 skel_gmat = op_gmat_.copy();
289 skel_gmat.scale(1.0/(double)pl->order());
290 pl->symmetrize(skel_gmat,ddo);
291
292 // F = H+G
293 cl_fock_.result_noupdate().assign(hcore_);
294 cl_fock_.result_noupdate().accumulate(dd);
295
296 // Fo = H+G-Go
297 op_fock_.result_noupdate().assign(cl_fock_.result_noupdate());
298 ddo.scale(-1.0);
299 op_fock_.result_noupdate().accumulate(ddo);
300 ddo=0;
301
302 dd.assign(0.0);
303 accumddh_->accum(dd);
304 cl_fock_.result_noupdate().accumulate(dd);
305 op_fock_.result_noupdate().accumulate(dd);
306 dd=0;
307
308 cl_fock_.computed()=1;
309 op_fock_.computed()=1;
310}
311
312/////////////////////////////////////////////////////////////////////////////
313
314void
315HSOSHF::two_body_deriv(double * tbgrad)
316{
317 two_body_deriv_hf(tbgrad, 1.0);
318}
319
320/////////////////////////////////////////////////////////////////////////////
321
322// Local Variables:
323// mode: c++
324// c-file-style: "ETS"
325// End:
Note: See TracBrowser for help on using the repository browser.