Skip to content

Commit

Permalink
Revert "add some types for io.exciting inputs"
Browse files Browse the repository at this point in the history
This reverts commit 1b501fc.
  • Loading branch information
DanielYang59 committed Jan 4, 2025
1 parent 1b501fc commit 0e1d11e
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions src/pymatgen/io/exciting/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
from pymatgen.symmetry.bandstructure import HighSymmKpath

if TYPE_CHECKING:
from typing import Literal
from pathlib import Path

from numpy.typing import ArrayLike
from typing_extensions import Self

from pymatgen.util.typing import PathLike

__author__ = "Christian Vorwerk"
__copyright__ = "Copyright 2016"
__version__ = "1.0"
Expand All @@ -40,10 +37,10 @@ class ExcitingInput(MSONable):
Attributes:
structure (Structure): Associated Structure.
title (str): Optional title string.
lockxyz (NDArray): Lockxyz attribute for each site if available. A Nx3 array of booleans.
lockxyz (numpy.ndarray): Lockxyz attribute for each site if available. A Nx3 array of booleans.
"""

def __init__(self, structure: Structure, title: str | None = None, lockxyz: ArrayLike | None = None):
def __init__(self, structure: Structure, title=None, lockxyz=None):
"""
Args:
structure (Structure): Structure object.
Expand All @@ -55,7 +52,7 @@ def __init__(self, structure: Structure, title: str | None = None, lockxyz: Arra
if structure.is_ordered:
site_properties = {}
if lockxyz:
site_properties["selective_dynamics"] = np.asarray(lockxyz)
site_properties["selective_dynamics"] = lockxyz
self.structure = structure.copy(site_properties=site_properties)
self.title = structure.formula if title is None else title
else:
Expand Down Expand Up @@ -167,7 +164,7 @@ def from_str(cls, data: str) -> Self:
return cls(structure_in, title_in, lockxyz)

@classmethod
def from_file(cls, filename: PathLike) -> Self:
def from_file(cls, filename: str | Path) -> Self:
"""
Args:
filename: Filename.
Expand All @@ -181,11 +178,11 @@ def from_file(cls, filename: PathLike) -> Self:

def write_etree(
self,
celltype: Literal["unchanged", "conventional", "primitive"],
cartesian: bool = False,
bandstr: bool = False,
celltype,
cartesian=False,
bandstr=False,
symprec: float = 0.4,
angle_tolerance: float = 5,
angle_tolerance=5,
**kwargs,
):
"""Write the exciting input parameters to an XML object.
Expand All @@ -194,14 +191,19 @@ def write_etree(
celltype (str): Choice of unit cell. Can be either the unit cell
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
cartesian (bool): Whether the atomic positions are provided in
Cartesian or unit-cell coordinates. Default is False.
bandstr (bool): Whether the bandstructure path along the
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
symprec (float): Tolerance for the symmetry finding. Default is 0.4.
angle_tolerance (float): Angle tolerance for the symmetry finding.
Default is 5.
Default is 5.
**kwargs: Additional parameters for the input file.
Returns:
Expand Down Expand Up @@ -295,27 +297,32 @@ def write_etree(

def write_string(
self,
celltype: Literal["unchanged", "conventional", "primitive"],
cartesian: bool = False,
bandstr: bool = False,
celltype,
cartesian=False,
bandstr=False,
symprec: float = 0.4,
angle_tolerance: float = 5,
angle_tolerance=5,
**kwargs,
) -> str:
"""Convert exciting input.xml to a string.
):
"""Write exciting input.xml as a string.
Args:
celltype (str): Choice of unit cell. Can be either the unit cell
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
cartesian (bool): Whether the atomic positions are provided in
Cartesian or unit-cell coordinates. Default is False.
Cartesian or unit-cell coordinates. Default is False.
bandstr (bool): Whether the bandstructure path along the
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
symprec (float): Tolerance for the symmetry finding. Default is 0.4.
angle_tolerance (float): Angle tolerance for the symmetry finding.
Default is 5.
Default is 5.
**kwargs: Additional parameters for the input file.
Returns:
Expand All @@ -326,37 +333,41 @@ def write_string(
self._indent(root)
# output should be a string not a bytes object
string = ET.tostring(root).decode("UTF-8")

except Exception:
raise ValueError("Incorrect celltype!")

return string

def write_file(
self,
celltype: Literal["unchanged", "conventional", "primitive"],
filename: str,
cartesian: bool = False,
bandstr: bool = False,
celltype,
filename,
cartesian=False,
bandstr=False,
symprec: float = 0.4,
angle_tolerance: float = 5,
angle_tolerance=5,
**kwargs,
) -> None:
):
"""Write exciting input file.
Args:
celltype (str): Choice of unit cell. Can be either the unit cell
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
filename (str): Filename for exciting input.
cartesian (bool): Whether the atomic positions are provided in
Cartesian or unit-cell coordinates. Default is False.
Cartesian or unit-cell coordinates. Default is False.
bandstr (bool): Whether the bandstructure path along the
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
symprec (float): Tolerance for the symmetry finding. Default is 0.4.
angle_tolerance (float): Angle tolerance for the symmetry finding.
Default is 5.
Default is 5.
**kwargs: Additional parameters for the input file.
"""
try:
Expand All @@ -369,7 +380,7 @@ def write_file(

# Missing PrettyPrint option in the current version of xml.etree.cElementTree
@staticmethod
def _indent(elem, level: int = 0) -> None:
def _indent(elem, level=0):
"""
Helper method to indent elements.
Expand All @@ -390,7 +401,7 @@ def _indent(elem, level: int = 0) -> None:
elif level and (not elem.tail or not elem.tail.strip()):
elem.tail = i

def _dicttoxml(self, paramdict_, element) -> None:
def _dicttoxml(self, paramdict_, element):
for key, value in paramdict_.items():
if isinstance(value, str) and key == "text()":
element.text = value
Expand Down

0 comments on commit 0e1d11e

Please sign in to comment.