Skip to content

Commit

Permalink
Update dependencies to allow for numpy 2.0 (#195)
Browse files Browse the repository at this point in the history
* Update dependencies to allow for numpy 2.0
* Make eigenvectors robust against sign changes
  • Loading branch information
martin-schlipf authored Feb 21, 2025
1 parent 212ae4e commit 15d66bf
Show file tree
Hide file tree
Showing 12 changed files with 1,976 additions and 1,695 deletions.
489 changes: 273 additions & 216 deletions core/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repository = "https://github.com/vasp-dev/py4vasp"

[tool.poetry.dependencies]
python = ">=3.9"
numpy = "^1.23"
numpy = ">=1.23"
h5py = ">=3.7.0"

[tool.poetry.group.dev.dependencies]
Expand Down
2,952 changes: 1,579 additions & 1,373 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repository = "https://github.com/vasp-dev/py4vasp"

[tool.poetry.dependencies]
python = ">=3.9"
numpy = "^1.23"
numpy = ">=1.23"
h5py = ">=3.7.0"
pandas = ">=1.4.3"
nglview = ">=3.0.5"
Expand Down
6 changes: 4 additions & 2 deletions src/py4vasp/_calculation/force_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ def _format_eigenvectors(self, eigenvectors):
)

def _format_eigenvector(self, index, eigenvector):
sign = np.sign(eigenvector.flatten()[np.argmax(np.abs(eigenvector))])
eigenvector_string = "\n".join(
self._format_vector(vector) for vector in eigenvector
self._format_vector(sign * vector) for vector in eigenvector
)
return f"vibration {index + 1}\n{eigenvector_string}"

def _format_vector(self, vector):
return " ".join(f"{x:12.6f}" for x in vector)
replace_nearly_zeros = lambda x: 0 if np.isclose(x, 0, atol=1e-9) else x
return " ".join(f"{replace_nearly_zeros(x):12.6f}" for x in vector)


@dataclasses.dataclass
Expand Down
1 change: 1 addition & 0 deletions src/py4vasp/_calculation/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@dataclass
class Selection:
"Helper class specifying which indices to extract their label."

indices: Iterable[int]
"Indices from which the specified quantity is read."
label: str = ""
Expand Down
8 changes: 8 additions & 0 deletions src/py4vasp/_raw/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def NONE():
@dataclasses.dataclass(order=True, frozen=True)
class Version:
"The version number of VASP."

major: int
"The major version number."
minor: int = 0
Expand Down Expand Up @@ -126,6 +127,7 @@ class CurrentDensity(mapping.Mapping):
@dataclasses.dataclass
class Density:
"The electronic charge and magnetization density on the Fourier grid."

structure: Structure
"The atomic structure to represent the densities."
charge: VaspData
Expand Down Expand Up @@ -247,6 +249,7 @@ class Energy:
@dataclasses.dataclass
class ExcitonDensity:
"The exciton charge density on the real space grid."

structure: Structure
"The atomic structure to represent the densities."
exciton_charge: VaspData
Expand Down Expand Up @@ -500,6 +503,7 @@ class Projector:
@dataclasses.dataclass
class Stoichiometry:
"Contains the type of ions in the system and how many of each type exist."

number_ion_types: VaspData
"Amount of ions of a particular type."
ion_types: VaspData
Expand All @@ -509,6 +513,7 @@ class Stoichiometry:
@dataclasses.dataclass
class Stress:
"The stress acting on the unit cell at all steps."

structure: Structure
"Structural information about the system to inform about the unit cell."
stress: VaspData
Expand All @@ -533,12 +538,14 @@ class Structure:
@dataclasses.dataclass
class System:
"The name of the system set in the input."

system: str


@dataclasses.dataclass
class Velocity:
"Contains the ion velocities along the trajectory."

structure: Structure
"Structural information to relate the velocities to."
velocities: VaspData
Expand All @@ -548,6 +555,7 @@ class Velocity:
@dataclasses.dataclass
class Workfunction:
"Describes the minimal energy needed to remove an electron from the crystal to the vacuum."

idipol: int
"INCAR tag of VASP describing the direction along which the potential is assessed."
distance: VaspData
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/_util/index.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
""" Select indices from an array based on a map.
"""Select indices from an array based on a map.
In multiple cases, VASP produces multiple outputs and the user wants to select one of
its components e.g. plotting the p DOS. This module provides the Selector class that
Expand Down
4 changes: 3 additions & 1 deletion src/py4vasp/_util/select.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
""" Parse a string to a Tree of selections.
"""Parse a string to a Tree of selections.
In many cases, a user may want to select a certain subset of quantities to be refined.
Examples include selecting the projected DOS or a particular component of the energy.
Expand Down Expand Up @@ -318,6 +318,7 @@ def _raise_error_if_content_and_operator_are_incompatible(self, operand):
@dataclasses.dataclass
class Group:
"A user selection where multiple elements should be treated together."

group: list
"The individual members of the group."
separator: str
Expand All @@ -341,6 +342,7 @@ class _Operator:
@dataclasses.dataclass
class Operation:
"A mathematical operation like addition and subtraction."

left_operand: tuple
"The selection on the left-hand side of the operation."
operator: str
Expand Down
3 changes: 2 additions & 1 deletion src/py4vasp/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
"""Deals with the possible exceptions in py4vasp.
The design goal is that all foreseeable exceptions in py4vasp issue an exception of the Py4VaspException class. Any other kind of exception would indicate a bug in the code. If possible the part standard users interact with should not raise any exception, but should give advice on how to overcome the issue."""
The design goal is that all foreseeable exceptions in py4vasp issue an exception of the Py4VaspException class. Any other kind of exception would indicate a bug in the code. If possible the part standard users interact with should not raise any exception, but should give advice on how to overcome the issue.
"""


class Py4VaspError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/raw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
""" Extract the raw data from the HDF5 file and transform it into dataclasses.
"""Extract the raw data from the HDF5 file and transform it into dataclasses.
In the HDF5 file, the raw data is stored with specific keys. To avoid
propagating the name of these keys to the higher tier modules, we transform
Expand Down
Loading

0 comments on commit 15d66bf

Please sign in to comment.