diff --git a/pymatgen/alchemy/materials.py b/pymatgen/alchemy/materials.py index 64df00e021c..934d6779b0f 100644 --- a/pymatgen/alchemy/materials.py +++ b/pymatgen/alchemy/materials.py @@ -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 @@ -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, @@ -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 diff --git a/pymatgen/alchemy/transmuters.py b/pymatgen/alchemy/transmuters.py index 37b502f15a6..aabec2f9862 100644 --- a/pymatgen/alchemy/transmuters.py +++ b/pymatgen/alchemy/transmuters.py @@ -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) @@ -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 @@ -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) diff --git a/pymatgen/analysis/graphs.py b/pymatgen/analysis/graphs.py index 0e5d9e4941b..ace3af8d22c 100644 --- a/pymatgen/analysis/graphs.py +++ b/pymatgen/analysis/graphs.py @@ -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"] @@ -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): @@ -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"] @@ -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: diff --git a/pymatgen/analysis/reaction_calculator.py b/pymatgen/analysis/reaction_calculator.py index 885720c75a9..7933761feff 100644 --- a/pymatgen/analysis/reaction_calculator.py +++ b/pymatgen/analysis/reaction_calculator.py @@ -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): """ diff --git a/pymatgen/core/operations.py b/pymatgen/core/operations.py index 9f930a4d1dd..844d1336edf 100644 --- a/pymatgen/core/operations.py +++ b/pymatgen/core/operations.py @@ -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. @@ -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: """ @@ -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 = [ @@ -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]: diff --git a/pymatgen/core/periodic_table.py b/pymatgen/core/periodic_table.py index a041dbcf1c2..b5a764cdfdc 100644 --- a/pymatgen/core/periodic_table.py +++ b/pymatgen/core/periodic_table.py @@ -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. diff --git a/pymatgen/core/trajectory.py b/pymatgen/core/trajectory.py index 60239676cb2..4f38e5522ed 100644 --- a/pymatgen/core/trajectory.py +++ b/pymatgen/core/trajectory.py @@ -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 diff --git a/pymatgen/core/units.py b/pymatgen/core/units.py index 32af4cb9afe..40fe7f41af6 100644 --- a/pymatgen/core/units.py +++ b/pymatgen/core/units.py @@ -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. diff --git a/pymatgen/io/abinit/inputs.py b/pymatgen/io/abinit/inputs.py index 2f034c0b6b8..27d2d7b90e1 100644 --- a/pymatgen/io/abinit/inputs.py +++ b/pymatgen/io/abinit/inputs.py @@ -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. @@ -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. diff --git a/pymatgen/io/abinit/netcdf.py b/pymatgen/io/abinit/netcdf.py index 499b6db4045..c93c4b57d53 100644 --- a/pymatgen/io/abinit/netcdf.py +++ b/pymatgen/io/abinit/netcdf.py @@ -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`. diff --git a/pymatgen/io/abinit/pseudos.py b/pymatgen/io/abinit/pseudos.py index 9b87b867ae1..2cc3edad92b 100644 --- a/pymatgen/io/abinit/pseudos.py +++ b/pymatgen/io/abinit/pseudos.py @@ -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.""" diff --git a/pymatgen/io/adf.py b/pymatgen/io/adf.py index 2948336dd1d..b2bf8604540 100644 --- a/pymatgen/io/adf.py +++ b/pymatgen/io/adf.py @@ -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 @@ -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: """ diff --git a/pymatgen/io/atat.py b/pymatgen/io/atat.py index 8c12976f3b2..31860a4c9a3 100644 --- a/pymatgen/io/atat.py +++ b/pymatgen/io/atat.py @@ -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 @@ -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: @@ -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): """ @@ -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("__", ",") diff --git a/pymatgen/io/babel.py b/pymatgen/io/babel.py index d58369ba47b..8704d3a3149 100644 --- a/pymatgen/io/babel.py +++ b/pymatgen/io/babel.py @@ -9,7 +9,6 @@ import copy import warnings -import numpy as np from monty.dev import requires from pymatgen.core.structure import IMolecule, Molecule @@ -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"): diff --git a/pymatgen/io/cif.py b/pymatgen/io/cif.py index b14439f9baf..2b349874cc7 100644 --- a/pymatgen/io/cif.py +++ b/pymatgen/io/cif.py @@ -84,7 +84,7 @@ def __str__(self): for loop in self.loops: # search for a corresponding loop if key in loop: - out.append(self._loop_to_string(loop)) + out.append(self._loop_to_str(loop)) written.extend(loop) break if key not in written: @@ -96,7 +96,7 @@ def __str__(self): out.extend([key, v]) return "\n".join(out) - def _loop_to_string(self, loop): + def _loop_to_str(self, loop): out = "loop_" for line in loop: out += "\n " + line @@ -165,11 +165,6 @@ def _process_string(cls, string): q.append(tuple(s)) return q - @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): """ @@ -236,11 +231,6 @@ def __str__(self): out = "\n".join(map(str, self.data.values())) return f"{self.comment}\n{out}\n" - @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) -> CifFile: """Reads CifFile from a string. @@ -367,11 +357,6 @@ def is_magcif_incommensurate() -> bool: # pass individual CifBlocks to _sanitize_data self._cif.data[key] = self._sanitize_data(self._cif.data[key]) - @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, cif_string: str, **kwargs) -> CifParser: """ @@ -1468,12 +1453,12 @@ def __init__( else: spg_analyzer = SpacegroupAnalyzer(struct, symprec) - symm_ops = [] + symm_ops: list[SymmOp] = [] for op in spg_analyzer.get_symmetry_operations(): v = op.translation_vector symm_ops.append(SymmOp.from_rotation_and_translation(op.rotation_matrix, v)) - ops = [op.as_xyz_string() for op in symm_ops] + ops = [op.as_xyz_str() for op in symm_ops] block["_symmetry_equiv_pos_site_id"] = [f"{i}" for i in range(1, len(ops) + 1)] block["_symmetry_equiv_pos_as_xyz"] = ops diff --git a/pymatgen/io/core.py b/pymatgen/io/core.py index 022e9fd6f75..fbdb8acbc92 100644 --- a/pymatgen/io/core.py +++ b/pymatgen/io/core.py @@ -33,7 +33,6 @@ from typing import TYPE_CHECKING from zipfile import ZipFile -import numpy as np from monty.io import zopen from monty.json import MSONable @@ -52,7 +51,7 @@ class InputFile(MSONable): is optional; it is possible create an InputSet that does not rely on underlying InputFile objects. - All InputFile classes must implement a get_string method, which is called by + All InputFile classes must implement a get_str method, which is called by write_file. If InputFile classes implement an __init__ method, they must assign all arguments @@ -63,11 +62,6 @@ class InputFile(MSONable): def get_str(self) -> str: """Return a string representation of an entire input file.""" - @np.deprecate(message="Use get_str instead") - @abc.abstractmethod - def get_string(self) -> str: - """Return a string representation of an entire input file.""" - def write_file(self, filename: str | PathLike) -> None: """ Write the input file. @@ -79,20 +73,6 @@ def write_file(self, filename: str | PathLike) -> None: with zopen(filename, mode="wt") as file: file.write(self.get_str()) - @classmethod - @np.deprecate(message="Use from_str instead") - @abc.abstractmethod - def from_string(cls, contents: str) -> InputFile: - """ - Create an InputFile object from a string. - - Args: - contents: The contents of the file as a single string - - Returns: - InputFile - """ - @classmethod @abc.abstractmethod def from_str(cls, contents: str) -> InputFile: diff --git a/pymatgen/io/cp2k/inputs.py b/pymatgen/io/cp2k/inputs.py index bc96b6ab98d..487de9000d0 100644 --- a/pymatgen/io/cp2k/inputs.py +++ b/pymatgen/io/cp2k/inputs.py @@ -35,7 +35,6 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Literal -import numpy as np from monty.io import zopen from monty.json import MSONable @@ -135,10 +134,6 @@ def as_dict(self): dct["verbose"] = self.verbose return dct - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """String representation of Keyword.""" return str(self) @@ -155,11 +150,6 @@ def from_dict(cls, d): verbose=d["verbose"], ) - @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, s): """ @@ -233,10 +223,6 @@ def extend(self, lst: Sequence[Keyword]) -> None: """Extend the keyword list.""" self.keywords.extend(lst) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, indent: int = 0) -> str: """String representation of Keyword.""" return " \n".join("\t" * indent + str(k) for k in self.keywords) @@ -560,10 +546,6 @@ def by_path(self, path: str): s = s.get_section(p) return s - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Get string representation of Section.""" return Section._get_str(self) @@ -658,10 +640,6 @@ def __deepcopy__(self, memodict=None): def _get_str(d, indent=0): return " \n".join(s._get_str(s, indent) for s in d) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Return string representation of section list.""" return SectionList._get_str(self.sections) @@ -737,11 +715,6 @@ def from_file(cls, file: str): txt = preprocessor(f.read(), os.path.dirname(f.name)) return cls.from_str(txt) - @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, s: str): """Initialize from a string.""" @@ -2243,11 +2216,6 @@ def softmatch(self, other): d2 = other.as_dict() return all(not (v is not None and v != d2[k]) for k, v in d1.items()) - @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) -> BasisInfo: """Get summary info from a string.""" @@ -2355,10 +2323,6 @@ def get_hash(self) -> str: md5.update(self.get_str().lower().encode("utf-8")) return md5.hexdigest() - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Get string representation.""" return str(self) @@ -2424,10 +2388,6 @@ def nexp(self): return [len(e) for e in self.exponents] @typing.no_type_check - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Get standard cp2k GTO formatted string.""" if ( # written verbosely so mypy can perform type narrowing @@ -2457,11 +2417,6 @@ def get_str(self) -> str: out += "\n" return out - @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) -> GaussianTypeOrbitalBasisSet: """Read from standard cp2k GTO formatted string.""" @@ -2562,11 +2517,6 @@ def softmatch(self, other): d2 = other.as_dict() return all(not (v is not None and v != d2[k]) for k, v in d1.items()) - @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): """Get a cp2k formatted string representation.""" @@ -2670,10 +2620,6 @@ def from_section(cls, section: Section) -> GthPotential: string = "\n".join(line for line in lst if not line.startswith("&")) return cls.from_str(string) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Convert model to a GTH-formatted string.""" if ( # written verbosely so mypy can perform type narrowing @@ -2707,11 +2653,6 @@ def get_str(self) -> str: out += "\n" return out - @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): """Initialize model from a GTH formatted string.""" @@ -2797,11 +2738,6 @@ def from_file(cls, fn): obj.filename = fn return data - @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): """Initialize from a string.""" @@ -2812,10 +2748,6 @@ def write_file(self, fn): with open(fn, mode="w") as f: f.write(self.get_str()) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Get string representation.""" return "\n".join(b.get_str() for b in self.objects or []) diff --git a/pymatgen/io/exciting/inputs.py b/pymatgen/io/exciting/inputs.py index 14c3af535b5..70d4532d959 100644 --- a/pymatgen/io/exciting/inputs.py +++ b/pymatgen/io/exciting/inputs.py @@ -63,11 +63,6 @@ def lockxyz(self): def lockxyz(self, lockxyz): self.structure.add_site_property("selective_dynamics", lockxyz) - @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, data): """Reads the exciting input from a string.""" diff --git a/pymatgen/io/feff/inputs.py b/pymatgen/io/feff/inputs.py index c86d63b7869..96d903a149a 100644 --- a/pymatgen/io/feff/inputs.py +++ b/pymatgen/io/feff/inputs.py @@ -276,11 +276,6 @@ def header_string_from_file(filename="feff.inp"): return "".join(feff_header_str) - @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, header_str): """ @@ -605,10 +600,6 @@ def from_dict(d): i[k] = v return i - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, sort_keys: bool = False, pretty: bool = False) -> str: """ Returns a string representation of the Tags. The reason why this @@ -882,7 +873,7 @@ def pot_string_from_file(filename="feff.inp"): return "".join(pot_str).rstrip("\n") @staticmethod - def pot_dict_from_string(pot_data): + def pot_dict_from_str(pot_data): """ Creates atomic symbol/potential number dictionary forward and reverse. diff --git a/pymatgen/io/feff/outputs.py b/pymatgen/io/feff/outputs.py index 092f8d071a3..bc736a1cba0 100644 --- a/pymatgen/io/feff/outputs.py +++ b/pymatgen/io/feff/outputs.py @@ -89,7 +89,7 @@ def from_file(cls, feff_inp_file="feff.inp", ldos_file="ldos"): begin = 1 else: pot_string = Potential.pot_string_from_file(feff_inp_file) - dicts = Potential.pot_dict_from_string(pot_string) + dicts = Potential.pot_dict_from_str(pot_string) pot_dict = dicts[0] with zopen(ldos_file + "00.dat", mode="r") as file: @@ -197,7 +197,7 @@ def charge_transfer_from_file(feff_inp_file, ldos_file): begin = 1 else: pot_string = Potential.pot_string_from_file(feff_inp_file) - dicts = Potential.pot_dict_from_string(pot_string) + dicts = Potential.pot_dict_from_str(pot_string) pot_dict = dicts[1] for idx in range(len(dicts[0]) + 1): @@ -222,7 +222,7 @@ def charge_transfer_from_file(feff_inp_file, ldos_file): return cht - def charge_transfer_to_string(self): + def charge_transfer_to_str(self): """Returns charge transfer as string.""" ch = self.charge_transfer chts = ["\nCharge Transfer\n\nabsorbing atom"] diff --git a/pymatgen/io/fiesta.py b/pymatgen/io/fiesta.py index 976329b41fa..a2d4ad8d499 100644 --- a/pymatgen/io/fiesta.py +++ b/pymatgen/io/fiesta.py @@ -16,7 +16,6 @@ import subprocess from string import Template -import numpy as np from monty.io import zopen from monty.json import MSONable @@ -555,11 +554,6 @@ def from_dict(cls, d): BSE_TDDFT_options=d["memory_options"], ) - @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_input): """ diff --git a/pymatgen/io/gaussian.py b/pymatgen/io/gaussian.py index 581ee0cc80a..2d34a7a3da3 100644 --- a/pymatgen/io/gaussian.py +++ b/pymatgen/io/gaussian.py @@ -274,11 +274,6 @@ def _parse_species(sp_str): return Molecule(species, coords) - @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, contents): """ @@ -382,10 +377,6 @@ def get_cart_coords(self) -> str: 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, cart_coords=False): """Return GaussianInput string. @@ -394,14 +385,14 @@ def to_str(self, cart_coords=False): Defaults to False. """ - def para_dict_to_string(para, joiner=" "): + def para_dict_to_str(para, joiner=" "): para_str = [] # sorted is only done to make unit tests work reliably for par, val in sorted(para.items()): if val is None or val == "": para_str.append(par) elif isinstance(val, dict): - val_str = para_dict_to_string(val, joiner=",") + val_str = para_dict_to_str(val, joiner=",") para_str.append(f"{par}=({val_str})") else: para_str.append(f"{par}={val}") @@ -409,7 +400,7 @@ def para_dict_to_string(para, joiner=" "): output = [] if self.link0_parameters: - output.append(para_dict_to_string(self.link0_parameters, "\n")) + output.append(para_dict_to_str(self.link0_parameters, "\n")) # Handle functional or basis set to None, empty string or whitespace func_str = "" if self.functional is None else self.functional.strip() @@ -422,7 +413,7 @@ def para_dict_to_string(para, joiner=" "): func_bset_str = f" {func_str}{bset_str}".rstrip() output.extend( - (f"{self.dieze_tag}{func_bset_str} {para_dict_to_string(self.route_parameters)}", "", self.title, "") + (f"{self.dieze_tag}{func_bset_str} {para_dict_to_str(self.route_parameters)}", "", self.title, "") ) charge_str = "" if self.charge is None else f"{self.charge:.0f}" @@ -439,7 +430,7 @@ def para_dict_to_string(para, joiner=" "): output.append("") if self.gen_basis is not None: output.append(f"{self.gen_basis}\n") - output.extend((para_dict_to_string(self.input_parameters, "\n"), "\n")) + output.extend((para_dict_to_str(self.input_parameters, "\n"), "\n")) return "\n".join(output) def write_file(self, filename, cart_coords=False): @@ -1102,19 +1093,12 @@ def read_scan(self): Read a potential energy surface from a gaussian scan calculation. Returns: - A dict: {"energies": [ values ], - "coords": {"d1": [ values ], "A2", [ values ], ... }} - + dict[str, list]: {"energies": [...], "coords": {"d1": [...], "A2", [...], ... }} "energies" are the energies of all points of the potential energy surface. "coords" are the internal coordinates used to compute the potential energy surface and the internal coordinates optimized, labelled by their name as defined in the calculation. """ - - def floatList(lst): - """Return a list of float from a list of string.""" - return [float(val) for val in lst] - scan_patt = re.compile(r"^\sSummary of the potential surface scan:") optscan_patt = re.compile(r"^\sSummary of Optimized Potential Surface Scan") coord_patt = re.compile(r"^\s*(\w+)((\s*[+-]?\d+\.\d+)+)") @@ -1132,14 +1116,14 @@ def floatList(lst): line = f.readline() endScan = False while not endScan: - data["energies"] += floatList(float_patt.findall(line)) + data["energies"] += list(map(float, float_patt.findall(line))) line = f.readline() while coord_patt.match(line): icname = line.split()[0].strip() if icname in data["coords"]: - data["coords"][icname] += floatList(float_patt.findall(line)) + data["coords"][icname] += list(map(float, float_patt.findall(line))) else: - data["coords"][icname] = floatList(float_patt.findall(line)) + data["coords"][icname] = list(map(float, float_patt.findall(line))) line = f.readline() if not re.search(r"^\s+((\s*\d+)+)", line): endScan = True @@ -1152,7 +1136,7 @@ def floatList(lst): f.readline() line = f.readline() while not re.search(r"^\s-+", line): - values = floatList(line.split()) + values = list(map(float, line.split())) data["energies"].append(values[-1]) for i, icname in enumerate(data["coords"]): data["coords"][icname].append(values[i + 1]) diff --git a/pymatgen/io/lammps/data.py b/pymatgen/io/lammps/data.py index a5041edd4b2..74e2fbf6e00 100644 --- a/pymatgen/io/lammps/data.py +++ b/pymatgen/io/lammps/data.py @@ -150,10 +150,6 @@ def volume(self) -> float: matrix = self._matrix return np.dot(np.cross(matrix[0], matrix[1]), matrix[2]) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, significant_figures: int = 6) -> str: """ Returns the string representation of simulation box in LAMMPS @@ -325,10 +321,6 @@ def structure(self) -> Structure: site_properties=site_properties, ) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, distance: int = 6, velocity: int = 8, charge: int = 4, hybrid: bool = True) -> str: """ Returns the string representation of LammpsData, essentially @@ -1462,10 +1454,6 @@ def from_lammpsdata( assert atom_style == style_return, "Data have different atom_style as specified." return cls(mols, names, list_of_numbers, coordinates, style_return) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, distance: int = 6, velocity: int = 8, charge: int = 4, hybrid: bool = True) -> str: """ Returns the string representation of CombinedData, essentially diff --git a/pymatgen/io/lammps/inputs.py b/pymatgen/io/lammps/inputs.py index 40bd481df27..100eb18cc9d 100644 --- a/pymatgen/io/lammps/inputs.py +++ b/pymatgen/io/lammps/inputs.py @@ -483,10 +483,6 @@ def append(self, lmp_input_file: LammpsInputFile) -> None: # Append the two list of stages self.stages += new_list_to_add - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, ignore_comments: bool = False, keep_stages: bool = True) -> str: """ Generates and ² the string representation of the LammpsInputFile. @@ -533,16 +529,11 @@ def write_file(self, filename: str | PathLike, ignore_comments: bool = False, ke filename (str or path): The filename to output to, including path. ignore_comments (bool): True if only the commands should be kept from the InputFile. keep_stages (bool): True if the block structure from the InputFile should be kept. - If False, a single block is assumed. + If False, a single block is assumed. """ filename = filename if isinstance(filename, Path) else Path(filename) - with zopen(filename, mode="wt") as f: - f.write(self.get_str(ignore_comments=ignore_comments, keep_stages=keep_stages)) - - @classmethod - @np.deprecate(message="Use from_str instead") - def from_string(cls, *args, **kwargs) -> LammpsInputFile: - return cls.from_str(*args, **kwargs) + with zopen(filename, mode="wt") as file: + file.write(self.get_str(ignore_comments=ignore_comments, keep_stages=keep_stages)) @classmethod def from_str(cls, contents: str, ignore_comments: bool = False, keep_stages: bool = False) -> LammpsInputFile: @@ -559,7 +550,7 @@ def from_str(cls, contents: str, ignore_comments: bool = False, keep_stages: boo contents (str): String representation of LammpsInputFile. ignore_comments (bool): True if only the commands should be kept from the input file. keep_stages (bool): True if the block structure from the input file should be kept. - If False, a single block is assumed. + If False, a single block is assumed. Returns: LammpsInputFile @@ -633,7 +624,7 @@ def from_file(cls, path: str | Path, ignore_comments: bool = False, keep_stages: path (str or path): Filename to read, including path. ignore_comments (bool): True if only the commands should be kept from the input file. keep_stages (bool): True if the block structure from the input file should be kept. - If False, a single block is assumed. + If False, a single block is assumed. Returns: LammpsInputFile diff --git a/pymatgen/io/lammps/outputs.py b/pymatgen/io/lammps/outputs.py index 94fe0cb3130..4bec0b2fa2f 100644 --- a/pymatgen/io/lammps/outputs.py +++ b/pymatgen/io/lammps/outputs.py @@ -46,11 +46,6 @@ def __init__(self, timestep: int, natoms: int, box: LammpsBox, data: pd.DataFram self.box = box self.data = data - @classmethod - @np.deprecate(message="Use from_str instead") - def from_string(cls, *args, **kwargs) -> LammpsDump: - return cls.from_str(*args, **kwargs) - @classmethod def from_str(cls, string: str) -> LammpsDump: """ diff --git a/pymatgen/io/lmto.py b/pymatgen/io/lmto.py index 46479677da5..0bb66da070a 100644 --- a/pymatgen/io/lmto.py +++ b/pymatgen/io/lmto.py @@ -58,10 +58,6 @@ def __str__(self): """String representation of the CTRL file.""" return self.get_str() - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, sigfigs=8) -> str: """ Generates the string representation of the CTRL file. This is @@ -155,11 +151,6 @@ def from_file(cls, filename="CTRL", **kwargs): contents = f.read() return LMTOCtrl.from_str(contents, **kwargs) - @classmethod - @np.deprecate(message="Use from_str instead") - def from_string(cls, *args, **kwargs): - return cls.from_str(*args, **kwargs) - @classmethod @no_type_check def from_str(cls, data: str, sigfigs: int = 8) -> LMTOCtrl: diff --git a/pymatgen/io/nwchem.py b/pymatgen/io/nwchem.py index 219654c6046..196192b5c41 100644 --- a/pymatgen/io/nwchem.py +++ b/pymatgen/io/nwchem.py @@ -416,11 +416,6 @@ def from_dict(cls, d): memory_options=d["memory_options"], ) - @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_input): """ diff --git a/pymatgen/io/prismatic.py b/pymatgen/io/prismatic.py index 5a1c0e19421..80b9ae02cfd 100644 --- a/pymatgen/io/prismatic.py +++ b/pymatgen/io/prismatic.py @@ -4,8 +4,6 @@ from typing import TYPE_CHECKING -import numpy as np - if TYPE_CHECKING: from pymatgen.core import Structure @@ -25,10 +23,6 @@ def __init__(self, structure: Structure, comment: str = "Generated by pymatgen") self.structure = structure self.comment = comment - @np.deprecate(message="Use to_str instead") - def to_string(cls, *args, **kwargs): - return cls.to_str(*args, **kwargs) - def to_str(self) -> str: """ Returns: diff --git a/pymatgen/io/pwscf.py b/pymatgen/io/pwscf.py index 73a663da2ac..9a48440b275 100644 --- a/pymatgen/io/pwscf.py +++ b/pymatgen/io/pwscf.py @@ -5,7 +5,6 @@ import re from collections import defaultdict -import numpy as np from monty.io import zopen from monty.re import regrep @@ -232,11 +231,6 @@ def from_file(cls, filename): with zopen(filename, mode="rt") as f: return cls.from_str(f.read()) - @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): """ diff --git a/pymatgen/io/qchem/inputs.py b/pymatgen/io/qchem/inputs.py index f3e68844217..8d994f59948 100644 --- a/pymatgen/io/qchem/inputs.py +++ b/pymatgen/io/qchem/inputs.py @@ -6,7 +6,6 @@ import re from typing import TYPE_CHECKING, Literal -import numpy as np from monty.io import zopen from pymatgen.core import Molecule @@ -238,10 +237,6 @@ def __init__( # - Validity checks specific to job type? # - Check OPT and PCM sections? - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: """Return a string representation of an entire input file.""" return str(self) diff --git a/pymatgen/io/vasp/inputs.py b/pymatgen/io/vasp/inputs.py index 2b22f091351..caeda4a25eb 100644 --- a/pymatgen/io/vasp/inputs.py +++ b/pymatgen/io/vasp/inputs.py @@ -23,7 +23,6 @@ import numpy as np import scipy.constants as const -from monty.dev import deprecated from monty.io import zopen from monty.json import MontyDecoder, MSONable from monty.os import cd @@ -276,11 +275,6 @@ def from_file(cls, filename, check_for_potcar=True, read_velocities=True, **kwar with zopen(filename, mode="rt") as f: return cls.from_str(f.read(), names, read_velocities=read_velocities) - @classmethod - @deprecated(message="Use from_str instead") - def from_string(cls, *args, **kwargs): - return cls.from_str(*args, **kwargs) - @classmethod def from_str(cls, data, default_names=None, read_velocities=True): """ @@ -489,10 +483,6 @@ def from_str(cls, data, default_names=None, read_velocities=True): lattice_velocities=lattice_velocities, ) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, direct: bool = True, vasp4_compatible: bool = False, significant_figures: int = 16) -> str: """ Returns a string to be written as a POSCAR file. By default, site @@ -584,7 +574,7 @@ def __str__(self): def write_file(self, filename: PathLike, **kwargs): """ Writes POSCAR to a file. The supported kwargs are the same as those for - the Poscar.get_string method and are passed through directly. + the Poscar.get_str method and are passed through directly. """ with zopen(filename, mode="wt") as f: f.write(self.get_str(**kwargs)) @@ -728,10 +718,6 @@ def from_dict(cls, d) -> Incar: d["MAGMOM"] = [Magmom.from_dict(m) for m in d["MAGMOM"]] return Incar({k: v for k, v in d.items() if k not in ("@module", "@class")}) - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, sort_keys: bool = False, pretty: bool = False) -> str: """ Returns a string representation of the INCAR. The reason why this @@ -798,11 +784,6 @@ def from_file(cls, filename: PathLike) -> Incar: with zopen(filename, mode="rt") as f: return cls.from_str(f.read()) - @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) -> Incar: """Reads an Incar object from a string. @@ -1002,11 +983,6 @@ class KpointsSupportedModes(Enum): def __str__(self): return str(self.name) - @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, mode: str) -> KpointsSupportedModes: """ @@ -1365,11 +1341,6 @@ def from_file(cls, filename): with zopen(filename, mode="rt") as f: return cls.from_str(f.read()) - @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): """ diff --git a/pymatgen/io/vasp/outputs.py b/pymatgen/io/vasp/outputs.py index 79c1ed1f178..58a1774f3bd 100644 --- a/pymatgen/io/vasp/outputs.py +++ b/pymatgen/io/vasp/outputs.py @@ -3997,10 +3997,6 @@ def concatenate(self, filename, ionicstep_start=1, ionicstep_end=None): structures.append(p.structure) self.structures = structures - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self, ionicstep_start: int = 1, ionicstep_end: int | None = None, significant_figures: int = 8) -> str: """ Write Xdatcar class to a string. @@ -4048,7 +4044,7 @@ def write_file(self, filename, **kwargs): Args: filename (str): Filename of output XDATCAR file. **kwargs: Supported kwargs are the same as those for the - Xdatcar.get_string method and are passed through directly. + Xdatcar.get_str method and are passed through directly. """ with zopen(filename, mode="wt") as f: f.write(self.get_str(**kwargs)) diff --git a/pymatgen/io/xcrysden.py b/pymatgen/io/xcrysden.py index 1a75ecccf22..ed7abae488e 100644 --- a/pymatgen/io/xcrysden.py +++ b/pymatgen/io/xcrysden.py @@ -2,8 +2,6 @@ from __future__ import annotations -import numpy as np - from pymatgen.core import Element, Structure __author__ = "Matteo Giantomassi" @@ -22,10 +20,6 @@ def __init__(self, structure: Structure): """ self.structure = structure - @np.deprecate(message="Use to_str instead") - def to_string(cls, *args, **kwargs): - return cls.to_str(*args, **kwargs) - def to_str(self, atom_symbol=True): """ Returns a string with the structure in XSF format @@ -56,11 +50,6 @@ def to_str(self, atom_symbol=True): return "\n".join(lines) - @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, input_string, cls_=None): """ diff --git a/pymatgen/io/xr.py b/pymatgen/io/xr.py index 72dd6c59674..e8ff79278c3 100644 --- a/pymatgen/io/xr.py +++ b/pymatgen/io/xr.py @@ -68,11 +68,6 @@ def write_file(self, filename): with zopen(filename, mode="wt") as f: f.write(str(self) + "\n") - @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, use_cores=True, thresh=1.0e-4): """ diff --git a/pymatgen/io/xyz.py b/pymatgen/io/xyz.py index 888cab9ca69..0ede5a167b7 100644 --- a/pymatgen/io/xyz.py +++ b/pymatgen/io/xyz.py @@ -6,7 +6,6 @@ from io import StringIO from typing import TYPE_CHECKING -import numpy as np import pandas as pd from monty.io import zopen @@ -52,7 +51,7 @@ def all_molecules(self) -> list[Molecule]: return self._mols # type: ignore[return-value] @staticmethod - def _from_frame_string(contents) -> Molecule: + def _from_frame_str(contents) -> Molecule: """Convert a single frame XYZ string to a molecule.""" lines = contents.split("\n") num_sites = int(lines[0]) @@ -71,11 +70,6 @@ def _from_frame_string(contents) -> Molecule: coords.append([float(val) for val in xyz]) return Molecule(sp, coords) - @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, contents) -> XYZ: """ @@ -98,7 +92,7 @@ def from_str(cls, contents) -> XYZ: mols = [] for xyz_match in pat.finditer(contents): xyz_text = xyz_match.group(0) - mols.append(XYZ._from_frame_string(xyz_text)) + mols.append(XYZ._from_frame_str(xyz_text)) return cls(mols) @classmethod diff --git a/pymatgen/io/zeopp.py b/pymatgen/io/zeopp.py index adc1a7db51a..34e5d7f6ba9 100644 --- a/pymatgen/io/zeopp.py +++ b/pymatgen/io/zeopp.py @@ -27,7 +27,6 @@ import os import re -import numpy as np from monty.dev import requires from monty.io import zopen from monty.tempfile import ScratchDir @@ -91,11 +90,6 @@ def __str__(self): return "\n".join(output) - @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): """ diff --git a/pymatgen/symmetry/groups.py b/pymatgen/symmetry/groups.py index a3855792a78..4867193c062 100644 --- a/pymatgen/symmetry/groups.py +++ b/pymatgen/symmetry/groups.py @@ -219,7 +219,7 @@ def __init__(self, int_symbol: str) -> None: for spg in SpaceGroup.SYMM_OPS: if int_symbol in [spg["hermann_mauguin"], spg["universal_h_m"]]: - ops = [SymmOp.from_xyz_string(s) for s in spg["symops"]] + ops = [SymmOp.from_xyz_str(s) for s in spg["symops"]] self.symbol = re.sub(r":", "", re.sub(r" ", "", spg["universal_h_m"])) if int_symbol in SpaceGroup.sg_encoding: self.full_symbol = SpaceGroup.sg_encoding[int_symbol]["full_symbol"] diff --git a/pymatgen/symmetry/maggroups.py b/pymatgen/symmetry/maggroups.py index 1dc1b4d3129..faa02738030 100644 --- a/pymatgen/symmetry/maggroups.py +++ b/pymatgen/symmetry/maggroups.py @@ -121,10 +121,10 @@ def __init__(self, label, setting_transformation="a,b,c;0,0,0"): raw_data = list(c.fetchone()) # Jones Faithful transformation - self.jf = JonesFaithfulTransformation.from_transformation_string("a,b,c;0,0,0") + self.jf = JonesFaithfulTransformation.from_transformation_str("a,b,c;0,0,0") if isinstance(setting_transformation, str): if setting_transformation != "a,b,c;0,0,0": - self.jf = JonesFaithfulTransformation.from_transformation_string(setting_transformation) + self.jf = JonesFaithfulTransformation.from_transformation_str(setting_transformation) elif isinstance(setting_transformation, JonesFaithfulTransformation) and setting_transformation != self.jf: self.jf = setting_transformation @@ -441,7 +441,7 @@ def data_str(self, include_og=True): # parse data into strings # indicate if non-standard setting specified - if self.jf != JonesFaithfulTransformation.from_transformation_string("a,b,c;0,0,0"): + if self.jf != JonesFaithfulTransformation.from_transformation_str("a,b,c;0,0,0"): description += "Non-standard setting: .....\n" description += repr(self.jf) description += "\n\nStandard setting information: \n" diff --git a/pymatgen/symmetry/settings.py b/pymatgen/symmetry/settings.py index 5ce377889af..a0d3050984f 100644 --- a/pymatgen/symmetry/settings.py +++ b/pymatgen/symmetry/settings.py @@ -27,7 +27,7 @@ def __init__(self, P, p): """Transform between settings using matrix P and origin shift vector p, using same notation as reference. - Should initialize using `from_transformation_string` in Jones + Should initialize using from_transformation_str in Jones faithful notation, given by a string specifying both a transformation matrix and an origin shift, with parts delimited by a semi-colon. Best shown by example: @@ -49,16 +49,10 @@ def __init__(self, P, p): See: International Tables for Crystallography (2016). Vol. A, Chapter 1.5, pp. 75-106. """ - # using capital letters in violation of PEP8 to - # be consistent with variables in supplied reference, - # for easier debugging in future + # using capital letters in violation of PEP8 to be consistent with variables + # in supplied reference, for easier debugging in future self._P, self._p = P, p - @classmethod - @np.deprecate(message="Use from_transformation_str instead") - def from_transformation_string(cls, *args, **kwargs): # noqa: D102 - return cls.from_transformation_str(*args, **kwargs) - @classmethod def from_transformation_str(cls, transformation_string="a,b,c;0,0,0"): """Construct SpaceGroupTransformation from its transformation string. diff --git a/pymatgen/util/string.py b/pymatgen/util/string.py index d522f836689..22fd959613f 100644 --- a/pymatgen/util/string.py +++ b/pymatgen/util/string.py @@ -256,8 +256,8 @@ def unicodeify_species(specie_string): if not specie_string: return "" - for character, unicode_character in SUPERSCRIPT_UNICODE.items(): - specie_string = specie_string.replace(character, unicode_character) + for char, unicode_char in SUPERSCRIPT_UNICODE.items(): + specie_string = specie_string.replace(char, unicode_char) return specie_string diff --git a/tests/core/test_periodic_table.py b/tests/core/test_periodic_table.py index 9efbc5e81a8..b3aa9d7e41e 100644 --- a/tests/core/test_periodic_table.py +++ b/tests/core/test_periodic_table.py @@ -479,7 +479,7 @@ def test_sort(self): els = map(get_el_sp, ["N3-", "Si4+", "Si3+"]) assert sorted(els) == [Species("Si", 3), Species("Si", 4), Species("N", -3)] - def test_to_from_string(self): + def test_to_from_str(self): fe3 = Species("Fe", 3, spin=5) assert str(fe3) == "Fe3+,spin=5" fe = Species.from_str("Fe3+,spin=5") @@ -547,7 +547,7 @@ def test_eq(self): assert DummySpecies("Xg") != DummySpecies("Xg", 3) assert DummySpecies("Xg", 3) == DummySpecies("Xg", 3) - def test_from_string(self): + def test_from_str(self): sp = DummySpecies.from_str("X") assert sp.oxi_state == 0 sp = DummySpecies.from_str("X2+") diff --git a/tests/core/test_structure.py b/tests/core/test_structure.py index 14484842c50..dbba7af0995 100644 --- a/tests/core/test_structure.py +++ b/tests/core/test_structure.py @@ -1282,7 +1282,7 @@ def test_to_from_abivars(self): assert s2 == self.struct assert isinstance(s2, Structure) - def test_to_from_file_string(self): + def test_to_from_file_str(self): # to/from string for fmt in ("cif", "json", "poscar", "cssr", "yaml", "yml", "xsf", "res"): struct = self.struct.to(fmt=fmt) @@ -2013,7 +2013,7 @@ def test_default_dict_attrs(self): assert d["charge"] == 0 assert d["spin_multiplicity"] == 1 - def test_to_from_file_string(self): + def test_to_from_file_str(self): self.mol.properties["test_prop"] = 42 for fmt in ("xyz", "json", "g03", "yaml", "yml"): mol = self.mol.to(fmt=fmt) @@ -2190,7 +2190,7 @@ def test_substitute(self): benzene.substitute(13, sub) assert benzene.formula == "H9 C8 Br1" - def test_to_from_file_string(self): + def test_to_from_file_str(self): for fmt in ["xyz", "json", "g03"]: mol = self.mol.to(fmt=fmt) assert mol is not None diff --git a/tests/io/feff/test_inputs.py b/tests/io/feff/test_inputs.py index 80311af2682..266b0e499d3 100644 --- a/tests/io/feff/test_inputs.py +++ b/tests/io/feff/test_inputs.py @@ -35,7 +35,7 @@ def test_init(self): assert line == hs[i] assert header_string.splitlines() == header.splitlines(), "Failed to read HEADER file" - def test_from_string(self): + def test_from_str(self): header = Header.from_str(header_string) assert header.struct.composition.reduced_formula == "CoO", "Failed to generate structure from HEADER string" @@ -211,7 +211,7 @@ class TestFeffPot(unittest.TestCase): def test_init(self): filepath = f"{TEST_FILES_DIR}/POTENTIALS" feff_pot = Potential.pot_string_from_file(filepath) - dct, dr = Potential.pot_dict_from_string(feff_pot) + dct, dr = Potential.pot_dict_from_str(feff_pot) assert dct["Co"] == 1, "Wrong symbols read in for Potential" assert dr == {0: "O", 1: "Co", 2: "O"} diff --git a/tests/io/feff/test_outputs.py b/tests/io/feff/test_outputs.py index 40ec283ea28..ad48ab1469e 100644 --- a/tests/io/feff/test_outputs.py +++ b/tests/io/feff/test_outputs.py @@ -28,9 +28,9 @@ def test_complete_dos(self): ), "Failed to construct complete_dos dict properly" def test_as_dict_and_from_dict(self): - l2 = TestFeffLdos.ldos.charge_transfer_to_string() + l2 = TestFeffLdos.ldos.charge_transfer_to_str() d = TestFeffLdos.ldos.as_dict() - l3 = LDos.from_dict(d).charge_transfer_to_string() + l3 = LDos.from_dict(d).charge_transfer_to_str() assert l2 == l3, "Feffldos to and from dict does not match" def test_reci_init(self): diff --git a/tests/io/feff/test_sets.py b/tests/io/feff/test_sets.py index 494c89470c6..268df463cb7 100644 --- a/tests/io/feff/test_sets.py +++ b/tests/io/feff/test_sets.py @@ -52,7 +52,7 @@ def test_get_feff_tags(self): def test_get_feff_pot(self): potential = str(self.mp_xanes.potential) - dct, dr = Potential.pot_dict_from_string(potential) + dct, dr = Potential.pot_dict_from_str(potential) assert dct["Co"] == 1, "Wrong symbols read in for Potential" assert dr == {0: "O", 1: "Co", 2: "O"} diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 1fcbac00cbf..2aeeb1a9ccf 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -79,7 +79,7 @@ def test_get_str(self): assert "pe\ndump dmp all atom 5 run.dump\nmin_style cg\nfix 1 all" in string assert "box/relax iso 0.0 vmax 0.001\nminimize 1.0e-16 1.0e-16 5000 10000\nwrite_data run.data" in string - def test_from_string(self): + def test_from_str(self): string = """# LGPS # 1) Initialization diff --git a/tests/io/lammps/test_outputs.py b/tests/io/lammps/test_outputs.py index a2c072aeb42..55933bd1592 100644 --- a/tests/io/lammps/test_outputs.py +++ b/tests/io/lammps/test_outputs.py @@ -17,14 +17,14 @@ class TestLammpsDump(unittest.TestCase): @classmethod def setUpClass(cls): - with open(f"{test_dir}/dump.rdx_wc.100") as f: - rdx_str = f.read() + with open(f"{test_dir}/dump.rdx_wc.100") as file: + rdx_str = file.read() cls.rdx = LammpsDump.from_str(string=rdx_str) - with open(f"{test_dir}/dump.tatb") as f: - tatb_str = f.read() + with open(f"{test_dir}/dump.tatb") as file: + tatb_str = file.read() cls.tatb = LammpsDump.from_str(string=tatb_str) - def test_from_string(self): + def test_from_str(self): assert self.rdx.timestep == 100 assert self.rdx.natoms == 21 np.testing.assert_array_equal(self.rdx.box.bounds, np.array([(35, 48)] * 3)) diff --git a/tests/io/qchem/test_inputs.py b/tests/io/qchem/test_inputs.py index bbf456d47a3..c2c29d10de8 100644 --- a/tests/io/qchem/test_inputs.py +++ b/tests/io/qchem/test_inputs.py @@ -510,7 +510,7 @@ def test_str(self): for i_str in str_actual_list: assert i_str in str_test - def test_from_string(self): + def test_from_str(self): string = """$molecule 0 1 S -0.00250959 -0.05817469 -0.02921636 diff --git a/tests/io/test_adf.py b/tests/io/test_adf.py index 209924861c5..16a481e7c6d 100644 --- a/tests/io/test_adf.py +++ b/tests/io/test_adf.py @@ -123,7 +123,7 @@ def test_subkeys_subkeys(self): assert str(zlmfit) == zlm_fit_string assert str(AdfKey.from_dict(zlmfit.as_dict())) == zlm_fit_string - def test_from_string(self): + def test_from_str(self): k1 = AdfKey.from_str("CHARGE -1 0") assert k1.key == "CHARGE" assert k1.options == [-1, 0] diff --git a/tests/io/test_babel.py b/tests/io/test_babel.py index 67c061621e0..4c0dae7c47e 100644 --- a/tests/io/test_babel.py +++ b/tests/io/test_babel.py @@ -60,7 +60,7 @@ def test_from_molecule_graph(self): mol = adaptor.pymatgen_mol assert mol.formula == "H4 C1" - def test_from_string(self): + def test_from_str(self): xyz = XYZ(self.mol) adaptor = BabelMolAdaptor.from_str(str(xyz), "xyz") mol = adaptor.pymatgen_mol diff --git a/tests/io/test_cif.py b/tests/io/test_cif.py index 52e9400dfb6..097fd6fbb6c 100644 --- a/tests/io/test_cif.py +++ b/tests/io/test_cif.py @@ -20,7 +20,7 @@ class TestCifBlock(PymatgenTest): - def test_to_string(self): + def test_to_str(self): with open(f"{TEST_FILES_DIR}/Graphite.cif") as file: cif_str = file.read() cif_block = CifBlock.from_str(cif_str) diff --git a/tests/io/test_core.py b/tests/io/test_core.py index 8be90e8b188..bb12ebedb23 100644 --- a/tests/io/test_core.py +++ b/tests/io/test_core.py @@ -3,7 +3,6 @@ import copy import os -import numpy as np import pytest from monty.serialization import MontyDecoder @@ -19,10 +18,6 @@ class StructInputFile(InputFile): def __init__(self, structure: Structure): self.structure = structure - @np.deprecate(message="Use get_str instead") - def get_string(self, *args, **kwargs) -> str: - return self.get_str(*args, **kwargs) - def get_str(self) -> str: cw = CifWriter(self.structure) return str(cw) diff --git a/tests/io/test_fiesta.py b/tests/io/test_fiesta.py index 68ca76e3468..8be84bbe101 100644 --- a/tests/io/test_fiesta.py +++ b/tests/io/test_fiesta.py @@ -47,7 +47,7 @@ def test_init(self): cell_in = FiestaInput(mol) assert cell_in.molecule.spin_multiplicity == 1 - def test_str_and_from_string(self): + def test_str_and_from_str(self): ans = ( "# number of atoms and species\n 5 2\n# number of valence bands\n 5\n" "# number of points and spacing in eV for correlation grid\n 14 0.500\n" diff --git a/tests/io/test_gaussian.py b/tests/io/test_gaussian.py index a0ab8a984cd..f209100c6b6 100644 --- a/tests/io/test_gaussian.py +++ b/tests/io/test_gaussian.py @@ -42,7 +42,7 @@ def test_init(self): ): GaussianInput(mol, spin_multiplicity=1) - def test_str_and_from_string(self): + def test_str_and_from_str(self): answer = """#P HF/6-31G(d) SCF=Tight SP H4 C1 @@ -124,7 +124,7 @@ def test_from_file(self): 5 H -0.580711 -0.766761 3.043012""" assert str(mol) == answer - def test_from_string(self): + def test_from_str(self): gau_str = """%mem=5000000 %chk=filename # mp2/6-31g* scf=direct diff --git a/tests/io/test_nwchem.py b/tests/io/test_nwchem.py index 9a0042f6d4e..e10ffc0c107 100644 --- a/tests/io/test_nwchem.py +++ b/tests/io/test_nwchem.py @@ -60,7 +60,7 @@ def test_multi_bset(self): task dft optimize""" assert str(t) == answer - def test_str_and_from_string(self): + def test_str(self): answer = """title "dft optimize" charge 0 basis cartesian @@ -326,7 +326,7 @@ def test_as_from_dict(self): assert isinstance(nwi_symm, NwInput) json.dumps(d) - def test_from_string_and_file(self): + def test_from_str_and_file(self): nwi = NwInput.from_file(f"{test_dir}/ch4.nw") assert nwi.tasks[0].theory == "dft" assert nwi.memory_options == "total 1000 mb stack 400 mb" diff --git a/tests/io/test_prismatic.py b/tests/io/test_prismatic.py index d3348c40ecb..81330adfcd2 100644 --- a/tests/io/test_prismatic.py +++ b/tests/io/test_prismatic.py @@ -8,7 +8,7 @@ class TestPrismatic(unittest.TestCase): - def test_to_string(self): + def test_to_str(self): structure = Structure.from_file(f"{TEST_FILES_DIR}/CuCl.cif") prismatic = Prismatic(structure) prismatic_str = prismatic.to_str() diff --git a/tests/io/test_xcrysden.py b/tests/io/test_xcrysden.py index 62a61a2d67d..88973b194bd 100644 --- a/tests/io/test_xcrysden.py +++ b/tests/io/test_xcrysden.py @@ -17,7 +17,7 @@ def test_xsf(self): xsf = XSF(structure) assert structure, XSF.from_str(xsf.to_str()) - def test_to_string(self): + def test_to_str(self): structure = self.get_structure("Li2O") xsf = XSF(structure) xsf_str = xsf.to_str() diff --git a/tests/io/test_xyz.py b/tests/io/test_xyz.py index 5ba4ab77733..4d9b7a677e8 100644 --- a/tests/io/test_xyz.py +++ b/tests/io/test_xyz.py @@ -55,7 +55,7 @@ def test_str(self): H 9.487 10.889 9.637""" assert mxyz_text == ans_multi - def test_from_string(self): + def test_from_str(self): expected = """5 H4 C1 C 0.000000 0.000000 0.000000 diff --git a/tests/symmetry/test_settings.py b/tests/symmetry/test_settings.py index a4b2c3c7221..3e907e6844a 100644 --- a/tests/symmetry/test_settings.py +++ b/tests/symmetry/test_settings.py @@ -32,7 +32,7 @@ def setUp(self): def test_init(self): for test_string, test_Pp in zip(self.test_strings, self.test_Pps): - jft = JonesFaithfulTransformation.from_transformation_string(test_string) + jft = JonesFaithfulTransformation.from_transformation_str(test_string) jft2 = JonesFaithfulTransformation(test_Pp[0], test_Pp[1]) assert_allclose(jft.P, jft2.P) assert_allclose(jft.p, jft2.p) @@ -41,7 +41,7 @@ def test_init(self): def test_inverse(self): for test_string in self.test_strings: - jft = JonesFaithfulTransformation.from_transformation_string(test_string) + jft = JonesFaithfulTransformation.from_transformation_str(test_string) assert jft == jft.inverse.inverse assert jft.transformation_string == jft.inverse.inverse.transformation_string @@ -80,7 +80,7 @@ def test_transform_symmops(self): # http://cryst.ehu.es/cryst/get_gen.html # Fm-3m - input_symmops = """x,y,z + input_symm_ops = """x,y,z -x,-y,z -x,y,-z x,-y,-z @@ -130,7 +130,7 @@ def test_transform_symmops(self): z,y,x""" # Fm-3m transformed by (a-b,a+b,2c;0,0,1/2) - ref_transformed_symmops = """x,y,z + ref_transformed_symm_ops = """x,y,z -x,-y,z -y,-x,-z+1/2 y,x,-z+1/2 @@ -179,12 +179,12 @@ def test_transform_symmops(self): -1/2x+1/2y+z+1/4,1/2x-1/2y+z+1/4,-1/2x-1/2y+3/4 1/2x-1/2y+z+1/4,-1/2x+1/2y+z+1/4,1/2x+1/2y+3/4""" - jft = JonesFaithfulTransformation.from_transformation_string(self.test_strings[1]) + jft = JonesFaithfulTransformation.from_transformation_str(self.test_strings[1]) - input_symmops = [SymmOp.from_xyz_string(s) for s in input_symmops.split()] - ref_transformed_symmops = [SymmOp.from_xyz_string(s) for s in ref_transformed_symmops.split()] + input_symm_ops = [SymmOp.from_xyz_str(s) for s in input_symm_ops.split()] + ref_transformed_symm_ops = [SymmOp.from_xyz_str(s) for s in ref_transformed_symm_ops.split()] - transformed_symmops = [jft.transform_symmop(op) for op in input_symmops] + transformed_symm_ops = [jft.transform_symmop(op) for op in input_symm_ops] - for transformed_op, ref_transformed_op in zip(transformed_symmops, ref_transformed_symmops): + for transformed_op, ref_transformed_op in zip(transformed_symm_ops, ref_transformed_symm_ops): assert transformed_op == ref_transformed_op diff --git a/tests/util/test_string.py b/tests/util/test_string.py index 4c72d556abc..2a71d6c1892 100644 --- a/tests/util/test_string.py +++ b/tests/util/test_string.py @@ -90,7 +90,7 @@ def test_charge_string(self): assert charge_string(0) == "(aq)" - def test_transformation_to_string(self): + def test_transformation_to_str(self): m = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] t = [0, 0, 0] s = "x,y,z"