Skip to content

Commit d4c3cc5

Browse files
authored
lots of from_string should be classmethod (#3177)
* `Incar.from_string` should be `classmethod` * fix other `from_string`
1 parent c945071 commit d4c3cc5

File tree

19 files changed

+27
-0
lines changed

19 files changed

+27
-0
lines changed

pymatgen/core/units.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ class FloatWithUnit(float):
309309

310310
Error = UnitError
311311

312+
@classmethod
312313
@np.deprecate(message="Use from_str instead")
313314
def from_string(cls, *args, **kwargs):
314315
"""Use from_str instead."""

pymatgen/io/adf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def from_dict(cls, d):
354354
subkeys = [AdfKey.from_dict(k) for k in subkey_list] or None
355355
return cls(key, options, subkeys)
356356

357+
@classmethod
357358
@np.deprecate(message="Use from_str instead")
358359
def from_string(cls, *args, **kwargs):
359360
return cls.from_str(*args, **kwargs)

pymatgen/io/babel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def from_molecule_graph(mol):
337337
"""
338338
return BabelMolAdaptor(mol.molecule)
339339

340+
@classmethod
340341
@np.deprecate(message="Use from_str instead")
341342
def from_string(cls, *args, **kwargs):
342343
return cls.from_str(*args, **kwargs)

pymatgen/io/cif.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def _process_string(cls, string):
165165
q.append(tuple(s))
166166
return q
167167

168+
@classmethod
168169
@np.deprecate(message="Use from_str instead")
169170
def from_string(cls, *args, **kwargs):
170171
return cls.from_str(*args, **kwargs)
@@ -233,6 +234,7 @@ def __str__(self):
233234
out = "\n".join(map(str, self.data.values()))
234235
return f"{self.comment}\n{out}\n"
235236

237+
@classmethod
236238
@np.deprecate(message="Use from_str instead")
237239
def from_string(cls, *args, **kwargs):
238240
return cls.from_str(*args, **kwargs)

pymatgen/io/cp2k/inputs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def from_dict(cls, d):
150150
verbose=d["verbose"],
151151
)
152152

153+
@classmethod
153154
@np.deprecate(message="Use from_str instead")
154155
def from_string(cls, *args, **kwargs):
155156
return cls.from_str(*args, **kwargs)
@@ -720,6 +721,7 @@ def from_file(file: str):
720721
txt = preprocessor(f.read(), os.path.dirname(f.name))
721722
return Cp2kInput.from_str(txt)
722723

724+
@classmethod
723725
@np.deprecate(message="Use from_str instead")
724726
def from_string(cls, *args, **kwargs):
725727
return cls.from_str(*args, **kwargs)
@@ -2247,6 +2249,7 @@ def softmatch(self, other):
22472249
d2 = other.as_dict()
22482250
return all(not (v is not None and v != d2[k]) for k, v in d1.items())
22492251

2252+
@classmethod
22502253
@np.deprecate(message="Use from_str instead")
22512254
def from_string(cls, *args, **kwargs):
22522255
return cls.from_str(*args, **kwargs)
@@ -2551,6 +2554,7 @@ def softmatch(self, other):
25512554
d2 = other.as_dict()
25522555
return all(not (v is not None and v != d2[k]) for k, v in d1.items())
25532556

2557+
@classmethod
25542558
@np.deprecate(message="Use from_str instead")
25552559
def from_string(cls, *args, **kwargs):
25562560
return cls.from_str(*args, **kwargs)
@@ -2692,6 +2696,7 @@ def get_string(self):
26922696
out += "\n"
26932697
return out
26942698

2699+
@classmethod
26952700
@np.deprecate(message="Use from_str instead")
26962701
def from_string(cls, *args, **kwargs):
26972702
return cls.from_str(*args, **kwargs)
@@ -2781,6 +2786,7 @@ def from_file(cls, fn):
27812786
obj.filename = fn
27822787
return data
27832788

2789+
@classmethod
27842790
@np.deprecate(message="Use from_str instead")
27852791
def from_string(cls, *args, **kwargs):
27862792
return cls.from_str(*args, **kwargs)

pymatgen/io/exciting/inputs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def lockxyz(self):
7373
def lockxyz(self, lockxyz):
7474
self.structure.add_site_property("selective_dynamics", lockxyz)
7575

76+
@classmethod
7677
@np.deprecate(message="Use from_str instead")
7778
def from_string(cls, *args, **kwargs):
7879
return cls.from_str(*args, **kwargs)

pymatgen/io/feff/inputs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def header_string_from_file(filename="feff.inp"):
278278

279279
return "".join(feff_header_str)
280280

281+
@classmethod
281282
@np.deprecate(message="Use from_str instead")
282283
def from_string(cls, *args, **kwargs):
283284
return cls.from_str(*args, **kwargs)

pymatgen/io/fiesta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ def from_dict(cls, d):
554554
BSE_TDDFT_options=d["memory_options"],
555555
)
556556

557+
@classmethod
557558
@np.deprecate(message="Use from_str instead")
558559
def from_string(cls, *args, **kwargs):
559560
return cls.from_str(*args, **kwargs)

pymatgen/io/gaussian.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def _parse_species(sp_str):
274274

275275
return Molecule(species, coords)
276276

277+
@classmethod
277278
@np.deprecate(message="Use from_str instead")
278279
def from_string(cls, *args, **kwargs):
279280
return cls.from_str(*args, **kwargs)

pymatgen/io/lammps/inputs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ def write_file(self, filename: str | Path, ignore_comments: bool = False, keep_s
521521
with zopen(filename, "wt") as f:
522522
f.write(self.get_string(ignore_comments=ignore_comments, keep_stages=keep_stages))
523523

524+
@classmethod
524525
@np.deprecate(message="Use from_str instead")
525526
def from_string(cls, *args, **kwargs):
526527
return cls.from_str(*args, **kwargs)

0 commit comments

Comments
 (0)