1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 //                    Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 //                    Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 /** @file
16  * @brief Declaration of a builder class for an ECP component for an ionic type
17  */
18 #ifndef QMCPLUSPLUS_ECPCOMPONENT_BUILDER_H
19 #define QMCPLUSPLUS_ECPCOMPONENT_BUILDER_H
20 #include "Particle/DistanceTableData.h"
21 #include "QMCHamiltonians/LocalECPotential.h"
22 #include "QMCHamiltonians/NonLocalECPotential.h"
23 #include "QMCHamiltonians/SOECPComponent.h"
24 #include "QMCHamiltonians/L2Potential.h"
25 
26 namespace qmcplusplus
27 {
28 struct ECPComponentBuilder : public MPIObjectBase, public QMCTraits
29 {
30   typedef LocalECPotential::GridType GridType;
31   typedef ParticleSet::Scalar_t mRealType;
32   typedef OneDimGridBase<mRealType> mGridType;
33   typedef LocalECPotential::RadialPotentialType RadialPotentialType;
34 
35   int NumNonLocal;
36   int Lmax, Llocal, Nrule, Srule;
37   int NumSO;  //The number of spin-orbit channels.
38   int LmaxSO; //The maximum angular momentum of spin-orbit channels.
39   int AtomicNumber;
40   RealType Zeff;
41   RealType RcutMax;
42   std::string Species;
43   mGridType* grid_global;
44   std::map<std::string, mGridType*> grid_inp;
45   std::unique_ptr<RadialPotentialType> pp_loc;
46   std::unique_ptr<NonLocalECPComponent> pp_nonloc;
47   std::unique_ptr<SOECPComponent> pp_so; //Spin-orbit potential component.
48   std::unique_ptr<L2RadialPotential> pp_L2;
49   std::map<std::string, int> angMon;
50 
51   ECPComponentBuilder(const std::string& aname, Communicate* c, int nrule = -1);
52 
53   bool parse(const std::string& fname, xmlNodePtr cur);
54   bool put(xmlNodePtr cur);
55   void addSemiLocal(xmlNodePtr cur);
56   void buildLocal(xmlNodePtr cur);
57   void buildSemiLocalAndLocal(std::vector<xmlNodePtr>& semiPtr);
58   void buildL2(xmlNodePtr cur);
59 
60   bool parseCasino(const std::string& fname, xmlNodePtr cur); //std::string& fname, RealType rc);
61   //bool parseCasino(std::string& fname, RealType rc);
62   // This sets the spherical quadrature rule used to apply the
63   // projection operators.  rule can be 1 to 7.  See
64   // J. Chem. Phys. 95 (3467) (1991)
65   // Rule     # points     lexact
66   //  1           1          0
67   //  2           4          2
68   //  3           6          3
69   //  4          12          5
70   //  5          18          5
71   //  6          26          7
72   //  7          50         11
73   void SetQuadratureRule(int rule);
74 
75   mGridType* createGrid(xmlNodePtr cur, bool useLinear = false);
76   RadialPotentialType* createVrWithBasisGroup(xmlNodePtr cur, mGridType* agrid);
77   RadialPotentialType* createVrWithData(xmlNodePtr cur, mGridType* agrid, int rCorrection = 0);
78 
79   void doBreakUp(const std::vector<int>& angList,
80                  const Matrix<mRealType>& vnn,
81                  RealType rmax,
82                  mRealType Vprefactor = 1.0);
83 
84   /** brief buildSO - takes the previously parsed angular momenta and spin-orbit tabulated potentials and uses
85   **     them to construct SOECPComponent* pp_so.  This is called in "doBreakUp".
86   **
87   ** param std::vector<int>& angList  The angular momentum for each SO potential.
88   ** param Matrix<mRealType>& vnnso (npot x ngrid) matrix storing all tabulated SO potentials.
89   ** param RealType rmax  max r on the specified grid.
90   ** param mRealType Vprefactor  optional scale factor.
91   **
92   ** return void
93   **
94   **/
95   void buildSO(const std::vector<int>& angList,
96                const Matrix<mRealType>& vnnso,
97                RealType rmax,
98                mRealType Vprefactor = 1.0);
99 
100   void printECPTable();
101   bool read_pp_file(const std::string& fname);
102 };
103 
104 // Read a file into a memory buffer.
105 // Under MPI, it reads the file with one node and broadcasts the contents to all the other nodes.
106 
107 class ReadFileBuffer
108 {
109   char* cbuffer;
110   std::ifstream* fin;
111   Communicate* myComm;
112   int get_file_length(std::ifstream* f) const;
113 
114 public:
115   bool is_open;
116   int length;
ReadFileBuffer(Communicate * c)117   ReadFileBuffer(Communicate* c) : cbuffer(NULL), fin(NULL), myComm(c), is_open(false), length(0) {}
118   bool open_file(const std::string& fname);
119   bool read_contents();
contents()120   char* contents() { return cbuffer; }
121   void reset();
122 
~ReadFileBuffer()123   ~ReadFileBuffer()
124   {
125     delete[] cbuffer;
126     if (fin)
127       delete fin;
128   }
129 };
130 
131 
132 } // namespace qmcplusplus
133 #endif
134