Skip to content

Commit 0f1952d

Browse files
committed
added tests for unrestricted IMOM; some cleanup
1 parent 95fc090 commit 0f1952d

15 files changed

+3957
-848
lines changed

src/scf_solver/GroundStateSolver.cpp

+25-30
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,11 @@ json GroundStateSolver::optimize(Molecule &mol, FockBuilder &F, OrbitalVector &P
325325
if (restricted) {
326326
DoubleVector occNew = getNewOccupations(Phi_n, Phi_mom);
327327
orbital::set_occupations(Phi_n, occNew);
328-
329-
// orbital::print(Phi_n);
330-
// mol.calculateOrbitalPositions();
331-
// mol.printOrbitalPositions();
328+
if (plevel > 1) {
329+
orbital::print(Phi_n);
330+
mol.calculateOrbitalPositions();
331+
mol.printOrbitalPositions();
332+
}
332333
}
333334
else {
334335
// in case of unrestricted calculation, get the new occupation for alpha and beta spins independently
@@ -341,10 +342,11 @@ json GroundStateSolver::optimize(Molecule &mol, FockBuilder &F, OrbitalVector &P
341342
DoubleVector occNew(occAlpha.size() + occBeta.size());
342343
occNew << occAlpha, occBeta;
343344
orbital::set_occupations(Phi_n, occNew);
344-
345-
// orbital::print(Phi_n);
346-
// mol.calculateOrbitalPositions();
347-
// mol.printOrbitalPositions();
345+
if (plevel > 1) {
346+
orbital::print(Phi_n);
347+
mol.calculateOrbitalPositions();
348+
mol.printOrbitalPositions();
349+
}
348350
}
349351
}
350352

@@ -475,36 +477,28 @@ bool GroundStateSolver::needDiagonalization(int nIter, bool converged) const {
475477
DoubleVector GroundStateSolver::getNewOccupations(OrbitalVector &Phi_n, OrbitalVector &Phi_mom) {
476478
DoubleMatrix overlap = orbital::calc_overlap_matrix(Phi_mom, Phi_n).real();
477479
DoubleVector occ = orbital::get_occupations(Phi_mom);// get occupation numbers of the orbitals of the first iteration
478-
// get all unique occupation numbers
479-
std::set<double> occupationNumbers(occ.begin(), occ.end());
480-
// for each unique occupation number, determine which orbitals should be assigned this occupation number; necessary???
481-
double hole, occupied = 0.0;
482-
for (auto& occNumber : occupationNumbers) {
483-
if (occNumber > occupied) {
484-
hole = occupied;
485-
occupied = occNumber;
486-
}
487-
else {
488-
hole = occNumber;
489-
}
490-
}
491-
DoubleVector occNew = DoubleVector::Constant(occ.size(), hole);
492-
// create vector which contains the positions of the unique occupation number
480+
double occ1 = occ(0);
481+
DoubleVector occNew = DoubleVector::Constant(occ.size(), occ1);
482+
483+
// create vector which contains the positions of the second occupation number
493484
DoubleVector currOcc = DoubleVector::Zero(occ.size());
494485
unsigned int nCurrOcc = 0;
495-
for (unsigned int i = 0; i < occ.size(); i++) {
496-
if (occ(i) == occupied) {
486+
double occ2 = 0.0;
487+
for (unsigned int i = 1; i < occ.size(); i++) {
488+
if (occ(i) != occ1) {
489+
occ2 = occ(i);
497490
currOcc(i) = 1.0;
498491
nCurrOcc++;
499492
}
500493
}
501-
// only consider overlap with orbitals with the current unique occupation number
494+
495+
// only consider overlap with orbitals with the second occupation number
502496
DoubleMatrix occOverlap = currOcc.asDiagonal() * overlap;
503497
DoubleVector p = occOverlap.colwise().norm();
504498

505499
//print section
506-
print_utils::matrix(2, "Overlap matrix", overlap, 2);
507-
print_utils::vector(2, "Total overlap", p, 2);
500+
print_utils::matrix(2, "MOM overlap matrix", overlap, 2);
501+
print_utils::vector(2, "MOM total overlap", p, 2);
508502

509503
// sort by highest overlap
510504
std::vector<std::pair<double, unsigned>> sortme;
@@ -513,9 +507,10 @@ DoubleVector GroundStateSolver::getNewOccupations(OrbitalVector &Phi_n, OrbitalV
513507
}
514508
std::stable_sort(sortme.begin(), sortme.end());
515509
std::reverse(sortme.begin(), sortme.end());
516-
// assign the current unique occupation number to orbitals with highest overlap
510+
511+
// assign the second occupation number to orbitals with highest overlap
517512
for (unsigned int q = 0; q < nCurrOcc; q++) {
518-
occNew(sortme[q].second) = occupied;
513+
occNew(sortme[q].second) = occ2;
519514
}
520515
sortme.clear();
521516
return occNew;

tests/li2h_imom/li2h_exc.inp tests/li2h_imom/li2h_exc_restricted.inp

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ $end
1818

1919
WaveFunction {
2020
method = PBE # Wave function method (HF or DFT)
21+
restricted = true
2122
}
2223

2324
OrbitalOccupancies {
@@ -26,6 +27,11 @@ OrbitalOccupancies {
2627

2728
SCF {
2829
run = true
30+
max_iter = 3
2931
guess_type = mw # Type of initial guess: none, mw, gto
3032
deltascf_method = IMOM
33+
}
34+
35+
Printer {
36+
print_level = 2
3137
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# vim:syntax=sh:
2+
3+
world_prec = 1.0e-3 # Overall relative precision
4+
world_size = 6 # Size of simulation box 2^n
5+
6+
MPI {
7+
numerically_exact = true # Guarantee identical results in MPI
8+
}
9+
10+
Molecule {
11+
charge = 1
12+
$coords
13+
Li -5.46737452 2.65708721 0.38412463
14+
Li 2.48697407 1.97066310 -0.29143356
15+
H -0.09374931 -1.62164958 -3.76992803
16+
$end
17+
}
18+
19+
WaveFunction {
20+
method = PBE # Wave function method (HF or DFT)
21+
restricted = false
22+
}
23+
24+
OrbitalOccupancies {
25+
occupancies = "1 1 0"
26+
}
27+
28+
SCF {
29+
run = true
30+
max_iter = 5
31+
guess_type = mw # Type of initial guess: none, mw, gto
32+
deltascf_method = IMOM
33+
}
34+
35+
Printer {
36+
print_level = 2
37+
}

tests/li2h_imom/li2h_gs.inp tests/li2h_imom/li2h_gs_restricted.inp

+2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ $end
1818

1919
WaveFunction {
2020
method = PBE # Wave function method (HF or DFT)
21+
restricted = true
2122
}
2223

2324
SCF {
25+
localize = true
2426
run = false
2527
write_orbitals = true
2628
path_orbitals = initial_guess
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# vim:syntax=sh:
2+
3+
world_prec = 1.0e-3 # Overall relative precision
4+
world_size = 6 # Size of simulation box 2^n
5+
6+
MPI {
7+
numerically_exact = true # Guarantee identical results in MPI
8+
}
9+
10+
Molecule {
11+
charge = 1
12+
$coords
13+
Li -5.46737452 2.65708721 0.38412463
14+
Li 2.48697407 1.97066310 -0.29143356
15+
H -0.09374931 -1.62164958 -3.76992803
16+
$end
17+
}
18+
19+
WaveFunction {
20+
method = PBE # Wave function method (HF or DFT)
21+
restricted = false
22+
}
23+
24+
SCF {
25+
localize = true
26+
run = false
27+
write_orbitals = true
28+
path_orbitals = initial_guess
29+
}

0 commit comments

Comments
 (0)