-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python interface for magnetic space-group type
- Loading branch information
Showing
11 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from moyopy import MagneticSpaceGroupType | ||
|
||
|
||
def test_magnetic_space_group_type(): | ||
msgt = MagneticSpaceGroupType(1262) | ||
assert msgt.bns_number == "151.32" | ||
assert msgt.og_number == "153.4.1270" | ||
assert msgt.construct_type == 4 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use pyo3::exceptions::PyValueError; | ||
use pyo3::prelude::*; | ||
|
||
use moyo::data::{ | ||
get_magnetic_space_group_type, ConstructType, MagneticSpaceGroupType, Number, UNINumber, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
#[pyclass(name = "MagneticSpaceGroupType", frozen)] | ||
pub struct PyMagneticSpaceGroupType(MagneticSpaceGroupType); | ||
|
||
#[pymethods] | ||
impl PyMagneticSpaceGroupType { | ||
#[new] | ||
pub fn new(uni_number: UNINumber) -> Result<Self, PyErr> { | ||
let magnetic_space_group_type = get_magnetic_space_group_type(uni_number).ok_or( | ||
PyValueError::new_err(format!("Unknown uni_number: {}", uni_number)), | ||
)?; | ||
Ok(PyMagneticSpaceGroupType(magnetic_space_group_type)) | ||
} | ||
|
||
#[getter] | ||
pub fn uni_number(&self) -> UNINumber { | ||
self.0.uni_number | ||
} | ||
|
||
#[getter] | ||
pub fn litvin_number(&self) -> i32 { | ||
self.0.litvin_number | ||
} | ||
|
||
#[getter] | ||
pub fn bns_number(&self) -> String { | ||
self.0.bns_number.to_string() | ||
} | ||
|
||
#[getter] | ||
pub fn og_number(&self) -> String { | ||
self.0.og_number.to_string() | ||
} | ||
|
||
#[getter] | ||
pub fn number(&self) -> Number { | ||
self.0.number | ||
} | ||
|
||
#[getter] | ||
pub fn construct_type(&self) -> i32 { | ||
match self.0.construct_type { | ||
ConstructType::Type1 => 1, | ||
ConstructType::Type2 => 2, | ||
ConstructType::Type3 => 3, | ||
ConstructType::Type4 => 4, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters