Skip to content

Commit

Permalink
added more vasp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Aug 5, 2024
1 parent 9bc46af commit 69368f6
Show file tree
Hide file tree
Showing 13 changed files with 391,874 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/tests-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 19 additions & 12 deletions ramannoodle/io/vasp/vasp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ..io_utils import _skip_file_until_line_contains
from ...exceptions import InvalidFileException, NoMatchingLineFoundException
from ...globals import ATOMIC_NUMBERS
from ...exceptions import get_type_error


def _get_atomic_symbol_from_potcar_line(line: str) -> str:
Expand All @@ -24,12 +25,12 @@ def _get_atomic_symbol_from_potcar_line(line: str) -> str:
"""
try:
symbol = line.split()[-2].split("_")[0]
except TypeError as exc:
raise TypeError("line is not a str") from exc
except AttributeError as exc:
raise get_type_error("line", line, "str") from exc
except IndexError as exc:
raise ValueError("line does not have the expected format") from exc
raise ValueError(f"could not parse atomic symbol: {line}") from exc
if symbol not in ATOMIC_NUMBERS:
raise ValueError("line does not have the expected format")
raise ValueError(f"unrecognized atomic symbol '{symbol}': {line}")
return symbol


Expand All @@ -56,8 +57,10 @@ def _read_atomic_symbols_from_outcar(outcar_file: TextIO) -> list[str]:
line = outcar_file.readline()
if "VRHFIN" in line:
potcar_symbols.pop() # We read one too many!
except (ValueError, NoMatchingLineFoundException) as exc:
raise InvalidFileException("POTCAR block could not be parsed") from exc
except NoMatchingLineFoundException as exc:
raise InvalidFileException("POTCAR block not found") from exc
except ValueError as exc:
raise InvalidFileException(f"POTCAR block could not be parsed: {line}") from exc

# Then get atom numbers
try:
Expand All @@ -69,7 +72,9 @@ def _read_atomic_symbols_from_outcar(outcar_file: TextIO) -> list[str]:
atomic_symbols += [symbol] * number
return atomic_symbols
except (NoMatchingLineFoundException, IndexError) as exc:
raise InvalidFileException("ion number block could not be parsed") from exc
raise InvalidFileException(
f"ion number block could not be parsed: {line}"
) from exc


def _read_eigenvector_from_outcar(
Expand All @@ -91,7 +96,7 @@ def _read_eigenvector_from_outcar(
eigenvector.append([float(item) for item in line.split()[3:]])
return np.array(eigenvector)
except (ValueError, IndexError) as exc:
raise InvalidFileException("eigenvector could not be parsed") from exc
raise InvalidFileException(f"eigenvector could not be parsed: {line}") from exc


def _read_cartesian_positions_from_outcar(
Expand All @@ -116,7 +121,7 @@ def _read_cartesian_positions_from_outcar(
cartesian_coordinates.append([float(item) for item in line.split()[0:3]])
except (EOFError, ValueError, IndexError) as exc:
raise InvalidFileException(
"cartesian coordinates could not be parsed"
f"cartesian positions could not be parsed: {line}"
) from exc

return np.array(cartesian_coordinates)
Expand Down Expand Up @@ -145,7 +150,7 @@ def _read_fractional_positions_from_outcar(
fractional_coordinates.append([float(item) for item in line.split()[0:3]])
except (EOFError, ValueError, IndexError) as exc:
raise InvalidFileException(
"fractional coordinates could not be parsed"
f"fractional positions could not be parsed: {line}"
) from exc
return np.array(fractional_coordinates)

Expand Down Expand Up @@ -175,7 +180,9 @@ def _read_polarizability_from_outcar(outcar_file: TextIO) -> NDArray[np.float64]
line = outcar_file.readline()
polarizability.append([float(item) for item in line.split()[0:3]])
except (EOFError, ValueError, IndexError) as exc:
raise InvalidFileException("polarizability could not be parsed") from exc
raise InvalidFileException(
f"polarizability could not be parsed: {line}"
) from exc
return np.array(polarizability)


Expand Down Expand Up @@ -222,6 +229,6 @@ def _read_lattice_from_outcar(outcar_file: TextIO) -> NDArray[np.float64]:
line = outcar_file.readline()
lattice.append(_get_lattice_vector_from_outcar_line(line))
except (EOFError, ValueError) as exc:
raise InvalidFileException("lattice could not be parsed") from exc
raise InvalidFileException(f"lattice could not be parsed: {line}") from exc

return np.array(lattice)
File renamed without changes.
Loading

0 comments on commit 69368f6

Please sign in to comment.