Skip to content

Commit 4d9e503

Browse files
patch to allow pyzeo to work (#4315)
1 parent 9523e3c commit 4d9e503

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

.github/workflows/test.yml

+29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Run the complete test suite incl. many external command line dependencies (like Openbabel)
2+
23
# as well as the pymatgen.ext package. Coverage used to be computed based on this workflow.
34
name: Tests
45

@@ -76,6 +77,28 @@ jobs:
7677
- name: Install uv
7778
uses: astral-sh/setup-uv@v4
7879

80+
- name: Install ZEO++ (Linux and macOS)
81+
if: matrix.config.os == 'ubuntu-latest' || matrix.config.os == 'macos-latest'
82+
run: |
83+
# Download and extract ZEO++
84+
wget -q http://www.zeoplusplus.org/zeo++-0.3.tar.gz
85+
tar -xzf zeo++-0.3.tar.gz
86+
87+
# Compile Voro++ library first
88+
cd zeo++-0.3/voro++/src
89+
make
90+
91+
# Add Voro++ to PATH
92+
echo "$(pwd)" >> $GITHUB_PATH
93+
94+
# Compile ZEO++
95+
cd ../../
96+
make
97+
98+
# Add ZEO++ to PATH
99+
echo "$(pwd)" >> $GITHUB_PATH
100+
101+
79102
- name: Install pymatgen and dependencies via uv
80103
run: |
81104
micromamba activate pmg
@@ -110,6 +133,12 @@ jobs:
110133
PMG_TEST_FILES_DIR: "${{ github.workspace }}/tests/files"
111134
run: |
112135
micromamba activate pmg
136+
# Print environment info and if ZEO++ is available
137+
if [ "${{ matrix.config.os }}" == "ubuntu-latest" ] || [ "${{ matrix.config.os }}" == "macos-latest" ]; then
138+
which network || echo "ZEO++ not found in PATH"
139+
python -c "try: import zeo; print('ZEO++ Python module found'); except ImportError: print('ZEO++ Python module not found')"
140+
fi
141+
113142
pytest --splits 10 --group ${{ matrix.split }} --durations-path tests/files/.pytest-split-durations tests
114143
115144
trigger_atomate2_ci:

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ electronic_structure = ["fdint>=2.0.2"]
9595
mlp = ["chgnet>=0.3.8", "matgl>=1.1.3"]
9696
numba = ["numba>=0.55"]
9797
numpy-v1 = ["numpy>=1.25.0,<2"] # Test NP1 on Windows (quite buggy ATM)
98+
zeopp = ["pyzeo"] # Note: requires voro++ and zeo++ to be installed as binaries
9899
optional = [
99100
"pymatgen[abinit,ase,mlp,tblite]",
100101
"beautifulsoup4",

src/pymatgen/io/zeopp.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@
4242
from zeo.netstorage import AtomNetwork
4343

4444
zeo_found = True
45+
zeo_source = "zeo"
4546
except ImportError:
46-
zeo_found = False
47-
AtomNetwork = prune_voronoi_network_close_node = None
47+
try:
48+
from pyzeo import AtomNetwork
49+
from pyzeo.extension import prune_voronoi_network_close_node
50+
51+
zeo_found = True
52+
zeo_source = "pyzeo"
53+
except ImportError:
54+
zeo_found = False
55+
zeo_source = None
56+
AtomNetwork = prune_voronoi_network_close_node = None
57+
4858

4959
if TYPE_CHECKING:
5060
from pathlib import Path

tests/io/test_zeopp.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import importlib.util
34
import unittest
45
from unittest import TestCase
56

@@ -14,10 +15,16 @@
1415
get_free_sphere_params,
1516
get_high_accuracy_voronoi_nodes,
1617
get_voronoi_nodes,
18+
zeo_found,
19+
zeo_source,
1720
)
1821
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR
1922

20-
pytest.importorskip("zeo", reason="zeo not installed")
23+
# Check if either zeo or pyzeo is available
24+
HAS_ZEO = importlib.util.find_spec("zeo") is not None or importlib.util.find_spec("pyzeo") is not None
25+
26+
if not HAS_ZEO:
27+
pytest.skip("neither zeo nor pyzeo is installed", allow_module_level=True)
2128

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

@@ -230,3 +237,15 @@ def test_get_voronoi_nodes(self):
230237
assert isinstance(vor_node_struct, Structure)
231238
assert isinstance(vor_edge_center_struct, Structure)
232239
assert isinstance(vor_face_center_struct, Structure)
240+
241+
242+
class TestZeoSource(TestCase):
243+
"""Test for zeo_source to verify which library was imported."""
244+
245+
def test_zeo_source_is_defined(self):
246+
"""Test that zeo_source is defined and is either 'zeo' or 'pyzeo'."""
247+
assert zeo_source in ["zeo", "pyzeo"]
248+
249+
def test_zeo_found_is_true(self):
250+
"""Test that zeo_found is True when either library is imported."""
251+
assert zeo_found is True

0 commit comments

Comments
 (0)