Skip to content

Commit

Permalink
Refactored project setup, added tests to CI, updated Cython.
Browse files Browse the repository at this point in the history
  • Loading branch information
lauri-codes committed Aug 20, 2024
1 parent 2cd206d commit 5878963
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 155 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will install Python dependencies, run tests and lint with a
# variety of Python versions For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: test

on:
push:
branches: [ "main"]
pull_request:
branches: [ "main"]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
cd ${GITHUB_WORKSPACE}/scripts && ./setup.sh
- name: Run unit tests
run: |
cd ${GITHUB_WORKSPACE}/scripts && ./test.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Python wrapper for the [Zeo++ library](http://zeoplusplus.org). Based on the lat

## Installation

We provide pre-built wheels for most platforms (including Apple Silicon). So in most cases you will want to install the package with `pip`:
We provide pre-built wheels for several platforms (including Apple Silicon). So in most cases you will want to install the package with `pip`:

```sh
pip install pyzeo
Expand Down
40 changes: 40 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = 'pyzeo'
version = '0.1.6'
description = 'Python interface to Zeo++'
readme = "README.md"
authors = [{ name = "Lauri Himanen" }]
license = { file = "LICENSE" }
requires-python = ">=3.8"
dependencies = []
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: C++",
"Programming Language :: Cython",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering"
]
keywords = ['zeo++', 'porous', 'materials', 'science']

[project.urls]
Source = "https://github.com/nomad-coe/pyzeo"

[project.optional-dependencies]
dev = [
"pytest",
]

[tool.setuptools.package-dir]
"" = "src"
3 changes: 3 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd ..
python -m pip install --upgrade pip
pip install .[dev]
3 changes: 3 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
cd ../tests
pytest
36 changes: 3 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import platform
from distutils.ccompiler import new_compiler
from distutils.sysconfig import customize_compiler
from setuptools import setup, find_packages
from setuptools import setup
from setuptools.extension import Extension
from subprocess import getoutput

Expand Down Expand Up @@ -89,35 +89,5 @@ def using_clang():
from Cython.Build import cythonize
extensions = cythonize(extensions)

setup(
name='pyzeo',
version='0.1.5',
description="Python interface to Zeo++",
long_description="Python interface to Zeo++",
url="https://github.com/nomad-coe/pyzeo",
author="Lauri Himanen",
license="",
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: C++",
"Programming Language :: Cython",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering"
],
# In the Cython build guide it is said that zip_safe should be disabled
# when building with setuptools
packages=find_packages('src'),
package_dir={'': 'src'},
zip_safe=False,
ext_modules=extensions,
keywords="zeo++ porous materials science",
python_requires=">=3.8",
)
if __name__ == "__main__":
setup(ext_modules=extensions)
20 changes: 7 additions & 13 deletions src/pyzeo/extension.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 31 additions & 30 deletions tests/test_areavol.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
from pyzeo.netstorage import AtomNetwork
from pyzeo.area_volume import volume, surface_area
def test_areavol():
from pyzeo.netstorage import AtomNetwork
from pyzeo.area_volume import volume, surface_area

atmnet = AtomNetwork.read_from_CSSR("MgO_vac1.cssr", rad_file="MgO.rad")
vol_str = volume(atmnet, 0.1, 0.05, 20000)
lines = vol_str.decode("utf-8").split('\n')
for line in lines:
if "Number_of_pockets" in line:
print('---------')
print(line)
print('---------')
vol_str, ha_atmnet = volume(atmnet, 0.1, 0.05, 7000, True)
lines = vol_str.decode("utf-8").split('\n')
for line in lines:
if "Number_of_pockets" in line:
print('---------')
print(line)
print('---------')
#print("--------")
#print(vol_str)
#print("--------")
sa_str = surface_area(atmnet, 0.1, 0.05, 7000, False)
lines = sa_str.decode("utf-8").split('\n')
for line in lines:
if "Number_of_pockets" in line:
print('---------')
print(line.split())
print('---------')
#print("--------")
#print(sa_str)
#print("--------")
atmnet = AtomNetwork.read_from_CSSR("MgO_vac1.cssr", rad_file="MgO.rad")
vol_str = volume(atmnet, 0.1, 0.05, 20000)
lines = vol_str.decode("utf-8").split('\n')
for line in lines:
if "Number_of_pockets" in line:
print('---------')
print(line)
print('---------')
vol_str, ha_atmnet = volume(atmnet, 0.1, 0.05, 7000, True)
lines = vol_str.decode("utf-8").split('\n')
for line in lines:
if "Number_of_pockets" in line:
print('---------')
print(line)
print('---------')
#print("--------")
#print(vol_str)
#print("--------")
sa_str = surface_area(atmnet, 0.1, 0.05, 7000, False)
lines = sa_str.decode("utf-8").split('\n')
for line in lines:
if "Number_of_pockets" in line:
print('---------')
print(line.split())
print('---------')
#print("--------")
#print(sa_str)
#print("--------")

25 changes: 13 additions & 12 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from pyzeo.netstorage import AtomNetwork
from pyzeo.cluster import pruned_highaccuracy_voronoi_network, \
get_nearest_largest_diameter_highaccuracy_vornode
def test_cluster():
from pyzeo.netstorage import AtomNetwork
from pyzeo.cluster import pruned_highaccuracy_voronoi_network, \
get_nearest_largest_diameter_highaccuracy_vornode

atmnet = AtomNetwork.read_from_CSSR("MgO.cssr", rad_file="MgO.rad")
vornet,ecs,fcs = atmnet.perform_voronoi_decomposition()
vornet.analyze_writeto_XYZ('mgo_low', 0.4, atmnet)
atmnet = AtomNetwork.read_from_CSSR("MgO.cssr", rad_file="MgO.rad")
vornet, ecs, fcs = atmnet.perform_voronoi_decomposition()
vornet.analyze_writeto_XYZ('mgo_low', 0.4, atmnet)

# Pruned high accuracy voronoi network
ha_vornet = pruned_highaccuracy_voronoi_network(atmnet, 0.7)
ha_vornet.analyze_writeto_XYZ('mgo_high_prune', 0.4, atmnet)
# Pruned high accuracy voronoi network
ha_vornet = pruned_highaccuracy_voronoi_network(atmnet, 0.7)
ha_vornet.analyze_writeto_XYZ('mgo_high_prune', 0.4, atmnet)

# Reduced high accuracy voronoi network
ha_red_vornet = get_nearest_largest_diameter_highaccuracy_vornode(atmnet)
ha_red_vornet.analyze_writeto_XYZ('mgo_high_red', 0.4, atmnet)
# Reduced high accuracy voronoi network
ha_red_vornet = get_nearest_largest_diameter_highaccuracy_vornode(atmnet)
ha_red_vornet.analyze_writeto_XYZ('mgo_high_red', 0.4, atmnet)


47 changes: 23 additions & 24 deletions tests/test_cycle.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import sys
from pyzeo.netstorage import AtomNetwork
from pyzeo.cycle import compute_centroid_4cycles, compute_face_centers
def test_cycle():
from pyzeo.netstorage import AtomNetwork
from pyzeo.cycle import compute_centroid_4cycles, compute_face_centers

atmnet = AtomNetwork.read_from_CSSR("MgO.cssr", rad_file="MgO.rad")
compute_face_centers(atmnet)
sys.exit()
atmnet = AtomNetwork.read_from_CSSR("MgO.cssr", rad_file="MgO.rad")
compute_face_centers(atmnet)

vornet = atmnet.perform_voronoi_decomposition()
oh_interstitials = compute_centroid_4cycles(vornet)
vornet, _, _ = atmnet.perform_voronoi_decomposition()
oh_interstitials = compute_centroid_4cycles(vornet)

ids_set = set()
i = 0
while i < len(oh_interstitials):
node_ids = frozenset(oh_interstitials[i]['ids'])
if node_ids not in ids_set:
ids_set.add(node_ids)
i = i+1
else:
oh_interstitials.pop(i)

print(len(oh_interstitials))
for inter in oh_interstitials:
node_ids = inter['ids']
print(node_ids)
coord = inter['coords']
print(coord.x, coord.y, coord.z)
ids_set = set()
i = 0
while i < len(oh_interstitials):
node_ids = frozenset(oh_interstitials[i]['ids'])
if node_ids not in ids_set:
ids_set.add(node_ids)
i = i+1
else:
oh_interstitials.pop(i)
print(len(oh_interstitials))
for inter in oh_interstitials:
node_ids = inter['ids']
print(node_ids)
coord = inter['coords']
print(coord.x, coord.y, coord.z)


Loading

0 comments on commit 5878963

Please sign in to comment.