JDFTx  1.2.0
SpeciesInfo.h
1 /*-------------------------------------------------------------------
2 Copyright 2011 Ravishankar Sundararaman, Deniz Gunceler
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_SPECIESINFO_H
22 #define JDFTX_ELECTRONIC_SPECIESINFO_H
23 
24 #include <electronic/common.h>
25 #include <electronic/RadialFunction.h>
26 #include <electronic/VanDerWaals.h>
27 #include <electronic/matrix.h>
28 #include <core/ScalarFieldArray.h>
29 #include <core/vector3.h>
30 #include <core/string.h>
31 
32 
34 {
35 public:
36 
37  double Z;
39  string name;
40  string potfilename, pulayfilename;
41  bool fromWildcard;
42 
43  std::vector<vector3<> > atpos;
44  std::vector<vector3<> > velocities;
45  #ifdef GPU_ENABLED
47  #endif
48  void sync_atpos();
50 
51  double dE_dnG;
52  double mass;
53  double coreRadius;
54  double ZfullCore;
55 
57  struct Constraint
58  { double moveScale;
60  enum ConstraintType {None, Linear, Planar, HyperPlane} type;
61 
62  vector3<> operator()(const vector3<>& grad);
63  bool isEquivalent(const Constraint& otherConstraint, const matrix3<>& transform) const;
64  int getDimension() const;
65  void print(FILE* fp, const Everything&) const;
66  };
67  std::vector<Constraint> constraints;
68 
69  std::vector< vector3<> > initialMagneticMoments;
71 
72  SpeciesInfo();
73  ~SpeciesInfo();
74  void setup(const Everything&);
75  void print(FILE* fp) const;
76  void populationAnalysis(const std::vector<matrix>& RhoAll) const; //print population analysis given the density matrix in the Lowdin basis
77  bool isRelativistic() const { return psi2j.size(); }
78 
80  { Fhi,
81  Uspp,
82  UPF
83  };
85  PseudopotentialFormat getPSPFormat(){return pspFormat;}
86 
87  std::shared_ptr<ColumnBundle> getV(const ColumnBundle& Cq, matrix* M=0) const; //get projectors with qnum and basis matching Cq (optionally cached, and optionally retrieve full M repeated over atoms)
88 
91  double EnlAndGrad(const QuantumNumber& qnum, const diagMatrix& Fq, const matrix& VdagCq, matrix& HVdagCq) const;
92 
94  void augmentOverlap(const ColumnBundle& Cq, ColumnBundle& OCq, matrix* VdagCq=0) const;
95 
97  void augmentDensityInit();
99  void augmentDensitySpherical(const QuantumNumber& qnum, const diagMatrix& Fq, const matrix& VdagCq);
101  void augmentDensityGrid(ScalarFieldArray& n) const;
102 
104  void augmentDensityGridGrad(const ScalarFieldArray& E_n, std::vector<vector3<> >* forces=0);
106  void augmentDensitySphericalGrad(const QuantumNumber& qnum, const diagMatrix& Fq, const matrix& VdagCq, matrix& HVdagCq) const;
107 
108  //DFT+U functions: handle IonInfo::rhoAtom_*() for this species
109  //The rhoAtom pointers point to the start of those relevant to this species (and ends at that pointer + rhoAtom_nMatrices())
110  size_t rhoAtom_nMatrices() const;
111  void rhoAtom_initZero(matrix* rhoAtomPtr) const;
112  void rhoAtom_calc(const std::vector<diagMatrix>& F, const std::vector<ColumnBundle>& C, matrix* rhoAtomPtr) const;
113  double rhoAtom_computeU(const matrix* rhoAtomPtr, matrix* U_rhoAtomPtr) const;
114  void rhoAtom_grad(const ColumnBundle& Cq, const matrix* U_rhoAtomPtr, ColumnBundle& HCq) const;
115  void rhoAtom_forces(const std::vector<diagMatrix>& F, const std::vector<ColumnBundle>& C, const matrix* U_rhoAtomPtr, std::vector<vector3<> >& forces) const;
116  void rhoAtom_getV(const ColumnBundle& Cq, const matrix* U_rhoAtomPtr, ColumnBundle& psi, matrix& M) const; //get DFT+U Hamiltonian in the same format as the nonlocal pseudopotential (psi = atomic orbitals, M = matrix in that order)
117 
118  //Atomic orbital related functions:
119  void accumulateAtomicDensity(ScalarFieldTildeArray& nTilde) const;
120  void accumulateAtomicPotential(ScalarFieldTilde& dTilde) const;
121  void setAtomicOrbitals(ColumnBundle& Y, bool applyO, int colOffset=0) const;
122  void setAtomicOrbitals(ColumnBundle& Y, bool applyO, unsigned n, int l, int colOffset=0, int atomColStride=0) const;
123  int nAtomicOrbitals() const;
125  int lMaxAtomicOrbitals() const;
126  int nAtomicOrbitals(int l) const;
127  int atomicOrbitalOffset(unsigned iAtom, unsigned n, int l, int m, int s) const;
128 
131  void updateLocal(ScalarFieldTilde& Vlocps, ScalarFieldTilde& rhoIon, ScalarFieldTilde& nChargeball,
132  ScalarFieldTilde& nCore, ScalarFieldTilde& tauCore) const;
133 
135  std::vector< vector3<> > getLocalForces(const ScalarFieldTilde& ccgrad_Vlocps, const ScalarFieldTilde& ccgrad_rhoIon,
136  const ScalarFieldTilde& ccgrad_nChargeball, const ScalarFieldTilde& ccgrad_nCore, const ScalarFieldTilde& ccgrad_tauCore) const;
137 
139  void accumNonlocalForces(const ColumnBundle& Cq, const matrix& VdagC, const matrix& E_VdagC, const matrix& grad_CdagOCq, std::vector<vector3<> >& forces) const;
140 
142  static matrix getYlmToSpinAngleMatrix(int l, int j2);
143  static matrix getYlmOverlapMatrix(int l, int j2);
144 private:
145  matrix3<> Rprev; void updateLatticeDependent();
146 
147  RadialFunctionG VlocRadial;
148  RadialFunctionG nCoreRadial;
149  RadialFunctionG tauCoreRadial;
150 
151  std::vector< std::vector<RadialFunctionG> > VnlRadial;
152  std::vector<matrix> Mnl;
153  matrix MnlAll;
154 
155  std::vector<matrix> Qint;
156  matrix QintAll;
157 
158  std::map<std::pair<vector3<>,const Basis*>, std::shared_ptr<ColumnBundle> > cachedV; //cached projectors (identified by k-point and basis pointer)
159 
160  struct QijIndex
161  { int l1, p1;
162  int l2, p2;
163  int l;
164  int index;
165  bool operator<(const QijIndex&) const;
166  private:
167  void sortIndices();
168  };
169  std::map<QijIndex,RadialFunctionG> Qradial;
170  matrix QradialMat;
171  matrix nAug;
172  matrix E_nAug;
173  uint64_t* nagIndex; size_t* nagIndexPtr;
174 
175  std::vector<std::vector<RadialFunctionG> > psiRadial;
176  std::vector<std::vector<RadialFunctionG> >* OpsiRadial;
177  std::vector<std::vector<double> > atomEigs;
178 
180  std::vector< std::vector<int> > Vnl2j, psi2j;
181  matrix fljAll;
182 
184  struct PlusU
185  { int n, l;
186  double UminusJ;
187 
188  std::vector<double> Vext;
189  };
190  std::vector<PlusU> plusU;
191 
193  std::shared_ptr<VanDerWaals::AtomParams> vdwOverride;
194 
195  PseudopotentialFormat pspFormat;
196 
197  // gaussian chargeball used to prevent dielectric spikes
198  // DEPRECATED: As far as possible, use partial core correction instead
199  double Z_chargeball;
200  double width_chargeball;
201 
202  const Everything* e;
203 
204  double tauCore_rCut; bool tauCorePlot;
205 
206  void setCore(RadialFunctionR&);
207  void readFhi(istream&); // Implemented in SpeciesInfo_readFhi.cpp
208  void readUspp(istream&); //Implemented in SpeciesInfo_readUspp.cpp
209  void readUPF(istream&); //Implemented in SpeciesInfo_readUPF.cpp
210  void setupPulay();
211 
212  //Following implemented in SpeciesInfo_atomFillings.cpp
213  void estimateAtomEigs();
214  void getAtom_nRadial(int spin, double magneticMoment, RadialFunctionG& nRadial, bool forceNeutral) const;
215  void getAtomPotential(RadialFunctionG& dRadial) const;
216 
217  friend struct CommandIonSpecies;
218  friend struct CommandSetVDW;
219  friend class VanDerWaals;
220  friend struct CommandAddU;
221  friend struct CommandChargeball;
222  friend struct CommandTauCore;
223  friend struct CommandWavefunction;
224  friend class WannierMinimizer;
225  friend class IonicMinimizer;
226  friend class Phonon;
227  friend class Dump;
228 };
229 
230 
232 ( SpeciesInfo::Constraint::None, "None",
233  SpeciesInfo::Constraint::Linear, "Linear",
234  SpeciesInfo::Constraint::Planar, "Planar",
235  SpeciesInfo::Constraint::HyperPlane, "HyperPlane"
236 );
237 
238 #endif // JDFTX_ELECTRONIC_SPECIESINFO_H
Base class for different wannier minimizers:
Definition: WannierMinimizer.h:48
void augmentOverlap(const ColumnBundle &Cq, ColumnBundle &OCq, matrix *VdagCq=0) const
Accumulate pseudopotential contribution to the overlap in OCq.
void setAtomicOrbitals(ColumnBundle &Y, bool applyO, int colOffset=0) const
Calculate atomic orbitals with/without O preapplied (store in Y with an optional column offset) ...
double EnlAndGrad(const QuantumNumber &qnum, const diagMatrix &Fq, const matrix &VdagCq, matrix &HVdagCq) const
string name
Identifier.
Definition: SpeciesInfo.h:39
void augmentDensityGridGrad(const ScalarFieldArray &E_n, std::vector< vector3<> > *forces=0)
Gradient propagation corresponding to augmentDensityGrid (stores intermediate spherical function resu...
std::vector< Constraint > constraints
List of all constraints on ions of this species.
Definition: SpeciesInfo.h:67
double mass
ionic mass (currently unused)
Definition: SpeciesInfo.h:52
std::vector< ScalarField > ScalarFieldArray
dynamic size collection of real space scalar fields
Definition: ScalarFieldArray.h:32
int atomicOrbitalOffset(unsigned iAtom, unsigned n, int l, int m, int s) const
s is 0/1 for up/dn spinors in non-relativistic case, s=0/1 is for j=l+/-0.5 and mj=m+/-0.5 in relativistic case
Quantum Espresso&#39;s Universal Pseudopotential Format (the XML version 2 only)
Definition: SpeciesInfo.h:82
STL strings and streams with case insensitive comparison.
double initialOxidationState
Initial oxidation state of this species (only affects LCAO)
Definition: SpeciesInfo.h:70
A template to ease option parsing (maps enums <–> strings)
Definition: Util.h:179
void accumulateAtomicPotential(ScalarFieldTilde &dTilde) const
Accumulate electrostatic potential of neutral atoms from this species.
General complex matrix.
Definition: matrix.h:58
Definition: VanDerWaals.h:28
std::vector< vector3<> > initialMagneticMoments
Initial magnetic moments of each atom (used only for LCAO and symmetries) (x and y magnetizations onl...
Definition: SpeciesInfo.h:69
std::shared_ptr< ScalarFieldTildeData > ScalarFieldTilde
A smart reference-counting pointer to ScalarFieldTildeData.
Definition: ScalarField.h:45
void updateLocal(ScalarFieldTilde &Vlocps, ScalarFieldTilde &rhoIon, ScalarFieldTilde &nChargeball, ScalarFieldTilde &nCore, ScalarFieldTilde &tauCore) const
Add contributions from this species to Vlocps, rhoIon, nChargeball and nCore/tauCore (if any) ...
Real diagonal matrix.
Definition: matrix.h:31
Definition: ElecInfo.h:35
static matrix getYlmOverlapMatrix(int l, int j2)
Get the ((2l+1)*2)x((2l+1)*2) overlap matrix of the spin-spherical harmonics for total angular moment...
Calculate phonon dispersion, free energies and electron-phonon matrix elements.
Definition: Phonon.h:47
double coreRadius
maximum pseudopotential core radius (used for core overlap checks during ionic/lattice relaxation) ...
Definition: SpeciesInfo.h:53
std::vector< vector3<> > atpos
array of atomic positions of this species
Definition: SpeciesInfo.h:43
bool isRelativistic() const
whether pseudopotential is relativistic
Definition: SpeciesInfo.h:77
void augmentDensityInit()
Clear internal data and prepare for density augmentation (call before a loop ober augmentDensitySpher...
int nAtomicOrbitals() const
return number of atomic orbitals in this species (all atoms)
FHI format with ABINIT header (.fhi files)
Definition: SpeciesInfo.h:80
void augmentDensitySphericalGrad(const QuantumNumber &qnum, const diagMatrix &Fq, const matrix &VdagCq, matrix &HVdagCq) const
Gradient propagation corresponding to augmentDensitySpherical (uses intermediate spherical function r...
double Z
Valence charge of the species (prefactor to 1/r in long-range part of pseudopotential) ...
Definition: SpeciesInfo.h:37
Definition: Basis.h:29
PseudopotentialFormat getPSPFormat()
Returns the pseudopotential format.
Definition: SpeciesInfo.h:85
PseudopotentialFormat
Definition: SpeciesInfo.h:79
Definition: IonicMinimizer.h:52
A function on a non-uniform real-space radial grid.
Definition: RadialFunction.h:101
vector3 operator()(const vector3<> &grad)
Type of the constraint that is being applied to the ion.
void augmentDensitySpherical(const QuantumNumber &qnum, const diagMatrix &Fq, const matrix &VdagCq)
Accumulate the pseudopotential dependent contribution to the density in the spherical functions nAug ...
ConstraintType
The direction or plane normal of the constraint (in cartesian coordinates)
Definition: SpeciesInfo.h:60
G-space radial function stored on a uniform grid (of |G|)
Definition: RadialFunction.h:28
Definition: Everything.h:41
int atomicNumber
Atomic number of the species (0 if unavailable)
Definition: SpeciesInfo.h:38
void sync_atpos()
update changes in atpos; call whenever atpos is changed (this will update atpos_gpu and invalidate ca...
void accumNonlocalForces(const ColumnBundle &Cq, const matrix &VdagC, const matrix &E_VdagC, const matrix &grad_CdagOCq, std::vector< vector3<> > &forces) const
Propagate gradient with respect to atomic projections (in E_VdagC, along with additional overlap cont...
bool fromWildcard
whether this pseudopotential was automatically added using a wildcard (for command printing purposes ...
Definition: SpeciesInfo.h:41
classes ScalarFieldArray, ScalarFieldTildeArray and just enough operators to enable CG w...
void accumulateAtomicDensity(ScalarFieldTildeArray &nTilde) const
Accumulate atomic density from this species.
Contains the information on the constraints of motion for each ion.
Definition: SpeciesInfo.h:57
vector3 d
preconditioning factor (0 fixes ion)
Definition: SpeciesInfo.h:59
vector3 * atposPref
points to atposGpu in GPU mode and atpos otherwise
Definition: SpeciesInfo.h:49
USPP format ultrasoft pseudopotential.
Definition: SpeciesInfo.h:81
double ZfullCore
number of electrons in full-core correction (atomicNumber - Z - integral(nCore))
Definition: SpeciesInfo.h:54
Definition: SpeciesInfo.h:33
static matrix getYlmToSpinAngleMatrix(int l, int j2)
Spin-angle helper functions:
void augmentDensityGrid(ScalarFieldArray &n) const
Accumulate the spherical augmentation functions nAug to the grid electron density (call only once...
double dE_dnG
Derivative of [total energy per atom] w.r.t [nPlanewaves per unit volume] (for Pulay corrections) ...
Definition: SpeciesInfo.h:51
int lMaxAtomicOrbitals() const
return maximum angular momentum in available atomic orbitals
std::vector< vector3<> > velocities
array of atomic velocities (null unless running MD) in lattice coordinates
Definition: SpeciesInfo.h:44
std::vector< vector3<> > getLocalForces(const ScalarFieldTilde &ccgrad_Vlocps, const ScalarFieldTilde &ccgrad_rhoIon, const ScalarFieldTilde &ccgrad_nChargeball, const ScalarFieldTilde &ccgrad_nCore, const ScalarFieldTilde &ccgrad_tauCore) const
Return the local forces (due to Vlocps, rhoIon, nChargeball and nCore/tauCore)
std::vector< ScalarFieldTilde > ScalarFieldTildeArray
dynamic size collection of reciprocal space scalar fields
Definition: ScalarFieldArray.h:33
Definition: ColumnBundle.h:30
vector3 * atposGpu
copy of atomic positions on the gpu
Definition: SpeciesInfo.h:46
Stores the list of what to dump and when, and implements the functions to do so.
Definition: Dump.h:59