votca 2026-dev
Loading...
Searching...
No Matches
qmregion.h
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#pragma once
21#ifndef VOTCA_XTP_QMREGION_H
22#define VOTCA_XTP_QMREGION_H
23
24// Local VOTCA includes
25#include "hist.h"
26#include "orbitals.h"
27#include "qmpackagefactory.h"
28#include "region.h"
29#include "statetracker.h"
30#include "vxc_grid.h"
31
38
39namespace votca {
40namespace xtp {
41
42class PolarRegion;
43class StaticRegion;
44class EwaldRegion;
45class QMRegion : public Region {
46
47 public:
48 QMRegion(Index id, Logger& log, std::string workdir)
49 : Region(id, log), workdir_(workdir) {};
50 ~QMRegion() override = default;
51
52 void Initialize(const tools::Property& prop) override;
53
54 bool Converged() const override;
55
56 void Evaluate(std::vector<std::unique_ptr<Region> >& regions) override;
57
58 void WriteToCpt(CheckpointWriter& w) const override;
59
60 void ReadFromCpt(CheckpointReader& r) override;
61
62 void ApplyQMFieldToPolarSegments(std::vector<PolarSegment>& segments) const;
63
64 // Builds the integration grid the background's potential is sampled on.
65 // Called lazily by InteractwithEwaldRegion rather than from Initialize,
66 // for two reasons. A job with no EwaldRegion must not pay for a grid it
67 // never uses -- and, less obviously, must not have ewald_grid_ready_ set,
68 // because Evaluate takes that flag as the signal to reject any qmpackage
69 // other than xtp. Building it eagerly would break every existing
70 // qmmm job that runs orca.
71 //
72 // Takes no options: the grid name and basis come from dftoptions_, which
73 // Initialize has already stored. They MUST be the ones DFTEngine uses --
74 // see the comment in the definition.
76
77 Index size() const override { return size_; }
78
79 void WritePDB(csg::PDBWriter& writer) const override;
80
81 std::string identify() const override { return "qmregion"; }
82
83 void push_back(const QMMolecule& mol);
84
85 void Reset() override;
86
87 double charge() const override;
88 double Etotal() const override { return E_hist_.back(); }
89
90 // Coordinates only, by value. That is not a convenience -- see
91 // ewaldgrid_ below for why the grid object itself must not leave this
92 // class.
93 std::vector<Eigen::Vector3d> copyEwaldGrid();
94
95 protected:
96 void AppendResult(tools::Property& prop) const override;
97 double InteractwithQMRegion(const QMRegion& region) override;
98 double InteractwithPolarRegion(const PolarRegion& region) override;
99 double InteractwithStaticRegion(const StaticRegion& region) override;
100 double InteractwithEwaldRegion(const EwaldRegion& region) override;
101
102 private:
103 void AddNucleiFields(std::vector<PolarSegment>& segments,
104 const StaticSegment& seg) const;
105
108
110 std::string workdir_ = "";
111 std::unique_ptr<QMPackage> qmpackage_ = nullptr;
112
114
117
118 // convergence options
119 double DeltaD_ = 5e-5;
120 double DeltaE_ = 5e-5;
121 double DeltaDmax_ = 5e-5;
122
123 bool do_gwbse_ = false;
124 bool do_localize_ = false;
125 bool do_dft_in_dft_ = false;
126
130
132
133 // for QMEwald. The periodic background reaches the Hamiltonian as a
134 // potential sampled on this grid, which the DFT engine integrates
135 // against the density.
136 //
137 // There used to be a second route, handing the engine multipole
138 // moments and k-vectors to build its own AO matrices from, gated by a
139 // second flag. Nothing ever set it up -- the legacy jobcalculator that
140 // once did was removed -- so it has been deleted along with the
141 // machinery behind it (DFTEngine's IntegrateEwald* helpers, the
142 // AOEwald* matrices, the ewaldcontainer types). Two things are worth
143 // recording about that, since the decision was to remove code that had
144 // been deliberately kept:
145 //
146 // - It was blocked anyway. A rank-1 (induced dipole) source needs
147 // operator-centre derivatives from libint2, which is why
148 // AOEwaldRealSpaceDipoles was never instantiated even from the dead
149 // path -- the real-space route split every dipole into a pair of
150 // point charges instead.
151 // - It would not have been the faster route in any case. It replaces
152 // a loop over grid points (linear in QM size) with one over shell
153 // pairs (quadratic), so it wins only for small QM regions -- the
154 // opposite of what it was being kept for.
155 //
156 // Recoverable from the git history if either of those ever changes.
157 //
158 // ONLY ITS POINTS AND VALUES ARE VALID. PrepareEwaldPotentialGrid
159 // builds this grid against a BasisSet, an AOBasis and a QMMolecule
160 // that are all locals of that function, and GridBox::
161 // FindSignificantShells stores raw `const AOShell*` into the basis it
162 // is handed (gridbox.cc, addShell(&store)). Those shells die with the
163 // function, so from the moment PrepareEwaldPotentialGrid returns this
164 // object holds dangling pointers.
165 //
166 // What remains safe is everything that does not follow them:
167 // getGridpoints, getPotentialValues, getBoxesSize, GridBox::size.
168 // CalcAOValues, Matrixsize, AddtoBigMatrix and anything else touching
169 // significant_shells is undefined behaviour. That is why the grid is
170 // never integrated on here or in QMPackage, and why DFTEngine rebuilds
171 // its own from grid_name_ and copies only the values across -- see
172 // dftengine.cc.
173 //
174 // Nothing dereferences them today. The public Vxc_Grid& accessor that
175 // used to sit next to copyEwaldGrid() was removed because it handed
176 // this object out with no way to know that, and had no callers.
177 // Giving the basis a longer life would remove the hazard, but it buys
178 // nothing on its own: the transport is by value either way, and
179 // DFTEngine has to integrate against the AO ordering of its own
180 // dftbasis_ regardless.
182 bool ewald_grid_ready_ = false;
183 // Whether the background's potential has already been laid down on that
184 // grid. Separate from ewald_grid_ready_ because the grid is built once
185 // and the potential is evaluated once, but for different reasons: the
186 // grid because geometry and basis are fixed, the potential because the
187 // background is frozen. See InteractwithEwaldRegion.
189 // sum_A Z_A phi(R_A). The grid carries the potential the ELECTRONS
190 // feel; the nuclei sit in the same potential and have no other way in.
192};
193
194} // namespace xtp
195} // namespace votca
196
197#endif // VOTCA_XTP_QMREGION_H
class to manage program options with xml serialization functionality
Definition property.h:55
The periodic Ewald background, as a Region.
Definition ewaldregion.h:76
Logger is used for thread-safe output of messages.
Definition logger.h:164
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
void AppendResult(tools::Property &prop) const override
Definition qmregion.cc:407
StateTracker statetracker_
Definition qmregion.h:131
hist< Eigen::MatrixXd > Dmat_hist_
Definition qmregion.h:116
void PrepareEwaldPotentialGrid()
Definition qmregion.cc:108
std::string grid_accuracy_for_ext_interaction_
Definition qmregion.h:113
std::string identify() const override
Definition qmregion.h:81
double Etotal() const override
Definition qmregion.h:88
hist< double > E_hist_
Definition qmregion.h:115
void AddNucleiFields(std::vector< PolarSegment > &segments, const StaticSegment &seg) const
Definition qmregion.cc:449
std::unique_ptr< QMPackage > qmpackage_
Definition qmregion.h:111
void push_back(const QMMolecule &mol)
Definition qmregion.cc:366
void WriteToCpt(CheckpointWriter &w) const override
Definition qmregion.cc:500
double InteractwithStaticRegion(const StaticRegion &region) override
Definition qmregion.cc:440
double ewald_nuclear_energy_
Definition qmregion.h:191
double InteractwithPolarRegion(const PolarRegion &region) override
Definition qmregion.cc:436
std::string workdir_
Definition qmregion.h:110
void Reset() override
Definition qmregion.cc:415
QMRegion(Index id, Logger &log, std::string workdir)
Definition qmregion.h:48
Index size() const override
Definition qmregion.h:77
void WritePDB(csg::PDBWriter &writer) const override
Definition qmregion.cc:445
double InteractwithEwaldRegion(const EwaldRegion &region) override
Definition qmregion.cc:545
void ReadFromCpt(CheckpointReader &r) override
Definition qmregion.cc:522
bool Converged() const override
Definition qmregion.cc:147
void Evaluate(std::vector< std::unique_ptr< Region > > &regions) override
Definition qmregion.cc:169
tools::Property localize_options_
Definition qmregion.h:129
std::vector< Eigen::Vector3d > copyEwaldGrid()
Definition qmregion.cc:99
double InteractwithQMRegion(const QMRegion &region) override
Definition qmregion.cc:431
void ApplyQMFieldToPolarSegments(std::vector< PolarSegment > &segments) const
Definition qmregion.cc:458
bool ewald_potential_evaluated_
Definition qmregion.h:188
~QMRegion() override=default
void Initialize(const tools::Property &prop) override
Definition qmregion.cc:39
double charge() const override
Definition qmregion.cc:375
tools::Property dftoptions_
Definition qmregion.h:127
tools::Property gwbseoptions_
Definition qmregion.h:128
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
Region(Index id, Logger &log)
Definition region.h:51
Tracks from a spectrum of states the state, which fullfills certain criteria.
ClassicalSegment< StaticSite > StaticSegment
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26