PAWpySeed
Parallel C/Python package for numerical analysis of PAW DFT wavefunctions
utils.h
Go to the documentation of this file.
1 
17 #ifndef UTILS_H
18 #define UTILS_H
19 #include <complex.h>
20 #include <math.h>
21 
30 typedef struct funcset {
31  int l;
32  double* proj;
33  double** proj_spline;
34  double* aewave;
35  double** aewave_spline;
36  double* pswave;
37  double** pswave_spline;
38  double* diffwave;
39  double** diffwave_spline;
40  double* kwave;
41  double** kwave_spline;
42  double* smooth_diffwave;
44  double* dense_kwave;
46 } funcset_t;
47 
48 typedef struct ppot {
49  int num_projs;
51  int lmax;
53  double rmax; //< maximum radius of the projector functions
54  double wave_rmax;
61  double* wave_grid;
62  double* kwave_grid;
63  double* proj_grid;
64  double* smooth_grid;
65  double* dense_kgrid;
66 } ppot_t;
67 
68 typedef struct projection {
69  int num_projs;
71  int* ns;
72  int* ls;
73  int* ms;
74  double complex* overlaps;
75 } projection_t;
76 
82 typedef struct band {
83  int n;
84  int num_waves;
85  double occ;
86  double N;
87  double energy;
88  float complex* Cs;
89  double complex* CRs;
94 } band_t;
95 
96 typedef struct rayleigh_set {
97  int l;
98  double complex* terms;
100 
101 typedef struct kpoint {
102  short int up;
103  int num_waves;
104  int* Gs;
105  double* k;
106  double weight;
107  int num_bands;
110 } kpoint_t;
111 
112 typedef struct pswf {
113  double encut;
114  int num_elems;
115  int* num_projs;
116  int num_sites;
118  int* G_bounds;
120  int nspin;
121  int nband;
122  int nwk;
123  double* lattice;
124  double* reclattice;
125  int* fftg;
126 
127  int is_ncl;
128 
129  int wp_num;
131  double* dcoords;
132  double complex** overlaps;
133 } pswf_t;
134 
135 typedef struct projgrid {
136  double complex* values;
137 } projgrid_t;
138 
139 typedef struct real_proj {
140  int l;
141  int m;
142  int func_num;
143  double complex* values;
144 } real_proj_t;
145 
146 typedef struct real_proj_site {
147  int index;
148  int elem;
152  int gridsize;
153  double rmax;
154  double* coord;
155  int* indices;
156  double* paths;
159 
160 void affine_transform(double* out, double* op, double* inv);
161 
162 void rotation_transform(double* out, double* op, double* inv);
163 
167 int min(int a, int b);
168 
172 int max(int a, int b);
173 
179 void vcross(double* res, double* top, double* bottom);
180 
185 double dot(double* x1, double* x2);
186 
190 double mag(double* x1);
191 
196 double determinant(double* m);
197 
206 double dist_from_frac(double* coords1, double* coords2, double* lattice);
207 
208 void frac_to_cartesian(double* coord, double* lattice);
209 
210 void cartesian_to_frac(double* coord, double* reclattice);
211 
212 void min_cart_path(double* coord, double* center, double* lattice, double* path, double* r);
213 
214 void trilinear_interpolate_values(double complex* x, double* frac, int* fftg, double complex* values);
215 
216 double complex trilinear_interpolate(double complex* c, double* frac, int* fftg);
217 
218 void free_projection_list(projection_t* projlist, int num);
219 
221 
222 void free_kpoint(kpoint_t* kpt, int num_elems, int num_sites, int wp_num, int* num_projs);
223 
224 void free_ppot(ppot_t* pp);
225 
227 
229 
230 void free_pswf(pswf_t* wf);
231 
232 void free_ptr(void* ptr);
233 
234 void free_real_proj_site_list(real_proj_site_t* sites, int length);
235 
236 void free_ppot_list(ppot_t* pps, int length);
237 
245 double* get_occs(pswf_t* wf);
246 
248 int get_nband(pswf_t* wf);
249 
251 int get_nwk(pswf_t* wf);
252 
254 int get_nspin(pswf_t* wf);
255 
257 int is_ncl(pswf_t* wf);
258 
260 double get_encut(pswf_t* wf);
261 
262 double get_energy(pswf_t* wf, int band, int kpt, int spin);
263 
264 double get_occ(pswf_t* wf, int band, int kpt, int spin);
265 
267 void set_num_sites(pswf_t* wf, int nsites);
268 
270 double legendre(int l, int m, double x);
271 void legendre_coeff(double* ptr, int l, int m);
272 double* legendre_product(int l1, int l2, int m1, int m2);
273 
275 double fac(int n);
276 
281 double complex Ylm(int l, int m, double theta, double phi);
282 
286 double complex Ylm2(int l, int m, double costheta, double phi);
287 
294 double proj_interpolate(double r, double rmax, int size, double* x,
295  double* proj, double** proj_spline);
296 
302 double wave_interpolate(double r, int size, double* x, double* f,
303  double** wave_spline);
304 
308 double complex proj_value_helper(double r, double rmax, int size,
309  double* pos, double* x, double* f, double** s, int l, int m);
310 
315 double complex proj_value(funcset_t funcs, double* x, int m, double rmax,
316  int size, double* ion_pos, double* pos, double* lattice);
317 
322 double complex smooth_wave_value(funcset_t funcs, double* x, int m, double rmax,
323  int size, double* ion_pos, double* pos, double* lattice);
324 
329 double complex wave_value(funcset_t funcs, int size, double* x, int m,
330  double* ion_pos, double* pos, double* lattice);
331 
336 double complex wave_value2(double* x, double* wave, double** spline, int size,
337  int l, int m, double* pos);
338 
342 void setup_site(real_proj_site_t* sites, ppot_t* pps, int num_sites, int* site_nums,
343  int* labels, double* coords, double* lattice, int* fftg, int pr0_pw1);
344 
351 double** spline_coeff(double* x, double* y, int N);
352 
359 double spline_integral(double* x, double* a, double** s, int size);
360 
361 void frac_from_index(int index, double* coord, int* fftg);
362 
363 double sph_bessel(double k, double r, int l);
364 
368 double sbf(double x, int l);
369 
375 pswf_t* expand_symm_wf(pswf_t* rwf, int num_kpts, int* maps,
376  double* ops, double* drs, double* kws, int* trs);
377 
382 void CHECK_ALLOCATION(void* ptr);
383 
387 void ALLOCATION_FAILED(void);
388 
393 void CHECK_STATUS(int status);
394 
395 #endif
int * G_bounds
highest-frequency plane-waves in basis set (xmin, xmax, ymin, ymax, zmin, zmax)
Definition: utils.h:118
int get_nband(pswf_t *wf)
int total_projs
number of projector functions
Definition: utils.h:70
double rmax
Definition: utils.h:153
band_t ** bands
bands with this k-point
Definition: utils.h:108
double * aewave
all electron partial wave
Definition: utils.h:34
real_proj_t * projs
Definition: utils.h:157
struct projection projection_t
double dist_from_frac(double *coords1, double *coords2, double *lattice)
short int up
spin
Definition: utils.h:102
double ** spline_coeff(double *x, double *y, int N)
double * lattice
lattice (length 9, each row is a lattice, vector, row major)
Definition: utils.h:123
double complex Ylm2(int l, int m, double costheta, double phi)
double * smooth_grid
Definition: utils.h:64
double occ
occupancy of the band
Definition: utils.h:85
double sbf(double x, int l)
int nspin
1 for non-spin-polarized/noncollinear, 2 for spin-polarized
Definition: utils.h:120
double * proj_grid
real radial grid for projector functions
Definition: utils.h:63
double ** smooth_diffwave_spline
spline coefficients for smooth_diffwave
Definition: utils.h:43
double complex * overlaps
list of <p_i|psi>
Definition: utils.h:74
void legendre_coeff(double *ptr, int l, int m)
double * pspw_overlap_matrix
overlap matrix for pseudo partial waves
Definition: utils.h:55
double complex wave_value(funcset_t funcs, int size, double *x, int m, double *ion_pos, double *pos, double *lattice)
int num_waves
number of plane waves
Definition: utils.h:84
double fac(int n)
double complex Ylm(int l, int m, double theta, double phi)
double * smooth_diffwave
diffwave on linear grid with high-frequency components removed
Definition: utils.h:42
int index
Definition: utils.h:147
double * dense_kwave
Definition: utils.h:44
double dot(double *x1, double *x2)
double complex proj_value(funcset_t funcs, double *x, int m, double rmax, int size, double *ion_pos, double *pos, double *lattice)
double weight
k-point weight
Definition: utils.h:106
int * Gs
plane wave coefficients, in sets of three
Definition: utils.h:104
Definition: utils.h:101
double * coord
Definition: utils.h:154
int nwk
number of kpoints
Definition: utils.h:122
int n
band number
Definition: utils.h:83
Definition: utils.h:68
Definition: utils.h:48
y
Definition: rayleigh.py:27
int num_projs
Definition: utils.h:149
double energy
energy of the band
Definition: utils.h:87
int num_projs
number of radial projector functions
Definition: utils.h:49
int total_projs
Definition: utils.h:150
double * diffwave
aewave-pswave
Definition: utils.h:38
double complex proj_value_helper(double r, double rmax, int size, double *pos, double *x, double *f, double **s, int l, int m)
void free_ppot(ppot_t *pp)
double * get_occs(pswf_t *wf)
projection_t * projections
length==number of sites in structure
Definition: utils.h:90
int m
Definition: utils.h:141
double N
Definition: utils.h:86
f
Definition: gaunt.py:28
double determinant(double *m)
int num_projs
number of radial projector functions
Definition: utils.h:69
void setup_site(real_proj_site_t *sites, ppot_t *pps, int num_sites, int *site_nums, int *labels, double *coords, double *lattice, int *fftg, int pr0_pw1)
double ** diffwave_spline
spline coefficients for diffwave
Definition: utils.h:39
double mag(double *x1)
double * proj
projector function
Definition: utils.h:32
projection_t * up_projections
length==number of sites in structure
Definition: utils.h:91
Definition: utils.h:139
void affine_transform(double *out, double *op, double *inv)
double * k
k-point vector
Definition: utils.h:105
double complex trilinear_interpolate(double complex *c, double *frac, int *fftg)
void free_real_proj_site(real_proj_site_t *site)
int * ns
radial projector index
Definition: utils.h:71
void free_ptr(void *ptr)
void vcross(double *res, double *top, double *bottom)
int wp_num
length==size of wave_projections in each band
Definition: utils.h:129
float complex * Cs
plane wave coefficients (normalized to 1)
Definition: utils.h:88
int l
angular momentum quantum number
Definition: utils.h:97
struct real_proj real_proj_t
list x
Definition: quadrature.py:9
void free_projection_list(projection_t *projlist, int num)
int nband
number of bands
Definition: utils.h:121
struct band band_t
Definition: utils.h:135
int num_indices
Definition: utils.h:151
double encut
Definition: utils.h:113
void set_num_sites(pswf_t *wf, int nsites)
int num_bands
number of bands
Definition: utils.h:107
rayleigh_set_t ** expansion
Definition: utils.h:109
struct real_proj_site real_proj_site_t
void rotation_transform(double *out, double *op, double *inv)
void clean_wave_projections(pswf_t *wf)
double complex ** overlaps
used for Projector operations
Definition: utils.h:132
double complex * values
Definition: utils.h:143
pswf_t * expand_symm_wf(pswf_t *rwf, int num_kpts, int *maps, double *ops, double *drs, double *kws, int *trs)
double legendre(int l, int m, double x)
int gridsize
Definition: utils.h:152
void free_pswf(pswf_t *wf)
double ** pswave_spline
ps partial wave spline coefficients
Definition: utils.h:37
int elem
Definition: utils.h:148
struct funcset funcset_t
int num_cart_gridpts
number of real space grid points that can fit in the projector sphere
Definition: utils.h:60
double complex * values
Definition: utils.h:136
void free_real_proj_site_list(real_proj_site_t *sites, int length)
double ** aewave_spline
ae partial wave spline coefficients
Definition: utils.h:35
int num_aug_overlap_sites
used for Projector operations
Definition: utils.h:130
int * num_projs
number of projectors for each element
Definition: utils.h:115
double sph_bessel(double k, double r, int l)
double ** kwave_spline
spline coefficients for kwave
Definition: utils.h:41
struct projgrid projgrid_t
Definition: utils.h:30
double rmax
Definition: utils.h:53
void cartesian_to_frac(double *coord, double *reclattice)
int max(int a, int b)
int lmax
maximum l-value of any projector
Definition: utils.h:51
Definition: utils.h:112
int get_nwk(pswf_t *wf)
double * kwave_grid
reciprocal radial grid for partial waves
Definition: utils.h:62
void trilinear_interpolate_values(double complex *x, double *frac, int *fftg, double complex *values)
double complex wave_value2(double *x, double *wave, double **spline, int size, int l, int m, double *pos)
int * fftg
FFT grid dimensions.
Definition: utils.h:125
void free_ppot_list(ppot_t *pps, int length)
void frac_from_index(int index, double *coord, int *fftg)
int is_ncl
1 if noncollinear, 0 otherwise
Definition: utils.h:127
struct kpoint kpoint_t
int proj_gridsize
number of points on projector radial grid
Definition: utils.h:58
struct rayleigh_set rayleigh_set_t
int func_num
Definition: utils.h:142
int total_projs
number of projector functions
Definition: utils.h:50
int is_ncl(pswf_t *wf)
void CHECK_STATUS(int status)
void free_kpoint(kpoint_t *kpt, int num_elems, int num_sites, int wp_num, int *num_projs)
int * ls
l values of projectors
Definition: utils.h:72
void ALLOCATION_FAILED(void)
struct pswf pswf_t
struct ppot ppot_t
double proj_interpolate(double r, double rmax, int size, double *x, double *proj, double **proj_spline)
int l
Definition: utils.h:140
double spline_integral(double *x, double *a, double **s, int size)
double * dense_kgrid
Definition: utils.h:65
int * indices
Definition: utils.h:155
double get_occ(pswf_t *wf, int band, int kpt, int spin)
Definition: utils.h:82
projection_t * down_projections
length==number of sites in structure
Definition: utils.h:92
int wave_gridsize
number of points on partial wave radial grid
Definition: utils.h:59
int k
Definition: rayleigh.py:4
void free_real_proj(real_proj_t *proj)
double * legendre_product(int l1, int l2, int m1, int m2)
int num_elems
number of elements in the structure
Definition: utils.h:114
r
Definition: rayleigh.py:38
double * reclattice
reciprocal lattice (with 2pi factor!), formatted like lattice
Definition: utils.h:124
int l
l quantum number
Definition: utils.h:31
double * aepw_overlap_matrix
overlap matrix for all electron partial waves
Definition: utils.h:56
double * dcoords
used for Projector operations
Definition: utils.h:131
double * paths
Definition: utils.h:156
Definition: utils.h:96
kpoint_t ** kpts
list of kpoint_t objects for the structure
Definition: utils.h:119
double * kwave
Expansion of diffwave in spherical Bessel functions.
Definition: utils.h:40
int * ms
m values of projectors
Definition: utils.h:73
void CHECK_ALLOCATION(void *ptr)
double ** dense_kwave_spline
Definition: utils.h:45
void min_cart_path(double *coord, double *center, double *lattice, double *path, double *r)
double wave_interpolate(double r, int size, double *x, double *f, double **wave_spline)
ppot_t * pps
list of ppot_t objects, one for each element
Definition: utils.h:117
funcset_t * funcs
funcset for each projector, see funcset
Definition: utils.h:52
double get_encut(pswf_t *wf)
double complex * CRs
wavefunction in real space
Definition: utils.h:89
int min(int a, int b)
int num_sites
number of sites in the structure
Definition: utils.h:116
double * wave_grid
real radial grid for partial waves
Definition: utils.h:61
double get_energy(pswf_t *wf, int band, int kpt, int spin)
Definition: utils.h:146
double * pswave
pseudo partial wave
Definition: utils.h:36
double complex smooth_wave_value(funcset_t funcs, double *x, int m, double rmax, int size, double *ion_pos, double *pos, double *lattice)
void frac_to_cartesian(double *coord, double *lattice)
double wave_rmax
maximum radius of the partial waves
Definition: utils.h:54
double complex * terms
rayleigh expansion terms
Definition: utils.h:98
double * diff_overlap_matrix
overlap matrix of difference between all electron and partial waves
Definition: utils.h:57
projection_t * wave_projections
used for offsite compensation terms
Definition: utils.h:93
int get_nspin(pswf_t *wf)
double ** proj_spline
projector function spline
Definition: utils.h:33
int num_waves
number of plane waves in a band
Definition: utils.h:103