@@ -101,7 +101,7 @@ def as_pseudo(cls, obj):
101
101
return obj if isinstance (obj , cls ) else cls .from_file (obj )
102
102
103
103
@staticmethod
104
- def from_file (filename ):
104
+ def from_file (filename ) -> Pseudo :
105
105
"""
106
106
Build an instance of a concrete Pseudo subclass from filename.
107
107
Note: the parser knows the concrete class that should be instantiated
@@ -118,20 +118,20 @@ def __eq__(self, other: object) -> bool:
118
118
and self .__class__ == other .__class__
119
119
)
120
120
121
- def __repr__ (self ):
121
+ def __repr__ (self ) -> str :
122
122
try :
123
123
return f"<{ type (self ).__name__ } at { os .path .relpath (self .filepath )} >"
124
124
except Exception :
125
125
# relpath can fail if the code is executed in demon mode.
126
126
return f"<{ type (self ).__name__ } at { self .filepath } >"
127
127
128
- def __str__ (self ):
128
+ def __str__ (self ) -> str :
129
129
return self .to_string ()
130
130
131
- def to_string (self , verbose = 0 ):
131
+ def to_string (self , verbose = 0 ) -> str :
132
132
"""String representation."""
133
133
# pylint: disable=E1101
134
- lines = []
134
+ lines : list [ str ] = []
135
135
app = lines .append
136
136
app (f"<{ type (self ).__name__ } : { self .basename } >" )
137
137
app (" summary: " + self .summary .strip ())
@@ -153,66 +153,64 @@ def to_string(self, verbose=0):
153
153
154
154
@property
155
155
@abc .abstractmethod
156
- def summary (self ):
156
+ def summary (self ) -> str :
157
157
"""String summarizing the most important properties."""
158
158
159
159
@property
160
- def filepath (self ):
160
+ def filepath (self ) -> str :
161
161
"""Absolute path to pseudopotential file."""
162
- # pylint: disable=E1101
163
162
return os .path .abspath (self .path )
164
163
165
164
@property
166
- def basename (self ):
165
+ def basename (self ) -> str :
167
166
"""File basename."""
168
- # pylint: disable=E1101
169
167
return os .path .basename (self .filepath )
170
168
171
169
@property
172
170
@abc .abstractmethod
173
- def Z (self ):
171
+ def Z (self ) -> int :
174
172
"""The atomic number of the atom."""
175
173
176
174
@property
177
175
@abc .abstractmethod
178
- def Z_val (self ):
176
+ def Z_val (self ) -> int :
179
177
"""Valence charge."""
180
178
181
179
@property
182
- def type (self ):
180
+ def type (self ) -> str :
183
181
"""Type of pseudo."""
184
182
return type (self ).__name__
185
183
186
184
@property
187
- def element (self ):
185
+ def element (self ) -> Element :
188
186
"""Pymatgen :class:`Element`."""
189
187
try :
190
188
return Element .from_Z (self .Z )
191
189
except (KeyError , IndexError ):
192
190
return Element .from_Z (int (self .Z ))
193
191
194
192
@property
195
- def symbol (self ):
193
+ def symbol (self ) -> str :
196
194
"""Element symbol."""
197
195
return self .element .symbol
198
196
199
197
@property
200
198
@abc .abstractmethod
201
- def l_max (self ):
199
+ def l_max (self ) -> int :
202
200
"""Maximum angular momentum."""
203
201
204
202
@property
205
203
@abc .abstractmethod
206
- def l_local (self ):
204
+ def l_local (self ) -> int :
207
205
"""Angular momentum used for the local part."""
208
206
209
207
@property
210
- def isnc (self ):
208
+ def isnc (self ) -> bool :
211
209
"""True if norm-conserving pseudopotential."""
212
210
return isinstance (self , NcPseudo )
213
211
214
212
@property
215
- def ispaw (self ):
213
+ def ispaw (self ) -> bool :
216
214
"""True if PAW pseudopotential."""
217
215
return isinstance (self , PawPseudo )
218
216
@@ -223,14 +221,17 @@ def md5(self):
223
221
return self .compute_md5 ()
224
222
225
223
def compute_md5 (self ):
226
- """Compute and erturn MD5 hash value."""
224
+ """Compute and return MD5 hash value."""
227
225
# pylint: disable=E1101
228
226
import hashlib
229
227
230
228
with open (self .path ) as fh :
231
229
text = fh .read ()
232
- m = hashlib .md5 (text .encode ("utf-8" ))
233
- return m .hexdigest ()
230
+ # usedforsecurity=False needed in FIPS mode (Federal Information Processing Standards)
231
+ # https://github.com/materialsproject/pymatgen/issues/2804
232
+ md5 = hashlib .new ("md5" , usedforsecurity = False ) # hashlib.md5(usedforsecurity=False) is py39+
233
+ md5 .update (text .encode ("utf-8" ))
234
+ return md5 .hexdigest ()
234
235
235
236
@property
236
237
@abc .abstractmethod
@@ -242,7 +243,6 @@ def supports_soc(self):
242
243
243
244
def as_dict (self , ** kwargs ):
244
245
"""Return dictionary for MSONable protocol."""
245
- # pylint: disable=E1101
246
246
return {
247
247
"@module" : type (self ).__module__ ,
248
248
"@class" : type (self ).__name__ ,
0 commit comments