bandu 1.2.0__tar.gz → 1.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bandu
3
- Version: 1.2.0
3
+ Version: 1.3.1
4
4
  Summary: The BandU program constructs a rank ordered series of crystal orbitals using principal component analysis. These principal orbital components can then be projected on the Fermi surface and visualized
5
5
  Author-email: Patrick Cross <pcross@wisc.edu>
6
6
  Project-URL: Homepage, https://github.com/pcross0405/BandU
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "bandu"
7
- version = "1.2.0"
7
+ version = "1.3.1"
8
8
  authors = [
9
9
  { name="Patrick Cross", email="pcross@wisc.edu" },
10
10
  ]
@@ -123,7 +123,7 @@ class BandU():
123
123
  if self.grid:
124
124
  wfk = wfk.GridWFK()
125
125
  if self.fft:
126
- wfk = wfk.FFT()
126
+ wfk = wfk.IFFT()
127
127
  if self.norm:
128
128
  wfk = wfk.Normalize()
129
129
  yield wfk
@@ -244,7 +244,7 @@ class BandU():
244
244
  ):
245
245
  total_states = self.found_states
246
246
  if nums is []:
247
- nums = [0,total_states-1]
247
+ nums = [1,total_states]
248
248
  else:
249
249
  # check if list has only 2 elements
250
250
  if len(nums) != 2:
@@ -268,6 +268,6 @@ class BandU():
268
268
  for i in range(nums[0]-1, nums[1]):
269
269
  file_name = xsf_name + f'_{i+1}'
270
270
  wfk = copy(self.bandu_fxns[i])
271
- wfk.wfk_coeffs = wfk.wfk_coeffs.reshape((z,y,x))
271
+ wfk.wfk_coeffs = wfk.wfk_coeffs.reshape((x,y,z))
272
272
  wfk = wfk.XSFFormat()
273
273
  wfk.WriteXSF(xsf_file=file_name)
@@ -338,8 +338,8 @@ class Plotter():
338
338
  self.p.app.exec_() # type: ignore
339
339
  #-----------------------------------------------------------------------------------------------------------------#
340
340
  # method to compute bandu fxn and one electron wfk overlaps
341
- def _Overlaps_w_sym(
342
- self, ir_wfk:wc.WFK, bandu:wc.WFK, num_bands:int
341
+ def _OverlapsWithSym(
342
+ self, ir_wfk:wc.WFK, bandu:wc.WFK
343
343
  )->np.ndarray:
344
344
  # kpoint to symmetrically generate
345
345
  kpt = ir_wfk.kpoints
@@ -348,15 +348,14 @@ class Plotter():
348
348
  dupes, unique_inds = ir_wfk._FindOrbit(sym_kpoints)
349
349
  count = sum([1 for i, _ in enumerate(unique_inds) if i not in dupes])
350
350
  # initialize array for overlap values
351
+ num_bands = len(self.isosurface.nbands)
351
352
  overlap_vals = np.zeros((count,num_bands), dtype=float)
352
- if self._debug:
353
- return overlap_vals
354
353
  # loop over bands
355
354
  for i, band in enumerate(self.isosurface.nbands):
356
355
  # generate symmetric coefficients for each band
357
356
  for j, wfk in enumerate(ir_wfk.SymWFKs(kpoint=kpt, band=band)):
358
357
  wfk = wfk.GridWFK()
359
- wfk = wfk.FFT()
358
+ wfk = wfk.IFFT()
360
359
  wfk = wfk.Normalize()
361
360
  overlap = np.sum(np.conj(bandu.wfk_coeffs)*wfk.wfk_coeffs)
362
361
  overlap = np.square(np.abs(overlap))
@@ -364,15 +363,16 @@ class Plotter():
364
363
  return overlap_vals
365
364
  #-----------------------------------------------------------------------------------------------------------------#
366
365
  # method to compute bandu fxn and one electron wfk overlaps
367
- def _Overlaps_no_sym(
368
- self, ir_wfk:wc.WFK, bandu:wc.WFK, num_bands:int
366
+ def _OverlapsNoSym(
367
+ self, ir_wfk:wc.WFK, bandu:wc.WFK
369
368
  )->np.ndarray:
370
369
  # initialize array for overlap values
370
+ num_bands = len(self.isosurface.nbands)
371
371
  overlap_vals = np.zeros((1,num_bands), dtype=float)
372
372
  # loop over bands
373
373
  for i, band in enumerate(self.isosurface.nbands):
374
374
  wfk = ir_wfk.GridWFK(band_index=band)
375
- wfk = wfk.FFT()
375
+ wfk = wfk.IFFT()
376
376
  wfk = wfk.Normalize()
377
377
  overlap = np.sum(np.conj(bandu.wfk_coeffs)*wfk.wfk_coeffs)
378
378
  overlap = np.square(np.abs(overlap))
@@ -430,7 +430,7 @@ class Plotter():
430
430
  # read fermi surface wavefunction
431
431
  fermi_wfk = ar.AbinitWFK(filename=wfk_path)
432
432
  # get number of bands
433
- nband = len(self.isosurface.nbands)
433
+ nbands = len(self.isosurface.nbands)
434
434
  # paths to real and imaginary bandu xsf files
435
435
  real_path = xsf_path + '_real.xsf'
436
436
  imag_path = xsf_path + '_imag.xsf'
@@ -440,7 +440,7 @@ class Plotter():
440
440
  print('XSF read')
441
441
  # convert xsf to wfk object
442
442
  bandu_fxn = wc.WFK(
443
- wfk_coeffs=real_fxn.ReadDensity() + 1j*imag_fxn.ReadDensity(),
443
+ wfk_coeffs=real_fxn.ReadGrid() + 1j*imag_fxn.ReadGrid(),
444
444
  ngfftx=real_fxn.ngfftx,
445
445
  ngffty=real_fxn.ngffty,
446
446
  ngfftz=real_fxn.ngfftz
@@ -450,9 +450,9 @@ class Plotter():
450
450
  # loop through fermi surface kpoints and calc overlap with bandu fxn
451
451
  for i, kpt in enumerate(fermi_wfk.ReadWFK()):
452
452
  if sym:
453
- vals = self._Overlaps_w_sym(kpt, bandu_fxn, nband)
453
+ vals = self._OverlapsWithSym(kpt, bandu_fxn)
454
454
  else:
455
- vals = self._Overlaps_no_sym(kpt, bandu_fxn, nband)
455
+ vals = self._OverlapsNoSym(kpt, bandu_fxn)
456
456
  if i == 0:
457
457
  overlaps = vals
458
458
  else:
@@ -463,8 +463,8 @@ class Plotter():
463
463
  nsym = fermi_wfk.nsym
464
464
  kpts = fermi_wfk.kpts
465
465
  all_kpts = np.zeros((1,3))
466
- all_overlaps = np.zeros((1,nband))
467
- new_wfk = wc.WFK(symrel=np.array(symrel), nsym=nsym, nbands=nband)
466
+ all_overlaps = np.zeros((1,nbands))
467
+ new_wfk = wc.WFK(symrel=np.array(symrel), nsym=nsym, nbands=nbands)
468
468
  for i, kpt in enumerate(kpts):
469
469
  unique_kpts, _ = new_wfk.Symmetrize(
470
470
  points=kpt,
@@ -138,16 +138,16 @@ class WFK():
138
138
  If nothing is passed, it is assumed the coefficients of a single band are supplied.
139
139
  '''
140
140
  # initialize 3D grid
141
- gridded_wfk = np.zeros((self.ngfftz, self.ngffty, self.ngfftx), dtype=complex)
141
+ gridded_wfk = np.zeros((self.ngfftx, self.ngffty, self.ngfftz), dtype=complex)
142
142
  # update grid with wfk coefficients
143
143
  for k, kpt in enumerate(self.pw_indices):
144
144
  kx = kpt[0]
145
145
  ky = kpt[1]
146
146
  kz = kpt[2]
147
147
  if band_index >= 0:
148
- gridded_wfk[kz, ky, kx] = self.wfk_coeffs[band_index][k]
148
+ gridded_wfk[kx, ky, kz] = self.wfk_coeffs[band_index][k]
149
149
  else:
150
- gridded_wfk[kz, ky, kx] = self.wfk_coeffs[k]
150
+ gridded_wfk[kx, ky, kz] = self.wfk_coeffs[k]
151
151
  new_WFK = copy(self)
152
152
  new_WFK.wfk_coeffs = gridded_wfk
153
153
  return new_WFK
@@ -166,9 +166,9 @@ class WFK():
166
166
  If nothing is passed, it is assumed the coefficients of a single band are supplied.
167
167
  '''
168
168
  # check if coefficients are gridded before undoing grid format
169
- if self.wfk_coeffs.shape != (self.ngfftz,self.ngffty,self.ngfftx):
169
+ if self.wfk_coeffs.shape != (self.ngfftx,self.ngffty,self.ngfftz):
170
170
  raise ValueError((
171
- f'Plane wave coefficients must be in 3D grid with shape ({self.ngfftz}, {self.ngffty}, {self.ngfftx})'
171
+ f'Plane wave coefficients must be in 3D grid with shape ({self.ngfftx}, {self.ngffty}, {self.ngfftz})'
172
172
  ' in order to remove the gridded format'
173
173
  ))
174
174
  if band_index >= 0:
@@ -189,10 +189,10 @@ class WFK():
189
189
  Returns copy of WFK with wavefunction coefficients expressed in real space.
190
190
  Assumes existing wavefunction coefficients are expressed in reciprocal space.
191
191
  '''
192
- # Fourier transform reciprocal grid to real space grid
193
- real_coeffs = fftn(self.wfk_coeffs, norm='ortho')
192
+ # Fourier transform real grid to reciprocal grid
193
+ reciprocal_coeffs = fftn(self.wfk_coeffs, norm='ortho')
194
194
  new_WFK = copy(self)
195
- new_WFK.wfk_coeffs = np.array(real_coeffs).reshape((self.ngfftz, self.ngffty, self.ngfftx))
195
+ new_WFK.wfk_coeffs = np.array(reciprocal_coeffs).reshape((self.ngfftx, self.ngffty, self.ngfftz))
196
196
  return new_WFK
197
197
  #-----------------------------------------------------------------------------------------------------------------#
198
198
  # method transforming real space wfks to reciprocal space
@@ -203,10 +203,10 @@ class WFK():
203
203
  Returns copy of WFK with wavefunction coefficients in expressed in reciprocal space.
204
204
  Assumes existing wavefunction coefficients are expressed in real space.
205
205
  '''
206
- # Fourier transform real space grid to reciprocal space grid
207
- reciprocal_coeffs = ifftn(self.wfk_coeffs, norm='ortho')
206
+ # Fourier transform reciprocal grid to real grid
207
+ real_coeffs = ifftn(self.wfk_coeffs, norm='ortho')
208
208
  new_WFK = copy(self)
209
- new_WFK.wfk_coeffs = np.array(reciprocal_coeffs).reshape((self.ngfftz,self.ngffty,self.ngfftx))
209
+ new_WFK.wfk_coeffs = np.array(real_coeffs).reshape((self.ngfftx,self.ngffty,self.ngfftz))
210
210
  return new_WFK
211
211
  #-----------------------------------------------------------------------------------------------------------------#
212
212
  # method for normalizing wfks
@@ -430,34 +430,34 @@ class WFK():
430
430
  # append zeros to ends of all axes in grid_wfk
431
431
  # zeros get replaced by values at beginning of each axis
432
432
  # this repetition is required by XSF format
433
- if np.shape(self.wfk_coeffs) != (self.ngfftz, self.ngffty, self.ngfftx):
433
+ if np.shape(self.wfk_coeffs) != (self.ngfftx, self.ngffty, self.ngfftz):
434
434
  raise ValueError(
435
435
  f'''Passed array is not the correct shape:
436
- Expected: ({self.ngfftz}, {self.ngffty}, {self.ngfftx}),
436
+ Expected: ({self.ngfftx}, {self.ngffty}, {self.ngfftz}),
437
437
  Received: {np.shape(self.wfk_coeffs)}
438
438
  ''')
439
439
  else:
440
440
  grid_wfk = self.wfk_coeffs
441
- grid_wfk = np.append(grid_wfk, np.zeros((1, self.ngffty, self.ngfftx)), axis=0)
442
- grid_wfk = np.append(grid_wfk, np.zeros((self.ngfftz+1, 1, self.ngfftx)), axis=1)
443
- grid_wfk = np.append(grid_wfk, np.zeros((self.ngfftz+1, self.ngffty+1, 1)), axis=2)
441
+ grid_wfk = np.append(grid_wfk, np.zeros((1, self.ngffty, self.ngfftz)), axis=0)
442
+ grid_wfk = np.append(grid_wfk, np.zeros((self.ngfftx+1, 1, self.ngfftz)), axis=1)
443
+ grid_wfk = np.append(grid_wfk, np.zeros((self.ngfftx+1, self.ngffty+1, 1)), axis=2)
444
444
  for x in range(self.ngfftx+1):
445
445
  for y in range(self.ngffty+1):
446
446
  for z in range(self.ngfftz+1):
447
447
  if x == self.ngfftx:
448
- grid_wfk[z][y][x] = grid_wfk[z][y][0]
448
+ grid_wfk[x,y,z] = grid_wfk[0,y,z]
449
449
  if y == self.ngffty:
450
- grid_wfk[z][y][x] = grid_wfk[z][0][x]
450
+ grid_wfk[x,y,z] = grid_wfk[x,0,z]
451
451
  if z == self.ngfftz:
452
- grid_wfk[z][y][x] = grid_wfk[0][x][y]
452
+ grid_wfk[x,y,z] = grid_wfk[x,y,0]
453
453
  if x == self.ngfftx and y == self.ngffty:
454
- grid_wfk[z][y][x] = grid_wfk[z][0][0]
454
+ grid_wfk[x,y,z] = grid_wfk[0,0,z]
455
455
  if x == self.ngfftx and z == self.ngfftz:
456
- grid_wfk[z][y][x] = grid_wfk[0][y][0]
456
+ grid_wfk[x,y,z] = grid_wfk[0,y,0]
457
457
  if z == self.ngfftz and y == self.ngffty:
458
- grid_wfk[z][y][x] = grid_wfk[0][0][x]
458
+ grid_wfk[x,y,z] = grid_wfk[x,0,0]
459
459
  if x == self.ngfftx and y == self.ngffty and z == self.ngfftz:
460
- grid_wfk[z][y][x] = grid_wfk[0][0][0]
460
+ grid_wfk[x,y,z] = grid_wfk[0,0,0]
461
461
  new_WFK = copy(self)
462
462
  new_WFK.wfk_coeffs = grid_wfk
463
463
  new_WFK.ngfftx += 1
@@ -474,18 +474,18 @@ class WFK():
474
474
  '''
475
475
  grid = self.wfk_coeffs
476
476
  # to_be_del will be used to remove all extra data points added for XSF formatting
477
- to_be_del = np.ones((self.ngfftz, self.ngfftx, self.ngffty), dtype=bool)
477
+ to_be_del = np.ones((self.ngfftx, self.ngffty, self.ngfftz), dtype=bool)
478
478
  for z in range(self.ngfftz):
479
- for x in range(self.ngffty):
480
- for y in range(self.ngfftx):
479
+ for y in range(self.ngffty):
480
+ for x in range(self.ngfftx):
481
481
  # any time you reach the last density point it is a repeat of the first point
482
482
  # remove the end points along each axis
483
483
  if y == self.ngffty - 1 or x == self.ngfftx - 1 or z == self.ngfftz - 1:
484
- to_be_del[z,y,x] = False
484
+ to_be_del[x,y,z] = False
485
485
  # remove xsf entries from array
486
486
  grid = grid[to_be_del]
487
487
  # restore grid shape
488
- grid = grid.reshape((self.ngfftz-1, self.ngffty-1, self.ngfftx-1))
488
+ grid = grid.reshape((self.ngfftx-1, self.ngffty-1, self.ngfftz-1))
489
489
  new_WFK = copy(self)
490
490
  new_WFK.wfk_coeffs = grid
491
491
  new_WFK.ngfftx -= 1
@@ -522,16 +522,16 @@ class WFK():
522
522
  print(f'{self.natom} 1', file=xsf)
523
523
  for i, coord in enumerate(self.xred):
524
524
  atomic_num = int(self.znucltypat[self.typat[i] - 1])
525
- cart_coord = np.dot(coord, self.lattice)
525
+ cart_coord = np.matmul(coord, self.lattice)
526
526
  print(f'{atomic_num} {cart_coord[0]} {cart_coord[1]} {cart_coord[2]}', file=xsf)
527
527
  print('ATOMS', file=xsf)
528
528
  for i, coord in enumerate(self.xred):
529
529
  atomic_num = int(self.znucltypat[self.typat[i] - 1])
530
- cart_coord = np.dot(coord, self.lattice)
530
+ cart_coord = np.matmul(coord, self.lattice)
531
531
  print(f'{atomic_num} {cart_coord[0]} {cart_coord[1]} {cart_coord[2]}', file=xsf)
532
- print('BEGIN_BLOCK_DATAGRID3D', file=xsf)
532
+ print('BEGIN_BLOCK_DATAGRID_3D', file=xsf)
533
533
  print('datagrids', file=xsf)
534
- print('DATAGRID_3D_DENSITY', file=xsf)
534
+ print('BEGIN_DATAGRID_3D_principal_orbital_component', file=xsf)
535
535
  print(f'{self.ngfftx} {self.ngffty} {self.ngfftz}', file=xsf)
536
536
  print('0.0 0.0 0.0', file=xsf)
537
537
  print(f'{self.lattice[0,0]} {self.lattice[0,1]} {self.lattice[0,2]}', file=xsf)
@@ -543,14 +543,14 @@ class WFK():
543
543
  for x in range(self.ngfftx):
544
544
  count += 1
545
545
  if _component:
546
- print(self.wfk_coeffs[z,y,x].real, file=xsf, end=' ')
546
+ print(self.wfk_coeffs[x,y,z].real, file=xsf, end=' ')
547
547
  else:
548
- print(self.wfk_coeffs[z,y,x].imag, file=xsf, end=' ')
548
+ print(self.wfk_coeffs[x,y,z].imag, file=xsf, end=' ')
549
549
  if count == 6:
550
550
  count = 0
551
551
  print('\n', file=xsf, end='')
552
552
  print('END_DATAGRID_3D', file=xsf)
553
- print('END_BLOCK_DATAGRID3D', file=xsf)
553
+ print('END_BLOCK_DATAGRID_3D', file=xsf)
554
554
  # rerun method to write out imaginary part
555
555
  if _component:
556
556
  xsf_file = xsf_file.split('_real')[0]
@@ -40,7 +40,7 @@ class XSF():
40
40
  del coord[0]
41
41
  self.coords[atom,:] = coord
42
42
  # once density block is reached, get ngfft spacing and end init
43
- if line.strip() == 'DATAGRID_3D_DENSITY':
43
+ if line.strip() == 'BEGIN_DATAGRID_3D_principal_orbital_component':
44
44
  ngfft_spacing = self.xsf_lines[i+1].strip().split(' ')
45
45
  ngfft_spacing = [int(val) for val in ngfft_spacing]
46
46
  self.ngfftx = ngfft_spacing[0]
@@ -49,7 +49,7 @@ class XSF():
49
49
  return None
50
50
  #-----------------------------------------------------------------------------------------------------------------#
51
51
  # method reading in BandU eigenfunction from XSF
52
- def ReadDensity(
52
+ def ReadGrid(
53
53
  self
54
54
  )->np.ndarray:
55
55
  '''
@@ -63,22 +63,22 @@ class XSF():
63
63
  density_lines:list|np.ndarray=[]
64
64
  for i, line in enumerate(self.xsf_lines):
65
65
  # get density block, this assumes density is the end most data grid in the XSF
66
- if line.strip() == 'DATAGRID_3D_DENSITY':
67
- # density starts 6 lines down from DATAGRID_3D_DENSITY header
66
+ if line.strip() == 'BEGIN_DATAGRID_3D_principal_orbital_component':
67
+ # density starts 6 lines down from BEGIN_DATAGRID_3D_principal_orbital_component header
68
68
  density_lines = self.xsf_lines[i+6:]
69
69
  # last line indicates end of data block, remove it
70
70
  del density_lines[-1]
71
- # last entry in density is a string indicating end of density, remove it
71
+ # last entry in datagrid has a string indicating end of grid, remove it
72
72
  last_line = density_lines[-1].strip().split(' ')
73
73
  last_line = [val for val in last_line if val != 'END_DATAGRID_3D']
74
74
  # cast line back to a single string
75
75
  last_line = ' '.join(last_line)
76
76
  density_lines[-1] = last_line
77
77
  if density_lines is []:
78
- raise LookupError('3D density data not found in XSF file')
78
+ raise LookupError('3D grid data not found in XSF file')
79
79
  # convert density to 3D array of floats
80
80
  density_lines = [line.strip().split(' ') for line in density_lines]
81
81
  density_lines = [val for line in density_lines for val in line if val != '']
82
82
  density_lines = np.array(density_lines, dtype=float)
83
- density_lines = density_lines.reshape((self.ngfftz, self.ngfftx, self.ngffty))
83
+ density_lines = density_lines.reshape((self.ngfftx, self.ngffty, self.ngfftz), order='F')
84
84
  return density_lines
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bandu
3
- Version: 1.2.0
3
+ Version: 1.3.1
4
4
  Summary: The BandU program constructs a rank ordered series of crystal orbitals using principal component analysis. These principal orbital components can then be projected on the Fermi surface and visualized
5
5
  Author-email: Patrick Cross <pcross@wisc.edu>
6
6
  Project-URL: Homepage, https://github.com/pcross0405/BandU
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes