Skip to content

Conversation

@janosh
Copy link
Collaborator

@janosh janosh commented Feb 1, 2025

this PR addresses my comment over at CompRhys/aviary#96 (comment)

Summary

  • add CrystalSystem enum to represent crystal system based on space group number
  • implement crystal system mapping for space groups 1-230
  • add Python bindings for CrystalSystem
  • update tests to verify crystal system detection for various structures

…roup number

- add crystal_system field to MoyoDataset
- implement crystal system mapping for space groups 1-230
- add Python bindings for CrystalSystem
- update tests to verify crystal system detection for various structures
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 23.25581% with 33 lines in your changes missing coverage. Please review.

Project coverage is 89.19%. Comparing base (b654463) to head (fcf81f5).

Files with missing lines Patch % Lines
moyopy/src/lib.rs 0.00% 28 Missing ⚠️
moyo/src/lib.rs 66.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
- Coverage   89.72%   89.19%   -0.53%     
==========================================
  Files          44       44              
  Lines        5624     5665      +41     
==========================================
+ Hits         5046     5053       +7     
- Misses        578      612      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +14 to +55
/// The crystal system of a space group.
#[derive(Debug, PartialEq, Eq)]
#[pyclass(name = "CrystalSystem", frozen)]
pub enum PyCrystalSystem {
Triclinic,
Monoclinic,
Orthorhombic,
Tetragonal,
Trigonal,
Hexagonal,
Cubic,
}

impl From<CrystalSystem> for PyCrystalSystem {
fn from(cs: CrystalSystem) -> Self {
match cs {
CrystalSystem::Triclinic => Self::Triclinic,
CrystalSystem::Monoclinic => Self::Monoclinic,
CrystalSystem::Orthorhombic => Self::Orthorhombic,
CrystalSystem::Tetragonal => Self::Tetragonal,
CrystalSystem::Trigonal => Self::Trigonal,
CrystalSystem::Hexagonal => Self::Hexagonal,
CrystalSystem::Cubic => Self::Cubic,
}
}
}

impl std::fmt::Display for PyCrystalSystem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

#[pymethods]
impl PyCrystalSystem {
fn __str__(&self) -> String {
self.to_string()
}

#[classattr]
const __module__: &'static str = "moyopy";
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the code in this file. looks needlessly verbose but couldn't find another way that silences all compiler warnings... maybe due to me not knowing my way round rust yet


/// The crystal system of a structure.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum CrystalSystem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have CrystalSystem class in data/classification.rs.

pub enum CrystalSystem {
Triclinic,
Monoclinic,
Orthorhombic,
Tetragonal,
Trigonal,
Hexagonal,
Cubic,
}

I am sorry that you already implemented this, but can I take over this issue? I am thinking to add a python function get_space_group_type to return crystal systems and other classifications for space group types.
#52

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ofc, feel free to take over/make any changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make it a python function, will the same information also be available on the rust side?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Rust side already has this information: space group type -> arithmetic crystal class -> geometric crystal class -> crystal system. So, I think the accessor for the Python interface is enough for implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i should have read the code more carefully. at least i understand it better now

@lan496
Copy link
Member

lan496 commented Feb 3, 2025

I'll close this PR because I believe moyopy.SpaceGroupType works for the purpose.
#52 (comment)

@lan496 lan496 closed this Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants