diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 62559c8fc65..ba774660509 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -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: diff --git a/pyproject.toml b/pyproject.toml index e6d054e20da..aa7041532a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/src/pymatgen/io/zeopp.py b/src/pymatgen/io/zeopp.py index 64f1557f4d1..358951e7c99 100644 --- a/src/pymatgen/io/zeopp.py +++ b/src/pymatgen/io/zeopp.py @@ -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 diff --git a/tests/io/test_zeopp.py b/tests/io/test_zeopp.py index 819f13a2ee8..ad03e9f33f0 100644 --- a/tests/io/test_zeopp.py +++ b/tests/io/test_zeopp.py @@ -1,5 +1,6 @@ from __future__ import annotations +import importlib.util import unittest from unittest import TestCase @@ -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" @@ -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