votca 2026-dev
Loading...
Searching...
No Matches
qmregion.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// Local VOTCA includes
21#include "votca/xtp/qmregion.h"
23#include "votca/xtp/aomatrix.h"
24#include "votca/xtp/basisset.h"
25#include "votca/xtp/citations.h"
28#include "votca/xtp/dftengine.h"
33#include "votca/xtp/gwbse.h"
36#include "votca/xtp/qmstate.h"
38#include "votca/xtp/vxc_grid.h"
40
41#include <algorithm>
42#include <iomanip>
43#include <sstream>
44#include <stdexcept>
45#include <utility>
46
47namespace votca {
48namespace xtp {
49
51 if (this->id_ != 0) {
52 throw std::runtime_error(
53 this->identify() +
54 " must always be region 0. Currently only one qm region is possible.");
55 }
56
57 initstate_ = prop.get("state").as<QMState>();
58 /*if (initstate_.Type() == QMStateType::Hole ||
59 initstate_.Type() == QMStateType::Electron) {
60 throw std::runtime_error(
61 "Charged QM Regions are not implemented currently");
62 }*/
63 if (initstate_.Type().isExciton() || initstate_.Type().isGWState()) {
64
65 do_gwbse_ = true;
66 gwbseoptions_ = prop.get("gwbse");
67 if (prop.exists("statetracker")) {
68 tools::Property filter = prop.get("statetracker");
69 statetracker_.setLogger(&log_);
70 statetracker_.Initialize(filter);
71 statetracker_.setInitialState(initstate_);
72 statetracker_.PrintInfo();
73 } else {
74 throw std::runtime_error(
75 "No statetracker options for excited states found");
76 }
77 }
78
79 if (initstate_.Type().isKSState()) {
80
81 if (prop.exists("statetracker")) {
82 tools::Property filter = prop.get("statetracker");
83 statetracker_.setLogger(&log_);
84 statetracker_.Initialize(filter);
85 statetracker_.setInitialState(initstate_);
86 statetracker_.PrintInfo();
87 } else {
88 throw std::runtime_error("No statetracker options for KS states found");
89 }
90 }
91
93 prop.get("grid_for_potential").as<std::string>();
94 DeltaE_ = prop.get("tolerance_energy").as<double>();
95 DeltaD_ = prop.get("tolerance_density").as<double>();
96 DeltaDmax_ = prop.get("tolerance_density_max").as<double>();
97
98 dftoptions_ = prop.get("dftpackage");
99 localize_options_ = prop.get("localize");
101 prop.ifExistsReturnElseReturnDefault<bool>("relaxed_density", false);
102
103 if (prop.get("dftpackage.xtpdft.dft_in_dft.activeatoms")
104 .as<std::string>()
105 .size() != 0) {
106 do_localize_ = true;
107 do_dft_in_dft_ = true;
108 }
109
110 if (prop.exists("environment_screening")) {
111 const tools::Property env = prop.get("environment_screening");
112 screening_ = env.ifExistsReturnElseReturnDefault<bool>("enabled", true);
113 }
114 if (screening_) {
115 const tools::Property env = prop.get("environment_screening");
116 // Excitations are what the screening is for. A charged DFT run would
117 // put the extra charge's polarization into the ground-state loop and
118 // again into W; a plain ground-state or KS-level run has no GW-BSE to
119 // screen.
120 if (initstate_.Type() == QMStateType::Electron ||
121 initstate_.Type() == QMStateType::Hole) {
122 throw std::runtime_error(
123 "environment_screening with state " + initstate_.ToString() +
124 ": the charged DFT state would be polarized in the QM/MM loop and "
125 "screened again in GW. Run the neutral molecule and ask for the "
126 "quasiparticle level instead: state pqpN (or dqpN) with N the "
127 "HOMO or LUMO index.");
128 }
129 if (initstate_.Type() == QMStateType::ExcitonUKS) {
130 throw std::runtime_error(
131 "environment_screening is implemented for closed-shell GW-BSE "
132 "only; the unrestricted exciton state " +
133 initstate_.ToString() + " is not supported.");
134 }
135 if (!do_gwbse_) {
136 throw std::runtime_error(
137 "environment_screening needs a GW-BSE state (an exciton or a "
138 "quasiparticle level); " +
139 initstate_.ToString() + " has no GW-BSE calculation to screen.");
140 }
142 env.ifExistsReturnElseReturnDefault<bool>("include_kreac", true);
144 env.ifExistsReturnElseReturnDefault<double>("shell_dielectric", 4.0);
146 env.ifExistsReturnElseReturnDefault<double>("site_width", 0.5);
147 if (!(screening_site_width_ >= 0.0)) {
148 throw std::runtime_error(
149 "environment_screening: site_width must be >= 0 (0 for point "
150 "sites), got " +
151 std::to_string(screening_site_width_) + ".");
152 }
153 std::string shells =
154 env.ifExistsReturnElseReturnDefault<std::string>("shell_regions", "");
155 std::replace(shells.begin(), shells.end(), ',', ' ');
156 std::istringstream in(shells);
157 Index id;
158 while (in >> id) {
159 screening_shell_regions_.push_back(id);
160 }
162 << " Environment screening on: ground-state QM/MM loop, then one "
163 "screened GW-BSE run. K_reac "
164 << (screening_include_kreac_ ? "included" : "excluded")
165 << ", shell dielectric " << screening_shell_dielectric_
166 << ", site width " << screening_site_width_ << " alpha^(1/3)"
167 << std::flush;
168 }
169 if (relaxed_density_) {
170 if (!do_gwbse_) {
171 throw std::runtime_error(
172 "relaxed_density: needs a GW-BSE state (exciton or QP level)");
173 }
174 if (screening_) {
175 throw std::runtime_error(
176 "relaxed_density: not available with environment_screening (the "
177 "screened GW-BSE energy has no relaxed density yet)");
178 }
179 if (do_dft_in_dft_) {
180 throw std::runtime_error(
181 "relaxed_density: not available with DFT-in-DFT embedding");
182 }
183 if (dftoptions_.get("name").as<std::string>() != "xtp") {
184 throw std::runtime_error("relaxed_density: needs the xtp DFT package");
185 }
186 }
187}
188
190 if (!do_dft_in_dft_ || orb_.isOpenShell()) {
191 return;
192 }
193 reference_.mos = orb_.MOs();
194 reference_.occupied = orb_.getNumberOfAlphaElectrons();
195 reference_.set = true;
196}
197
199 if (!reference_.set) {
200 return;
201 }
202 orb_.MOs() = reference_.mos;
203 orb_.setNumberOfOccupiedLevels(reference_.occupied);
204 orb_.setNumberOfOccupiedLevelsBeta(reference_.occupied);
205 orb_.setNumberOfAlphaElectrons(reference_.occupied);
206 orb_.setNumberOfBetaElectrons(reference_.occupied);
207}
208
210 citations::Cite("Baumeier:2014");
211 citations::Cite("Tirimbo:2020b");
212 citations::Cite("Tirimbo:2024a");
213 if (orb_.isOpenShell()) {
214 throw std::runtime_error("GWBSE not implemented for open-shell systems");
215 }
216 const InactiveScreeningInput::Mode inactive_mode =
218 gwbseoptions_.ifExistsReturnElseReturnDefault<std::string>(
219 "inactive_screening", "none"));
220 if (inactive_mode != InactiveScreeningInput::Mode::None && !do_dft_in_dft_) {
221 throw std::runtime_error(
222 "gwbse.inactive_screening needs a projection-based embedding "
223 "(dftpackage.xtpdft.dft_in_dft).");
224 }
225 InactiveScreeningInput inactive;
226 if (do_dft_in_dft_) {
227 Index active_electrons = orb_.getNumOfActiveElectrons();
228
229 if (active_electrons % 2 != 0) {
230 throw std::runtime_error(
231 "DFT-in-DFT embedded GWBSE currently supports only closed-shell "
232 "active spaces with an even number of electrons");
233 }
234
235 // from the full MOs of this iteration's reference calculation, which
236 // the embedded ones replace below
238 orb_, inactive_mode,
239 gwbseoptions_.ifExistsReturnElseReturnDefault<bool>(
240 "inactive_screening_complete_g", false),
241 gwbseoptions_.ifExistsReturnElseReturnDefault<double>(
242 "inactive_screening_radius", 0.0) *
244 orb_.MOs() = orb_.getEmbeddedMOs();
245
246 Index active_occ = active_electrons / 2;
247 if (inactive.complete_g) {
248 // inactive occupied levels in front of the active ones
249 orb_.MOs() = InactiveScreening::CompleteGOrbitals(orb_.getEmbeddedMOs(),
250 active_occ, inactive);
251 active_occ += inactive.n_inactive;
252 }
253
254 // Restricted closed-shell rewrite of the embedded orbital object
255 orb_.setNumberOfOccupiedLevels(active_occ);
256 orb_.setNumberOfOccupiedLevelsBeta(active_occ);
257 orb_.setNumberOfAlphaElectrons(active_occ);
258 orb_.setNumberOfBetaElectrons(active_occ);
259 orb_.setChargeAndSpin(orb_.getCharge(), 1);
260 }
261 return inactive;
262}
263
264double QMRegion::StateEnergy(const QMState& state) const {
265 if (state.Type().isExciton()) {
266 return orb_.getExcitedStateEnergy(state);
267 }
268 // quasiparticle: adding an electron to an unoccupied level, removing one
269 // from an occupied level
270 if (state.StateIdx() > orb_.getHomo()) {
271 return orb_.getExcitedStateEnergy(state);
272 }
273 return -orb_.getExcitedStateEnergy(state);
274}
275
277 const std::vector<std::unique_ptr<Region> >& regions) const {
282 bool have_damp = false;
283 PolarRegion Polardummy(0, log_);
284 for (const std::unique_ptr<Region>& reg : regions) {
285 if (reg->identify() != Polardummy.identify()) {
286 continue;
287 }
288 const PolarRegion& polar = dynamic_cast<const PolarRegion&>(*reg);
289 const bool shell =
290 std::find(screening_shell_regions_.begin(),
292 polar.getId()) != screening_shell_regions_.end();
293 if (shell) {
294 if (polar.hasChargeResponse()) {
295 throw std::runtime_error(
296 "environment_screening: shell region " +
297 std::to_string(polar.getId()) +
298 " has charge-response segments; a shell responds with "
299 "alpha/epsilon per site, which has no induced charges. Use "
300 "Thole segments there.");
301 }
302 env.shell_segments.insert(env.shell_segments.end(), polar.begin(),
303 polar.end());
304 continue;
305 }
306 if (have_damp && polar.ExpDamp() != env.exp_damp) {
307 throw std::runtime_error(
308 "environment_screening: the explicit polar regions respond as one "
309 "coupled Thole system and must share exp_damp; found " +
310 std::to_string(env.exp_damp) + " and " +
311 std::to_string(polar.ExpDamp()) + ".");
312 }
313 env.exp_damp = polar.ExpDamp();
314 have_damp = true;
315 env.explicit_segments.insert(env.explicit_segments.end(), polar.begin(),
316 polar.end());
317 }
319 const bool is_polar = std::any_of(
320 regions.begin(), regions.end(),
321 [&](const std::unique_ptr<Region>& reg) {
322 return reg->getId() == id && reg->identify() == Polardummy.identify();
323 });
324 if (!is_polar) {
325 throw std::runtime_error("environment_screening: shell region " +
326 std::to_string(id) +
327 " is not a polar region of this job.");
328 }
329 }
330 if (env.empty()) {
332 << TimeStamp()
333 << " WARNING: environment_screening is on but there is no polar "
334 "region; GW-BSE runs unscreened."
335 << std::flush;
336 }
337 return env;
338}
339
341 // The auxiliary basis GWBSE::Initialize will pick: the DFT run's own
342 // (dftpackage.auxbasisset), else gwbse.auxbasisset, else aux-<basis>.
343 if (dftoptions_.exists("auxbasisset") &&
344 !dftoptions_.get("auxbasisset").as<std::string>().empty()) {
345 return dftoptions_.get("auxbasisset").as<std::string>();
346 }
347 if (gwbseoptions_.exists("auxbasisset") &&
348 !gwbseoptions_.get("auxbasisset").as<std::string>().empty()) {
349 return gwbseoptions_.get("auxbasisset").as<std::string>();
350 }
351 return "aux-" + dftoptions_.get("basisset").as<std::string>();
352}
353
355 const std::vector<std::unique_ptr<Region> >& regions) const {
356 if (!screening_) {
357 return;
358 }
359 // R depends on the QM atoms, the auxiliary basis on them and the polar
360 // sites -- none of which the QM/MM loop changes -- so it is checked
361 // here, before the loop, rather than after the ground state has
362 // converged. Failing now costs seconds; failing in EvaluateScreenedGWBSE
363 // costs the whole loop.
365 if (env.empty()) {
366 return;
367 }
368 const std::string auxname = ScreeningAuxBasisName();
369 BasisSet bs;
370 bs.Load(auxname);
371 AOBasis auxbasis;
372 auxbasis.Fill(bs, orb_.QMAtoms());
374 << TimeStamp() << " Checking the screening environment (" << auxname
375 << ", " << auxbasis.AOBasisSize() << " functions)" << std::flush;
377 auxbasis, orb_.QMAtoms(), env, EnvironmentScreening::Metric(auxbasis));
378 if (!check.ok()) {
379 throw std::runtime_error(
380 "environment_screening: 1 + R is not positive definite (lowest "
381 "eigenvalue of R " +
382 std::to_string(check.lowest) +
383 "): the environment would screen some charge fluctuation of the QM "
384 "region by more than the fluctuation itself. Diagnosis:\n" +
385 check.report);
386 }
388 << TimeStamp() << " Screening environment is stable: lowest eigenvalue "
389 << "of R " << check.lowest << " (must be > -1)" << std::flush;
390 XTP_LOG(Log::info, log_) << check.report << std::flush;
391}
392
394 std::vector<std::unique_ptr<Region> >& regions) {
395 if (!screening_) {
396 return;
397 }
398 if (orb_.getCalculationType() == "Truncated") {
399 throw std::runtime_error(
400 "environment_screening is not implemented for truncated active "
401 "regions.");
402 }
403
405
407 << TimeStamp() << " Running environment-screened GW-BSE" << std::flush;
408 const double e_dft = orb_.getDFTTotalEnergy();
411 GWBSE gwbse(orb_);
412 gwbse.setLogger(&log_);
413 gwbse.setInactiveScreening(std::move(inactive));
415 gwbse.setScreeningEnvironment(env);
416 gwbse.Evaluate();
417 const QMState state = statetracker_.CalcStateAndUpdate(orb_);
418 const double energy = e_dft + StateEnergy(state);
420 << TimeStamp() << " Screened state " << state.ToString() << ": "
421 << std::setprecision(10) << StateEnergy(state) * tools::conv::hrt2ev
422 << " eV, region energy " << energy << " Hartree" << std::flush;
423 E_hist_.push_back(energy);
424 screened_state_ = state;
425 screened_done_ = true;
426}
427
429 if (!screened_done_) {
430 return;
431 }
432 // Site energies as -j read stores them: the energy of the state relative
433 // to the neutral ground state of the same environment, in eV. One
434 // screened job provides all of them, from one GW(-BSE) run on top of
435 // the converged ground state:
436 // h: E_h - E_n = -eps_HOMO e: E_e - E_n = eps_LUMO
437 // s/t: Omega of the tracked exciton, if the job's state is one.
438 // Quasiparticle energies are the diagonalized ones (DQP) if available.
439 const Index homo = orb_.getHomo();
440 auto qp = [&](Index level) {
441 const std::string kind = orb_.hasQPdiag() ? "dqp" : "pqp";
442 return orb_.getExcitedStateEnergy(QMState(kind + std::to_string(level)));
443 };
444 tools::Property& out = prop.add("screened_site_energies", "");
445 out.add("h", std::to_string(-qp(homo) * tools::conv::hrt2ev));
446 out.add("e", std::to_string(qp(homo + 1) * tools::conv::hrt2ev));
448 out.add("s",
450 } else if (screened_state_.Type() == QMStateType::Triplet) {
451 out.add("t",
453 }
454 out.add("state", screened_state_.ToString());
455}
456
457// helper function to hand the grid changable over to Ewald
458std::vector<Eigen::Vector3d> QMRegion::copyEwaldGrid() {
459
460 std::vector<const Eigen::Vector3d*> src = ewaldgrid_.getGridpoints();
461 std::vector<Eigen::Vector3d> dst(src.size());
462 std::transform(src.begin(), src.end(), dst.begin(),
463 [](const Eigen::Vector3d* v) { return *v; });
464 return dst;
465}
466
468
469 // purpose: prepare a grid integration object that can
470 // - hand over the grid to Ewald
471 // - after Ewald calculates the potential at the grid points, be put into
472 // xtpdft
473 //
474 // The grid name is xtpdft's own integration_grid, NOT grid_for_potential.
475 // That is a constraint, not a preference: what comes back from Ewald is a
476 // potential VALUE at each quadrature point, and DFTEngine forms <rho|phi>
477 // on the grid it rebuilds from grid_name_, which is this same key. A
478 // different quality here gives a different number of boxes and a
479 // different number of points per box, and the size checks on the
480 // DFTEngine side would throw. grid_for_potential governs the opposite
481 // direction -- the QM density's influence outward on classical regions,
482 // in ApplyQMFieldToPolarSegments -- and has no business here.
483 if (orb_.QMAtoms().size() == 0) {
484 throw std::runtime_error(
485 "QMRegion::PrepareEwaldPotentialGrid: the region holds no atoms. The "
486 "grid is built over the QM molecule, so this must run after the "
487 "region has been filled.");
488 }
489 std::string dftbasis_name = dftoptions_.get("basisset").as<std::string>();
490 std::string grid_name =
491 dftoptions_.get("xtpdft.integration_grid").as<std::string>();
492 QMMolecule mol = orb_.QMAtoms();
493 BasisSet bs;
494 bs.Load(dftbasis_name);
495 AOBasis dftbasis;
496 dftbasis.Fill(bs, mol);
497 ewaldgrid_.GridSetup(grid_name, mol, dftbasis);
499 << TimeStamp() << " Constructed Grid for Integration of Ewald Potential"
500 << std::flush;
501 // Vxc_Potential<Vxc_Grid> vxc(grid);
502 ewald_grid_ready_ = true;
503 return;
504}
505
507 if (!E_hist_.filled()) {
508 return false;
509 }
510
511 const double Echange = E_hist_.getDiff();
512 const Eigen::MatrixXd diff_ao = Dmat_hist_.getDiff();
513 const double n = double(diff_ao.cols());
514 // The density change is measured in the Loewdin-orthonormalised basis,
515 // S^1/2 dD S^1/2. In the AO basis, a near-linearly dependent basis lets
516 // density-matrix elements move a lot along near-redundant directions while
517 // the density itself hardly changes (C60/def2-TZVP: max change ~170 times
518 // the RMS), which made the max criterion decide the convergence alone.
519 const bool orthonormal = overlap_sqrt_.rows() == diff_ao.rows();
520 const Eigen::MatrixXd diff =
521 orthonormal ? Eigen::MatrixXd(overlap_sqrt_ * diff_ao * overlap_sqrt_)
522 : diff_ao;
523 const double Dchange = diff.norm() / n;
524 const double Dmax = diff.cwiseAbs().maxCoeff();
525 std::string info = "not converged";
526 bool converged = false;
527 if (Dchange < DeltaD_ && Dmax < DeltaDmax_ && std::abs(Echange) < DeltaE_) {
528 info = "converged";
529 converged = true;
530 }
531 std::ostringstream measure;
532 if (orthonormal) {
533 measure << " (orthonormal basis; AO basis: RMS " << diff_ao.norm() / n
534 << " Max " << diff_ao.cwiseAbs().maxCoeff() << ")";
535 } else {
536 measure << " (AO basis)";
537 }
539 << " Region:" << this->identify() << " " << this->getId() << " is "
540 << info << " deltaE=" << Echange << " RMS Dmat=" << Dchange
541 << " MaxDmat=" << Dmax << measure.str() << std::flush;
542 return converged;
543}
544
545void QMRegion::Evaluate(std::vector<std::unique_ptr<Region> >& regions) {
546
547 std::vector<double> interact_energies = ApplyInfluenceOfOtherRegions(regions);
548 double e_ext =
549 std::accumulate(interact_energies.begin(), interact_energies.end(), 0.0);
551 << TimeStamp()
552 << " Calculated interaction potentials with other regions. E[hrt]= "
553 << e_ext << std::flush;
554 XTP_LOG(Log::info, log_) << "Writing inputs" << std::flush;
555
556 Index crg = 0;
557 if (initstate_.Type() == QMStateType::Electron) {
558 crg = -1;
559 } else if (initstate_.Type() == QMStateType::Hole) {
560 crg = +1;
561 }
562 qmpackage_->setCharge(crg);
563 qmpackage_->setRunDir(workdir_);
564 // PbE: start from the previous full reference, not the embedded MOs
566 qmpackage_->WriteInputFile(orb_);
567
568 // Attach the periodic background to xtpdft as a potential sampled on
569 // the integration grid. This used to be one of two routes -- the other
570 // handed over multipole moments and k-vectors for the engine to build
571 // its own AO matrices from -- but nothing ever set that one up, so it
572 // has been removed. See the git history of this file if it is ever
573 // wanted back.
574 if (ewald_grid_ready_) {
575 if (qmpackage_->getPackageName() != "xtp") {
576 throw std::runtime_error("QMEwald can only run with XTP as qmpackage.");
577 }
578 qmpackage_->setEwaldgrid(ewaldgrid_);
579 qmpackage_->setEwaldNuclearEnergy(ewald_nuclear_energy_);
580 }
581
582 // From the second inter-region iteration on, only the environment has
583 // changed: start the SCF from the previous iteration's orbitals.
584 const bool warm_start = E_hist_.filled() && orb_.hasMOs();
585 qmpackage_->setWarmStart(warm_start);
586 // From the second inter-region iteration on, the inner SCF only needs to
587 // be converged a factor 10 beyond what the outer loop resolves: its
588 // energy error is second order in the density error, and its density
589 // error stays below the outer density tolerance. Not with GW-BSE, which
590 // takes the orbitals as they are; capped at 1e-5 in both.
591 if (warm_start && !do_gwbse_) {
592 qmpackage_->setSCFToleranceFloor(std::min(0.1 * DeltaE_, 1e-5),
593 std::min(0.1 * DeltaD_, 1e-5));
594 }
595 // Basis sets and geometry stay the same over the inter-region iterations:
596 // keep the RI integrals and the Ewald potential matrix for the next one.
597 // Not with GW-BSE, whose own three-centre integrals would come on top of
598 // the cached ones in memory. The cache lives here because Reset()
599 // recreates the QM package every iteration.
600 if (!do_gwbse_) {
601 if (!setup_cache_) {
602 setup_cache_ = std::make_shared<DFTSetupCache>();
603 }
604 qmpackage_->setSetupCache(setup_cache_);
605 }
606
607 XTP_LOG(Log::error, log_) << "Running DFT calculation" << std::flush;
608 bool run_success = qmpackage_->Run();
609 if (!run_success) {
610 info_ = false;
611 errormsg_ = "DFT-run failed";
612 return;
613 }
614
615 bool Logfile_parse = qmpackage_->ParseLogFile(orb_);
616 if (!Logfile_parse) {
617 info_ = false;
618 errormsg_ = "Parsing DFT logfile failed.";
619 return;
620 }
621 bool Orbfile_parse = qmpackage_->ParseMOsFile(orb_);
622 if (!Orbfile_parse) {
623 info_ = false;
624 errormsg_ = "Parsing DFT orbfile failed.";
625 return;
626 }
628 if (do_localize_) {
629 if (orb_.isOpenShell()) {
630 throw std::runtime_error(
631 "MO localization not implemented for open-shell systems");
632 }
634 pml.computePML(orb_);
635 }
636 QMMolecule originalmol = orb_.QMAtoms();
637 if (do_dft_in_dft_) {
638 if (orb_.isOpenShell()) {
639 throw std::runtime_error(
640 "DFT-in-DFT not implemented for open-shell systems");
641 }
642 // this only works with XTPDFT, so locally override global qmpackage_
643 std::unique_ptr<QMPackage> xtpdft =
644 std::unique_ptr<QMPackage>(QMPackageFactory().Create("xtp"));
645 xtpdft->setLog(&log_);
646 xtpdft->Initialize(dftoptions_);
647 xtpdft->setRunDir(workdir_);
648 Index charge = 0;
649 if (initstate_.Type() == QMStateType::Electron) {
650 charge = -1;
651 } else if (initstate_.Type() == QMStateType::Hole) {
652 charge = +1;
653 }
654 xtpdft->setCharge(charge);
655
656 std::vector<double> energies = std::vector<double>(regions.size(), 0.0);
657 for (std::unique_ptr<Region>& reg : regions) {
658 Index id = reg->getId();
659 if (id == this->getId()) {
660 continue;
661 }
662
663 StaticRegion Staticdummy(0, log_);
664 PolarRegion Polardummy(0, log_);
666 << TimeStamp() << " Evaluating interaction between "
667 << this->identify() << " " << this->getId() << " and "
668 << reg->identify() << " " << reg->getId() << std::flush;
669 if (reg->identify() == Staticdummy.identify()) {
670 StaticRegion* staticregion = dynamic_cast<StaticRegion*>(reg.get());
671 xtpdft->AddRegion(*staticregion);
672 } else if (reg->identify() == Polardummy.identify()) {
673 PolarRegion* polarregion = dynamic_cast<PolarRegion*>(reg.get());
674 xtpdft->AddRegion(*polarregion);
675 } else {
676 throw std::runtime_error(
677 "Interaction of regions with types:" + this->identify() + " and " +
678 reg->identify() + " not implemented");
679 }
680 }
681
682 e_ext = std::accumulate(interact_energies.begin(), interact_energies.end(),
683 0.0);
685 << TimeStamp()
686 << " Calculated interaction potentials with other regions. E[hrt]= "
687 << e_ext << std::flush;
688 XTP_LOG(Log::info, log_) << "Writing inputs" << std::flush;
689 xtpdft->WriteInputFile(orb_);
690 bool active_run = xtpdft->RunActiveRegion();
691 if (!active_run) {
692 throw std::runtime_error("\n DFT in DFT embedding failed. Stopping!");
693 }
694 Logfile_parse = xtpdft->ParseLogFile(orb_);
695 if (!Logfile_parse) {
696 throw std::runtime_error("\n Parsing DFT logfile failed. Stopping!");
697 }
698 }
699
700 QMState state = QMState("groundstate");
701 double energy = orb_.getDFTTotalEnergy();
702
703 if (initstate_.Type().isKSState()) {
704 state = statetracker_.CalcStateAndUpdate(orb_);
705 // if unoccupied, add QP level energy
706 if (state.StateIdx() > orb_.getHomo()) {
707 energy += orb_.getExcitedStateEnergy(state);
708 } else {
709 // if unoccupied, subtract QP level energy
710 energy -= orb_.getExcitedStateEnergy(state);
711 }
712 }
713
714 // With environment screening the loop converges the ground state only;
715 // GW-BSE runs once afterwards (EvaluateScreenedGWBSE).
716 if (do_gwbse_ && !screening_) {
718 GWBSE gwbse(orb_);
719 gwbse.setLogger(&log_);
720 gwbse.setInactiveScreening(std::move(inactive));
722 gwbse.Evaluate();
723 relaxed_dmat_valid_ = false;
724 state = statetracker_.CalcStateAndUpdate(orb_);
725 energy += StateEnergy(state);
726 }
727 // If truncation was enabled then rewrite full basis/aux-basis, MOs in full
728 // basis and full QMAtoms
729 if (orb_.getCalculationType() == "Truncated") {
730 orb_.MOs().eigenvectors() = orb_.getTruncMOsFullBasis();
731 orb_.QMAtoms().clearAtoms();
732 orb_.QMAtoms() = originalmol;
733 orb_.SetupDftBasis(orb_.getDftBasis().Name());
734 orb_.SetupAuxBasis(orb_.getAuxBasis().Name());
735 }
736 E_hist_.push_back(energy);
737
738 Dmat_hist_.push_back(StateDensity(state));
740 return;
741}
742
743Eigen::MatrixXd QMRegion::StateDensity(const QMState& state) const {
744 const bool relaxable =
745 state.Type().isExciton() || state.Type() == QMStateType::PQPstate;
746 if (!relaxed_density_ || !relaxable) {
747 return orb_.DensityMatrixFull(state);
748 }
749 if (!relaxed_dmat_valid_ || !(relaxed_dmat_state_ == state)) {
750 DFTEngine dft;
751 dft.setLogger(&log_);
752 tools::Property dftoptions = dftoptions_; // Initialize takes non-const
753 dft.Initialize(dftoptions);
755 relaxed_dmat_state_ = state;
756 relaxed_dmat_valid_ = true;
757 const Eigen::MatrixXd unrelaxed = orb_.DensityMatrixFull(state);
758 AOOverlap overlap;
759 overlap.Fill(orb_.getDftBasis());
760 AODipole dipole;
761 dipole.setCenter(orb_.QMAtoms().getPos());
762 dipole.Fill(orb_.getDftBasis());
763 Eigen::Vector3d change;
764 for (Index k = 0; k < 3; ++k) {
765 change(k) =
766 -(dipole.Matrix()[k].cwiseProduct(relaxed_dmat_ - unrelaxed)).sum();
767 }
769 << TimeStamp() << " Relaxed density of " << state.ToString()
770 << ": electronic dipole change by the relaxation (e*bohr) "
771 << change.transpose() << std::flush;
772 }
773 return relaxed_dmat_;
774}
775
777 if (overlap_sqrt_.rows() == Dmat_hist_.back().rows()) {
778 return;
779 }
780 overlap_sqrt_.resize(0, 0);
781 if (orb_.getBasisSetSize() != Dmat_hist_.back().rows() ||
782 orb_.getDFTbasisName().empty()) {
783 return; // no matching basis to orthonormalise with: AO measure
784 }
785 AOOverlap overlap;
786 try {
787 overlap.Fill(orb_.getDftBasis());
788 } catch (const std::runtime_error&) {
789 return;
790 }
791 if (overlap.Matrix().rows() != Dmat_hist_.back().rows()) {
792 return;
793 }
794 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es(overlap.Matrix());
795 overlap_sqrt_ = es.eigenvectors() *
796 es.eigenvalues().cwiseMax(0.0).cwiseSqrt().asDiagonal() *
797 es.eigenvectors().transpose();
798}
799
801 if (orb_.QMAtoms().size() == 0) {
802 orb_.QMAtoms() = mol;
803 } else {
804 orb_.QMAtoms().AddContainer(mol);
805 }
806 size_++;
807}
808
809double QMRegion::charge() const {
810 double charge = 0.0;
811 if (!do_gwbse_) {
812 Index nuccharge = 0;
813 for (const QMAtom& a : orb_.QMAtoms()) {
814 nuccharge += a.getNuccharge();
815 }
816
817 Index electrons = orb_.getNumberOfAlphaElectrons();
818 if (orb_.isOpenShell()) {
819 electrons += orb_.getNumberOfBetaElectrons();
820 } else {
821 electrons *= 2;
822 }
823
824 charge = double(nuccharge - electrons);
825 } else {
826 QMState state = statetracker_.InitialState();
827 if (state.Type().isExciton()) {
828 charge = 0.0;
829 } else if (state.Type().isSingleParticleState() ||
830 state.Type().isKSState()) {
831 if (state.StateIdx() <= orb_.getHomo()) {
832 charge = +1.0;
833 } else {
834 charge = -1.0;
835 }
836 }
837 }
838 return charge;
839}
840
842 prop.add("E_total", std::to_string(E_hist_.back() * tools::conv::hrt2ev));
843 if (do_gwbse_) {
844 prop.add("Initial_State", statetracker_.InitialState().ToString());
845 prop.add("Final_State", statetracker_.CalcState(orb_).ToString());
846 }
847}
848
850
851 std::string dft_package_name = dftoptions_.get("name").as<std::string>();
852 qmpackage_ =
853 std::unique_ptr<QMPackage>(QMPackageFactory().Create(dft_package_name));
854 qmpackage_->setLog(&log_);
855 qmpackage_->Initialize(dftoptions_);
856 Index charge = 0;
857 if (initstate_.Type() == QMStateType::Electron) {
858 charge = -1;
859 } else if (initstate_.Type() == QMStateType::Hole) {
860 charge = +1;
861 }
862 qmpackage_->setCharge(charge);
863 return;
864}
866 throw std::runtime_error(
867 "QMRegion-QMRegion interaction is not implemented yet.");
868 return 0.0;
869}
871 // Charge-response segments put Gaussian induced charges and dipoles into
872 // the QM Hamiltonian (DFTEngine, AOGaussianSites). Other packages get
873 // the environment as point charges (ORCA: permanent charges and split
874 // dipoles) and would silently miss the induced charges, while the
875 // environment still responds to the QM density.
876 if (region.hasChargeResponse() && qmpackage_->getPackageName() != "xtp") {
877 throw std::runtime_error(
878 "polar region " + std::to_string(region.getId()) +
879 " has charge-response segments, which only the xtp DFT package "
880 "supports (dftpackage name " +
881 qmpackage_->getPackageName() + "). Use xtp or Thole segments.");
882 }
883 qmpackage_->AddRegion(region);
884 return 0.0;
885}
887 qmpackage_->AddRegion(region);
888 return 0.0;
889}
890
892 writer.WriteContainer(orb_.QMAtoms());
893}
894
895void QMRegion::AddNucleiFields(std::vector<PolarSegment>& segments,
896 const StaticSegment& seg) const {
898#pragma omp parallel for
899 for (Index i = 0; i < Index(segments.size()); ++i) {
900 if (segments[i].hasChargeResponse()) {
901 continue; // Gaussian sites, see ApplyQMFieldToPolarSegments
902 }
903 e.ApplyStaticField<StaticSegment, Estatic::noE_V>(seg, segments[i]);
904 }
905}
906
908 std::vector<PolarSegment>& segments) const {
909
910 Vxc_Grid grid;
911 AOBasis basis =
912 orb_.getDftBasis(); // grid needs a basis in scope all the time
913 grid.GridSetup(grid_accuracy_for_ext_interaction_, orb_.QMAtoms(), basis);
914 DensityIntegration<Vxc_Grid> numint(grid);
915
916 // With environment screening the environment is polarized by the
917 // ground state only: the excitation's own polarization is in W.
918 QMState state = QMState("groundstate");
919 if ((do_gwbse_ && !screening_) || initstate_.Type().isKSState()) {
920 state = statetracker_.CalcState(orb_);
921 }
922 Eigen::MatrixXd dmat = StateDensity(state);
923 double Ngrid = numint.IntegrateDensity(dmat);
924 AOOverlap overlap;
925 overlap.Fill(basis);
926 double N_comp = dmat.cwiseProduct(overlap.Matrix()).sum();
927 if (std::abs(Ngrid - N_comp) > 0.001) {
928 XTP_LOG(Log::error, log_) << "=======================" << std::flush;
930 << "WARNING: Calculated Densities at Numerical Grid, Number of "
931 "electrons "
932 << Ngrid << " is far away from the the real value " << N_comp
933 << ", you should increase the accuracy of the integration grid."
934 << std::flush;
935 }
936#pragma omp parallel for
937 for (Index i = 0; i < Index(segments.size()); ++i) {
938 PolarSegment& seg = segments[i];
939 if (seg.hasChargeResponse()) {
940 continue;
941 }
942 for (PolarSite& site : seg) {
943 site.V_noE() += numint.IntegrateField(site.getPos());
944 }
945 }
946
947 // Charge-response sites are Gaussians: the potential and field of the QM
948 // region they see are averaged over their Gaussian, with the same
949 // three-centre integrals that put their induced charges and dipoles into
950 // the QM Hamiltonian (DFTEngine), so the coupling is symmetric.
951 std::vector<PolarSite*> cr_sites;
952 for (PolarSegment& seg : segments) {
953 if (seg.hasChargeResponse()) {
954 for (PolarSite& site : seg) {
955 cr_sites.push_back(&site);
956 }
957 }
958 }
959 if (!cr_sites.empty()) {
960 std::vector<Eigen::Vector3d> points;
961 std::vector<double> widths;
962 for (const PolarSite* site : cr_sites) {
963 points.push_back(site->getPos());
964 widths.push_back(site->CRWidth());
965 }
966 // electrons: the density is -dmat
967 const Eigen::MatrixXd electrons =
968 AOGaussianSites::PotentialAndGradientAt(basis, dmat, points, widths);
969 for (Index k = 0; k < Index(cr_sites.size()); ++k) {
970 PolarSite& site = *cr_sites[std::size_t(k)];
971 site.Phi_noE() -= electrons(k, 0);
972 site.V_noE() -= electrons.block<1, 3>(k, 1).transpose();
973 for (const QMAtom& atom : orb_.QMAtoms()) {
974 const Eigen::Vector3d r = site.getPos() - atom.getPos();
975 const GaussianKernel kern(r.norm(), site.CRWidth());
976 const double Z = double(atom.getNuccharge());
977 site.Phi_noE() += Z * kern.B0;
978 site.V_noE() -= Z * kern.B1 * r; // grad phi = -field
979 }
980 }
981 }
982
983 StaticSegment seg(orb_.QMAtoms().getType(), orb_.QMAtoms().getId());
984 for (const QMAtom& atom : orb_.QMAtoms()) {
985 seg.push_back(StaticSite(atom, double(atom.getNuccharge())));
986 }
987 AddNucleiFields(segments, seg);
988}
989
991 w(id_, "id");
992 w(identify(), "type");
993 w(size_, "size");
994 w(do_gwbse_, "GWBSE");
995 w(initstate_.ToString(), "initial_state");
997 CheckpointWriter v = w.openChild("QMdata");
998 orb_.WriteToCpt(v);
999 orb_.WriteBasisSetsToCpt(v);
1000
1001 CheckpointWriter v2 = w.openChild("E-hist");
1002 E_hist_.WriteToCpt(v2);
1003
1004 CheckpointWriter v3 = w.openChild("D-hist");
1005 Dmat_hist_.WriteToCpt(v3);
1006 if (do_gwbse_) {
1007 CheckpointWriter v4 = w.openChild("statefilter");
1008 statetracker_.WriteToCpt(v4);
1009 }
1010}
1011
1013 r(id_, "id");
1014 r(size_, "size");
1015 r(do_gwbse_, "GWBSE");
1016 std::string state;
1017 r(state, "initial_state");
1018 initstate_.FromString(state);
1020 CheckpointReader rr = r.openChild("QMdata");
1021 orb_.ReadFromCpt(rr);
1022 orb_.ReadBasisSetsFromCpt(rr);
1023
1024 CheckpointReader rr2 = r.openChild("E-hist");
1025 E_hist_.ReadFromCpt(rr2);
1026
1027 CheckpointReader rr3 = r.openChild("D-hist");
1028 Dmat_hist_.ReadFromCpt(rr3);
1029 if (do_gwbse_) {
1030 CheckpointReader rr4 = r.openChild("statefilter");
1031 statetracker_.ReadFromCpt(rr4);
1032 }
1033}
1034
1036 // First contact with an EwaldRegion is what decides this region takes its
1037 // environment as a potential on a grid, so the grid is built here rather
1038 // than in Initialize. See the declaration for why eagerly would be wrong.
1039 if (!ewald_grid_ready_) {
1041 }
1042
1043 // ONCE PER JOB, not once per iteration. phi is the potential of a FROZEN
1044 // background evaluated at FIXED points: the registry is converged before
1045 // the job starts and nothing re-polarizes it, the foreground registration
1046 // is made once by JobTopology, and the grid follows the QM geometry,
1047 // which does not move inside the inter-region SCF loop. The QM density
1048 // enters nowhere in it. So re-evaluating would give bit-identical numbers
1049 // at the cost of a full lattice sum over every quadrature point, every
1050 // iteration. The values stay where they were written -- in ewaldgrid_'s
1051 // own boxes and in ewald_nuclear_energy_, both members of this region
1052 // that Reset() does not touch.
1053 //
1054 // This stops being true the moment the background is allowed to respond
1055 // to the foreground. If that ever changes, this is the guard to remove.
1057 return 0.0;
1058 }
1059
1060 // ELECTRONS. The potential on the integration grid, which the DFT
1061 // engine integrates against the density into H0. The nuclei (below) are
1062 // appended to the same call: every call recomputes the reciprocal-space
1063 // structure factors of the whole background, whatever the point count.
1064 std::vector<Eigen::Vector3d> points = copyEwaldGrid();
1065 const Index n_grid = Index(points.size());
1066 for (const QMAtom& atom : orb_.QMAtoms()) {
1067 points.push_back(atom.getPos());
1068 }
1069 const Eigen::VectorXd phi_all = region.PotentialAt(points);
1070 const Eigen::VectorXd phi = phi_all.head(n_grid);
1071 const Eigen::VectorXd phi_nuclei = phi_all.tail(phi_all.size() - n_grid);
1072
1073 // Vxc_Grid::getGridpoints() walks grid_boxes_ in order and each box's
1074 // own points in order, so the flat vector maps back by giving each box
1075 // its share in turn. Checked rather than assumed: a mispairing here is
1076 // a wrong Hamiltonian with nothing to notice it by.
1077 Index offset = 0;
1078 for (Index i = 0; i < ewaldgrid_.getBoxesSize(); ++i) {
1079 GridBox& box = ewaldgrid_[i];
1080 const Index n_box = Index(box.getGridPoints().size());
1081 std::vector<double>& values = box.getPotentialValues();
1082 values.resize(std::size_t(n_box));
1083 for (Index p = 0; p < n_box; ++p) {
1084 values[std::size_t(p)] = phi[offset + p];
1085 }
1086 offset += n_box;
1087 }
1088 if (offset != phi.size()) {
1089 throw std::runtime_error(
1090 "QMRegion::InteractwithEwaldRegion: the grid holds " +
1091 std::to_string(offset) + " points across its boxes but " +
1092 std::to_string(phi.size()) +
1093 " potential values were evaluated. getGridpoints() and the box "
1094 "walk above disagree about the point ordering.");
1095 }
1096
1097 // NUCLEI. The grid potential reaches the electron density only; the
1098 // nuclei sit in the same potential and have no other route in. Handed
1099 // to the engine as a scalar to add to E0, NOT returned from here --
1100 // QMRegion::Evaluate accumulates the Interactwith* return values into
1101 // e_ext, logs it, and drops it on the floor.
1103 Index a = 0;
1104 for (const QMAtom& atom : orb_.QMAtoms()) {
1105 ewald_nuclear_energy_ += double(atom.getNuccharge()) * phi_nuclei[a];
1106 ++a;
1107 }
1108
1110
1111 // 0.0, matching this class's own InteractwithPolarRegion and
1112 // InteractwithStaticRegion: the environment enters the Hamiltonian, and
1113 // its energy comes out in the DFT total rather than here.
1114 return 0.0;
1115}
1116
1117} // namespace xtp
1118} // namespace votca
void WriteContainer(T &container)
Definition pdbwriter.h:102
class to manage program options with xml serialization functionality
Definition property.h:55
Property & add(const std::string &key, const std::string &value)
add a new property to structure
Definition property.cc:108
Property & get(const std::string &key)
get existing property
Definition property.cc:79
bool exists(const std::string &key) const
check whether property exists
Definition property.cc:122
T as() const
return value as type
Definition property.h:283
T ifExistsReturnElseReturnDefault(const std::string &key, T defaultvalue) const
Definition property.h:332
Container to hold Basisfunctions for all atoms.
Definition aobasis.h:42
Index AOBasisSize() const
Definition aobasis.h:46
void Fill(const BasisSet &bs, const QMMolecule &atoms)
Definition aobasis.cc:85
void setCenter(const Eigen::Vector3d &r)
Definition aomatrix.h:98
const std::array< Eigen::MatrixXd, 3 > & Matrix() const
Definition aomatrix.h:96
void Fill(const AOBasis &aobasis) final
static Eigen::MatrixXd PotentialAndGradientAt(const AOBasis &basis, const Eigen::MatrixXd &D, const std::vector< Eigen::Vector3d > &points, const std::vector< double > &widths)
void Fill(const AOBasis &aobasis) final
const Eigen::MatrixXd & Matrix() const
Definition aomatrix.h:52
void push_back(const T &atom)
void Load(const std::string &name)
Definition basisset.cc:149
CheckpointReader openChild(const std::string &childName) const
CheckpointWriter openChild(const std::string &childName) const
Electronic ground-state via Density-Functional Theory.
Definition dftengine.h:89
void setLogger(Logger *pLog)
Attach the logger used for SCF progress and diagnostics.
Definition dftengine.h:95
Eigen::MatrixXd RelaxedDensityMatrix(const Orbitals &orb, const QMState &state, const tools::Property &gwbse, bool qp_response=true)
void Initialize(tools::Property &options)
Read DFT, grid, and SCF settings from the user options tree.
Definition dftengine.cc:99
Eigen::Vector3d IntegrateField(const Eigen::Vector3d &rvector) const
double IntegrateDensity(const Eigen::MatrixXd &density_matrix)
static Eigen::MatrixXd Metric(const AOBasis &auxbasis)
T for an auxiliary basis on its own: the metric TCMatrix_gwbse::Fill folds into the three-centre inte...
static ScreeningCheck Check(const AOBasis &auxbasis, const QMMolecule &atoms, const ScreeningEnvironment &env, const Eigen::MatrixXd &T, Index n_modes=3)
Builds R for env and reports whether 1 + R is positive definite, and why not.
The periodic Ewald background, as a Region.
Definition ewaldregion.h:74
Eigen::VectorXd PotentialAt(const std::vector< Eigen::Vector3d > &points) const
Electronic excitations from GW-BSE.
Definition gwbse.h:61
void setScreeningEnvironment(const ScreeningEnvironment &env)
Definition gwbse.h:73
void setInactiveScreening(InactiveScreeningInput input)
Definition gwbse.h:80
void Initialize(tools::Property &options)
Definition gwbse.cc:77
void setLogger(Logger *pLog)
Definition gwbse.h:68
const std::vector< Eigen::Vector3d > & getGridPoints() const
Definition gridbox.h:55
std::vector< double > & getPotentialValues()
Definition gridbox.h:58
static tools::EigenSystem CompleteGOrbitals(const tools::EigenSystem &embedded, Index n_active_occupied, const InactiveScreeningInput &input)
The MOs GW-BSE works with for complete G: the inactive occupied orbitals (semicanonical,...
static InactiveScreeningInput Prepare(const Orbitals &full, InactiveScreeningInput::Mode mode, bool complete_g=false, double radius=0.0)
The input for GWBSE, from the full reference orbitals (before they are replaced by the embedded ones)...
std::vector< T >::iterator begin()
Definition mmregion.h:60
std::vector< T >::iterator end()
Definition mmregion.h:61
void computePML(Orbitals &orbitals)
bool hasChargeResponse() const
std::string identify() const override
Definition polarregion.h:52
double ExpDamp() const
Definition polarregion.h:66
Class to represent Atom/Site in electrostatic+polarization.
Definition polarsite.h:36
double CRWidth() const
Definition polarsite.h:107
const Eigen::Vector3d & V_noE() const
Definition polarsite.h:72
double Phi_noE() const
Definition polarsite.h:80
container for QM atoms
Definition qmatom.h:37
void AppendResult(tools::Property &prop) const override
Definition qmregion.cc:841
StateTracker statetracker_
Definition qmregion.h:207
hist< Eigen::MatrixXd > Dmat_hist_
Definition qmregion.h:149
void PrepareEwaldPotentialGrid()
Definition qmregion.cc:467
std::string grid_accuracy_for_ext_interaction_
Definition qmregion.h:146
std::string identify() const override
Definition qmregion.h:83
hist< double > E_hist_
Definition qmregion.h:148
void AddNucleiFields(std::vector< PolarSegment > &segments, const StaticSegment &seg) const
Definition qmregion.cc:895
std::shared_ptr< DFTSetupCache > setup_cache_
Definition qmregion.h:144
void SaveReferenceOrbitals()
Definition qmregion.cc:189
std::unique_ptr< QMPackage > qmpackage_
Definition qmregion.h:141
bool screening_include_kreac_
Definition qmregion.h:175
void push_back(const QMMolecule &mol)
Definition qmregion.cc:800
ReferenceOrbitals reference_
Definition qmregion.h:199
void WriteToCpt(CheckpointWriter &w) const override
Definition qmregion.cc:990
double InteractwithStaticRegion(const StaticRegion &region) override
Definition qmregion.cc:886
void EvaluateScreenedGWBSE(std::vector< std::unique_ptr< Region > > &regions)
Definition qmregion.cc:393
QMState relaxed_dmat_state_
Definition qmregion.h:167
void AppendScreenedSiteEnergies(tools::Property &prop) const
Definition qmregion.cc:428
std::string ScreeningAuxBasisName() const
Definition qmregion.cc:340
double ewald_nuclear_energy_
Definition qmregion.h:267
double InteractwithPolarRegion(const PolarRegion &region) override
Definition qmregion.cc:870
std::string workdir_
Definition qmregion.h:140
void Reset() override
Definition qmregion.cc:849
QMState screened_state_
Definition qmregion.h:180
QMRegion(Index id, Logger &log, std::string workdir)
Definition qmregion.h:50
double StateEnergy(const QMState &state) const
Definition qmregion.cc:264
void WritePDB(csg::PDBWriter &writer) const override
Definition qmregion.cc:891
void RestoreReferenceOrbitals()
Definition qmregion.cc:198
double InteractwithEwaldRegion(const EwaldRegion &region) override
Definition qmregion.cc:1035
void ReadFromCpt(CheckpointReader &r) override
Definition qmregion.cc:1012
ScreeningEnvironment BuildScreeningEnvironment(const std::vector< std::unique_ptr< Region > > &regions) const
Definition qmregion.cc:276
InactiveScreeningInput PrepareOrbitalsForGWBSE()
Definition qmregion.cc:209
bool Converged() const override
Definition qmregion.cc:506
void Evaluate(std::vector< std::unique_ptr< Region > > &regions) override
Definition qmregion.cc:545
tools::Property localize_options_
Definition qmregion.h:205
std::vector< Eigen::Vector3d > copyEwaldGrid()
Definition qmregion.cc:458
double InteractwithQMRegion(const QMRegion &region) override
Definition qmregion.cc:865
void ApplyQMFieldToPolarSegments(std::vector< PolarSegment > &segments) const
Definition qmregion.cc:907
bool ewald_potential_evaluated_
Definition qmregion.h:264
Eigen::MatrixXd StateDensity(const QMState &state) const
Definition qmregion.cc:743
Eigen::MatrixXd overlap_sqrt_
Definition qmregion.h:152
double screening_shell_dielectric_
Definition qmregion.h:177
void Initialize(const tools::Property &prop) override
Definition qmregion.cc:50
std::vector< Index > screening_shell_regions_
Definition qmregion.h:176
double charge() const override
Definition qmregion.cc:809
double screening_site_width_
Definition qmregion.h:178
Eigen::MatrixXd relaxed_dmat_
Definition qmregion.h:166
void CheckScreeningEnvironment(const std::vector< std::unique_ptr< Region > > &regions) const
Definition qmregion.cc:354
tools::Property dftoptions_
Definition qmregion.h:203
tools::Property gwbseoptions_
Definition qmregion.h:204
bool isKSState() const
Definition qmstate.h:92
bool isSingleParticleState() const
Definition qmstate.h:83
bool isExciton() const
Definition qmstate.h:73
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
std::string ToString() const
Definition qmstate.cc:155
Index StateIdx() const
Definition qmstate.h:157
const QMStateType & Type() const
Definition qmstate.h:154
std::vector< double > ApplyInfluenceOfOtherRegions(std::vector< std::unique_ptr< Region > > &regions)
Definition region.cc:33
Index getId() const
Definition region.h:80
std::string errormsg_
Definition region.h:92
Logger & log_
Definition region.h:106
std::string identify() const override
Class to represent Atom/Site in electrostatic.
Definition staticsite.h:37
const Eigen::Vector3d & getPos() const
Definition staticsite.h:80
Timestamp returns the current time as a string Example: cout << TimeStamp().
Definition logger.h:224
void GridSetup(const std::string &type, const QMMolecule &atoms, const AOBasis &basis)
Definition vxc_grid.cc:230
Mediates interaction between polar and static sites.
#define XTP_LOG(level, log)
Definition logger.h:40
const double ang2bohr
Definition constants.h:48
const double hrt2ev
Definition constants.h:53
void Cite(const std::string &key)
marks a reference as used (thread safe; unknown keys are printed as such)
Definition citations.cc:289
Charge transport classes.
Definition ERIs.h:28
ClassicalSegment< PolarSite > PolarSegment
ClassicalSegment< StaticSite > StaticSegment
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Interaction of two normalized Gaussian charge distributions exp(-r^2/s_i^2) and exp(-r^2/s_j^2): erf(...
What GWBSE needs to add the static screening of the inactive region: the mode and the orbitals of the...
static Mode Parse(const std::string &name)
Outcome of EnvironmentScreening::Check: whether 1 + R is positive definite, and a human-readable acco...
The polarizable environment a GW-BSE calculation is screened by: what a QM/MM job hands to GWBSE (GWB...
std::vector< PolarSegment > explicit_segments
std::vector< PolarSegment > shell_segments