use std::os::raw::c_int;
use spglib_sys as ffi;
use crate::error::SpglibError;
#[derive(Clone, Debug)]
pub struct Cell {
pub lattice: [[f64; 3]; 3],
pub positions: Vec<[f64; 3]>,
pub types: Vec<i32>,
}
impl Cell {
pub fn new(lattice: &[[f64; 3]; 3], positions: &[[f64; 3]], types: &[i32]) -> Cell {
let lattice = *lattice;
let positions = Vec::from(positions);
let types = Vec::from(types);
Cell {
lattice,
positions,
types,
}
}
pub fn standardize(
&mut self,
to_primitive: bool,
no_idealize: bool,
symprec: f64,
) -> Result<(), SpglibError> {
let to_primitive = if to_primitive { 1 } else { 0 };
let no_idealize = if no_idealize { 1 } else { 0 };
let res = unsafe {
ffi::spg_standardize_cell(
self.lattice.as_ptr() as *mut [f64; 3],
self.positions.as_ptr() as *mut [f64; 3],
self.types.as_ptr() as *mut c_int,
self.positions.len() as c_int,
to_primitive,
no_idealize,
symprec,
)
};
if res == 0 {
return Err(SpglibError::CellStandardizationFailed);
}
Ok(())
}
pub fn delaunay_reduce(&mut self, eps: f64) -> Result<(), SpglibError> {
let res = unsafe { ffi::spg_delaunay_reduce(self.lattice.as_ptr() as *mut [f64; 3], eps) };
if res == 0 {
return Err(SpglibError::DelaunayFailed);
}
Ok(())
}
pub fn niggli_reduce(&mut self, eps: f64) -> Result<(), SpglibError> {
let res = unsafe { ffi::spg_niggli_reduce(self.lattice.as_ptr() as *mut [f64; 3], eps) };
if res == 0 {
return Err(SpglibError::NiggliFailed);
}
Ok(())
}
pub fn ir_reciprocal_mesh(
&self,
mesh: (i32, i32, i32),
shift: (bool, bool, bool),
) -> Result<(), SpglibError> {
unimplemented!()
}
}