JDFTx  1.2.0
IonInfo.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman
3 Copyright 1996-2003 Sohrab Ismail-Beigi
4 
5 This file is part of JDFTx.
6 
7 JDFTx is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 JDFTx is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with JDFTx. If not, see <http://www.gnu.org/licenses/>.
19 -------------------------------------------------------------------*/
20 
21 #ifndef JDFTX_ELECTRONIC_IONINFO_H
22 #define JDFTX_ELECTRONIC_IONINFO_H
23 
24 #include <electronic/common.h>
25 #include <electronic/SpeciesInfo.h>
26 #include <electronic/IonicMinimizer.h>
27 #include <electronic/matrix.h>
28 #include <core/ScalarField.h>
29 #include <vector>
30 #include <core/Thread.h>
31 
33 enum CoordsType {CoordsLattice, CoordsCartesian};
34 
36 enum ForcesOutputCoords { ForcesCoordsPositions, ForcesCoordsLattice, ForcesCoordsCartesian, ForcesCoordsContravariant };
37 static EnumStringMap<ForcesOutputCoords> forcesOutputCoordsMap(
38  ForcesCoordsPositions, "Positions",
39  ForcesCoordsLattice, "Lattice",
40  ForcesCoordsCartesian, "Cartesian",
41  ForcesCoordsContravariant, "Contravariant");
42 
44 enum coreOverlapCheck { additive, vector, none };
45 
46 class IonInfo
47 {
48 public:
49  std::vector< std::shared_ptr<SpeciesInfo> > species;
50  std::vector<string> pspFilenamePatterns;
51 
52  CoordsType coordsType;
53  ForcesOutputCoords forcesOutputCoords;
54  coreOverlapCheck coreOverlapCondition;
55  bool vdWenable;
56  double vdWscale;
57 
59 
65 
66  IonInfo();
67 
68  void setup(const Everything&);
69  void printPositions(FILE*) const;
70  bool checkPositions() const;
71  double getZtot() const;
72 
74  void update(Energies&);
75 
77  double ionicEnergyAndGrad(IonicGradient& forces) const;
78 
81  double EnlAndGrad(const QuantumNumber& qnum, const diagMatrix& Fq, const std::vector<matrix>& VdagCq, std::vector<matrix>& HVdagCq) const;
82 
84  void augmentOverlap(const ColumnBundle& Cq, ColumnBundle& OCq, std::vector<matrix>* VdagCq=0) const;
85 
86  //Multi-stage density augmentation and gradient propagation (see corresponding functions in SpeciesInfo)
87  void augmentDensityInit() const;
88  void augmentDensitySpherical(const QuantumNumber& qnum, const diagMatrix& Fq, const std::vector<matrix>& VdagCq) const;
89  void augmentDensityGrid(ScalarFieldArray& n) const;
90  void augmentDensityGridGrad(const ScalarFieldArray& E_n, IonicGradient* forces=0) const;
91  void augmentDensitySphericalGrad(const QuantumNumber& qnum, const diagMatrix& Fq, const std::vector<matrix>& VdagCq, std::vector<matrix>& HVdagCq) const;
92 
93  void project(const ColumnBundle& Cq, std::vector<matrix>& VdagCq, matrix* rotExisting=0) const; //Update pseudopotential projections (optionally retain non-zero ones with specified rotation)
94  void projectGrad(const std::vector<matrix>& HVdagCq, const ColumnBundle& Cq, ColumnBundle& HCq) const; //Propagate projected gradient (HVdagCq) to full gradient (HCq)
95 
97  //rhoAtom is a flat array of atomic density matrices per U type, with index order (outer to inner): species, Uparam(n,l), spin, atom
98  size_t rhoAtom_nMatrices() const;
99  void rhoAtom_initZero(std::vector<matrix>& rhoAtom) const;
100  void rhoAtom_calc(const std::vector<diagMatrix>& F, const std::vector<ColumnBundle>& C, std::vector<matrix>& rhoAtom) const;
101  double rhoAtom_computeU(const std::vector<matrix>& rhoAtom, std::vector<matrix>& U_rhoAtom) const;
102  void rhoAtom_grad(const ColumnBundle& Cq, const std::vector<matrix>& U_rhoAtom, ColumnBundle& HCq) const;
103  void rhoAtom_forces(const std::vector<diagMatrix>& F, const std::vector<ColumnBundle>& C, const std::vector<matrix>& U_rhoAtom, IonicGradient& forces) const;
104  void rhoAtom_getV(const ColumnBundle& Cq, const std::vector<matrix>& U_rhoAtom, std::vector<ColumnBundle>& psi, std::vector<matrix>& M) const;
105 
106  ColumnBundle rHcommutator(const ColumnBundle &Y, int iDir) const;
107 
108  int nAtomicOrbitals() const;
109  ColumnBundle getAtomicOrbitals(int q, bool applyO, int extraCols=0) const;
110 
115  }
117  double ionWidth;
118  bool shouldPrintForceComponents;
119 
120 private:
121  const Everything* e;
122 
124  void pairPotentialsAndGrad(Energies* ener=0, IonicGradient* forces=0) const;
125 };
126 
127 #endif // JDFTX_ELECTRONIC_IONINFO_H
double EnlAndGrad(const QuantumNumber &qnum, const diagMatrix &Fq, const std::vector< matrix > &VdagCq, std::vector< matrix > &HVdagCq) const
bool checkPositions() const
check for overlapping atoms, return true if okay
std::vector< ScalarField > ScalarFieldArray
dynamic size collection of real space scalar fields
Definition: ScalarFieldArray.h:32
Definition: IonInfo.h:46
std::vector< std::shared_ptr< SpeciesInfo > > species
list of ionic species
Definition: IonInfo.h:49
void rhoAtom_initZero(std::vector< matrix > &rhoAtom) const
initialize matrices of appropriate size to zero
void rhoAtom_forces(const std::vector< diagMatrix > &F, const std::vector< ColumnBundle > &C, const std::vector< matrix > &U_rhoAtom, IonicGradient &forces) const
propagate U_rhoAtom to forces
A template to ease option parsing (maps enums <–> strings)
Definition: Util.h:179
ForcesOutputCoords forcesOutputCoords
coordinate system to print forces in
Definition: IonInfo.h:53
General complex matrix.
Definition: matrix.h:58
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:45
void rhoAtom_getV(const ColumnBundle &Cq, const std::vector< matrix > &U_rhoAtom, std::vector< ColumnBundle > &psi, std::vector< matrix > &M) const
get DFT+U Hamiltonian basis (atomic orbitals) and matrices
Definition: Energies.h:26
double ionWidth
width for gaussian representation of nuclei
Definition: IonInfo.h:117
ScalarField tauCore
Model for the KE density of the core (TF+vW applied to nCore) (used by meta-GGAs) ...
Definition: IonInfo.h:64
Real diagonal matrix.
Definition: matrix.h:31
Definition: ElecInfo.h:35
IonicGradient forces
forces at current atomic positions
Definition: IonInfo.h:58
ScalarFieldTilde nChargeball
Extra electron density around ionic cores to keep fluid out (DEPRECATED)
Definition: IonInfo.h:62
Real and complex scalar fields in real and reciprocal space.
ColumnBundle rHcommutator(const ColumnBundle &Y, int iDir) const
Apply commutator operator [r_iDir,H] = D_iDir + nonlocal corrections.
CoordsType coordsType
coordinate system for ionic positions etc.
Definition: IonInfo.h:52
Utilities for threading (wrappers around std::thread)
bool vdWenable
Check method used for determining whether pseudopotential cores overlap.
Definition: IonInfo.h:55
double getZtot() const
get total Z of all species and atoms
ColumnBundle getAtomicOrbitals(int q, bool applyO, int extraCols=0) const
Get all atomic orbitals of a given state number q, optionally with operator O pre-applied (with room ...
void rhoAtom_grad(const ColumnBundle &Cq, const std::vector< matrix > &U_rhoAtom, ColumnBundle &HCq) const
propagate U_rhoAtom to wavefunction gradient (per k-point to enable band structure) ...
double rhoAtom_computeU(const std::vector< matrix > &rhoAtom, std::vector< matrix > &U_rhoAtom) const
compute U energy and gradient w.r.t atomic density matrices
IonWidthMethod
Definition: IonInfo.h:111
manually specify the ion width
Definition: IonInfo.h:114
ScalarFieldTilde rhoIon
Total ionic charge density (with width ionWidth, used for interactions with fluid) ...
Definition: IonInfo.h:61
void augmentOverlap(const ColumnBundle &Cq, ColumnBundle &OCq, std::vector< matrix > *VdagCq=0) const
Accumulate pseudopotential dependent contribution to the overlap in OCq.
Definition: Everything.h:41
determine ion width from grid spacing
Definition: IonInfo.h:113
void update(Energies &)
Update Vlocps, rhoIon, nChargeball, nCore and the energies dependent only on ionic positions...
void rhoAtom_calc(const std::vector< diagMatrix > &F, const std::vector< ColumnBundle > &C, std::vector< matrix > &rhoAtom) const
compute atomic density matrices
enum IonInfo::IonWidthMethod ionWidthMethod
method for determining ion charge width
std::shared_ptr< ScalarFieldData > ScalarField
A smart reference-counting pointer to ScalarFieldData.
Definition: ScalarField.h:41
int nAtomicOrbitals() const
Get total number of atomic orbitals.
ScalarField nCore
Core electron density for partial (nonlinear) core correction.
Definition: IonInfo.h:63
determine ion width from Ecut
Definition: IonInfo.h:112
size_t rhoAtom_nMatrices() const
Compute U corrections (DFT+U in the simplified rotationally-invariant scheme [Dudarev et al...
Object to hold all the forces.
Definition: IonicMinimizer.h:31
double ionicEnergyAndGrad(IonicGradient &forces) const
Return the total (free) energy and calculate the ionic gradient (forces)
Definition: ColumnBundle.h:30
double vdWscale
If non-zero, override the default scale parameter.
Definition: IonInfo.h:56
std::vector< string > pspFilenamePatterns
list of wildcards for pseudopotential sets
Definition: IonInfo.h:50
ScalarFieldTilde Vlocps
Net local pseudopotential.
Definition: IonInfo.h:60