Skip to content

Commit

Permalink
changed all _A to dict handling of InfoAttr
Browse files Browse the repository at this point in the history
Added more typing in orca and vasp siles

Signed-off-by: Nick Papior <[email protected]>
  • Loading branch information
zerothi committed Oct 28, 2024
1 parent a57d235 commit 70cbf77
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 64 deletions.
61 changes: 30 additions & 31 deletions src/sisl/io/orca/stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import annotations

from typing import Literal, Optional, Union

import numpy as np

from sisl._internal import set_module
Expand All @@ -18,37 +20,34 @@
__all__ = ["outputSileORCA", "stdoutSileORCA"]


_A = SileORCA.InfoAttr


@set_module("sisl.io.orca")
class stdoutSileORCA(SileORCA):
"""Output file from ORCA"""

_info_attributes_ = [
_A(
"na",
r".*Number of atoms",
lambda attr, instance, match: int(match.string.split()[-1]),
dict(
name="na",
searcher=r".*Number of atoms",
parser=lambda attr, instance, match: int(match.string.split()[-1]),
not_found="error",
),
_A(
"no",
r".*Number of basis functions",
lambda attr, instance, match: int(match.string.split()[-1]),
dict(
name="no",
searcher=r".*Number of basis functions",
parser=lambda attr, instance, match: int(match.string.split()[-1]),
not_found="error",
),
_A(
"vdw_correction",
r".*DFT DISPERSION CORRECTION",
lambda attr, instance, match: True,
dict(
name="vdw_correction",
searcher=r".*DFT DISPERSION CORRECTION",
parser=lambda attr, instance, match: True,
default=False,
not_found="ignore",
),
_A(
"completed",
r".*ORCA TERMINATED NORMALLY",
lambda attr, instance, match: True,
dict(
name="completed",
searcher=r".*ORCA TERMINATED NORMALLY",
parser=lambda attr, instance, match: True,
default=False,
not_found="warn",
),
Expand Down Expand Up @@ -85,7 +84,7 @@ def no(self):

@SileBinder(postprocess=np.array)
@sile_fh_open()
def read_electrons(self):
def read_electrons(self) -> Optional[tuple[float, float]]:
"""Read number of electrons (alpha, beta)
Returns
Expand All @@ -105,25 +104,25 @@ def read_electrons(self):
@sile_fh_open()
def read_charge(
self,
name="mulliken",
projection="orbital",
name: Literal["mulliken", "loewdin"] = "mulliken",
projection: Literal["orbital", "atom"] = "orbital",
orbitals=None,
reduced=True,
spin=False,
):
reduced: bool = True,
spin: bool = False,
) -> Union[PropertyDict, np.ndarray]:
"""Reads from charge (or spin) population analysis
Parameters
----------
name : {'mulliken', 'loewdin'}
name :
name of the charge scheme to be read
projection : {'orbital', 'atom'}
projection :
whether to get orbital- or atom-resolved quantities
orbitals : str, optional
allows to extract the atom-resolved orbitals matching this keyword
reduced : bool, optional
reduced :
whether to search for full or reduced orbital projections
spin : bool, optional
spin :
whether to return the spin block instead of charge
Returns
Expand Down Expand Up @@ -276,7 +275,7 @@ def read_block(step_to):

@SileBinder()
@sile_fh_open()
def read_energy(self, units: UnitsVar = "eV"):
def read_energy(self, units: UnitsVar = "eV") -> Optional[PropertyDict]:
"""Reads the energy blocks
Parameters
Expand Down Expand Up @@ -329,7 +328,7 @@ def read_energy(self, units: UnitsVar = "eV"):

@SileBinder()
@sile_fh_open()
def read_orbital_energies(self, units: UnitsVar = "eV"):
def read_orbital_energies(self, units: UnitsVar = "eV") -> Optional[np.ndarray]:
"""Reads the "ORBITAL ENERGIES" blocks
Parameters
Expand Down
32 changes: 16 additions & 16 deletions src/sisl/io/orca/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import annotations

from typing import Optional

import numpy as np

from sisl._core.geometry import Geometry
Expand All @@ -18,30 +20,28 @@

__all__ = ["txtSileORCA"]

_A = SileORCA.InfoAttr


@set_module("sisl.io.orca")
class txtSileORCA(SileORCA):
"""Output from the ORCA property.txt file"""

_info_attributes_ = [
_A(
"na",
r".*Number of atoms:",
lambda attr, instance, match: int(match.string.split()[-1]),
dict(
name="na",
searcher=r".*Number of atoms:",
parser=lambda attr, instance, match: int(match.string.split()[-1]),
not_found="error",
),
_A(
"no",
r".*number of basis functions:",
lambda attr, instance, match: int(match.string.split()[-1]),
dict(
name="no",
searcher=r".*number of basis functions:",
parser=lambda attr, instance, match: int(match.string.split()[-1]),
not_found="error",
),
_A(
"vdw_correction",
r".*\$ VdW_Correction",
lambda attr, instance, match: True,
dict(
name="vdw_correction",
searcher=r".*\$ VdW_Correction",
parser=lambda attr, instance, match: True,
default=False,
not_found="ignore",
),
Expand All @@ -65,7 +65,7 @@ def no(self):

@SileBinder(postprocess=np.array)
@sile_fh_open()
def read_electrons(self):
def read_electrons(self) -> Optional[tuple[float, float]]:
"""Read number of electrons (alpha, beta)
Returns
Expand All @@ -83,7 +83,7 @@ def read_electrons(self):

@SileBinder()
@sile_fh_open()
def read_energy(self, units: UnitsVar = "eV"):
def read_energy(self, units: UnitsVar = "eV") -> PropertyDict:
"""Reads the energy blocks
Parameters
Expand Down
9 changes: 3 additions & 6 deletions src/sisl/io/vasp/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
__all__ = ["carSileVASP"]


_A = SileVASP.InfoAttr


def _search_name(info, instance, line):
"""Names for CAR files are always in the first line"""
return instance._line == 1
Expand All @@ -34,9 +31,9 @@ class carSileVASP(SileVASP):
"""

_info_attributes_ = [
_A(
"name",
_search_name,
dict(
name="name",
searcher=_search_name,
default="<unknown>",
not_found="error",
),
Expand Down
19 changes: 8 additions & 11 deletions src/sisl/io/vasp/outcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@
__all__ = ["outcarSileVASP"]


_A = SileVASP.InfoAttr


@set_module("sisl.io.vasp")
class outcarSileVASP(SileVASP):
"""OUTCAR file from VASP"""

_info_attributes_ = [
_A(
"completed",
r".*General timing and accounting",
lambda attr, instance, match: lambda: True,
dict(
name="completed",
searcher=r".*General timing and accounting",
parser=lambda attr, instance, match: lambda: True,
default=lambda: False,
not_found="warn",
),
_A(
"accuracy_reached",
r".*reached required accuracy",
lambda attr, instance, match: lambda: True,
dict(
name="accuracy_reached",
searcher=r".*reached required accuracy",
parser=lambda attr, instance, match: lambda: True,
default=lambda: False,
not_found="warn",
),
Expand Down

0 comments on commit 70cbf77

Please sign in to comment.