Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch to allow pyzeo to work #4315

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Run the complete test suite incl. many external command line dependencies (like Openbabel)

# as well as the pymatgen.ext package. Coverage used to be computed based on this workflow.
name: Tests

Expand Down Expand Up @@ -76,6 +77,28 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install ZEO++ (Linux and macOS)
if: matrix.config.os == 'ubuntu-latest' || matrix.config.os == 'macos-latest'
run: |
# Download and extract ZEO++
wget -q http://www.zeoplusplus.org/zeo++-0.3.tar.gz
tar -xzf zeo++-0.3.tar.gz

# Compile Voro++ library first
cd zeo++-0.3/voro++/src
make

# Add Voro++ to PATH
echo "$(pwd)" >> $GITHUB_PATH

# Compile ZEO++
cd ../../
make

# Add ZEO++ to PATH
echo "$(pwd)" >> $GITHUB_PATH


- name: Install pymatgen and dependencies via uv
run: |
micromamba activate pmg
Expand Down Expand Up @@ -110,6 +133,12 @@ jobs:
PMG_TEST_FILES_DIR: "${{ github.workspace }}/tests/files"
run: |
micromamba activate pmg
# Print environment info and if ZEO++ is available
if [ "${{ matrix.config.os }}" == "ubuntu-latest" ] || [ "${{ matrix.config.os }}" == "macos-latest" ]; then
which network || echo "ZEO++ not found in PATH"
python -c "try: import zeo; print('ZEO++ Python module found'); except ImportError: print('ZEO++ Python module not found')"
fi

pytest --splits 10 --group ${{ matrix.split }} --durations-path tests/files/.pytest-split-durations tests

trigger_atomate2_ci:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ electronic_structure = ["fdint>=2.0.2"]
mlp = ["chgnet>=0.3.8", "matgl>=1.1.3"]
numba = ["numba>=0.55"]
numpy-v1 = ["numpy>=1.25.0,<2"] # Test NP1 on Windows (quite buggy ATM)
zeopp = ["pyzeo"] # Note: requires voro++ and zeo++ to be installed as binaries
optional = [
"pymatgen[abinit,ase,mlp,tblite]",
"beautifulsoup4",
Expand Down
14 changes: 12 additions & 2 deletions src/pymatgen/io/zeopp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,19 @@
from zeo.netstorage import AtomNetwork

zeo_found = True
zeo_source = "zeo"
except ImportError:
zeo_found = False
AtomNetwork = prune_voronoi_network_close_node = None
try:
from pyzeo import AtomNetwork
from pyzeo.extension import prune_voronoi_network_close_node

zeo_found = True
zeo_source = "pyzeo"
except ImportError:
zeo_found = False
zeo_source = None
AtomNetwork = prune_voronoi_network_close_node = None


if TYPE_CHECKING:
from pathlib import Path
Expand Down
21 changes: 20 additions & 1 deletion tests/io/test_zeopp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import importlib.util
import unittest
from unittest import TestCase

Expand All @@ -14,10 +15,16 @@
get_free_sphere_params,
get_high_accuracy_voronoi_nodes,
get_voronoi_nodes,
zeo_found,
zeo_source,
)
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR

pytest.importorskip("zeo", reason="zeo not installed")
# Check if either zeo or pyzeo is available
HAS_ZEO = importlib.util.find_spec("zeo") is not None or importlib.util.find_spec("pyzeo") is not None

if not HAS_ZEO:
pytest.skip("neither zeo nor pyzeo is installed", allow_module_level=True)

TEST_DIR = f"{TEST_FILES_DIR}/io/zeopp"

Expand Down Expand Up @@ -230,3 +237,15 @@ def test_get_voronoi_nodes(self):
assert isinstance(vor_node_struct, Structure)
assert isinstance(vor_edge_center_struct, Structure)
assert isinstance(vor_face_center_struct, Structure)


class TestZeoSource(TestCase):
"""Test for zeo_source to verify which library was imported."""

def test_zeo_source_is_defined(self):
"""Test that zeo_source is defined and is either 'zeo' or 'pyzeo'."""
assert zeo_source in ["zeo", "pyzeo"]

def test_zeo_found_is_true(self):
"""Test that zeo_found is True when either library is imported."""
assert zeo_found is True