-
Notifications
You must be signed in to change notification settings - Fork 434
/
mintshelper.cc
4197 lines (3533 loc) · 160 KB
/
mintshelper.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* @BEGIN LICENSE
*
* Psi4: an open-source quantum chemistry software package
*
* Copyright (c) 2007-2024 The Psi4 Developers.
*
* The copyrights for code used from other parties are included in
* the corresponding files.
*
* This file is part of Psi4.
*
* Psi4 is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* Psi4 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with Psi4; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @END LICENSE
*/
#include "x2cint.h"
#include "psi4/libmints/mintshelper.h"
#include "psi4/libmints/molecule.h"
#include "psi4/libmints/matrix.h"
#include "psi4/psifiles.h"
#include "psi4/libpsio/psio.hpp"
#include "psi4/libiwl/iwl.hpp"
#include "psi4/libciomr/libciomr.h"
#ifdef USING_ecpint
#include "psi4/libmints/ecpint.h"
#endif
#include "psi4/libmints/sointegral_twobody.h"
#include "psi4/libmints/petitelist.h"
#include "psi4/libmints/potential.h"
#include "psi4/libmints/factory.h"
#include "psi4/libmints/3coverlap.h"
#include "psi4/libmints/potentialint.h"
#include "psi4/libqt/qt.h"
#include "psi4/libmints/sointegral_onebody.h"
#include "psi4/psi4-dec.h"
#include "psi4/libpsi4util/PsiOutStream.h"
#include "psi4/libpsi4util/process.h"
#include "electricfield.h"
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <unordered_map>
#include <utility>
#include <vector>
#ifdef _OPENMP
#include <omp.h>
#endif
#ifdef USING_dkh
#include <DKH/DKH_MANGLE.h>
#define F_DKH DKH_MANGLE_MODULE(dkh_main, dkh, DKH_MAIN, DKH)
extern "C" {
void F_DKH(double *S, double *V, double *T, double *pVp, int *nbf, int *dkh_order);
}
#endif
#ifdef USING_BrianQC
#include <use_brian_wrapper.h>
#include <brian_macros.h>
#include <brian_common.h>
#include <brian_scf.h>
#include <brian_geom_opt.h>
extern void checkBrian();
extern BrianCookie brianCookie;
extern bool brianEnable;
extern brianInt brianRestrictionType;
#endif
namespace psi {
/**
* IWLWriter functor for use with SO TEIs
**/
class PSI_API IWLWriter {
IWL &writeto_;
size_t count_;
int ¤t_buffer_count_;
Label *plabel_;
Value *pvalue_;
public:
IWLWriter(IWL &writeto) : writeto_(writeto), count_(0), current_buffer_count_(writeto_.index()) {
plabel_ = writeto_.labels();
pvalue_ = writeto_.values();
}
void operator()(int i, int j, int k, int l, int, int, int, int, int, int, int, int, double value) {
int current_label_position = 4 * current_buffer_count_;
// Save the labels
plabel_[current_label_position++] = i;
plabel_[current_label_position++] = j;
plabel_[current_label_position++] = k;
plabel_[current_label_position] = l;
// Save the value
pvalue_[current_buffer_count_++] = value;
// Increment overall counter
count_++;
// If our IWL buffer is full dump to disk.
if (current_buffer_count_ == writeto_.ints_per_buffer()) {
writeto_.last_buffer() = 0;
writeto_.buffer_count() = current_buffer_count_;
writeto_.put();
current_buffer_count_ = 0;
}
}
size_t count() const { return count_; }
};
MintsHelper::MintsHelper(std::shared_ptr<BasisSet> basis, Options &options, int print)
: options_(options), print_(print) {
init_helper(basis);
}
MintsHelper::MintsHelper(std::shared_ptr<BasisSet> basis,
std::map<std::string, std::shared_ptr<psi::BasisSet>> basissets, Options &options, int print)
: options_(options), print_(print) {
init_helper(basis, basissets);
}
MintsHelper::MintsHelper(std::shared_ptr<Wavefunction> wavefunction)
: options_(wavefunction->options()), print_(wavefunction->get_print()) {
init_helper(wavefunction);
}
MintsHelper::~MintsHelper() {}
void MintsHelper::init_helper(std::shared_ptr<Wavefunction> wavefunction) {
if (wavefunction->basisset().get() == 0) {
outfile->Printf(" Wavefunction does not have a basisset!");
throw PSIEXCEPTION("Wavefunction does not have a basisset, what did you do?!");
}
psio_ = wavefunction->psio();
basisset_ = wavefunction->basisset();
basissets_ = wavefunction->basissets();
molecule_ = basisset_->molecule();
// Make sure molecule is valid.
molecule_->update_geometry();
common_init();
}
void MintsHelper::init_helper(std::shared_ptr<BasisSet> basis,
std::map<std::string, std::shared_ptr<psi::BasisSet>> basissets) {
basisset_ = basis;
basissets_ = basissets;
molecule_ = basis->molecule();
psio_ = _default_psio_lib_;
// Make sure molecule is valid.
molecule_->update_geometry();
common_init();
}
void MintsHelper::common_init() {
// Print the molecule.
if (print_) molecule_->print();
// Print the basis set
if (print_) basisset_->print_detail();
// How many threads?
nthread_ = 1;
#ifdef _OPENMP
nthread_ = Process::environment.get_n_threads();
#endif
// Create integral factory
integral_ = std::make_shared<IntegralFactory>(basisset_);
// Get the SO basis object.
sobasis_ = std::make_shared<SOBasisSet>(basisset_, integral_);
// Obtain dimensions from the sobasis
const Dimension dimension = sobasis_->dimension();
// Create a matrix factory and initialize it
factory_ = std::make_shared<MatrixFactory>();
factory_->init_with(dimension, dimension);
// Integral cutoff
cutoff_ = Process::environment.options.get_double("INTS_TOLERANCE");
}
std::shared_ptr<PetiteList> MintsHelper::petite_list() const {
auto pt = std::make_shared<PetiteList>(basisset_, integral_);
return pt;
}
std::shared_ptr<PetiteList> MintsHelper::petite_list(bool val) const {
auto pt = std::make_shared<PetiteList>(basisset_, integral_, val);
return pt;
}
std::shared_ptr<BasisSet> MintsHelper::basisset() const { return basisset_; }
std::shared_ptr<SOBasisSet> MintsHelper::sobasisset() const { return sobasis_; }
std::shared_ptr<BasisSet> MintsHelper::get_basisset(std::string label) {
// This may be slightly confusing, but better than changing this in 800 other places
if (label == "ORBITAL") {
return basisset_;
} else if (not basisset_exists(label)) {
outfile->Printf("Could not find requested basisset (%s).", label.c_str());
throw PSIEXCEPTION("MintsHelper::get_basisset: Requested basis set (" + label + ") was not set!\n");
} else {
return basissets_[label];
}
}
void MintsHelper::set_basisset(std::string label, std::shared_ptr<BasisSet> basis) {
if (label == "ORBITAL") {
throw PSIEXCEPTION("Cannot set the ORBITAL basis after the Wavefunction is built!");
} else {
basissets_[label] = basis;
}
}
bool MintsHelper::basisset_exists(std::string label) {
if (basissets_.count(label) == 0)
return false;
else
return true;
}
std::shared_ptr<MatrixFactory> MintsHelper::factory() const { return factory_; }
std::shared_ptr<IntegralFactory> MintsHelper::integral() const { return integral_; }
int MintsHelper::nbf() const { return basisset_->nbf(); }
void MintsHelper::integrals() {
if (print_) {
outfile->Printf(" MINTS: Wrapper to libmints.\n by Justin Turney\n\n");
}
// Get ERI object
std::vector<std::shared_ptr<TwoBodyAOInt>> tb(nthread_);
tb[0] = std::shared_ptr<TwoBodyAOInt>(integral_->eri());
for (int i = 1; i < nthread_; ++i) tb[i] = std::shared_ptr<TwoBodyAOInt>(tb.front()->clone());
auto eri = std::make_shared<TwoBodySOInt>(tb, integral_);
//// Print out some useful information
if (print_) {
outfile->Printf(" Calculation information:\n");
outfile->Printf(" Number of threads: %4d\n", nthread_);
outfile->Printf(" Number of atoms: %4d\n", molecule_->natom());
outfile->Printf(" Number of AO shells: %4d\n", basisset_->nshell());
outfile->Printf(" Number of SO shells: %4d\n", sobasis_->nshell());
outfile->Printf(" Number of primitives: %4d\n", basisset_->nprimitive());
outfile->Printf(" Number of atomic orbitals: %4d\n", basisset_->nao());
outfile->Printf(" Number of basis functions: %4d\n\n", basisset_->nbf());
outfile->Printf(" Number of irreps: %4d\n", sobasis_->nirrep());
outfile->Printf(" Integral cutoff %4.2e\n", cutoff_);
outfile->Printf(" Number of functions per irrep: [");
for (int i = 0; i < sobasis_->nirrep(); ++i) {
outfile->Printf("%4d ", sobasis_->nfunction_in_irrep(i));
}
outfile->Printf("]\n\n");
}
// Compute one-electron integrals.
one_electron_integrals();
// Open the IWL buffer where we will store the integrals.
IWL ERIOUT(psio_.get(), PSIF_SO_TEI, cutoff_, 0, 0);
IWLWriter writer(ERIOUT);
// Let the user know what we're doing.
if (print_) {
outfile->Printf(" Computing two-electron integrals...");
}
SOShellCombinationsIterator shellIter(sobasis_, sobasis_, sobasis_, sobasis_);
for (shellIter.first(); shellIter.is_done() == false; shellIter.next()) {
eri->compute_shell(shellIter, writer);
}
// Flush out buffers.
ERIOUT.flush(1);
// We just did all this work to create the file, let's keep it around
ERIOUT.set_keep_flag(true);
ERIOUT.close();
if (print_) {
outfile->Printf("done\n");
outfile->Printf(
" Computed %lu non-zero two-electron integrals.\n"
" Stored in file %d.\n\n",
writer.count(), PSIF_SO_TEI);
}
}
void MintsHelper::integrals_erf(double w) {
double omega = (w == -1.0 ? options_.get_double("OMEGA_ERF") : w);
IWL ERIOUT(psio_.get(), PSIF_SO_ERF_TEI, cutoff_, 0, 0);
IWLWriter writer(ERIOUT);
// Get ERI object
std::vector<std::shared_ptr<TwoBodyAOInt>> tb(nthread_);
tb[0] = std::shared_ptr<TwoBodyAOInt>(integral_->erf_eri(omega));
for (int i = 1; i < nthread_; ++i) tb[i] = std::shared_ptr<TwoBodyAOInt>(tb.front()->clone());
auto erf = std::make_shared<TwoBodySOInt>(tb, integral_);
// Let the user know what we're doing.
outfile->Printf(" Computing non-zero ERF integrals (omega = %.3f)...", omega);
SOShellCombinationsIterator shellIter(sobasis_, sobasis_, sobasis_, sobasis_);
for (shellIter.first(); shellIter.is_done() == false; shellIter.next()) erf->compute_shell(shellIter, writer);
// Flush the buffers
ERIOUT.flush(1);
// Keep the integrals around
ERIOUT.set_keep_flag(true);
ERIOUT.close();
outfile->Printf("done\n");
outfile->Printf(
" Computed %lu non-zero ERF integrals.\n"
" Stored in file %d.\n\n",
writer.count(), PSIF_SO_ERF_TEI);
}
void MintsHelper::integrals_erfc(double w) {
double omega = (w == -1.0 ? options_.get_double("OMEGA_ERF") : w);
IWL ERIOUT(psio_.get(), PSIF_SO_ERFC_TEI, cutoff_, 0, 0);
IWLWriter writer(ERIOUT);
// Get ERI object
std::vector<std::shared_ptr<TwoBodyAOInt>> tb(nthread_);
tb[0] = std::shared_ptr<TwoBodyAOInt>(integral_->erf_complement_eri(omega));
for (int i = 1; i < nthread_; ++i)
tb[i] = std::shared_ptr<TwoBodyAOInt>(tb.front()->clone());
auto erf = std::make_shared<TwoBodySOInt>(tb, integral_);
// Let the user know what we're doing.
outfile->Printf(" Computing non-zero ERFComplement integrals...");
SOShellCombinationsIterator shellIter(sobasis_, sobasis_, sobasis_, sobasis_);
for (shellIter.first(); shellIter.is_done() == false; shellIter.next()) erf->compute_shell(shellIter, writer);
// Flush the buffers
ERIOUT.flush(1);
// Keep the integrals around
ERIOUT.set_keep_flag(true);
ERIOUT.close();
outfile->Printf("done\n");
outfile->Printf(
" Computed %lu non-zero ERFComplement integrals.\n"
" Stored in file %d.\n\n",
writer.count(), PSIF_SO_ERFC_TEI);
}
void MintsHelper::one_electron_integrals() {
// Dipoles
std::vector<SharedMatrix> dipole_mats = so_dipole();
for (SharedMatrix m : dipole_mats) {
m->save(psio_, PSIF_OEI);
}
// Quadrupoles
std::vector<SharedMatrix> quadrupole_mats = so_quadrupole();
for (SharedMatrix m : quadrupole_mats) {
m->save(psio_, PSIF_OEI);
}
if (print_) {
outfile->Printf(
" OEINTS: Overlap, kinetic, potential, dipole, and quadrupole integrals\n"
" stored in file %d.\n\n",
PSIF_OEI);
}
}
void MintsHelper::integral_gradients() {
throw FeatureNotImplemented("libmints", "MintsHelper::integral_derivatives", __FILE__, __LINE__);
}
void MintsHelper::integral_hessians() {
throw FeatureNotImplemented("libmints", "MintsHelper::integral_hessians", __FILE__, __LINE__);
}
void MintsHelper::one_body_ao_computer(std::vector<std::shared_ptr<OneBodyAOInt>> ints, SharedMatrix out, bool symm) {
// Grab basis info
std::shared_ptr<BasisSet> bs1 = ints[0]->basis1();
std::shared_ptr<BasisSet> bs2 = ints[0]->basis2();
// Limit to the number of incoming onebody ints
size_t nthread = nthread_;
if (nthread > ints.size()) {
nthread = ints.size();
}
double **outp = out->pointer();
const auto &shell_pairs = ints[0]->shellpairs();
size_t n_pairs = shell_pairs.size();
// Loop it
#pragma omp parallel for schedule(guided) num_threads(nthread)
for (size_t p = 0; p < n_pairs; ++p) {
size_t rank = 0;
#ifdef _OPENMP
rank = omp_get_thread_num();
#endif
auto mu = shell_pairs[p].first;
auto nu = shell_pairs[p].second;
const size_t num_mu = bs1->shell(mu).nfunction();
const size_t index_mu = bs1->shell(mu).function_index();
const size_t num_nu = bs2->shell(nu).nfunction();
const size_t index_nu = bs2->shell(nu).function_index();
ints[rank]->compute_shell(mu, nu);
const auto *ints_buff = ints[rank]->buffers()[0];
size_t index = 0;
if (symm) {
for (size_t mu = index_mu; mu < (index_mu + num_mu); ++mu) {
for (size_t nu = index_nu; nu < (index_nu + num_nu); ++nu) {
outp[nu][mu] = outp[mu][nu] = ints_buff[index++];
}
}
} else {
for (size_t mu = index_mu; mu < (index_mu + num_mu); ++mu) {
for (size_t nu = index_nu; nu < (index_nu + num_nu); ++nu) {
outp[mu][nu] = ints_buff[index++];
}
}
}
}
}
void MintsHelper::grad_two_center_computer(std::vector<std::shared_ptr<OneBodyAOInt>> ints, SharedMatrix D,
SharedMatrix out) {
// Grab basis info
std::shared_ptr<BasisSet> bs1 = ints[0]->basis1();
std::shared_ptr<BasisSet> bs2 = ints[0]->basis2();
if (bs1 != bs2) {
throw PSIEXCEPTION("BasisSets must be the same for deriv1");
}
if (D->nirrep() > 1) {
throw PSIEXCEPTION("Density must be of C1 symmetry");
}
// Limit to the number of incoming onbody ints
size_t nthread = nthread_;
if (nthread > ints.size()) {
nthread = ints.size();
}
double **outp = out->pointer();
double **Dp = D->pointer();
const auto &shell_pairs = ints[0]->shellpairs();
size_t n_pairs = shell_pairs.size();
// Loop it
#pragma omp parallel for schedule(guided) num_threads(nthread)
for (size_t p = 0; p < n_pairs; ++p) {
size_t rank = 0;
#ifdef _OPENMP
rank = omp_get_thread_num();
#endif
auto P = shell_pairs[p].first;
auto Q = shell_pairs[p].second;
ints[rank]->compute_shell_deriv1(P, Q);
const auto &ints_buff = ints[rank]->buffers();
size_t nP = basisset_->shell(P).nfunction();
size_t oP = basisset_->shell(P).function_index();
size_t aP = basisset_->shell(P).ncenter();
size_t nQ = basisset_->shell(Q).nfunction();
size_t oQ = basisset_->shell(Q).function_index();
size_t aQ = basisset_->shell(Q).ncenter();
size_t offset = nP * nQ;
double perm = (P == Q ? 1.0 : 2.0);
// Px
double Px = 0.0;
const double *ref = ints_buff[0];
for (size_t p = 0; p < nP; p++) {
for (size_t q = 0; q < nQ; q++) {
Px += perm * Dp[p + oP][q + oQ] * (*ref++);
}
}
#pragma omp atomic update
outp[aP][0] += Px;
// Py
double Py = 0.0;
ref = ints_buff[1];
for (size_t p = 0; p < nP; p++) {
for (size_t q = 0; q < nQ; q++) {
Py += perm * Dp[p + oP][q + oQ] * (*ref++);
}
}
#pragma omp atomic update
outp[aP][1] += Py;
// Pz
double Pz = 0.0;
ref = ints_buff[2];
for (size_t p = 0; p < nP; p++) {
for (size_t q = 0; q < nQ; q++) {
Pz += perm * Dp[p + oP][q + oQ] * (*ref++);
}
}
#pragma omp atomic update
outp[aP][2] += Pz;
// Qx
double Qx = 0.0;
ref = ints_buff[3];
for (size_t p = 0; p < nP; p++) {
for (size_t q = 0; q < nQ; q++) {
Qx += perm * Dp[p + oP][q + oQ] * (*ref++);
}
}
#pragma omp atomic update
outp[aQ][0] += Qx;
// Qy
double Qy = 0.0;
ref = ints_buff[4];
for (size_t p = 0; p < nP; p++) {
for (size_t q = 0; q < nQ; q++) {
Qy += perm * Dp[p + oP][q + oQ] * (*ref++);
}
}
#pragma omp atomic update
outp[aQ][1] += Qy;
// Qz
double Qz = 0.0;
ref = ints_buff[5];
for (size_t p = 0; p < nP; p++) {
for (size_t q = 0; q < nQ; q++) {
Qz += perm * Dp[p + oP][q + oQ] * (*ref++);
}
}
#pragma omp atomic update
outp[aQ][2] += Qz;
}
}
SharedMatrix MintsHelper::ao_overlap() {
// Overlap
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(integral_->ao_overlap()));
}
auto overlap_mat = std::make_shared<Matrix>(PSIF_AO_S, basisset_->nbf(), basisset_->nbf());
#ifdef USING_BrianQC
if (brianEnable) {
brianInt integralType = BRIAN_INTEGRAL_TYPE_OVERLAP;
brianSCFBuild1e(&brianCookie, &integralType, overlap_mat->get_pointer());
checkBrian();
return overlap_mat;
}
#endif
one_body_ao_computer(ints_vec, overlap_mat, true);
return overlap_mat;
}
// JWM 4/3/2015
SharedMatrix MintsHelper::ao_overlap(std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2) {
// Overlap
IntegralFactory factory(bs1, bs2, bs1, bs2);
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(factory.ao_overlap()));
}
auto overlap_mat = std::make_shared<Matrix>(PSIF_AO_S, bs1->nbf(), bs2->nbf());
one_body_ao_computer(ints_vec, overlap_mat, bs1 == bs2);
return overlap_mat;
}
SharedMatrix MintsHelper::ao_kinetic() {
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(integral_->ao_kinetic()));
}
auto kinetic_mat = std::make_shared<Matrix>("AO-basis Kinetic Ints", basisset_->nbf(), basisset_->nbf());
#ifdef USING_BrianQC
if (brianEnable) {
brianInt integralType = BRIAN_INTEGRAL_TYPE_KINETIC;
brianSCFBuild1e(&brianCookie, &integralType, kinetic_mat->get_pointer());
checkBrian();
return kinetic_mat;
}
#endif
one_body_ao_computer(ints_vec, kinetic_mat, true);
return kinetic_mat;
}
SharedMatrix MintsHelper::ao_kinetic(std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2) {
IntegralFactory factory(bs1, bs2, bs1, bs2);
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(factory.ao_kinetic()));
}
auto kinetic_mat = std::make_shared<Matrix>("AO-basis Kinetic Ints", bs1->nbf(), bs2->nbf());
one_body_ao_computer(ints_vec, kinetic_mat, bs1 == bs2);
return kinetic_mat;
}
SharedMatrix MintsHelper::ao_potential() {
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(integral_->ao_potential()));
}
SharedMatrix potential_mat =
std::make_shared<Matrix>("AO-basis Potential Ints", basisset_->nbf(), basisset_->nbf());
#ifdef USING_BrianQC
if (brianEnable) {
brianInt integralType = BRIAN_INTEGRAL_TYPE_NUCLEAR;
brianSCFBuild1e(&brianCookie, &integralType, potential_mat->get_pointer());
checkBrian();
return potential_mat;
}
#endif
one_body_ao_computer(ints_vec, potential_mat, true);
return potential_mat;
}
SharedMatrix MintsHelper::ao_potential(std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2) {
IntegralFactory factory(bs1, bs2, bs1, bs2);
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(factory.ao_potential()));
}
auto potential_mat = std::make_shared<Matrix>("AO-basis Potential Ints", bs1->nbf(), bs2->nbf());
one_body_ao_computer(ints_vec, potential_mat, bs1 == bs2);
return potential_mat;
}
#ifdef USING_ecpint
SharedMatrix MintsHelper::ao_ecp() {
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(integral_->ao_ecp()));
}
auto ecp_mat = std::make_shared<Matrix>("AO-basis ECP Ints", basisset_->nbf(), basisset_->nbf());
one_body_ao_computer(ints_vec, ecp_mat, true);
return ecp_mat;
}
SharedMatrix MintsHelper::ao_ecp(std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2) {
IntegralFactory factory(bs1, bs2, bs1, bs2);
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(factory.ao_ecp()));
}
auto ecp_mat = std::make_shared<Matrix>("AO-basis ECP Ints", bs1->nbf(), bs2->nbf());
one_body_ao_computer(ints_vec, ecp_mat, bs1 == bs2);
return ecp_mat;
}
#endif
SharedMatrix MintsHelper::ao_pvp() {
std::vector<std::shared_ptr<OneBodyAOInt>> ints_vec;
for (size_t i = 0; i < nthread_; i++) {
ints_vec.push_back(std::shared_ptr<OneBodyAOInt>(integral_->ao_rel_potential()));
}
auto pVp_mat = std::make_shared<Matrix>("AO-basis pVp Ints", basisset_->nbf(), basisset_->nbf());
one_body_ao_computer(ints_vec, pVp_mat, true);
return pVp_mat;
}
SharedMatrix MintsHelper::ao_dkh(int dkh_order) {
#ifdef USING_dkh
MintsHelper decon(get_basisset("BASIS_RELATIVISTIC"));
SharedMatrix S = decon.ao_overlap();
SharedMatrix T = decon.ao_kinetic();
SharedMatrix Torig = T->clone();
SharedMatrix V = decon.ao_potential();
SharedMatrix Vorig = V->clone();
SharedMatrix pVp = decon.ao_pvp();
SharedMatrix H_dk = T->clone();
H_dk->zero();
double *Sp = S->pointer()[0];
double *Tp = T->pointer()[0];
double *Vp = V->pointer()[0];
double *pVpp = pVp->pointer()[0];
if (dkh_order < 1) dkh_order = 2;
if (dkh_order > 4) dkh_order = 4;
outfile->Printf(" Computing %d-order Douglas-Kroll-Hess integrals.\n", dkh_order);
int nbf = get_basisset("BASIS_RELATIVISTIC")->nbf();
// rel_basisset_->print_detail();
// Call DKH code from Markus Reiher
F_DKH(Sp, Vp, Tp, pVpp, &nbf, &dkh_order);
H_dk->add(V);
H_dk->add(T);
H_dk->subtract(Vorig);
H_dk->subtract(Torig);
H_dk->set_name("AO-basis DKH Ints");
// H_dk->print();
// DKH is solved in the decontracted basis ... transform to the contracted.
SharedMatrix S_inv = S->clone();
S_inv->general_invert();
SharedMatrix S_cd = ao_overlap(basisset_, get_basisset("BASIS_RELATIVISTIC"));
// S_cd->print();
auto D = std::make_shared<Matrix>("D", nbf, basisset_->nbf());
// Form D = S_uu^{-1} S_uc. Notice that we transpose S_cu
D->gemm(false, true, 1.0, S_inv, S_cd, 0.0);
auto H_dk_cc = std::make_shared<Matrix>("AO-basis DKH Ints", basisset_->nbf(), basisset_->nbf());
H_dk_cc->transform(H_dk, D);
// H_dk_cc->print();
return H_dk_cc;
#else
outfile->Printf(" Douglas-Kroll-Hess integrals of order %d requested but are not available.\n", dkh_order);
throw PSIEXCEPTION("Douglas-Kroll-Hess integrals requested but were not compiled in.");
#endif
}
SharedMatrix MintsHelper::so_dkh(int dkh_order) {
SharedMatrix dkh = factory_->create_shared_matrix("SO Douglas-Kroll-Hess Integrals");
dkh->apply_symmetry(ao_dkh(dkh_order), petite_list()->aotoso());
return dkh;
}
SharedMatrix MintsHelper::ao_helper(const std::string &label, std::shared_ptr<TwoBodyAOInt> ints) {
std::shared_ptr<BasisSet> bs1 = ints->basis1();
std::shared_ptr<BasisSet> bs2 = ints->basis2();
std::shared_ptr<BasisSet> bs3 = ints->basis3();
std::shared_ptr<BasisSet> bs4 = ints->basis4();
int nbf1 = bs1->nbf();
int nbf2 = bs2->nbf();
int nbf3 = bs3->nbf();
int nbf4 = bs4->nbf();
auto I = std::make_shared<Matrix>(label, nbf1 * nbf2, nbf3 * nbf4);
double **Ip = I->pointer();
for (int M = 0; M < bs1->nshell(); M++) {
for (int N = 0; N < bs2->nshell(); N++) {
for (int P = 0; P < bs3->nshell(); P++) {
for (int Q = 0; Q < bs4->nshell(); Q++) {
ints->compute_shell(M, N, P, Q);
const double *buffer = ints->buffer();
for (int m = 0, index = 0; m < bs1->shell(M).nfunction(); m++) {
for (int n = 0; n < bs2->shell(N).nfunction(); n++) {
for (int p = 0; p < bs3->shell(P).nfunction(); p++) {
for (int q = 0; q < bs4->shell(Q).nfunction(); q++, index++) {
Ip[(bs1->shell(M).function_index() + m) * nbf2 + bs2->shell(N).function_index() + n]
[(bs3->shell(P).function_index() + p) * nbf4 + bs4->shell(Q).function_index() +
q] = buffer[index];
}
}
}
}
}
}
}
}
// Build numpy and final matrix shape
std::vector<int> nshape{nbf1, nbf2, nbf3, nbf4};
I->set_numpy_shape(nshape);
return I;
}
SharedMatrix MintsHelper::ao_shell_getter(const std::string &label, std::shared_ptr<TwoBodyAOInt> ints, int M, int N,
int P, int Q) {
int mfxn = basisset_->shell(M).nfunction();
int nfxn = basisset_->shell(N).nfunction();
int pfxn = basisset_->shell(P).nfunction();
int qfxn = basisset_->shell(Q).nfunction();
auto I = std::make_shared<Matrix>(label, mfxn * nfxn, pfxn * qfxn);
double **Ip = I->pointer();
ints->compute_shell(M, N, P, Q);
const double *buffer = ints->buffer();
for (int m = 0, index = 0; m < mfxn; m++) {
for (int n = 0; n < nfxn; n++) {
for (int p = 0; p < pfxn; p++) {
for (int q = 0; q < qfxn; q++, index++) {
Ip[m * nfxn + n][p * qfxn + q] = buffer[index];
}
}
}
}
// Build numpy and final matrix shape
std::vector<int> nshape{mfxn, nfxn, pfxn, qfxn};
I->set_numpy_shape(nshape);
return I;
}
SharedMatrix MintsHelper::ao_erf_eri(double omega, std::shared_ptr<IntegralFactory> input_factory) {
std::shared_ptr<IntegralFactory> factory;
if (input_factory) {
factory = input_factory;
} else {
factory = integral_;
}
return ao_helper("AO ERF ERI Integrals", std::shared_ptr<TwoBodyAOInt>(factory->erf_eri(omega)));
}
SharedMatrix MintsHelper::ao_eri(std::shared_ptr<IntegralFactory> input_factory) {
std::shared_ptr<IntegralFactory> factory;
if (input_factory) {
factory = input_factory;
} else {
factory = integral_;
}
return ao_helper("AO ERI Tensor", std::shared_ptr<TwoBodyAOInt>(factory->eri()));
}
SharedMatrix MintsHelper::ao_eri(std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2,
std::shared_ptr<BasisSet> bs3, std::shared_ptr<BasisSet> bs4) {
IntegralFactory intf(bs1, bs2, bs3, bs4);
std::shared_ptr<TwoBodyAOInt> ints(intf.eri());
return ao_helper("AO ERI Tensor", ints);
}
SharedMatrix MintsHelper::ao_eri_shell(int M, int N, int P, int Q) {
if (eriInts_ == 0) {
eriInts_ = std::shared_ptr<TwoBodyAOInt>(integral_->eri());
}
return ao_shell_getter("AO ERI Tensor", eriInts_, M, N, P, Q);
}
SharedMatrix MintsHelper::ao_erfc_eri(double omega) {
std::shared_ptr<TwoBodyAOInt> ints(integral_->erf_complement_eri(omega));
return ao_helper("AO ERFC ERI Tensor", ints);
}
SharedMatrix MintsHelper::ao_f12(std::vector<std::pair<double, double>> exp_coeff) {
std::shared_ptr<TwoBodyAOInt> ints(integral_->f12(exp_coeff));
return ao_helper("AO F12 Tensor", ints);
}
SharedMatrix MintsHelper::ao_f12(std::vector<std::pair<double, double>> exp_coeff, std::shared_ptr<BasisSet> bs1,
std::shared_ptr<BasisSet> bs2, std::shared_ptr<BasisSet> bs3,
std::shared_ptr<BasisSet> bs4) {
IntegralFactory intf(bs1, bs2, bs3, bs4);
std::shared_ptr<TwoBodyAOInt> ints(intf.f12(exp_coeff));
return ao_helper("AO F12 Tensor", ints);
}
SharedMatrix MintsHelper::ao_f12_squared(std::vector<std::pair<double, double>> exp_coeff) {
std::shared_ptr<TwoBodyAOInt> ints(integral_->f12_squared(exp_coeff));
return ao_helper("AO F12 Squared Tensor", ints);
}
SharedMatrix MintsHelper::ao_f12_squared(std::vector<std::pair<double, double>> exp_coeff,
std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2,
std::shared_ptr<BasisSet> bs3, std::shared_ptr<BasisSet> bs4) {
IntegralFactory intf(bs1, bs2, bs3, bs4);
std::shared_ptr<TwoBodyAOInt> ints(intf.f12_squared(exp_coeff));
return ao_helper("AO F12 Squared Tensor", ints);
}
std::vector<std::pair<double, double>> MintsHelper::f12_cgtg(double exponent) {
// The fitting coefficients and the exponents
std::vector<std::pair<double, double>> exp_coeff = {};
std::vector<double> coeffs = {-0.31442480597241274, -0.30369575353387201, -0.16806968430232927,
-0.098115812152857612, -0.060246640234342785, -0.037263541968504843};
std::vector<double> exps = {0.22085085450735284, 1.0040191632019282, 3.6212173098378728,
12.162483236221904, 45.855332448029337, 254.23460688554644};
for (int i = 0; i < exps.size(); i++){
auto exp_scaled = (exponent * exponent) * exps[i];
exp_coeff.push_back(std::make_pair(exp_scaled, coeffs[i]));
}
return exp_coeff;
}
SharedMatrix MintsHelper::ao_3coverlap_helper(const std::string &label, std::shared_ptr<ThreeCenterOverlapInt> ints) {
std::shared_ptr<BasisSet> bs1 = ints->basis1();
std::shared_ptr<BasisSet> bs2 = ints->basis2();
std::shared_ptr<BasisSet> bs3 = ints->basis3();
int nbf1 = bs1->nbf();
int nbf2 = bs2->nbf();
int nbf3 = bs3->nbf();
auto I = std::make_shared<Matrix>(label, nbf1 * nbf2, nbf3);
double **Ip = I->pointer();
for (int M = 0; M < bs1->nshell(); M++) {
for (int N = 0; N < bs2->nshell(); N++) {
for (int P = 0; P < bs3->nshell(); P++) {
ints->compute_shell(M, N, P);
const double *buffer = ints->buffers()[0];
int Mfi = bs1->shell(M).function_index();
int Nfi = bs2->shell(N).function_index();
int Pfi = bs3->shell(P).function_index();
for (int m = Mfi, index = 0; m < (Mfi + bs1->shell(M).nfunction()); m++) {
for (int n = Nfi; n < (Nfi + bs2->shell(N).nfunction()); n++) {
for (int p = Pfi; p < (Pfi + bs3->shell(P).nfunction()); p++) {
Ip[m * nbf2 + n][p] = buffer[index++];
}
}
}
}
}
}
// Build numpy and final matrix shape
std::vector<int> nshape{nbf1, nbf2, nbf3};
I->set_numpy_shape(nshape);
return I;
}
SharedMatrix MintsHelper::ao_3coverlap() {
std::shared_ptr<ThreeCenterOverlapInt> ints =
std::make_shared<ThreeCenterOverlapInt>(basisset_, basisset_, basisset_);
return ao_3coverlap_helper("AO 3-Center Overlap Tensor", ints);
}
SharedMatrix MintsHelper::ao_3coverlap(std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2,
std::shared_ptr<BasisSet> bs3) {
auto ints = std::make_shared<ThreeCenterOverlapInt>(bs1, bs2, bs3);
return ao_3coverlap_helper("AO 3-Center Overlap Tensor", ints);
}
SharedMatrix MintsHelper::ao_f12g12(std::vector<std::pair<double, double>> exp_coeff) {
std::shared_ptr<TwoBodyAOInt> ints(integral_->f12g12(exp_coeff));
return ao_helper("AO F12G12 Tensor", ints);
}
SharedMatrix MintsHelper::ao_f12g12(std::vector<std::pair<double, double>> exp_coeff,
std::shared_ptr<BasisSet> bs1, std::shared_ptr<BasisSet> bs2,
std::shared_ptr<BasisSet> bs3, std::shared_ptr<BasisSet> bs4) {