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

Hide internal APIs and optimize performance #45

Merged
merged 8 commits into from
Jan 11, 2025
Merged
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
68 changes: 34 additions & 34 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -30,7 +30,8 @@ cargo install cargo-release cargo-edit cargo-deny

### How to release

1. `cargo install cargo-release cargo-edit`
1. `cargo install cargo-release cargo-edit cargo-semver-checks`
1. `cargo semver-checks` to lint a new release
1. `cargo set-version --bump patch` for patch version increment
1. Write change log and git-commit
1. `cargo release --execute` (If you already release the package in crates.io, run `cargo release --execute --no-publish`)
3 changes: 2 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
@@ -19,8 +19,9 @@ test-python:
build-python-docs:
sphinx-autobuild moyopy/docs moyopy/docs/_build

# at moyo/
profile:
cargo flamegraph --test test_moyo_dataset --root
CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --test test_moyo_dataset --root

doc:
cargo doc --open
14 changes: 7 additions & 7 deletions moyo/src/base.rs
Original file line number Diff line number Diff line change
@@ -14,15 +14,15 @@ pub use error::MoyoError;
pub use lattice::Lattice;
pub use magnetic_cell::{Collinear, MagneticCell, MagneticMoment, NonCollinear};
pub use operation::{
project_rotations, MagneticOperation, MagneticOperations, Operation, Operations, Rotation,
Rotations, Translation,
MagneticOperation, MagneticOperations, Operation, Operations, Rotation, Rotations, Translation,
};
pub use permutation::Permutation;
pub use tolerance::{AngleTolerance, MagneticSymmetryTolerances, SymmetryTolerances};
pub use tolerance::AngleTolerance;
pub use transformation::{Linear, OriginShift};

pub use cell::orbits_from_permutations;
pub(super) use cell::orbits_from_permutations;
pub(super) use operation::project_rotations;
#[allow(unused_imports)]
pub use operation::traverse;
pub use tolerance::{ToleranceHandler, EPS};
pub use transformation::{Transformation, UnimodularLinear, UnimodularTransformation};
pub(super) use operation::traverse;
pub(super) use tolerance::{MagneticSymmetryTolerances, SymmetryTolerances, ToleranceHandler, EPS};
pub(super) use transformation::{Transformation, UnimodularLinear, UnimodularTransformation};
2 changes: 1 addition & 1 deletion moyo/src/base/operation.rs
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ pub fn project_operations(magnetic_operations: &MagneticOperations) -> Operation
pub fn traverse(generators: &Rotations) -> Rotations {
let mut queue = VecDeque::new();
let mut visited = HashSet::new();
let mut group = vec![];
let mut group = Vec::with_capacity(48);

queue.push_back(Rotation::identity());

2 changes: 1 addition & 1 deletion moyo/src/base/tolerance.rs
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ impl<T: Tolerances + Debug> ToleranceHandler<T> {

pub fn update(&mut self, err: MoyoError) {
// Update stride
if !self.prev_error.is_none() && self.prev_error != Some(err) {
if self.prev_error.is_some() && self.prev_error != Some(err) {
self.stride = self.stride.sqrt()
}
self.prev_error = Some(err);
14 changes: 9 additions & 5 deletions moyo/src/base/transformation.rs
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ impl UnimodularTransformation {
Self::new(linear, OriginShift::zeros())
}

#[allow(dead_code)]
pub fn from_origin_shift(origin_shift: OriginShift) -> Self {
Self::new(UnimodularLinear::identity(), origin_shift)
}
@@ -102,6 +103,7 @@ impl UnimodularTransformation {
pub struct Transformation {
pub linear: Linear,
pub origin_shift: OriginShift,
#[allow(dead_code)]
pub size: usize,
pub linear_inv: Matrix3<f64>,
}
@@ -127,6 +129,7 @@ impl Transformation {
Self::new(linear, OriginShift::zeros())
}

#[allow(dead_code)]
pub fn from_origin_shift(origin_shift: OriginShift) -> Self {
Self::new(Linear::identity(), origin_shift)
}
@@ -150,7 +153,7 @@ impl Transformation {
/// (P, p)^-1 (W, w) (P, p)
pub fn transform_operation(&self, operation: &Operation) -> Option<Operation> {
transform_operation_as_f64(
&operation,
operation,
&self.linear.map(|e| e as f64),
&self.linear_inv,
&self.origin_shift,
@@ -169,7 +172,7 @@ impl Transformation {
/// (P, p) (W, w) (P, p)^-1
pub fn inverse_transform_operation(&self, operation: &Operation) -> Option<Operation> {
transform_operation_as_f64(
&operation,
operation,
&self.linear_inv,
&self.linear.map(|e| e as f64),
&(-self.linear_as_f64() * self.origin_shift),
@@ -211,9 +214,10 @@ impl Transformation {
.map(|(f0, f1, f2)| (linv * Vector3::new(f0, f1, f2)).map(|e| e as f64))
.collect::<Vec<_>>();

let mut new_positions = vec![];
let mut new_numbers = vec![];
let mut site_mapping = vec![];
let new_num_atoms = cell.num_atoms() * lattice_points.len();
let mut new_positions = Vec::with_capacity(new_num_atoms);
let mut new_numbers = Vec::with_capacity(new_num_atoms);
let mut site_mapping = Vec::with_capacity(new_num_atoms);
for (i, (pos, number)) in cell.positions.iter().zip(cell.numbers.iter()).enumerate() {
for lattice_point in lattice_points.iter() {
// Fractional coordinates in the new sublattice
25 changes: 12 additions & 13 deletions moyo/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
mod arithmetic_crystal_class;
mod centering;
mod classification;
mod hall_symbol;
mod hall_symbol_database;
mod point_group;
mod setting;
mod wyckoff;

pub use arithmetic_crystal_class::{
arithmetic_crystal_class_entry, iter_arithmetic_crystal_entry, ArithmeticCrystalClassEntry,
ArithmeticNumber,
};
pub use classification::{
BravaisClass, CrystalFamily, CrystalSystem, GeometricCrystalClass, LatticeSystem, LaueClass,
};
pub use hall_symbol::{Centering, HallSymbol};
pub use hall_symbol_database::{
hall_symbol_entry, iter_hall_symbol_entry, HallNumber, HallSymbolEntry, Number,
};
pub use point_group::PointGroupRepresentative;
pub use arithmetic_crystal_class::ArithmeticNumber;
pub use centering::Centering;
pub use hall_symbol::HallSymbol;
pub use hall_symbol_database::{hall_symbol_entry, HallNumber, HallSymbolEntry, Number};
pub use setting::Setting;
pub use wyckoff::{iter_wyckoff_positions, WyckoffPosition, WyckoffPositionSpace};

pub(super) use arithmetic_crystal_class::{
arithmetic_crystal_class_entry, iter_arithmetic_crystal_entry,
};
pub(super) use classification::{CrystalSystem, GeometricCrystalClass, LatticeSystem};
pub(super) use point_group::PointGroupRepresentative;
pub(super) use wyckoff::{iter_wyckoff_positions, WyckoffPosition, WyckoffPositionSpace};
1 change: 1 addition & 0 deletions moyo/src/data/arithmetic_crystal_class.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ pub type ArithmeticNumber = i32;
#[derive(Debug, Clone)]
pub struct ArithmeticCrystalClassEntry {
pub arithmetic_number: ArithmeticNumber,
#[allow(dead_code)]
pub symbol: &'static str,
pub geometric_crystal_class: GeometricCrystalClass,
pub bravais_class: BravaisClass,
Loading