@@ -335,8 +335,10 @@ def is_metal(self, efermi_tol=1e-4) -> bool:
335
335
True if a metal, False if not
336
336
"""
337
337
for values in self .bands .values ():
338
- for i in range (self .nb_bands ):
339
- if np .any (values [i , :] - self .efermi < - efermi_tol ) and np .any (values [i , :] - self .efermi > efermi_tol ):
338
+ for idx in range (self .nb_bands ):
339
+ if np .any (values [idx , :] - self .efermi < - efermi_tol ) and np .any (
340
+ values [idx , :] - self .efermi > efermi_tol
341
+ ):
340
342
return True
341
343
return False
342
344
@@ -690,7 +692,7 @@ def from_dict(cls, dct):
690
692
def from_old_dict (cls , dct ):
691
693
"""
692
694
Args:
693
- dct (dict): A dict with all data for a band structure symm line object.
695
+ dct (dict): A dict with all data for a band structure symmetry line object.
694
696
695
697
Returns:
696
698
A BandStructureSymmLine object
@@ -863,57 +865,56 @@ def get_branch(self, index):
863
865
branches
864
866
"""
865
867
to_return = []
866
- for i in self .get_equivalent_kpoints (index ):
868
+ for idx in self .get_equivalent_kpoints (index ):
867
869
for b in self .branches :
868
- if b ["start_index" ] <= i <= b ["end_index" ]:
870
+ if b ["start_index" ] <= idx <= b ["end_index" ]:
869
871
to_return .append (
870
872
{
871
873
"name" : b ["name" ],
872
874
"start_index" : b ["start_index" ],
873
875
"end_index" : b ["end_index" ],
874
- "index" : i ,
876
+ "index" : idx ,
875
877
}
876
878
)
877
879
return to_return
878
880
879
881
def apply_scissor (self , new_band_gap ):
880
882
"""
881
883
Apply a scissor operator (shift of the CBM) to fit the given band gap.
882
- If it's a metal. We look for the band crossing the fermi level
884
+ If it's a metal, we look for the band crossing the Fermi level
883
885
and shift this one up. This will not work all the time for metals!
884
886
885
887
Args:
886
888
new_band_gap: the band gap the scissor band structure need to have.
887
889
888
890
Returns:
889
- a BandStructureSymmLine object with the applied scissor shift
891
+ BandStructureSymmLine: with the applied scissor shift
890
892
"""
891
893
if self .is_metal ():
892
- # moves then the highest index band crossing the fermi level
893
- # find this band...
894
+ # moves then the highest index band crossing the fermi level find this band...
894
895
max_index = - 1000
895
896
# spin_index = None
896
- for i in range (self .nb_bands ):
897
+ for idx in range (self .nb_bands ):
897
898
below = False
898
899
above = False
899
900
for j in range (len (self .kpoints )):
900
- if self .bands [Spin .up ][i ][j ] < self .efermi :
901
+ if self .bands [Spin .up ][idx ][j ] < self .efermi :
901
902
below = True
902
- if self .bands [Spin .up ][i ][j ] > self .efermi :
903
+ if self .bands [Spin .up ][idx ][j ] > self .efermi :
903
904
above = True
904
- if above and below and i > max_index :
905
- max_index = i
905
+ if above and below and idx > max_index :
906
+ max_index = idx
906
907
# spin_index = Spin.up
907
908
if self .is_spin_polarized :
908
909
below = False
909
910
above = False
910
911
for j in range (len (self .kpoints )):
911
- if self .bands [Spin .down ][i ][j ] < self .efermi :
912
+ if self .bands [Spin .down ][idx ][j ] < self .efermi :
912
913
below = True
913
- if self .bands [Spin .down ][i ][j ] > self .efermi :
914
+ if self .bands [Spin .down ][idx ][j ] > self .efermi :
914
915
above = True
915
- if above and below and i > max_index :
916
- max_index = i
916
+ if above and below and idx > max_index :
917
+ max_index = idx
917
918
# spin_index = Spin.down
918
919
old_dict = self .as_dict ()
919
920
shift = new_band_gap
@@ -937,9 +938,9 @@ def as_dict(self):
937
938
"""
938
939
JSON-serializable dict representation of BandStructureSymmLine.
939
940
"""
940
- d = super ().as_dict ()
941
- d ["branches" ] = self .branches
942
- return d
941
+ dct = super ().as_dict ()
942
+ dct ["branches" ] = self .branches
943
+ return dct
943
944
944
945
945
946
class LobsterBandStructureSymmLine (BandStructureSymmLine ):
@@ -951,7 +952,7 @@ def as_dict(self):
951
952
"""
952
953
JSON-serializable dict representation of BandStructureSymmLine.
953
954
"""
954
- d = {
955
+ dct = {
955
956
"@module" : type (self ).__module__ ,
956
957
"@class" : type (self ).__name__ ,
957
958
"lattice_rec" : self .lattice_rec .as_dict (),
@@ -961,62 +962,62 @@ def as_dict(self):
961
962
# kpoints are not kpoint objects dicts but are frac coords (this makes
962
963
# the dict smaller and avoids the repetition of the lattice
963
964
for k in self .kpoints :
964
- d ["kpoints" ].append (k .as_dict ()["fcoords" ])
965
- d ["branches" ] = self .branches
966
- d ["bands" ] = {str (int (spin )): self .bands [spin ].tolist () for spin in self .bands }
967
- d ["is_metal" ] = self .is_metal ()
965
+ dct ["kpoints" ].append (k .as_dict ()["fcoords" ])
966
+ dct ["branches" ] = self .branches
967
+ dct ["bands" ] = {str (int (spin )): self .bands [spin ].tolist () for spin in self .bands }
968
+ dct ["is_metal" ] = self .is_metal ()
968
969
vbm = self .get_vbm ()
969
- d ["vbm" ] = {
970
+ dct ["vbm" ] = {
970
971
"energy" : vbm ["energy" ],
971
972
"kpoint_index" : [int (x ) for x in vbm ["kpoint_index" ]],
972
973
"band_index" : {str (int (spin )): vbm ["band_index" ][spin ] for spin in vbm ["band_index" ]},
973
974
"projections" : {str (spin ): v for spin , v in vbm ["projections" ].items ()},
974
975
}
975
976
cbm = self .get_cbm ()
976
- d ["cbm" ] = {
977
+ dct ["cbm" ] = {
977
978
"energy" : cbm ["energy" ],
978
979
"kpoint_index" : [int (x ) for x in cbm ["kpoint_index" ]],
979
980
"band_index" : {str (int (spin )): cbm ["band_index" ][spin ] for spin in cbm ["band_index" ]},
980
981
"projections" : {str (spin ): v for spin , v in cbm ["projections" ].items ()},
981
982
}
982
- d ["band_gap" ] = self .get_band_gap ()
983
- d ["labels_dict" ] = {}
984
- d ["is_spin_polarized" ] = self .is_spin_polarized
983
+ dct ["band_gap" ] = self .get_band_gap ()
984
+ dct ["labels_dict" ] = {}
985
+ dct ["is_spin_polarized" ] = self .is_spin_polarized
985
986
# MongoDB does not accept keys starting with $. Add a blank space to fix the problem
986
987
for c , label in self .labels_dict .items ():
987
988
mongo_key = c if not c .startswith ("$" ) else " " + c
988
- d ["labels_dict" ][mongo_key ] = label .as_dict ()["fcoords" ]
989
+ dct ["labels_dict" ][mongo_key ] = label .as_dict ()["fcoords" ]
989
990
if len (self .projections ) != 0 :
990
- d ["structure" ] = self .structure .as_dict ()
991
- d ["projections" ] = {str (int (spin )): np .array (v ).tolist () for spin , v in self .projections .items ()}
992
- return d
991
+ dct ["structure" ] = self .structure .as_dict ()
992
+ dct ["projections" ] = {str (int (spin )): np .array (v ).tolist () for spin , v in self .projections .items ()}
993
+ return dct
993
994
994
995
@classmethod
995
- def from_dict (cls , d ):
996
+ def from_dict (cls , dct ):
996
997
"""
997
998
Args:
998
- d (dict): A dict with all data for a band structure symm line
999
+ dct (dict): A dict with all data for a band structure symmetry line
999
1000
object.
1000
1001
1001
1002
Returns:
1002
1003
A BandStructureSymmLine object
1003
1004
"""
1004
1005
try :
1005
1006
# Strip the label to recover initial string (see trick used in as_dict to handle $ chars)
1006
- labels_dict = {k .strip (): v for k , v in d ["labels_dict" ].items ()}
1007
+ labels_dict = {k .strip (): v for k , v in dct ["labels_dict" ].items ()}
1007
1008
projections = {}
1008
1009
structure = None
1009
- if d .get ("projections" ):
1010
- if isinstance (d ["projections" ]["1" ][0 ][0 ], dict ):
1010
+ if dct .get ("projections" ):
1011
+ if isinstance (dct ["projections" ]["1" ][0 ][0 ], dict ):
1011
1012
raise ValueError ("Old band structure dict format detected!" )
1012
- structure = Structure .from_dict (d ["structure" ])
1013
- projections = {Spin (int (spin )): np .array (v ) for spin , v in d ["projections" ].items ()}
1013
+ structure = Structure .from_dict (dct ["structure" ])
1014
+ projections = {Spin (int (spin )): np .array (v ) for spin , v in dct ["projections" ].items ()}
1014
1015
1015
1016
return LobsterBandStructureSymmLine (
1016
- d ["kpoints" ],
1017
- {Spin (int (k )): d ["bands" ][k ] for k in d ["bands" ]},
1018
- Lattice (d ["lattice_rec" ]["matrix" ]),
1019
- d ["efermi" ],
1017
+ dct ["kpoints" ],
1018
+ {Spin (int (k )): dct ["bands" ][k ] for k in dct ["bands" ]},
1019
+ Lattice (dct ["lattice_rec" ]["matrix" ]),
1020
+ dct ["efermi" ],
1020
1021
labels_dict ,
1021
1022
structure = structure ,
1022
1023
projections = projections ,
@@ -1028,39 +1029,39 @@ def from_dict(cls, d):
1028
1029
"format. The old format will be retired in pymatgen "
1029
1030
"5.0."
1030
1031
)
1031
- return LobsterBandStructureSymmLine .from_old_dict (d )
1032
+ return LobsterBandStructureSymmLine .from_old_dict (dct )
1032
1033
1033
1034
@classmethod
1034
- def from_old_dict (cls , d ):
1035
+ def from_old_dict (cls , dct ):
1035
1036
"""
1036
1037
Args:
1037
- d (dict): A dict with all data for a band structure symm line
1038
+ dct (dict): A dict with all data for a band structure symmetry line
1038
1039
object.
1039
1040
1040
1041
Returns:
1041
1042
A BandStructureSymmLine object
1042
1043
"""
1043
1044
# Strip the label to recover initial string (see trick used in as_dict to handle $ chars)
1044
- labels_dict = {k .strip (): v for k , v in d ["labels_dict" ].items ()}
1045
+ labels_dict = {k .strip (): v for k , v in dct ["labels_dict" ].items ()}
1045
1046
projections = {}
1046
1047
structure = None
1047
- if "projections" in d and len (d ["projections" ]) != 0 :
1048
- structure = Structure .from_dict (d ["structure" ])
1048
+ if "projections" in dct and len (dct ["projections" ]) != 0 :
1049
+ structure = Structure .from_dict (dct ["structure" ])
1049
1050
projections = {}
1050
- for spin in d ["projections" ]:
1051
+ for spin in dct ["projections" ]:
1051
1052
dd = []
1052
- for i in range (len (d ["projections" ][spin ])):
1053
+ for i in range (len (dct ["projections" ][spin ])):
1053
1054
ddd = []
1054
- for j in range (len (d ["projections" ][spin ][i ])):
1055
- ddd .append (d ["projections" ][spin ][i ][j ])
1055
+ for j in range (len (dct ["projections" ][spin ][i ])):
1056
+ ddd .append (dct ["projections" ][spin ][i ][j ])
1056
1057
dd .append (np .array (ddd ))
1057
1058
projections [Spin (int (spin ))] = np .array (dd )
1058
1059
1059
1060
return LobsterBandStructureSymmLine (
1060
- d ["kpoints" ],
1061
- {Spin (int (k )): d ["bands" ][k ] for k in d ["bands" ]},
1062
- Lattice (d ["lattice_rec" ]["matrix" ]),
1063
- d ["efermi" ],
1061
+ dct ["kpoints" ],
1062
+ {Spin (int (k )): dct ["bands" ][k ] for k in dct ["bands" ]},
1063
+ Lattice (dct ["lattice_rec" ]["matrix" ]),
1064
+ dct ["efermi" ],
1064
1065
labels_dict ,
1065
1066
structure = structure ,
1066
1067
projections = projections ,
0 commit comments