Skip to content

Commit

Permalink
Working ExcitedStatesSolver. Pol. tests failing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielgerez committed Jan 9, 2023
1 parent 348ee8b commit dd9273f
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 88 deletions.
1 change: 1 addition & 0 deletions pilot/mrchem.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@




#
# MRChem, a numerical real-space code for molecular electronic structure
# calculations within the self-consistent field (SCF) approximations of quantum
Expand Down
1 change: 1 addition & 0 deletions python/mrchem.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3



#
# MRChem, a numerical real-space code for molecular electronic structure
# calculations within the self-consistent field (SCF) approximations of quantum
Expand Down
3 changes: 2 additions & 1 deletion python/mrchem/update_input_parser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python


#
# MRChem, a numerical real-space code for molecular electronic structure
# calculations within the self-consistent field (SCF) approximations of quantum
# chemistry (Hartree-Fock and Density Functional Theory).
# Copyright (C) 2022 Stig Rune Jensen, Luca Frediani, Peter Wind and contributors.
# Copyright (C) 2023 Stig Rune Jensen, Luca Frediani, Peter Wind and contributors.
#
# This file is part of MRChem.
#
Expand Down
21 changes: 16 additions & 5 deletions src/chemistry/Molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,27 @@ Molecule::Molecule(const std::vector<std::string> &coord_str, int c, int m)
}

void Molecule::initPerturbedOrbitals(bool dynamic, int n_states) {
this->orbitals_x.reserve(n_states);
this->orbitals_y.reserve(n_states);
MSG_INFO("before reserving the size of the vectors");
std::cout << "size of state_vector to initialize " << n_states << "\n";
// this->orbitals_x.reserve(n_states);
// this->orbitals_y.reserve(n_states);
// MSG_INFO("after reserving the size of the vectors");
std::cout << "size of state_vector after reserving " << this->orbitals_x.size() << "\n";
MSG_INFO("before loop to add vector pointers to nstate vecotr ");
for (auto i = 0; i < n_states; i++) {
this->orbitals_x[i] = std::make_shared<OrbitalVector>();
auto orbital_x = std::make_shared<OrbitalVector>();
std::cout << "in the loop \n";
this->orbitals_x.push_back(orbital_x);
// this->orbitals_x[i] = std::make_shared<OrbitalVector>();
std::cout << "size of state_vector to initialize " << this->orbitals_x.size() << "\n";
if (dynamic) {
this->orbitals_y[i] = std::make_shared<OrbitalVector>();
auto orbital_y = std::make_shared<OrbitalVector>();
this->orbitals_y.push_back(orbital_y);
} else {
this->orbitals_y[i] = this->orbitals_x[i];
this->orbitals_y.push_back(orbital_x);
}
}
std::cout << "size of state_vector after loop " << this->orbitals_x.size() << "\n";
}

/** @brief Return number of electrons */
Expand Down
20 changes: 3 additions & 17 deletions src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ json driver::rsp::run(const json &json_rsp, Molecule &mol) {
///////////////////////////////////////////////////////////
////////////// Preparing Perturbed System /////////////
///////////////////////////////////////////////////////////
double omega;
double omega = 0.0;
auto dynamic = false;
auto run_tda = false;
auto iter_var = 0;
Expand All @@ -754,6 +754,7 @@ json driver::rsp::run(const json &json_rsp, Molecule &mol) {
json_out["frequency"] = omega;
json_out["components"] = {};
} else if (run_exc) {

run_tda = json_rsp["run_tda"];
iter_var = json_rsp["states"].size();
mol.initPerturbedOrbitals(dynamic, iter_var);
Expand Down Expand Up @@ -802,7 +803,6 @@ json driver::rsp::run(const json &json_rsp, Molecule &mol) {
auto helmholtz_prec = json_comp["exc_solver"]["helmholtz_prec"];

ExcitedStatesSolver solver(run_tda);
MSG_INFO("");
solver.setHistory(kain);
solver.setMethodName(method);
solver.setMaxIterations(max_iter);
Expand All @@ -812,22 +812,15 @@ json driver::rsp::run(const json &json_rsp, Molecule &mol) {
solver.setOrbitalPrec(start_prec, final_prec);
solver.setThreshold(orbital_thrs, property_thrs);
solver.setOrthPrec(orth_prec);
MSG_INFO("");
comp_out["exc_solver"] = solver.optimize(mol, F_0, F_1, i);
MSG_INFO("");
json_out["success"] = comp_out["exc_solver"]["converged"];
MSG_INFO("");
if (json_out["success"]) {
if (json_comp.contains("write_orbitals")) rsp::write_orbitals(json_comp["write_orbitals"], mol, dynamic);
if (json_rsp.contains("properties")) rsp::calc_properties(json_rsp["properties"], mol, 2, json_rsp["frequency"], i);
}
MSG_INFO("");
mol.getOrbitalsX(i).clear(); // Clear orbital vector
MSG_INFO("");
mol.getOrbitalsY(i).clear(); // Clear orbital vector
MSG_INFO("");
json_out["states"].push_back(comp_out);
MSG_INFO("");

} else if (json_comp.contains("rsp_solver")) {
auto kain = json_comp["rsp_solver"]["kain"];
Expand Down Expand Up @@ -869,21 +862,14 @@ json driver::rsp::run(const json &json_rsp, Molecule &mol) {
mol.getOrbitalsY(0).clear(); // Clear orbital vector
json_out["components"].push_back(comp_out);
}
MSG_INFO("");
}
MSG_INFO("");

F_0.clear();
MSG_INFO("");
mpi::barrier(mpi::comm_orb);
MSG_INFO("");
if (run_exc) {
MSG_INFO("");
for (auto i = 0; i < iter_var; i++) {
MSG_INFO("");
mol.getOrbitalsX_p(i).reset(); // Release shared_ptr
MSG_INFO("");
mol.getOrbitalsY_p(i).reset(); // Release shared_ptr
MSG_INFO("");
}
} else {
mol.getOrbitalsX_p(0).reset(); // Release shared_ptr
Expand Down
2 changes: 1 addition & 1 deletion src/mrchem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* MRChem, a numerical real-space code for molecular electronic structure
* calculations within the self-consistent field (SCF) approximations of quantum
* chemistry (Hartree-Fock and Density Functional Theory).
* Copyright (C) 2022 Stig Rune Jensen, Luca Frediani, Peter Wind and contributors.
* Copyright (C) 2023 Stig Rune Jensen, Luca Frediani, Peter Wind and contributors.
*
* This file is part of MRChem.
*
Expand Down
25 changes: 0 additions & 25 deletions src/qmfunctions/OrbitalIterator.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
/*
* MRChem, a numerical real-space code for molecular electronic structure
* calculations within the self-consistent field (SCF) approximations of quantum
* chemistry (Hartree-Fock and Density Functional Theory).
* Copyright (C) 2022 Stig Rune Jensen, Luca Frediani, Peter Wind and contributors.
*
* This file is part of MRChem.
*
* MRChem 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, either version 3 of the License, or
* (at your option) any later version.
*
* MRChem 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 MRChem. If not, see <https://www.gnu.org/licenses/>.
*
* For information on the complete list of contributors to MRChem, see:
* <https://mrchem.readthedocs.io/>
*/

/*
* Mrchem, a numerical real-space code for molecular electronic structure
* calculations within the self-consistent field (SCF) approximations of quantum
Expand Down
15 changes: 1 addition & 14 deletions src/qmfunctions/QMFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,15 @@ void QMFunction::alloc(int type, mrcpp::MultiResolutionAnalysis<3> *mra) {
}

void QMFunction::free(int type) {
MSG_INFO("");
if (type == NUMBER::Real or type == NUMBER::Total) {
MSG_INFO("");
if (hasReal()) {
std::cout << "has real \n";
delete this->func_ptr->re;
MSG_INFO("");
}
MSG_INFO("");
if (this->hasReal()) { delete this->func_ptr->re; }
this->func_ptr->re = nullptr;
MSG_INFO("");
if (this->func_ptr->shared_mem_re) this->func_ptr->shared_mem_re->clear();
MSG_INFO("");
}
if (type == NUMBER::Imag or type == NUMBER::Total) {
MSG_INFO("");
if (hasImag()) delete this->func_ptr->im;
MSG_INFO("");
this->func_ptr->im = nullptr;
MSG_INFO("");
if (this->func_ptr->shared_mem_im) this->func_ptr->shared_mem_im->clear();
MSG_INFO("");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/qmfunctions/density_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void density::compute_local_X(double prec, Density &rho, OrbitalVector &Phi, Orb

Density rho_i(false);
qmfunction::multiply_real(rho_i, X[i], Phi[i], mult_prec);
std::cout << "run tda = " << run_tda << "\n";
if (run_tda) {
rho.add(1.0 * occ, rho_i); // should only be one for tda else 2.0 for standard
} else {
Expand Down
8 changes: 2 additions & 6 deletions src/qmoperators/two_electron/CoulombPotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,9 @@ void CoulombPotential::setup(double prec) {
* The operator can now be reused after another setup.
*/
void CoulombPotential::clear() {
MSG_INFO("");
QMFunction::free(NUMBER::Total); // delete FunctionTree pointers
MSG_INFO("");
QMFunction::free(NUMBER::Total); // delete FunctionTree pointers
this->density.free(NUMBER::Total); // delete FunctionTree pointers
MSG_INFO("");
clearApplyPrec(); // apply_prec = -1
MSG_INFO("");
clearApplyPrec(); // apply_prec = -1
}

/** @brief compute Coulomb potential
Expand Down
6 changes: 0 additions & 6 deletions src/qmoperators/two_electron/FockBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,14 @@ void FockBuilder::setup(double prec) {
* to the state after construction. The operator can now be reused after another setup.
*/
void FockBuilder::clear() {
MSG_INFO("");
if (this->mom != nullptr) this->momentum().clear();
MSG_INFO("");
this->potential().clear();
MSG_INFO("");
this->perturbation().clear();
MSG_INFO("");
if (isZora()) {
MSG_INFO("");
this->kappa->clear();
this->kappa_inv->clear();
this->zora_base.clear();
}
MSG_INFO("");
}

/** @brief rotate orbitals of two-electron operators
Expand Down
4 changes: 2 additions & 2 deletions src/scf_solver/ExcitedStatesSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ json ExcitedStatesSolver::optimize(Molecule &mol, FockBuilder &F_0, FockBuilder
OrbitalVector &Phi_0 = mol.getOrbitals();

OrbitalVector &X_n = mol.getOrbitalsX(state);
MSG_INFO("testing size of NStatevector ");
std::cout << "size of states vector " << mol.getStatesX().size() << "\n";

ComplexMatrix &F_mat_0 = mol.getFockMatrix();

Expand Down Expand Up @@ -122,7 +124,6 @@ json ExcitedStatesSolver::optimize(Molecule &mol, FockBuilder &F_0, FockBuilder
printConvergenceHeader("Excited state energy");
if (plevel < 1) printConvergenceRow(0);
}

for (auto nIter = 0; (nIter < this->maxIter) or (this->maxIter < 0); nIter++) {
json json_cycle;
std::stringstream o_header;
Expand Down Expand Up @@ -161,7 +162,6 @@ json ExcitedStatesSolver::optimize(Molecule &mol, FockBuilder &F_0, FockBuilder

// Apply Helmholtz operators
OrbitalVector X_np1 = H_x.apply(V_0, X_n, Psi);
Psi.clear();
// Projecting (1 - rho_0)X
mrcpp::print::header(2, "Projecting occupied space");
t_lap.start();
Expand Down
12 changes: 1 addition & 11 deletions src/tensor/RankZeroOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,8 @@ void RankZeroOperator::setup(double prec) {
/** @brief run clear on all operators in the expansion
*/
void RankZeroOperator::clear() {
MSG_INFO(" ");
std::cout << "length of the operator vector: " << this->oper_exp.size() << "\n";
std::cout << "name of operator: " << this->name() << "\n";
for (auto &i : this->oper_exp) {
MSG_INFO(" ");
for (int j = 0; j < i.size(); j++) {
MSG_INFO(" ");
std::cout << "\t j? " << j << "\n";
i[j]->clear();
MSG_INFO(" ");
}
MSG_INFO(" ");
for (int j = 0; j < i.size(); j++) { i[j]->clear(); }
}
}

Expand Down

0 comments on commit dd9273f

Please sign in to comment.