Skip to content

Commit

Permalink
Remove deprecated (to|from|as|get)_string methods (#3561)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
janosh authored Jan 17, 2024
1 parent 021a280 commit 7da8d0a
Show file tree
Hide file tree
Showing 60 changed files with 92 additions and 443 deletions.
11 changes: 0 additions & 11 deletions pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import TYPE_CHECKING, Any
from warnings import warn

import numpy as np
from monty.json import MSONable, jsanitize

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

@classmethod
@np.deprecate(message="Use from_cif_str instead")
def from_cif_string(cls, *args, **kwargs): # noqa: D102
return cls.from_cif_str(*args, **kwargs)

@classmethod
def from_cif_str(
cls,
Expand Down Expand Up @@ -295,11 +289,6 @@ def from_cif_str(
}
return cls(struct, transformations, history=[source_info])

@classmethod
@np.deprecate(message="Use from_poscar_str instead")
def from_poscar_string(cls, *args, **kwargs): # noqa: D102
return cls.from_poscar_str(*args, **kwargs)

@classmethod
def from_poscar_str(
cls, poscar_string: str, transformations: list[AbstractTransformation] | None = None
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/alchemy/transmuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def __init__(self, cif_string, transformations=None, primitive=True, extend_coll
if read_data:
structure_data[-1].append(line)
for data in structure_data:
trafo_struct = TransformedStructure.from_cif_string("\n".join(data), [], primitive)
trafo_struct = TransformedStructure.from_cif_str("\n".join(data), [], primitive)
transformed_structures.append(trafo_struct)
super().__init__(transformed_structures, transformations, extend_collection)

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

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


Expand Down
12 changes: 6 additions & 6 deletions pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ def __rmul__(self, other):
return self.__mul__(other)

@classmethod
def _edges_to_string(cls, g):
def _edges_to_str(cls, g):
header = "from to to_image "
header_line = "---- ---- ------------"
edge_weight_name = g.graph["edge_weight_name"]
Expand Down Expand Up @@ -1286,14 +1286,14 @@ def __str__(self):
out = "Structure Graph"
out += f"\nStructure: \n{self.structure}"
out += f"\nGraph: {self.name}\n"
out += self._edges_to_string(self.graph)
out += self._edges_to_str(self.graph)
return out

def __repr__(self):
s = "Structure Graph"
s += f"\nStructure: \n{self.structure!r}"
s += f"\nGraph: {self.name}\n"
s += self._edges_to_string(self.graph)
s += self._edges_to_str(self.graph)
return s

def __len__(self):
Expand Down Expand Up @@ -2608,7 +2608,7 @@ def from_dict(cls, dct):
return cls(mol, dct["graphs"])

@classmethod
def _edges_to_string(cls, g):
def _edges_to_str(cls, g):
header = "from to to_image "
header_line = "---- ---- ------------"
edge_weight_name = g.graph["edge_weight_name"]
Expand Down Expand Up @@ -2643,14 +2643,14 @@ def __str__(self) -> str:
out = "Molecule Graph"
out += f"\nMolecule: \n{self.molecule}"
out += f"\nGraph: {self.name}\n"
out += self._edges_to_string(self.graph)
out += self._edges_to_str(self.graph)
return out

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

def __len__(self) -> int:
Expand Down
5 changes: 0 additions & 5 deletions pymatgen/analysis/reaction_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ def from_dict(cls, d):
products = {Composition(comp): coeff for comp, coeff in d["products"].items()}
return cls(reactants, products)

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

@classmethod
def from_str(cls, rxn_str):
"""
Expand Down
30 changes: 6 additions & 24 deletions pymatgen/core/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,6 @@ def as_dict(self) -> dict[str, Any]:
"tolerance": self.tol,
}

@np.deprecate(message="Use as_xyz_str instead")
def as_xyz_string(self, *args, **kwargs): # noqa: D102
return self.as_xyz_str(*args, **kwargs)

def as_xyz_str(self) -> str:
"""Returns a string of the form 'x, y, z', '-x, -y, z', '-y+1/2, x+1/2, z+1/2', etc.
Only works for integer rotation matrices.
Expand All @@ -425,11 +421,6 @@ def as_xyz_str(self) -> str:

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

@classmethod
@np.deprecate(message="Use from_xyz_str instead")
def from_xyz_string(cls, *args, **kwargs): # noqa: D102
return cls.from_xyz_str(*args, **kwargs)

@classmethod
def from_xyz_str(cls, xyz_str: str) -> SymmOp:
"""
Expand Down Expand Up @@ -501,7 +492,7 @@ def __eq__(self, other: object) -> bool:
)

def __str__(self) -> str:
return self.as_xyzt_string()
return self.as_xyzt_str()

def __repr__(self) -> str:
output = [
Expand Down Expand Up @@ -584,36 +575,27 @@ def from_rotation_and_translation_and_time_reversal(
return MagSymmOp.from_symmop(symm_op, time_reversal)

@classmethod
@np.deprecate(message="Use from_xyzt_str instead")
def from_xyzt_string(cls, *args, **kwargs): # noqa: D102
return cls.from_xyzt_str(*args, **kwargs)

@classmethod
def from_xyzt_str(cls, xyzt_string: str) -> MagSymmOp:
def from_xyzt_str(cls, xyzt_str: str) -> MagSymmOp:
"""
Args:
xyzt_string (str): of the form 'x, y, z, +1', '-x, -y, z, -1',
xyzt_str (str): of the form 'x, y, z, +1', '-x, -y, z, -1',
'-2y+1/2, 3x+1/2, z-y+1/2, +1', etc.
Returns:
MagSymmOp object
"""
symm_op = SymmOp.from_xyz_string(xyzt_string.rsplit(",", 1)[0])
symm_op = SymmOp.from_xyz_str(xyzt_str.rsplit(",", 1)[0])
try:
time_reversal = int(xyzt_string.rsplit(",", 1)[1])
time_reversal = int(xyzt_str.rsplit(",", 1)[1])
except Exception:
raise Exception("Time reversal operator could not be parsed.")
return cls.from_symmop(symm_op, time_reversal)

@np.deprecate(message="Use as_xyzt_str instead")
def as_xyzt_string(self, *args, **kwargs): # noqa: D102
return self.as_xyzt_str(*args, **kwargs)

def as_xyzt_str(self) -> str:
"""Returns a string of the form 'x, y, z, +1', '-x, -y, z, -1',
'-y+1/2, x+1/2, z+1/2, +1', etc. Only works for integer rotation matrices.
"""
xyzt_string = SymmOp.as_xyz_string(self)
xyzt_string = SymmOp.as_xyz_str(self)
return f"{xyzt_string}, {self.time_reversal:+}"

def as_dict(self) -> dict[str, Any]:
Expand Down
6 changes: 0 additions & 6 deletions pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,12 +1044,6 @@ def ionic_radius(self) -> float | None:
warnings.warn(f"No ionic radius for {self}!")
return None

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

@classmethod
def from_str(cls, species_string: str) -> Species:
"""Returns a Species from a string representation.
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def write_Xdatcar(
"""Writes to Xdatcar file.
The supported kwargs are the same as those for the
Xdatcar_from_structs.get_string method and are passed through directly.
Xdatcar_from_structs.get_str method and are passed through directly.
Args:
filename: Name of file to write. It's prudent to end the filename with
Expand Down
6 changes: 0 additions & 6 deletions pymatgen/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,6 @@ class FloatWithUnit(float):

Error = UnitError

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

@classmethod
def from_str(cls, s):
"""Parse string to FloatWithUnit.
Expand Down
8 changes: 0 additions & 8 deletions pymatgen/io/abinit/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,6 @@ def _check_varname(self, key):
"Use Structure objects to prepare the input file."
)

@np.deprecate(message="Use to_str instead")
def to_string(cls, *args, **kwargs):
return cls.to_str(*args, **kwargs)

def to_str(self, post=None, with_structure=True, with_pseudos=True, exclude=None):
"""
String representation.
Expand Down Expand Up @@ -1226,10 +1222,6 @@ def has_same_structures(self):
def __str__(self):
return self.to_str()

@np.deprecate(message="Use to_str instead")
def to_string(cls, *args, **kwargs):
return cls.to_str(*args, **kwargs)

def to_str(self, with_pseudos=True):
"""
String representation i.e. the input file read by Abinit.
Expand Down
4 changes: 0 additions & 4 deletions pymatgen/io/abinit/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ class AbinitHeader(AttrDict):
def __str__(self):
return self.to_str()

@np.deprecate(message="Use to_str instead")
def to_string(cls, *args, **kwargs):
return cls.to_str(*args, **kwargs)

def to_str(self, verbose=0, title=None, **kwargs):
"""
String representation. kwargs are passed to `pprint.pformat`.
Expand Down
4 changes: 0 additions & 4 deletions pymatgen/io/abinit/pseudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self.to_str()

@np.deprecate(message="Use to_str instead")
def to_string(cls, *args, **kwargs):
return cls.to_str(*args, **kwargs)

def to_str(self, verbose=0) -> str:
"""String representation."""

Expand Down
6 changes: 0 additions & 6 deletions pymatgen/io/adf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import re
from typing import TYPE_CHECKING

import numpy as np
from monty.io import reverse_readline
from monty.itertools import chunks
from monty.json import MSONable
Expand Down Expand Up @@ -333,11 +332,6 @@ def from_dict(cls, d):
subkeys = [AdfKey.from_dict(k) for k in subkey_list] or None
return cls(key, options, subkeys)

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

@classmethod
def from_str(cls, string: str) -> AdfKey:
"""
Expand Down
11 changes: 1 addition & 10 deletions pymatgen/io/atat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import numpy as np
from monty.dev import deprecated

from pymatgen.core import Lattice, Structure, get_el_sp

Expand All @@ -28,10 +27,6 @@ def __init__(self, structure: Structure):
"""
self.structure = structure

@deprecated(message="Use to_str instead")
def to_string(cls, *args, **kwargs):
return cls.to_str(*args, **kwargs)

def to_str(self):
"""
Returns:
Expand Down Expand Up @@ -59,10 +54,6 @@ def to_str(self):

return "\n".join(output)

@deprecated(message="Use from_str instead")
def structure_from_string(cls, *args, **kwargs):
return cls.from_str(*args, **kwargs)

@staticmethod
def structure_from_str(data):
"""
Expand Down Expand Up @@ -134,7 +125,7 @@ def structure_from_str(data):
species_occ = [species_occ[0], 1.0]

if "_" in species_occ[0]:
# see to_string() method in this file, since , and = are not valid
# see to_str() method in this file, since , and = are not valid
# species names in AT-AT we replace "," with "__" and "=" with "___",
# for pymatgen to parse these back correctly we have to replace them back
species_occ[0] = species_occ[0].replace("___", "=").replace("__", ",")
Expand Down
6 changes: 0 additions & 6 deletions pymatgen/io/babel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import copy
import warnings

import numpy as np
from monty.dev import requires

from pymatgen.core.structure import IMolecule, Molecule
Expand Down Expand Up @@ -339,11 +338,6 @@ def from_molecule_graph(mol):
"""
return BabelMolAdaptor(mol.molecule)

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

@needs_openbabel
@classmethod
def from_str(cls, string_data, file_format="xyz"):
Expand Down
Loading

0 comments on commit 7da8d0a

Please sign in to comment.