From f45cb8f8ac0aea9e6cfadc73df32f9b98b2c60a6 Mon Sep 17 00:00:00 2001 From: lan496 Date: Sun, 10 Mar 2024 14:36:42 +0900 Subject: [PATCH] Fix array major --- justfile | 3 +++ moyo/tests/test_moyo_dataset.rs | 2 +- moyo_py/python/moyo/_moyo.pyi | 2 +- moyo_py/python/tests/conftest.py | 12 +++++++++--- moyo_py/python/tests/test_moyo_dataset.py | 3 ++- moyo_py/src/base.rs | 9 +++++++-- moyo_py/src/lib.rs | 2 +- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/justfile b/justfile index aa6590d..410d06c 100644 --- a/justfile +++ b/justfile @@ -4,6 +4,9 @@ set positional-arguments default: just --list +build-python: + maturin develop --release --manifest-path moyo_py/Cargo.toml + install-python: maturin develop --release --manifest-path moyo_py/Cargo.toml pip install -e "moyo_py[dev]" diff --git a/moyo/tests/test_moyo_dataset.rs b/moyo/tests/test_moyo_dataset.rs index 6e74666..c0c854c 100644 --- a/moyo/tests/test_moyo_dataset.rs +++ b/moyo/tests/test_moyo_dataset.rs @@ -254,7 +254,7 @@ fn test_with_wurtzite() { let numbers = vec![0, 0, 1, 1]; let cell = Cell::new(lattice, positions, numbers); - let symprec = 1e-2; + let symprec = 1e-4; let angle_tolerance = AngleTolerance::Default; let setting = Setting::Standard; diff --git a/moyo_py/python/moyo/_moyo.pyi b/moyo_py/python/moyo/_moyo.pyi index 71f4046..d2f55a8 100644 --- a/moyo_py/python/moyo/_moyo.pyi +++ b/moyo_py/python/moyo/_moyo.pyi @@ -40,7 +40,7 @@ class MoyoDataset: def __init__( self, structure: Structure, - symprec: float = 1e-5, + symprec: float = 1e-4, angle_tolerance: float | None = None, setting: Setting | None = None, ): ... diff --git a/moyo_py/python/tests/conftest.py b/moyo_py/python/tests/conftest.py index 69c9e3c..9c176d5 100644 --- a/moyo_py/python/tests/conftest.py +++ b/moyo_py/python/tests/conftest.py @@ -15,11 +15,17 @@ def wurtzite() -> moyo.Structure: [-a / 2.0, a * sqrt(3.0) / 2.0, 0.0], [0.0, 0.0, c], ] + z1_2b = 0.00014 + z2_2b = 0.37486 positions = [ - [1 / 3, 2 / 3, 0.00014], - [1 / 3, 2 / 3, 0.37486], + # 2b + [1 / 3, 2 / 3, z1_2b], + [2 / 3, 1 / 3, z1_2b + 0.5], + # 2b + [1 / 3, 2 / 3, z2_2b], + [2 / 3, 1 / 3, z2_2b + 0.5], ] - numbers = [0, 1] + numbers = [0, 0, 1, 1] structure = moyo.Structure(basis, positions, numbers) return structure diff --git a/moyo_py/python/tests/test_moyo_dataset.py b/moyo_py/python/tests/test_moyo_dataset.py index 6c4f02e..0d1eadc 100644 --- a/moyo_py/python/tests/test_moyo_dataset.py +++ b/moyo_py/python/tests/test_moyo_dataset.py @@ -2,4 +2,5 @@ def test_moyo_dataset(wurtzite: moyo.Structure): - _dataset = moyo.MoyoDataset(wurtzite) + dataset = moyo.MoyoDataset(wurtzite) + assert dataset.number == 186 diff --git a/moyo_py/src/base.rs b/moyo_py/src/base.rs index 6a84d5b..cd9a9d6 100644 --- a/moyo_py/src/base.rs +++ b/moyo_py/src/base.rs @@ -1,4 +1,4 @@ -use nalgebra::{OMatrix, Vector3}; +use nalgebra::{OMatrix, RowVector3, Vector3}; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; @@ -24,7 +24,12 @@ impl PyStructure { )); } - let lattice = Lattice::new(OMatrix::from(basis)); + // let lattice = Lattice::new(OMatrix::from(basis)); + let lattice = Lattice::new(OMatrix::from_rows(&[ + RowVector3::from(basis[0]), + RowVector3::from(basis[1]), + RowVector3::from(basis[2]), + ])); let positions = positions .iter() .map(|x| Vector3::new(x[0], x[1], x[2])) diff --git a/moyo_py/src/lib.rs b/moyo_py/src/lib.rs index a7a900d..349e416 100644 --- a/moyo_py/src/lib.rs +++ b/moyo_py/src/lib.rs @@ -19,7 +19,7 @@ pub struct PyMoyoDataset(MoyoDataset); #[pymethods] impl PyMoyoDataset { #[new] - #[pyo3(signature = (structure, *, symprec=1e-5, angle_tolerance=None, setting=None))] + #[pyo3(signature = (structure, *, symprec=1e-4, angle_tolerance=None, setting=None))] pub fn new( structure: &PyStructure, symprec: f64,