bandu 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

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.
bandu/abinit_reader.py CHANGED
@@ -193,9 +193,23 @@ class Abinit7WFK():
193
193
  print('WFK header read')
194
194
  wfk.close()
195
195
  #-----------------------------------------------------------------------------------------------------------------#
196
+ # check for time reversal symmetry
197
+ def _CheckTimeRev(
198
+ self
199
+ ):
200
+ # if system is centrosymmetric, do not double reciprocal symmetry operations
201
+ if True in [np.array_equal(-np.identity(3),mat) for mat in self.symrel]:
202
+ self.time_reversal = False
203
+ else:
204
+ self.time_reversal = True
205
+ print((
206
+ 'Noncentrosymmetric system identified, assuming time reversal symmetry\n'
207
+ 'To change this, set "check_time_rev" keyword to False when calling ReadWFK() or ReadEigenvalues()'
208
+ ))
209
+ #-----------------------------------------------------------------------------------------------------------------#
196
210
  # method to read entire body of abinit version 7 wavefunction file
197
211
  def ReadWFK(
198
- self, energy_level=np.nan, width=np.nan
212
+ self, energy_level=np.nan, width=np.nan, check_time_rev:bool=True
199
213
  )->Generator[wc.WFK, None, None]:
200
214
  '''
201
215
  Method that constructs WFK objects from ABINIT v7 WFK file
@@ -212,6 +226,12 @@ class Abinit7WFK():
212
226
  Total range is equal to width, so look width/2 above and below energy_level
213
227
  If not defined but energy_level is defined, default is 0.005 Hartree
214
228
  '''
229
+ # check for time reversal symmetry
230
+ if check_time_rev:
231
+ self._CheckTimeRev()
232
+ else:
233
+ self.time_reversal = False
234
+ # read wfk file
215
235
  wfk = open(self.filename, 'rb')
216
236
  skip = True
217
237
  if energy_level is np.nan:
@@ -322,16 +342,23 @@ class Abinit7WFK():
322
342
  typat=self.typat,
323
343
  znucltypat=self.znucltypat,
324
344
  fermi_energy=self.fermi,
325
- non_symm_vecs=np.array(self.tnons)
345
+ non_symm_vecs=np.array(self.tnons),
346
+ time_reversal=self.time_reversal
326
347
  )
327
348
  #-----------------------------------------------------------------------------------------------------------------#
328
349
  # method to read only eigenvalues from body of abinit version 7 wavefunction file
329
350
  def ReadEigenvalues(
330
- self
351
+ self, check_time_rev:bool=True
331
352
  )->Generator[wc.WFK, None, None]:
332
353
  '''
333
354
  Method that constructs WFK objects from ABINIT v7 WFK file.
334
355
  '''
356
+ # check for time reversal symmetry
357
+ if check_time_rev:
358
+ self._CheckTimeRev()
359
+ else:
360
+ self.time_reversal = False
361
+ # read wfk
335
362
  wfk = open(self.filename, 'rb')
336
363
  #-----------#
337
364
  # skip header
@@ -378,7 +405,8 @@ class Abinit7WFK():
378
405
  typat=self.typat,
379
406
  znucltypat=self.znucltypat,
380
407
  fermi_energy=self.fermi,
381
- non_symm_vecs=np.array(self.tnons)
408
+ non_symm_vecs=np.array(self.tnons),
409
+ time_reversal=self.time_reversal
382
410
  )
383
411
  print('WFK body read')
384
412
  wfk.close()
@@ -648,9 +676,23 @@ class Abinit10WFK():
648
676
  print('WFK header read')
649
677
  wfk.close()
650
678
  #-----------------------------------------------------------------------------------------------------------------#
679
+ # check for time reversal symmetry
680
+ def _CheckTimeRev(
681
+ self
682
+ ):
683
+ # if system is centrosymmetric, do not double reciprocal symmetry operations
684
+ if True in [np.array_equal(-np.identity(3),mat) for mat in self.symrel]:
685
+ self.time_reversal = False
686
+ else:
687
+ self.time_reversal = True
688
+ print((
689
+ 'Noncentrosymmetric system identified, assuming time reversal symmetry\n'
690
+ 'To change this, set "check_time_rev" keyword to False when calling ReadWFK() or ReadEigenvalues()'
691
+ ))
692
+ #-----------------------------------------------------------------------------------------------------------------#
651
693
  # method to read entire body of abinit version 7 wavefunction file
652
694
  def ReadWFK(
653
- self, energy_level=np.nan, width=np.nan
695
+ self, energy_level=np.nan, width=np.nan, check_time_rev:bool=True
654
696
  )->Generator[wc.WFK, None, None]:
655
697
  '''
656
698
  Method that constructs WFK objects from ABINIT v10 WFK file.
@@ -667,6 +709,12 @@ class Abinit10WFK():
667
709
  Total range is equal to width, so look width/2 above and below energy_level
668
710
  If not defined but energy_level is defined, default is 0.005 Hartree
669
711
  '''
712
+ # check for time reversal symmetry
713
+ if check_time_rev:
714
+ self._CheckTimeRev()
715
+ else:
716
+ self.time_reversal = False
717
+ # read wfk
670
718
  wfk = open(self.filename, 'rb')
671
719
  skip = True
672
720
  if energy_level is np.nan:
@@ -798,16 +846,23 @@ class Abinit10WFK():
798
846
  typat=self.typat,
799
847
  znucltypat=self.znucltypat,
800
848
  fermi_energy=self.fermi,
801
- non_symm_vecs=np.array(self.tnons)
849
+ non_symm_vecs=np.array(self.tnons),
850
+ time_reversal=self.time_reversal
802
851
  )
803
852
  #-----------------------------------------------------------------------------------------------------------------#
804
853
  # method to read only eigenvalues from body of abinit version 10 wavefunction file
805
854
  def ReadEigenvalues(
806
- self
855
+ self, check_time_rev:bool=True
807
856
  )->Generator[wc.WFK, None, None]:
808
857
  '''
809
858
  Method that constructs WFK objects from ABINIT v10 WFK file.
810
859
  '''
860
+ # check for time reversal symmetry
861
+ if check_time_rev:
862
+ self._CheckTimeRev()
863
+ else:
864
+ self.time_reversal = False
865
+ # read wfk
811
866
  wfk = open(self.filename, 'rb')
812
867
  #-----------#
813
868
  # skip header
@@ -874,7 +929,8 @@ class Abinit10WFK():
874
929
  typat=self.typat,
875
930
  znucltypat=self.znucltypat,
876
931
  fermi_energy=self.fermi,
877
- non_symm_vecs=np.array(self.tnons)
932
+ non_symm_vecs=np.array(self.tnons),
933
+ time_reversal=self.time_reversal
878
934
  )
879
935
  print('WFK body read')
880
936
  wfk.close()
@@ -907,7 +963,11 @@ class AbinitNetCDF():
907
963
  self.nband:int = int(self.dataset.dimensions['bantot'].size / self.nkpt)
908
964
  self.typat:list = self.dataset.variables['atom_species'][:].tolist()
909
965
  self.zion:np.ndarray = self.dataset.variables['atomic_numbers'][:]
910
- self.znucltypat:list = [int(self.zion[i-1]) for i in self.typat]
966
+ _all_ions = [int(self.zion[i-1]) for i in self.typat]
967
+ self.znucltypat:list = []
968
+ for i in _all_ions:
969
+ if i not in self.znucltypat:
970
+ self.znucltypat.append(i)
911
971
  self.bands = [self.nband]
912
972
  #---------------------------------------------------------------------------------------------------------------------#
913
973
  #------------------------------------------------------ METHODS ------------------------------------------------------#
@@ -919,31 +979,52 @@ class AbinitNetCDF():
919
979
  from netCDF4 import Dataset
920
980
  return Dataset(self.filename,format='NETCDF4')
921
981
  #-----------------------------------------------------------------------------------------------------------------#
982
+ # check for time reversal symmetry
983
+ def _CheckTimeRev(
984
+ self
985
+ ):
986
+ # if system is centrosymmetric, do not double reciprocal symmetry operations
987
+ if True in [np.array_equal(-np.identity(3),mat) for mat in self.symrel]:
988
+ self.time_reversal = False
989
+ else:
990
+ self.time_reversal = True
991
+ print((
992
+ 'Noncentrosymmetric system identified, assuming time reversal symmetry\n'
993
+ 'To change this, set "check_time_rev" keyword to False when calling ReadWFK() or ReadEigenvalues()'
994
+ ))
995
+ #-----------------------------------------------------------------------------------------------------------------#
922
996
  # fetch wavefunction coefficients from netcdf dataset
923
997
  def ReadWFK(
924
- self, energy_level:float=np.nan, width:float=np.nan
998
+ self, energy_level:float=np.nan, width:float=np.nan, check_time_rev:bool=True
925
999
  )->Generator[wc.WFK, None, None]:
1000
+ # check for time reversal symmetry
1001
+ if check_time_rev:
1002
+ self._CheckTimeRev()
1003
+ else:
1004
+ self.time_reversal = False
926
1005
  eigs:np.ndarray = self.dataset.variables['eigenvalues'][:][0]
927
1006
  pw_inds:np.ndarray = self.dataset.variables['reduced_coordinates_of_plane_waves'][:]
928
1007
  # restructure wavefunction coefficients
929
- coeffs:np.ndarray = self.dataset.variables['coefficients_of_wavefunctions'][:][0]
930
- for i, kpt in enumerate(coeffs):
931
- print(f'Reading kpoint {i+1} of {self.nkpt}', end='\r')
1008
+ for kpt in range(self.nkpt):
1009
+ print(f'Reading kpoint {kpt+1} of {self.nkpt}', end='\r')
932
1010
  kpt_coeffs = []
933
1011
  # format plane wave indices
934
- kpt_pw_inds = pw_inds[i]
1012
+ kpt_pw_inds = pw_inds[kpt]
935
1013
  kpt_pw_inds = kpt_pw_inds[~kpt_pw_inds.mask]
936
1014
  kpt_pw_inds = kpt_pw_inds.reshape((-1,3))
937
- for band in kpt:
1015
+ kpt_pw_inds = np.ma.getdata(kpt_pw_inds)
1016
+ coeffs = self.dataset.variables['coefficients_of_wavefunctions'][0,kpt]
1017
+ for band in coeffs:
938
1018
  band = band[0]
939
1019
  band = band[~band.mask]
940
1020
  band = band.reshape((-1,2))
1021
+ band = np.ma.getdata(band)
941
1022
  kpt_coeffs.append(band[:,0] + 1j*band[:,1])
942
1023
  yield wc.WFK(
943
- eigenvalues=eigs[i,:],
1024
+ eigenvalues=eigs[kpt,:],
944
1025
  wfk_coeffs=np.array(kpt_coeffs),
945
1026
  pw_indices=kpt_pw_inds,
946
- kpoints=self.kpts[i],
1027
+ kpoints=self.kpts[kpt],
947
1028
  nkpt=self.nkpt,
948
1029
  nbands=self.nband,
949
1030
  ngfftx=self.ngfftx,
@@ -957,13 +1038,19 @@ class AbinitNetCDF():
957
1038
  typat=self.typat,
958
1039
  znucltypat=self.znucltypat,
959
1040
  fermi_energy=self.fermi,
960
- non_symm_vecs=self.tnons
1041
+ non_symm_vecs=self.tnons,
1042
+ time_reversal=self.time_reversal
961
1043
  )
962
1044
  #-----------------------------------------------------------------------------------------------------------------#
963
1045
  # fetch eigenvalues from netcdf dataset
964
1046
  def ReadEigenvalues(
965
- self, energy_level:float=np.nan, width:float=np.nan
1047
+ self, energy_level:float=np.nan, width:float=np.nan, check_time_rev:bool=True
966
1048
  )->Generator[wc.WFK, None, None]:
1049
+ # check for time reversal symmetry
1050
+ if check_time_rev:
1051
+ self._CheckTimeRev()
1052
+ else:
1053
+ self.time_reversal = False
967
1054
  eigs:np.ndarray = self.dataset.variables['eigenvalues'][:][0]
968
1055
  for i, kpt in enumerate(self.kpts):
969
1056
  print(f'Reading kpoint {i+1} of {self.nkpt}', end='\r')
@@ -983,7 +1070,8 @@ class AbinitNetCDF():
983
1070
  typat=self.typat,
984
1071
  znucltypat=self.znucltypat,
985
1072
  fermi_energy=self.fermi,
986
- non_symm_vecs=self.tnons
1073
+ non_symm_vecs=self.tnons,
1074
+ time_reversal=self.time_reversal
987
1075
  )
988
1076
 
989
1077
  #---------------------------------------------------------------------------------------------------------------------#
bandu/bandu.py CHANGED
@@ -51,7 +51,6 @@ class BandU():
51
51
  self.low_mem:bool=low_mem
52
52
  self.found_states:int=0
53
53
  self.bandu_fxns:list[wc.WFK]=[]
54
- self.duped_states:int=0
55
54
  self.plot=plot
56
55
  # find all states within width
57
56
  self._FindStates(energy_level, width, wfks)
@@ -62,7 +61,7 @@ class BandU():
62
61
  if plot:
63
62
  self._PlotEigs(principal_vals)
64
63
  # normalize bandu functions
65
- for i in range(self.found_states + self.duped_states):
64
+ for i in range(self.found_states):
66
65
  self.bandu_fxns[i] = self.bandu_fxns[i].Normalize()
67
66
  # compute ratios
68
67
  omega_vals, omega_check = self._CheckOmega()
@@ -169,7 +168,7 @@ class BandU():
169
168
  def _PrincipalComponents(
170
169
  self
171
170
  )->np.ndarray:
172
- total_states = self.found_states + self.duped_states
171
+ total_states = self.found_states
173
172
  # organize wfk coefficients
174
173
  x = self.bandu_fxns[0].ngfftx
175
174
  y = self.bandu_fxns[0].ngffty
@@ -196,7 +195,7 @@ class BandU():
196
195
  def _CheckOmega(
197
196
  self
198
197
  )->tuple[np.ndarray, np.ndarray]:
199
- total_states = self.found_states + self.duped_states
198
+ total_states = self.found_states
200
199
  omega_vals = np.zeros((total_states, 3), dtype=float)
201
200
  vals = np.linspace(start=-0.01, stop=0.01, num=3)
202
201
  for i, val in enumerate(vals):
@@ -209,7 +208,7 @@ class BandU():
209
208
  omega_diff1 = (omega_vals[:,1] - omega_vals[:,0])
210
209
  omega_diff2 = (omega_vals[:,2] - omega_vals[:,1])
211
210
  omega_check = np.sign(omega_diff1) + np.sign(omega_diff2)
212
- return omega_vals, omega_check
211
+ return omega_vals[:,1], omega_check
213
212
  #-----------------------------------------------------------------------------------------------------------------#
214
213
  # plot eigenvalues from PCA
215
214
  def _PlotEigs(
@@ -243,7 +242,7 @@ class BandU():
243
242
  def ToXSF(
244
243
  self, nums:list[int]=[], xsf_name:str='Principal_orbital_component'
245
244
  ):
246
- total_states = self.found_states + self.duped_states
245
+ total_states = self.found_states
247
246
  if nums is []:
248
247
  nums = [0,total_states-1]
249
248
  else:
bandu/plotter.py CHANGED
@@ -462,9 +462,20 @@ class Plotter():
462
462
  symrel = fermi_wfk.symrel
463
463
  nsym = fermi_wfk.nsym
464
464
  kpts = fermi_wfk.kpts
465
- permute_overlaps = wc.WFK(symrel=np.array(symrel), nsym=nsym, nbands=nband)
466
- new_pts, overlaps = permute_overlaps.Symmetrize(points=np.array(kpts), values=overlaps, reciprocal=True)
467
- self.isosurface.points = new_pts
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)
468
+ for i, kpt in enumerate(kpts):
469
+ unique_kpts, _ = new_wfk.Symmetrize(
470
+ points=kpt,
471
+ reciprocal=True
472
+ )
473
+ all_kpts = np.concatenate((all_kpts, unique_kpts), axis=0)
474
+ new_overlaps = np.repeat(overlaps[i,:].reshape((1,-1)), unique_kpts.shape[0], axis=0)
475
+ all_overlaps = np.concatenate((all_overlaps, new_overlaps), axis=0)
476
+ kpts = np.delete(all_kpts, 0, axis=0)
477
+ overlaps = np.delete(all_overlaps, 0, axis=0)
478
+ self.isosurface.points = np.matmul(kpts, self.isosurface.rec_latt)
468
479
  # interpolate overlap values for smooth coloration
469
480
  scalars = []
470
481
  for i in range(overlaps.shape[1]):
bandu/wfk_class.py CHANGED
@@ -376,8 +376,6 @@ class WFK():
376
376
  Choose which band to pull coefficients from (indexed starting from zero).
377
377
  Default assumes coefficients from a single band are provided (-1).
378
378
  '''
379
- # first check for time reversal symmetry
380
- self._CheckTimeRevSym()
381
379
  # find symmetric kpoints
382
380
  kpoint = kpoint.reshape((1,3))
383
381
  sym_kpoints, _ = self.Symmetrize(kpoint, unique=False, reciprocal=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bandu
3
- Version: 1.0.0
3
+ Version: 1.1.0
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
@@ -0,0 +1,14 @@
1
+ bandu/abinit_reader.py,sha256=U4HUUTnju9MpyGtWMOedUQLln90k2F0XIv0Q0zcP05c,47704
2
+ bandu/bandu.py,sha256=EA8AsM517NrnUL6Za5q4W0NAklOCbLomvY_7v51jQ48,12786
3
+ bandu/brillouin_zone.py,sha256=-SarCuvUthk5h_sFHM6KDHLns1eCWGk_v5fHngWFu08,7997
4
+ bandu/colors.py,sha256=OcIBwVh9ieu04n1cruRgyoYslKsdfJKf-u4oWMd3CwQ,2316
5
+ bandu/isosurface_class.py,sha256=o9VqcZ8b1tqkSQN6oJp7PSPkt-QNZg1V_IUbhAsFcgA,10018
6
+ bandu/plotter.py,sha256=wSIA1TpwhioPUHpBe4_gc14e8K98fv3q0LwwD5NLboo,27725
7
+ bandu/translate.py,sha256=YGTkwne4bdrw649OjRKBio7IBsCNVoa__rjkFZK6uRI,2217
8
+ bandu/wfk_class.py,sha256=zsgC17OcWTLan4riaGW2ObBvFHICmZqbizClJV8hsmI,26158
9
+ bandu/xsf_reader.py,sha256=gfv7LsTofWw4PrcOeqltOREJD6RLDq8CeFSsnlfohEw,4778
10
+ bandu-1.1.0.dist-info/licenses/LICENSE,sha256=jk_B-WYDiyH9RtxC45pO6JUtBxmfX5i240dVzv1okCg,1088
11
+ bandu-1.1.0.dist-info/METADATA,sha256=RiyKZil80B49SCmAxMNyzdn93TOOZWV9o_XCBRru3QM,5611
12
+ bandu-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ bandu-1.1.0.dist-info/top_level.txt,sha256=AxbMFU3BRdjCr75K9gAdblwlBMQ3qr9-AaCC-IS8OWs,6
14
+ bandu-1.1.0.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- bandu/abinit_reader.py,sha256=T_GjUi4MOUqhr41wMg5bAgP6tqbhwf0TduC9CLKSTOI,43836
2
- bandu/bandu.py,sha256=RmaJDdbMEechutwUKoOQSuUBYjIP8RUCx5ElqRekwkE,12894
3
- bandu/brillouin_zone.py,sha256=-SarCuvUthk5h_sFHM6KDHLns1eCWGk_v5fHngWFu08,7997
4
- bandu/colors.py,sha256=OcIBwVh9ieu04n1cruRgyoYslKsdfJKf-u4oWMd3CwQ,2316
5
- bandu/isosurface_class.py,sha256=o9VqcZ8b1tqkSQN6oJp7PSPkt-QNZg1V_IUbhAsFcgA,10018
6
- bandu/plotter.py,sha256=Ae0fCSwsbxWlmJ1vnK22pbxt_igjffNuR4a9J587Kzw,27169
7
- bandu/translate.py,sha256=YGTkwne4bdrw649OjRKBio7IBsCNVoa__rjkFZK6uRI,2217
8
- bandu/wfk_class.py,sha256=Bbyf8OKocEQde3mda-sd2F-l9Pd9hrvPMSESycv9wto,26241
9
- bandu/xsf_reader.py,sha256=gfv7LsTofWw4PrcOeqltOREJD6RLDq8CeFSsnlfohEw,4778
10
- bandu-1.0.0.dist-info/licenses/LICENSE,sha256=jk_B-WYDiyH9RtxC45pO6JUtBxmfX5i240dVzv1okCg,1088
11
- bandu-1.0.0.dist-info/METADATA,sha256=Cy1aP_MxQnm3piKcy0729_i5Y4ITNv_52cQaRbSHIOg,5611
12
- bandu-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- bandu-1.0.0.dist-info/top_level.txt,sha256=AxbMFU3BRdjCr75K9gAdblwlBMQ3qr9-AaCC-IS8OWs,6
14
- bandu-1.0.0.dist-info/RECORD,,
File without changes