Pyxaid2
 All Classes
wfc.h
1 /***********************************************************
2  * Copyright (C) 2013 Alexey V. Akimov
3  * This file is distributed under the terms of the
4  * GNU General Public License as published by the
5  * Free Software Foundation; either version 3 of the
6  * License, or (at your option) any later version.
7  * http://www.gnu.org/copyleft/gpl.txt
8 ***********************************************************/
9 
10 #ifndef wfc_h
11 #define wfc_h
12 
13 
14 #include <iostream>
15 #include <fstream>
16 #include <vector>
17 #include <complex>
18 #include <string>
19 #include <boost/python.hpp>
20 //#include "matrix.h"
21 #include "liblibra_core.h"
22 
23 using namespace boost::python;
24 using namespace std;
25 using namespace liblibra;
26 using namespace liblibra::libutil;
27 using namespace liblibra::liblinalg;
28 using namespace liblibra::libmeigen;
29 
30 
31 /*
32 // Some useful (potentially) macros
33 #define SWAP_2(x) ( (((x) & 0xff) << 8) | ((unsigned short)(x) >> 8) )
34 #define SWAP_4(x) ( ((x) << 24) | (((x) << 8) & 0x00ff0000) | \
35  (((x) >> 8) & 0x0000ff00) | ((x) >> 24) )
36 #define FIX_SHORT(x) (*(unsigned short *)&(x) = SWAP_2(*(unsigned short *)&(x)))
37 #define FIX_LONG(x) (*(unsigned *)&(x) = SWAP_4(*(unsigned *)&(x)))
38 #define FIX_FLOAT(x) FIX_LONG(x)
39 
40 
41 template<class T>
42 void get_value(T& val,char* memblock,int& pos){
43  memcpy((void*)&val, &memblock[pos], sizeof(T)); pos += sizeof(T);
44 // cout<<val<<endl;
45 }
46 */
47 
48 class MO{
49 
50 public:
51  int npw; // number of plane waves in MO expansion
52  double energy; // energy of this orbital (eigenvalue)
53  double gweight;
54  double fweight;
55 // vector< complex<float> > coeff_f; // expansion coefficients
56  vector< complex<double> > coeff; // coefficients in double precision
57 
58  // Constructor
59  MO(){ npw = 0; energy = 0.0; gweight = 0.0; fweight = 0.0; }
60  MO(int _npw){
61  npw = _npw;
62  energy = 0.0; gweight = 0.0; fweight = 0.0;
63  coeff = vector<complex<double> >(npw,complex<double>(0.0,0.0));
64  }
65  // Copy constructor
66 // MO(const& MO);
67 
68  // Destructor
69  ~MO(){ if(coeff.size()>0){ coeff.clear(); } npw = 0; }
70 
71  // Operators
72  MO operator-(); // Negation;
73  MO operator+(MO ob);
74  MO operator-(MO ob);
75  void operator+=(MO ob);
76  void operator-=(MO ob);
77  MO operator/(double num);
78  MO operator/(complex<double> num);
79 
80 
81  // Methods
82  MO conj();
83  void normalize();
84  void complete(); // add complex conjugate part of the wavefunction
85 
86  // Friends
87  friend MO operator*(const double& f, const MO& m1); // Multiplication of MO and double;
88  friend MO operator*(const MO& m1, const double &f); // Multiplication of MO and double;
89  friend MO operator*(const float& f, const MO& m1); // Multiplication of MO and float;
90  friend MO operator*(const MO& m1, const float &f); // Multiplication of MO and float;
91  friend MO operator*(const complex<double>& f, const MO& m1); // Multiplication of MO and complex<double>;
92  friend MO operator*(const MO& m1, const complex<double> &f); // Multiplication of MO and complex<double>;
93  friend MO operator*(const complex<float>& f, const MO& m1); // Multiplication of MO and complex<float>;
94  friend MO operator*(const MO& m1, const complex<float> &f); // Multiplication of MO and complex<float>;
95 
96  friend complex<double> operator*(const MO& m1, const MO& m2); // Multiplication of MO and MO
97 
98 
99 };
100 
101 
102 class K_point{
103 
104 public:
105  int kx,ky,kz; // indexes of this kpoint
106  int nbands; // number of bands (MOs) in this k-point
107  int npw; // number of plane waves in each MO
108  vector<MO> mo; // array of MOs
109 
110  // Constructor
111  K_point(){ nbands = 0; npw = 0; kx = ky = kz = 0; }
112  K_point(int _nbnds){ nbands = _nbnds; npw = 0; kx = ky = kz = 0; mo = vector<MO>(nbands,MO()); }
113  K_point(int _nbnds,int _npw){ nbands = _nbnds; npw = _npw; kx = ky = kz = 0; mo = vector<MO>(nbands,MO(npw)); }
114  K_point(K_point& k1,int min1,int max1, K_point& k2,int min2,int max2);
115 
116  // Copy constructor
117  //K_point(const& K_point);
118 
119  // Destructor
120  ~K_point(){ if(mo.size()>0){ mo.clear(); } nbands = 0; npw = 0; }
121 
122  // Methods
123  void complete();
124  void normalize();
125  void transform(CMATRIX&);
126 };
127 
128 
129 class wfc{
130 
131  void aux_line2vec(string line,vector<double>& a);
132 
133 public:
134  // Info
135  int nspin; // type of the spin-polarization used in calculations
136  int gamma_only; // gamma trick: =1 (true), =0 (false)
137  int natoms; // number of atoms
138  double tpiba; // units of the lattice vectors (reciprocal)
139  double alat; // units of the lattice vectors (real)
140  double omega; // volume of the unit cell
141  double efermi; // fermi energy
142  std::string cell_units; // units of the simulation cell
143  std::string energy_units; // units of the energy (eigenvalues)
144  vector<double> a1,a2,a3; // lattice vectors
145  vector<double> b1,b2,b3; // reciprocal lattice vectors
146 
147  // Data
148  int nkpts; // number of k-points
149  int nbands; // number of bands - the same for all k-points
150  int npw; // number of plane waves in each mo - same for all mos
151  int is_allocated; // flag that says which level of memory is allocated
152  vector<K_point> kpts; // array of k-points
153  vector<vector<int> > grid;// internal vector<int> consists of 3 integers
154 
155 
156 
157  // Constructor
158  wfc(){ nkpts = 0; nbands = 0; npw = 0; is_allocated = 0; }
159  wfc(int _nkpts){ nkpts = _nkpts; nbands = 0; npw = 0; kpts = vector<K_point>(nkpts,K_point()); is_allocated = 1; }
160  wfc(int _nkpts,int _nbnds){ nkpts = _nkpts; nbands = _nbnds; npw = 0; kpts = vector<K_point>(nkpts,K_point(nbands)); is_allocated = 2; }
161  wfc(int _nkpts,int _nbnds,int _npw){nkpts = _nkpts; nbands = _nbnds; npw = _npw; kpts = vector<K_point>(nkpts,K_point(nbands,npw)); is_allocated = 3; }
162  wfc(wfc& wfc1,int min1,int max1, wfc& wfc2,int min2,int max2);
163 
164  // Destructor
165  ~wfc(){ if(kpts.size()>0){ kpts.clear(); } if(grid.size()>0){ grid.clear();} nkpts = 0; nbands = 0; npw = 0; is_allocated = 0; }
166 
167  // Copy constructor
168  //wfc(const wfc&);
169 
170  // Methods:
171  // QE methods
172  void QE_read_binary_wfc(std::string filename,int,int,int);
173  void QE_read_acsii_wfc(std::string filename);
174  void QE_read_acsii_grid(std::string filename);
175  void QE_read_acsii_index(std::string filename);
176 
177  // Common methods
178  void complete();
179  void normalize();
180  void transform(int k,CMATRIX&);
181  void restore(int k1,int do_complete);
182  void set_latt_vectors(boost::python::list);
183  void set_reci_vectors(boost::python::list);
184  void compute_Hprime(int minband,int maxband,std::string filename);
185 };
186 
187 
188 // Functions using the arguments of wfc type
189 void overlap(wfc& wfc1,int k1,int minband,int maxband,std::string filename);
190 void pw_energy(wfc& wfc1,int k,int minband,int maxband,std::string filename);
191 void nac(wfc& wfc1,wfc& wfc2,int k1,int k2,int minband,int maxband,double dt,std::string filename);
192 void ham(wfc& wfc1,wfc& wfc2,int k1,int k2,int minband,int maxband,double dt,std::string filename);
193 
194 #endif //wfc_h
Definition: wfc.h:129
Definition: wfc.h:102
Definition: wfc.h:48