Skip to content

Commit 7da8d0a

Browse files
authored
Remove deprecated (to|from|as|get)_string methods (#3561)
* Remove deprecated (to/from/as/get)_string methods * refactor GaussianOutput.read_scan float conversion * update test names and doc strings still saying (get/to)_string -> (get/to)_str * fix doc str indent * fix tests * drop double @classmethod
1 parent 021a280 commit 7da8d0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+92
-443
lines changed

pymatgen/alchemy/materials.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from typing import TYPE_CHECKING, Any
1212
from warnings import warn
1313

14-
import numpy as np
1514
from monty.json import MSONable, jsanitize
1615

1716
from pymatgen.core.structure import Structure
@@ -244,11 +243,6 @@ def structures(self) -> list[Structure]:
244243
h_structs = [Structure.from_dict(s["input_structure"]) for s in self.history if "input_structure" in s]
245244
return [*h_structs, self.final_structure]
246245

247-
@classmethod
248-
@np.deprecate(message="Use from_cif_str instead")
249-
def from_cif_string(cls, *args, **kwargs): # noqa: D102
250-
return cls.from_cif_str(*args, **kwargs)
251-
252246
@classmethod
253247
def from_cif_str(
254248
cls,
@@ -295,11 +289,6 @@ def from_cif_str(
295289
}
296290
return cls(struct, transformations, history=[source_info])
297291

298-
@classmethod
299-
@np.deprecate(message="Use from_poscar_str instead")
300-
def from_poscar_string(cls, *args, **kwargs): # noqa: D102
301-
return cls.from_poscar_str(*args, **kwargs)
302-
303292
@classmethod
304293
def from_poscar_str(
305294
cls, poscar_string: str, transformations: list[AbstractTransformation] | None = None

pymatgen/alchemy/transmuters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def __init__(self, cif_string, transformations=None, primitive=True, extend_coll
251251
if read_data:
252252
structure_data[-1].append(line)
253253
for data in structure_data:
254-
trafo_struct = TransformedStructure.from_cif_string("\n".join(data), [], primitive)
254+
trafo_struct = TransformedStructure.from_cif_str("\n".join(data), [], primitive)
255255
transformed_structures.append(trafo_struct)
256256
super().__init__(transformed_structures, transformations, extend_collection)
257257

@@ -291,7 +291,7 @@ def __init__(self, poscar_string, transformations=None, extend_collection=False)
291291
extend_collection: Whether to use more than one output structure
292292
from one-to-many transformations.
293293
"""
294-
trafo_struct = TransformedStructure.from_poscar_string(poscar_string, [])
294+
trafo_struct = TransformedStructure.from_poscar_str(poscar_string, [])
295295
super().__init__([trafo_struct], transformations, extend_collection=extend_collection)
296296

297297
@staticmethod
@@ -309,7 +309,7 @@ def from_filenames(poscar_filenames, transformations=None, extend_collection=Fal
309309
trafo_structs = []
310310
for filename in poscar_filenames:
311311
with open(filename) as file:
312-
trafo_structs.append(TransformedStructure.from_poscar_string(file.read(), []))
312+
trafo_structs.append(TransformedStructure.from_poscar_str(file.read(), []))
313313
return StandardTransmuter(trafo_structs, transformations, extend_collection=extend_collection)
314314

315315

pymatgen/analysis/graphs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ def __rmul__(self, other):
12511251
return self.__mul__(other)
12521252

12531253
@classmethod
1254-
def _edges_to_string(cls, g):
1254+
def _edges_to_str(cls, g):
12551255
header = "from to to_image "
12561256
header_line = "---- ---- ------------"
12571257
edge_weight_name = g.graph["edge_weight_name"]
@@ -1286,14 +1286,14 @@ def __str__(self):
12861286
out = "Structure Graph"
12871287
out += f"\nStructure: \n{self.structure}"
12881288
out += f"\nGraph: {self.name}\n"
1289-
out += self._edges_to_string(self.graph)
1289+
out += self._edges_to_str(self.graph)
12901290
return out
12911291

12921292
def __repr__(self):
12931293
s = "Structure Graph"
12941294
s += f"\nStructure: \n{self.structure!r}"
12951295
s += f"\nGraph: {self.name}\n"
1296-
s += self._edges_to_string(self.graph)
1296+
s += self._edges_to_str(self.graph)
12971297
return s
12981298

12991299
def __len__(self):
@@ -2608,7 +2608,7 @@ def from_dict(cls, dct):
26082608
return cls(mol, dct["graphs"])
26092609

26102610
@classmethod
2611-
def _edges_to_string(cls, g):
2611+
def _edges_to_str(cls, g):
26122612
header = "from to to_image "
26132613
header_line = "---- ---- ------------"
26142614
edge_weight_name = g.graph["edge_weight_name"]
@@ -2643,14 +2643,14 @@ def __str__(self) -> str:
26432643
out = "Molecule Graph"
26442644
out += f"\nMolecule: \n{self.molecule}"
26452645
out += f"\nGraph: {self.name}\n"
2646-
out += self._edges_to_string(self.graph)
2646+
out += self._edges_to_str(self.graph)
26472647
return out
26482648

26492649
def __repr__(self) -> str:
26502650
out = "Molecule Graph"
26512651
out += f"\nMolecule: \n{self.molecule!r}"
26522652
out += f"\nGraph: {self.name}\n"
2653-
out += self._edges_to_string(self.graph)
2653+
out += self._edges_to_str(self.graph)
26542654
return out
26552655

26562656
def __len__(self) -> int:

pymatgen/analysis/reaction_calculator.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ def from_dict(cls, d):
244244
products = {Composition(comp): coeff for comp, coeff in d["products"].items()}
245245
return cls(reactants, products)
246246

247-
@classmethod
248-
@np.deprecate(message="Use from_str instead")
249-
def from_string(cls, *args, **kwargs):
250-
return cls.from_str(*args, **kwargs)
251-
252247
@classmethod
253248
def from_str(cls, rxn_str):
254249
"""

pymatgen/core/operations.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,6 @@ def as_dict(self) -> dict[str, Any]:
411411
"tolerance": self.tol,
412412
}
413413

414-
@np.deprecate(message="Use as_xyz_str instead")
415-
def as_xyz_string(self, *args, **kwargs): # noqa: D102
416-
return self.as_xyz_str(*args, **kwargs)
417-
418414
def as_xyz_str(self) -> str:
419415
"""Returns a string of the form 'x, y, z', '-x, -y, z', '-y+1/2, x+1/2, z+1/2', etc.
420416
Only works for integer rotation matrices.
@@ -425,11 +421,6 @@ def as_xyz_str(self) -> str:
425421

426422
return transformation_to_string(self.rotation_matrix, translation_vec=self.translation_vector, delim=", ")
427423

428-
@classmethod
429-
@np.deprecate(message="Use from_xyz_str instead")
430-
def from_xyz_string(cls, *args, **kwargs): # noqa: D102
431-
return cls.from_xyz_str(*args, **kwargs)
432-
433424
@classmethod
434425
def from_xyz_str(cls, xyz_str: str) -> SymmOp:
435426
"""
@@ -501,7 +492,7 @@ def __eq__(self, other: object) -> bool:
501492
)
502493

503494
def __str__(self) -> str:
504-
return self.as_xyzt_string()
495+
return self.as_xyzt_str()
505496

506497
def __repr__(self) -> str:
507498
output = [
@@ -584,36 +575,27 @@ def from_rotation_and_translation_and_time_reversal(
584575
return MagSymmOp.from_symmop(symm_op, time_reversal)
585576

586577
@classmethod
587-
@np.deprecate(message="Use from_xyzt_str instead")
588-
def from_xyzt_string(cls, *args, **kwargs): # noqa: D102
589-
return cls.from_xyzt_str(*args, **kwargs)
590-
591-
@classmethod
592-
def from_xyzt_str(cls, xyzt_string: str) -> MagSymmOp:
578+
def from_xyzt_str(cls, xyzt_str: str) -> MagSymmOp:
593579
"""
594580
Args:
595-
xyzt_string (str): of the form 'x, y, z, +1', '-x, -y, z, -1',
581+
xyzt_str (str): of the form 'x, y, z, +1', '-x, -y, z, -1',
596582
'-2y+1/2, 3x+1/2, z-y+1/2, +1', etc.
597583
598584
Returns:
599585
MagSymmOp object
600586
"""
601-
symm_op = SymmOp.from_xyz_string(xyzt_string.rsplit(",", 1)[0])
587+
symm_op = SymmOp.from_xyz_str(xyzt_str.rsplit(",", 1)[0])
602588
try:
603-
time_reversal = int(xyzt_string.rsplit(",", 1)[1])
589+
time_reversal = int(xyzt_str.rsplit(",", 1)[1])
604590
except Exception:
605591
raise Exception("Time reversal operator could not be parsed.")
606592
return cls.from_symmop(symm_op, time_reversal)
607593

608-
@np.deprecate(message="Use as_xyzt_str instead")
609-
def as_xyzt_string(self, *args, **kwargs): # noqa: D102
610-
return self.as_xyzt_str(*args, **kwargs)
611-
612594
def as_xyzt_str(self) -> str:
613595
"""Returns a string of the form 'x, y, z, +1', '-x, -y, z, -1',
614596
'-y+1/2, x+1/2, z+1/2, +1', etc. Only works for integer rotation matrices.
615597
"""
616-
xyzt_string = SymmOp.as_xyz_string(self)
598+
xyzt_string = SymmOp.as_xyz_str(self)
617599
return f"{xyzt_string}, {self.time_reversal:+}"
618600

619601
def as_dict(self) -> dict[str, Any]:

pymatgen/core/periodic_table.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,6 @@ def ionic_radius(self) -> float | None:
10441044
warnings.warn(f"No ionic radius for {self}!")
10451045
return None
10461046

1047-
@classmethod
1048-
@np.deprecate(message="Use from_str instead")
1049-
def from_string(cls, *args, **kwargs):
1050-
"""Use from_str instead."""
1051-
return cls.from_str(*args, **kwargs)
1052-
10531047
@classmethod
10541048
def from_str(cls, species_string: str) -> Species:
10551049
"""Returns a Species from a string representation.

pymatgen/core/trajectory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def write_Xdatcar(
397397
"""Writes to Xdatcar file.
398398
399399
The supported kwargs are the same as those for the
400-
Xdatcar_from_structs.get_string method and are passed through directly.
400+
Xdatcar_from_structs.get_str method and are passed through directly.
401401
402402
Args:
403403
filename: Name of file to write. It's prudent to end the filename with

pymatgen/core/units.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,6 @@ class FloatWithUnit(float):
291291

292292
Error = UnitError
293293

294-
@classmethod
295-
@np.deprecate(message="Use from_str instead")
296-
def from_string(cls, *args, **kwargs):
297-
"""Use from_str instead."""
298-
return cls.from_str(*args, **kwargs)
299-
300294
@classmethod
301295
def from_str(cls, s):
302296
"""Parse string to FloatWithUnit.

pymatgen/io/abinit/inputs.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,6 @@ def _check_varname(self, key):
816816
"Use Structure objects to prepare the input file."
817817
)
818818

819-
@np.deprecate(message="Use to_str instead")
820-
def to_string(cls, *args, **kwargs):
821-
return cls.to_str(*args, **kwargs)
822-
823819
def to_str(self, post=None, with_structure=True, with_pseudos=True, exclude=None):
824820
"""
825821
String representation.
@@ -1226,10 +1222,6 @@ def has_same_structures(self):
12261222
def __str__(self):
12271223
return self.to_str()
12281224

1229-
@np.deprecate(message="Use to_str instead")
1230-
def to_string(cls, *args, **kwargs):
1231-
return cls.to_str(*args, **kwargs)
1232-
12331225
def to_str(self, with_pseudos=True):
12341226
"""
12351227
String representation i.e. the input file read by Abinit.

pymatgen/io/abinit/netcdf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,6 @@ class AbinitHeader(AttrDict):
457457
def __str__(self):
458458
return self.to_str()
459459

460-
@np.deprecate(message="Use to_str instead")
461-
def to_string(cls, *args, **kwargs):
462-
return cls.to_str(*args, **kwargs)
463-
464460
def to_str(self, verbose=0, title=None, **kwargs):
465461
"""
466462
String representation. kwargs are passed to `pprint.pformat`.

0 commit comments

Comments
 (0)