Skip to content

Commit

Permalink
build: release py4vasp.0.10 (#177)
Browse files Browse the repository at this point in the history
* Bump version number
* Update documentation
* Update VASP colors
* Update numpy types for numpy 2.0
  • Loading branch information
martin-schlipf authored Dec 20, 2024
1 parent ac58bf6 commit c10cb39
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
shell: bash -el {0}
run: |
conda info
conda install -q -c conda-forge mdtraj
conda install -q -c conda-forge "mdtraj<1.10.2"
- name: Test with pytest
shell: bash -el {0}
run: |
Expand Down
2 changes: 1 addition & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "py4vasp-core"
version = "0.9.0"
version = "0.10.0"
description = "Tool for assisting with the analysis and setup of VASP calculations."
authors = [
"VASP Software GmbH <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = "VASP Software GmbH"

# The full version, including alpha/beta/rc tags
release = "0.9.0"
release = "0.10.0"


# -- General configuration ---------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions docs/convert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ latest:
- dirhtml/_packages/py4vasp.calculation
- dirhtml/_classes/py4vasp.Calculation
- dirhtml/_packages/py4vasp.calculation.*
- raw:
- dirhtml/raw
- dirhtml/api/py4vasp.raw.*
- exception:
- dirhtml/exception
- dirhtml/api/py4vasp.exception.*
20 changes: 10 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@ You can then install *py4vasp* from PyPI_ using the pip package installer
pip install py4vasp
This will automatically download *py4vasp* as well as most of the required dependencies.
However, we do not install the *mdtraj* dependency by default because it does not
reliably work with pip. We recommend to install *mdtraj* using conda

.. code-block:: bash
conda install -c conda-forge mdtraj
if you need the features that depend on it (plotting a trajectory of structures).
This will automatically download *py4vasp* and its required dependencies.

For a minimalistic setup where you use py4vasp as a library, you can install the
core package
Expand All @@ -59,7 +51,6 @@ the next VASP version is released.
git clone https://github.com/vasp-dev/py4vasp.git
cd py4vasp
pip install .
conda install -c conda-forge mdtraj
If these commands succeed, you should be able to use *py4vasp*. You can make a quick
test of your installation running the following command
Expand Down Expand Up @@ -153,6 +144,7 @@ how you can apply *py4vasp* in your research.
:recursive:

calculation
exception

.. rubric:: Classes

Expand All @@ -162,6 +154,14 @@ how you can apply *py4vasp* in your research.

Calculation


Optional dependencies
---------------------
You can install mdtraj if you want to analyze molecular dynamics trajectories
beyond the pair correlation function. We recommend using conda for the installation
which we found to be more robust than pip.


----------------------------------------------------------------------------------------

.. _venv: https://docs.python.org/3/tutorial/venv.html
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "py4vasp"
version = "0.9.0"
version = "0.10.0"
description = "Tool for assisting with the analysis and setup of VASP calculations."
authors = [
"VASP Software GmbH <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
from py4vasp._third_party.interactive import set_error_handling
from py4vasp.calculation._class import Calculation

__version__ = "0.9.0"
__version__ = "0.10.0"
set_error_handling("Minimal")
11 changes: 9 additions & 2 deletions src/py4vasp/_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
VASP_COLORS = ("#4C265F", "#2FB5AB", "#2C68FC", "#A82C35", "#808080", "#212529")
VASP_PURPLE, VASP_CYAN, VASP_BLUE, VASP_RED, VASP_GRAY, VASP_DARK = VASP_COLORS
VASP_COLORS = {
"purple": "#8342A4",
"cyan": "#35CABF",
"blue": "#3E70EA",
"red": "#A82C35",
"gray": "#424242",
"dark": "#202429",
"green": "#89AD01",
}
10 changes: 7 additions & 3 deletions src/py4vasp/_third_party/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
import copy

from py4vasp._config import VASP_BLUE, VASP_COLORS, VASP_GRAY, VASP_RED
from py4vasp._config import VASP_COLORS
from py4vasp._util import import_

from .contour import Contour
Expand All @@ -17,9 +17,13 @@
if import_.is_imported(go) and import_.is_imported(pio):
axis_format = {"showexponent": "all", "exponentformat": "power"}
contour = copy.copy(pio.templates["ggplot2"].data.contour[0])
contour.colorscale = [[0, VASP_BLUE], [0.5, VASP_GRAY], [1, VASP_RED]]
begin_blue = [0, VASP_COLORS["blue"]]
middle_gray = [0.5, VASP_COLORS["gray"]]
end_red = [1, VASP_COLORS["red"]]
contour.colorscale = [begin_blue, middle_gray, end_red]
data = {"contour": (contour,)}
layout = {"colorway": VASP_COLORS, "xaxis": axis_format, "yaxis": axis_format}
colorway = list(VASP_COLORS.values())
layout = {"colorway": colorway, "xaxis": axis_format, "yaxis": axis_format}
pio.templates["vasp"] = go.layout.Template(data=data, layout=layout)
pio.templates["ggplot2"].layout.shapedefaults = {}
pio.templates.default = "ggplot2+vasp"
3 changes: 2 additions & 1 deletion src/py4vasp/_third_party/graph/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def _create_unit_cell(self):
corners = (vectors[0], vectors[0] + vectors[1], vectors[1])
to_corners = (f"L {pos_to_str(corner)}" for corner in corners)
path = f"M 0 0 {' '.join(to_corners)} Z"
unit_cell = {"type": "path", "line": {"color": _config.VASP_DARK}, "path": path}
color = _config.VASP_COLORS["dark"]
unit_cell = {"type": "path", "line": {"color": color}, "path": path}
return (unit_cell,)

def _label_unit_cell_vectors(self):
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/_util/slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _rotate_normal_to_cartesian_axis(vectors, normal):


def _get_old_normal(vectors):
old_normal = np.cross(*vectors).astype(np.float_)
old_normal = np.cross(*vectors).astype(np.float64)
return old_normal / np.linalg.norm(old_normal)


Expand Down
7 changes: 4 additions & 3 deletions src/py4vasp/calculation/_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ def _isosurfaces(self, component, isolevel=0.2, color=None, opacity=0.6):
if self._use_symmetric_isosurface(component):
_raise_error_if_color_is_specified(color)
return [
view.Isosurface(isolevel, _config.VASP_BLUE, opacity),
view.Isosurface(-isolevel, _config.VASP_RED, opacity),
view.Isosurface(isolevel, _config.VASP_COLORS["blue"], opacity),
view.Isosurface(-isolevel, _config.VASP_COLORS["red"], opacity),
]
else:
return [view.Isosurface(isolevel, color or _config.VASP_CYAN, opacity)]
color = color or _config.VASP_COLORS["cyan"]
return [view.Isosurface(isolevel, color, opacity)]

def _use_symmetric_isosurface(self, component):
if component > 0 and self.is_nonpolarized():
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/calculation/_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def to_view(self, supercell=None):
ion_arrow = view.IonArrow(
quantity=forces,
label="forces",
color=_config.VASP_PURPLE,
color=_config.VASP_COLORS["purple"],
radius=0.2,
)
viewer.ion_arrows = [ion_arrow]
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/calculation/_magnetism.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def to_view(self, selection="total", supercell=None):
ion_arrows = view.IonArrow(
quantity=moments,
label=f"{selection} moments",
color=_config.VASP_BLUE,
color=_config.VASP_COLORS["blue"],
radius=0.2,
)
viewer.ion_arrows = [ion_arrows]
Expand Down
3 changes: 2 additions & 1 deletion src/py4vasp/calculation/_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def to_view(self, selection="total", supercell=None, **user_options):
return viewer

def _create_potential_isosurface(
self, kind, component, isolevel=0, color=_config.VASP_CYAN, opacity=0.6
self, kind, component, isolevel=0, color=None, opacity=0.6
):
self._raise_error_if_kind_incorrect(kind)
potential_data = self._get_potential(kind)
Expand All @@ -120,6 +120,7 @@ def _create_potential_isosurface(
potential = potential_data[0] - potential_data[1]
else:
potential = potential_data[0]
color = color or _config.VASP_COLORS["cyan"]
return view.GridQuantity(
quantity=potential.T[np.newaxis],
label=f"{kind} potential" + (f"({component})" if component else ""),
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/calculation/_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _topology(self):
return calculation.topology.from_data(self._raw_data.topology)

def _scale(self):
if isinstance(self._raw_data.cell.scale, np.float_):
if isinstance(self._raw_data.cell.scale, np.float64):
return self._raw_data.cell.scale
if not self._raw_data.cell.scale.is_none():
return self._raw_data.cell.scale[()]
Expand Down
2 changes: 1 addition & 1 deletion src/py4vasp/calculation/_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def to_view(self, supercell=None):
ion_arrow = view.IonArrow(
quantity=velocities,
label="velocities",
color=_config.VASP_GRAY,
color=_config.VASP_COLORS["gray"],
radius=0.2,
)
viewer.ion_arrows = [ion_arrow]
Expand Down
17 changes: 10 additions & 7 deletions tests/calculation/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def test_empty_density(empty_density):
@pytest.mark.parametrize("selection", [None, "0", "unity", "sigma_0", "scalar"])
def test_charge_plot(selection, reference_density, Assert):
source = reference_density.ref.source
isosurfaces = [Isosurface(isolevel=0.2, color=_config.VASP_CYAN, opacity=0.6)]
color = _config.VASP_COLORS["cyan"]
isosurfaces = [Isosurface(isolevel=0.2, color=color, opacity=0.6)]
if source == "charge":
expected = Expectation(
label=selection if selection else "charge",
Expand Down Expand Up @@ -156,8 +157,8 @@ def test_accessing_spin_raises_error(nonpolarized_density):
def test_collinear_plot(selection, collinear_density, Assert):
source = collinear_density.ref.source
isosurfaces = [
Isosurface(isolevel=0.1, color=_config.VASP_BLUE, opacity=0.6),
Isosurface(isolevel=-0.1, color=_config.VASP_RED, opacity=0.6),
Isosurface(isolevel=0.1, color=_config.VASP_COLORS["blue"], opacity=0.6),
Isosurface(isolevel=-0.1, color=_config.VASP_COLORS["red"], opacity=0.6),
]
if source == "charge":
expected = Expectation(
Expand Down Expand Up @@ -211,8 +212,8 @@ def test_plotting_noncollinear_density(selections, noncollinear_density, Assert)
if "(" in selections[0]: # magnetization not allowed for kinetic_energy
return
isosurfaces = [
Isosurface(isolevel=0.2, color=_config.VASP_BLUE, opacity=0.3),
Isosurface(isolevel=-0.2, color=_config.VASP_RED, opacity=0.3),
Isosurface(isolevel=0.2, color=_config.VASP_COLORS["blue"], opacity=0.3),
Isosurface(isolevel=-0.2, color=_config.VASP_COLORS["red"], opacity=0.3),
]
for selection, density, label in zip(selections, expected_density, expected_labels):
expected = Expectation(label, density, isosurfaces)
Expand All @@ -228,18 +229,20 @@ def test_adding_components(noncollinear_density, Assert):
else:
expected_label = f"{source}(1 + 2)"
expected_density = noncollinear_density.ref.output[source][1:]
color = _config.VASP_COLORS["cyan"]
expected = Expectation(
label=expected_label,
density=expected_density[0] + expected_density[1],
isosurfaces=[Isosurface(isolevel=0.4, color=_config.VASP_CYAN, opacity=0.6)],
isosurfaces=[Isosurface(isolevel=0.4, color=color, opacity=0.6)],
)
check_view(noncollinear_density, expected, Assert, selection="1 + 2", isolevel=0.4)


@pytest.mark.parametrize("supercell", [2, (3, 2, 1)])
def test_plotting_supercell(supercell, reference_density, Assert):
source = reference_density.ref.source
isosurfaces = [Isosurface(isolevel=0.2, color=_config.VASP_CYAN, opacity=0.6)]
color = _config.VASP_COLORS["cyan"]
isosurfaces = [Isosurface(isolevel=0.2, color=color, opacity=0.6)]
if source == "charge":
expected = Expectation(
label=source,
Expand Down
2 changes: 1 addition & 1 deletion tests/calculation/test_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_plot(forces, steps, supercell, Assert):
assert arrows.quantity.ndim == 3
Assert.allclose(arrows.quantity, forces.force_rescale * forces.ref.forces[steps])
assert arrows.label == "forces"
assert arrows.color == _config.VASP_PURPLE
assert arrows.color == _config.VASP_COLORS["purple"]
assert arrows.radius == 0.2


Expand Down
2 changes: 1 addition & 1 deletion tests/calculation/test_magnetism.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def check_view(view, reference_moments, selection, Assert):
Assert.allclose(arrows.quantity, reference_moments)
expected_label = f"{selection} moments" if selection else "total moments"
assert arrows.label == expected_label
assert arrows.color == _config.VASP_BLUE
assert arrows.color == _config.VASP_COLORS["blue"]
assert arrows.radius == 0.2


Expand Down
15 changes: 10 additions & 5 deletions tests/calculation/test_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ def test_read(reference_potential, Assert):

def test_plot_total_potential(reference_potential, Assert):
view = reference_potential.plot()
color = _config.VASP_COLORS["cyan"]
expectation = Expectation(
label="total potential",
potential=reference_potential.ref.output["total"],
isosurface=Isosurface(isolevel=0, color=_config.VASP_CYAN, opacity=0.6),
isosurface=Isosurface(isolevel=0, color=color, opacity=0.6),
)
check_view(reference_potential, view, [expectation], Assert)

Expand All @@ -114,10 +115,11 @@ def test_plot_selected_potential(reference_potential, Assert):
else:
selection = "total"
view = reference_potential.plot(selection, isolevel=0.2)
color = _config.VASP_COLORS["cyan"]
expectation = Expectation(
label=f"{selection} potential",
potential=reference_potential.ref.output[selection],
isosurface=Isosurface(isolevel=0.2, color=_config.VASP_CYAN, opacity=0.6),
isosurface=Isosurface(isolevel=0.2, color=color, opacity=0.6),
)
check_view(reference_potential, view, [expectation], Assert)

Expand All @@ -126,18 +128,20 @@ def test_plot_selected_potential(reference_potential, Assert):
def test_plot_spin_potential(raw_data, selection, Assert):
potential = make_reference_potential(raw_data, "Fe3O4 collinear", "total")
view = potential.plot(selection, opacity=0.3)
color = _config.VASP_COLORS["cyan"]
expectation = Expectation(
label=f"total potential({selection})",
potential=potential.ref.output[f"total_{selection}"],
isosurface=Isosurface(isolevel=0.0, color=_config.VASP_CYAN, opacity=0.3),
isosurface=Isosurface(isolevel=0.0, color=color, opacity=0.3),
)
check_view(potential, view, [expectation], Assert)


def test_plot_multiple_selections(raw_data, Assert):
potential = make_reference_potential(raw_data, "Fe3O4 collinear", "all")
view = potential.plot("up(total) hartree xc(down)")
isosurface = Isosurface(isolevel=0.0, color=_config.VASP_CYAN, opacity=0.6)
color = _config.VASP_COLORS["cyan"]
isosurface = Isosurface(isolevel=0.0, color=color, opacity=0.6)
expectations = [
Expectation(
label="total potential(up)",
Expand All @@ -162,10 +166,11 @@ def test_plot_multiple_selections(raw_data, Assert):
def test_plot_supercell(raw_data, supercell, Assert):
potential = make_reference_potential(raw_data, "Sr2TiO4", "total")
view = potential.plot(supercell=supercell)
color = _config.VASP_COLORS["cyan"]
expectation = Expectation(
label="total potential",
potential=potential.ref.output[f"total"],
isosurface=Isosurface(isolevel=0, color=_config.VASP_CYAN, opacity=0.6),
isosurface=Isosurface(isolevel=0, color=color, opacity=0.6),
)
check_view(potential, view, [expectation], Assert, supercell=supercell)

Expand Down
2 changes: 1 addition & 1 deletion tests/calculation/test_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_plot(velocities, steps, supercell, Assert):
expected_velocities = velocities.velocity_rescale * velocities.ref.velocities[steps]
Assert.allclose(arrows.quantity, expected_velocities)
assert arrows.label == "velocities"
assert arrows.color == _config.VASP_GRAY
assert arrows.color == _config.VASP_COLORS["gray"]
assert arrows.radius == 0.2


Expand Down
2 changes: 1 addition & 1 deletion tests/third_party/graph/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_contour_supercell(rectangle_contour, Assert, not_core):
def check_unit_cell(unit_cell, x, y, zero):
assert unit_cell.type == "path"
assert unit_cell.path == f"M 0 0 L {x} {zero} L {x} {y} L {zero} {y} Z"
assert unit_cell.line.color == _config.VASP_DARK
assert unit_cell.line.color == _config.VASP_COLORS["dark"]


def check_annotations(lattice, annotations, Assert):
Expand Down
7 changes: 4 additions & 3 deletions tests/util/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def test_matrix_to_complex(Assert):


def test_hex_to_rgb(Assert):
colors = [
colors = ("#4C265F", "#2FB5AB", "#2C68FC", "#A82C35", "#808080", "#212529")
converted = [
[76, 38, 95],
[47, 181, 171],
[44, 104, 252],
[168, 44, 53],
[128, 128, 128],
[33, 37, 41],
]
expected = np.array(colors) / 255
actual = np.array([to_rgb(color) for color in VASP_COLORS])
expected = np.array(converted) / 255
actual = np.array([to_rgb(color) for color in colors])
Assert.allclose(expected, actual)

0 comments on commit c10cb39

Please sign in to comment.