Skip to content

Commit

Permalink
fixes of merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWolloch committed May 16, 2024
2 parents eef83b0 + 3b620a1 commit e56f041
Show file tree
Hide file tree
Showing 25 changed files with 3,509 additions and 1,662 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: 3.8
python-version: 3.9
- name: Install py4vasp and testing tools
shell: bash -el {0}
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up poetry
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ will test whether everything worked
~~~shell
conda create --name py4vasp-env python=3.8
git clone [email protected]:vasp-dev/py4vasp.git
conda activate py4vasp-env
pip install poetry
cd py4vasp
poetry install
conda install -c conda-forge mdtraj
poetry run pytest
Expand Down
582 changes: 223 additions & 359 deletions core/poetry.lock

Large diffs are not rendered by default.

3,227 changes: 2,046 additions & 1,181 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/py4vasp/_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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")
VASP_PURPLE, VASP_CYAN, VASP_BLUE, VASP_RED, VASP_GRAY = VASP_COLORS
VASP_COLORS = ("#4C265F", "#2FB5AB", "#2C68FC", "#A82C35", "#808080", "#212529")
VASP_PURPLE, VASP_CYAN, VASP_BLUE, VASP_RED, VASP_GRAY, VASP_DARK = VASP_COLORS
4 changes: 4 additions & 0 deletions src/py4vasp/_raw/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ class OSZICAR:

convergence_data: VaspData
"All columns of the OSZICAR file stored for all ionic steps."
label: VaspData
"Label of all the data from the OSZICAR file."
is_elmin_converged: VaspData
"Is the electronic minimization step converged?"


@dataclasses.dataclass
Expand Down
2 changes: 2 additions & 0 deletions src/py4vasp/_raw/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ def selections(quantity):
schema.add(
raw.OSZICAR,
required=raw.Version(6, 5),
label="intermediate/ion_dynamics/oszicar_label",
convergence_data="intermediate/ion_dynamics/oszicar",
is_elmin_converged="/intermediate/ion_dynamics/electronic_step_converged",
)
#
group = "intermediate/pair_correlation"
Expand Down
9 changes: 7 additions & 2 deletions src/py4vasp/_third_party/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
from py4vasp._config import VASP_COLORS
import copy

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

from .contour import Contour
Expand All @@ -14,7 +16,10 @@

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]]
data = {"contour": (contour,)}
layout = {"colorway": VASP_COLORS, "xaxis": axis_format, "yaxis": axis_format}
pio.templates["vasp"] = go.layout.Template(layout=layout)
pio.templates["vasp"] = go.layout.Template(data=data, layout=layout)
pio.templates["ggplot2"].layout.shapedefaults = {}
pio.templates.default = "ggplot2+vasp"
117 changes: 101 additions & 16 deletions src/py4vasp/_third_party/graph/contour.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
from __future__ import annotations

import dataclasses
import itertools

import numpy as np

from py4vasp import _config
from py4vasp._third_party.graph import trace
from py4vasp._util import import_

ff = import_.optional("plotly.figure_factory")
go = import_.optional("plotly.graph_objects")
interpolate = import_.optional("scipy.interpolate")

Expand All @@ -17,44 +21,87 @@ class Contour(trace.Trace):
"""Represents data on a 2d slice through the unit cell.
This class creates a visualization of the data within the unit cell based on its
configuration. Currently it supports the creation of heatmaps where each datapoint
corresponds to one point on the grid.
configuration. Currently it supports the creation of heatmaps and quiver plots.
For heatmaps each data point corresponds to one point on the grid. For quiver plots
each data point should be a 2d vector within the plane.
"""

interpolation_factor = 2
_interpolation_factor = 2
"""If the lattice does not align with the cartesian axes, the data is interpolated
to by approximately this factor along each line."""
_shift_label_pixels = 10
"Shift the labels by this many pixels to avoid overlap."

data: np.array
"2d grid data in the plane spanned by the lattice vectors."
lattice: np.array
"""2d or 3d grid data in the plane spanned by the lattice vectors. If the data is
the dimensions should be the ones of the grid, if the data is 3d the first dimension
should be a 2 for a vector in the plane of the grid and the other two dimensions
should be the grid."""
lattice: Lattice
"""2 vectors spanning the plane in which the data is represented. Each vector should
have two components, so remove any element normal to the plane."""
label: str
"Assign a label to the visualization that may be used to identify one among multiple plots."
isolevels: bool = False
"Defines whether isolevels should be added or a heatmap is used."
supercell: np.array = (1, 1)
"Multiple of each lattice vector to be drawn."
show_cell: bool = True
"Show the unit cell in the resulting visualization."

def to_plotly(self):
lattice_supercell = np.diag(self.supercell) @ self.lattice
lattice_supercell = np.diag(self.supercell) @ self.lattice.vectors
# swap a and b axes because that is the way plotly expects the data
data = np.tile(self.data, self.supercell).T
if self._is_contour():
yield self._make_contour(lattice_supercell, data), self._options()
elif self._is_heatmap():
yield self._make_heatmap(lattice_supercell, data), self._options()
else:
yield self._make_quiver(lattice_supercell, data), self._options()

def _is_contour(self):
return self.data.ndim == 2 and self.isolevels

def _is_heatmap(self):
return self.data.ndim == 2 and not self.isolevels

def _make_contour(self, lattice, data):
x, y, z = self._interpolate_data_if_necessary(lattice, data)
return go.Contour(x=x, y=y, z=z, name=self.label, autocontour=True)

def _make_heatmap(self, lattice, data):
x, y, z = self._interpolate_data_if_necessary(lattice, data)
return go.Heatmap(x=x, y=y, z=z, name=self.label, colorscale="turbid_r")

def _make_quiver(self, lattice, data):
u = data[:, :, 0].flatten()
v = data[:, :, 1].flatten()
meshes = [
np.linspace(np.zeros(2), vector, num_points, endpoint=False)
for vector, num_points in zip(reversed(lattice), data.shape)
# remember that b and a axis are swapped
]
x, y = np.array([sum(points) for points in itertools.product(*meshes)]).T
fig = ff.create_quiver(x, y, u, v, scale=1)
return fig.data[0]

def _interpolate_data_if_necessary(self, lattice, data):
if self._interpolation_required():
x, y, z = self._interpolate_data(lattice_supercell, data)
x, y, z = self._interpolate_data(lattice, data)
else:
x, y, z = self._use_data_without_interpolation(lattice_supercell, data)
heatmap = go.Heatmap(x=x, y=y, z=z, name=self.label, colorscale="turbid_r")
yield heatmap, self._options()
x, y, z = self._use_data_without_interpolation(lattice, data)
return x, y, z

def _interpolation_required(self):
return not np.allclose((self.lattice[1, 0], self.lattice[0, 1]), 0)
y_position_first_vector = self.lattice.vectors[0, 1]
x_position_second_vector = self.lattice.vectors[1, 0]
return not np.allclose((y_position_first_vector, x_position_second_vector), 0)

def _interpolate_data(self, lattice, data):
area_cell = abs(np.cross(lattice[0], lattice[1]))
points_per_area = data.size / area_cell
points_per_line = np.sqrt(points_per_area) * self.interpolation_factor
points_per_line = np.sqrt(points_per_area) * self._interpolation_factor
lengths = np.sum(np.abs(lattice), axis=0)
shape = np.ceil(points_per_line * lengths).astype(int)
line_mesh_a = self._make_mesh(lattice, data.shape[1], 0)
Expand Down Expand Up @@ -83,11 +130,49 @@ def _make_mesh(self, lattice, num_point, index):
)

def _options(self):
return {
"shapes": self._create_unit_cell(),
"annotations": self._label_unit_cell_vectors(),
}

def _create_unit_cell(self):
if not self.show_cell:
return {}
return ()
pos_to_str = lambda pos: f"{pos[0]} {pos[1]}"
corners = (self.lattice[0], self.lattice[0] + self.lattice[1], self.lattice[1])
vectors = self.lattice.vectors
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_GRAY}, "path": path}
return {"shapes": [unit_cell]}
unit_cell = {"type": "path", "line": {"color": _config.VASP_DARK}, "path": path}
return (unit_cell,)

def _label_unit_cell_vectors(self):
if self.lattice.cut is None:
return []
vectors = self.lattice.vectors
labels = tuple("abc".replace(self.lattice.cut, ""))
return [
{
"text": label,
"showarrow": False,
"x": 0.5 * vectors[i, 0],
"y": 0.5 * vectors[i, 1],
**self._shift_label(vectors[i], vectors[1 - i]),
}
for i, label in enumerate(labels)
]

def _shift_label(self, current_vector, other_vector):
invert = np.cross(current_vector, other_vector) < 0
norm = np.linalg.norm(current_vector)
shifts = self._shift_label_pixels * current_vector[::-1] / norm
if invert:
return {
"xshift": -shifts[0],
"yshift": shifts[1],
}
else:
return {
"xshift": shifts[0],
"yshift": -shifts[1],
}
2 changes: 2 additions & 0 deletions src/py4vasp/_third_party/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def to_plotly(self):
figure.add_trace(trace, row=options["row"], col=1)
for shape in options.get("shapes", ()):
figure.add_shape(**shape)
for annotation in options.get("annotations", ()):
figure.add_annotation(**annotation)
return figure

def show(self):
Expand Down
Loading

0 comments on commit e56f041

Please sign in to comment.