[−][src]Struct chemfiles::UnitCell
An UnitCell
represent the box containing the atoms, and its periodicity.
An unit cell is fully represented by three lengths (a, b, c); and three angles (alpha, beta, gamma). The angles are stored in degrees, and the lengths in Angstroms.
A cell also has a matricial representation, by projecting the three base vector into an orthonormal base. We choose to represent such matrix as an upper triangular matrix:
| a_x b_x c_x |
| 0 b_y c_y |
| 0 0 c_z |
Methods
impl UnitCell
[src]
pub fn new(lengths: [f64; 3]) -> UnitCell
[src]
Create an Orthorhombic
UnitCell
from the three lengths, in Angstroms.
Example
let cell = UnitCell::new([30.0, 30.0, 23.0]); assert_eq!(cell.lengths(), [30.0, 30.0, 23.0]); assert_eq!(cell.angles(), [90.0, 90.0, 90.0]); assert_eq!(cell.shape(), CellShape::Orthorhombic);
pub fn infinite() -> UnitCell
[src]
Create an Infinite
UnitCell
.
Example
let cell = UnitCell::infinite(); assert_eq!(cell.lengths(), [0.0, 0.0, 0.0]); assert_eq!(cell.angles(), [90.0, 90.0, 90.0]); assert_eq!(cell.shape(), CellShape::Infinite);
pub fn triclinic(lengths: [f64; 3], angles: [f64; 3]) -> UnitCell
[src]
Create an Triclinic
UnitCell
from the three lengths (in Angstroms)
and three angles (in degree). alpha
is the angle between the vectors
b
and c
; beta
is the between the vectors a
and c
and gamma
is the angle between the vectors a
and b
.
Example
let cell = UnitCell::triclinic([10.0, 10.0, 10.0], [98.0, 99.0, 90.0]); assert_eq!(cell.lengths(), [10.0, 10.0, 10.0]); assert_eq!(cell.angles(), [98.0, 99.0, 90.0]); assert_eq!(cell.shape(), CellShape::Triclinic);
pub fn lengths(&self) -> [f64; 3]
[src]
Get the three lengths of the cell, in Angstroms.
Example
let cell = UnitCell::new([30.0, 30.0, 23.0]); assert_eq!(cell.lengths(), [30.0, 30.0, 23.0]);
pub fn set_lengths(&mut self, lengths: [f64; 3]) -> Result<(), Error>
[src]
Set the three lengths of the cell, in Angstroms.
This fails if the unit cell is infinite
Example
let mut cell = UnitCell::new([30.0, 30.0, 23.0]); cell.set_lengths([10.0, 30.0, 42.0]).unwrap(); assert_eq!(cell.lengths(), [10.0, 30.0, 42.0]); assert!(UnitCell::infinite().set_lengths([1.0, 1.0, 1.0]).is_err());
pub fn angles(&self) -> [f64; 3]
[src]
Get the three angles of the cell, in degrees.
Example
let cell = UnitCell::new([20.0, 20.0, 20.0]); assert_eq!(cell.angles(), [90.0, 90.0, 90.0]); let cell = UnitCell::triclinic([20.0, 20.0, 20.0], [100.0, 120.0, 90.0]); assert_eq!(cell.angles(), [100.0, 120.0, 90.0]);
pub fn set_angles(&mut self, angles: [f64; 3]) -> Result<(), Error>
[src]
Set the three angles of the cell, in degrees. This is only possible
with Triclinic
cells.
Example
let mut cell = UnitCell::triclinic([20.0, 20.0, 20.0], [100.0, 120.0, 90.0]); assert_eq!(cell.angles(), [100.0, 120.0, 90.0]); cell.set_angles([90.0, 90.0, 90.0]).unwrap(); assert_eq!(cell.angles(), [90.0, 90.0, 90.0]);
pub fn matrix(&self) -> [[f64; 3]; 3]
[src]
Get the unit cell matricial representation.
The unit cell representation is obtained by aligning the a vector along the x axis and putting the b vector in the xy plane. This make the matrix an upper triangular matrix:
| a_x b_x c_x |
| 0 b_y c_y |
| 0 0 c_z |
Example
let cell = UnitCell::new([10.0, 20.0, 30.0]); let matrix = cell.matrix(); assert_eq!(matrix[0][0], 10.0); assert_eq!(matrix[1][1], 20.0); assert_eq!(matrix[2][2], 30.0); assert!(matrix[1][2].abs() < 1e-9);
pub fn shape(&self) -> CellShape
[src]
Get the shape of the unit cell.
Example
let cell = UnitCell::new([10.0, 20.0, 30.0]); assert_eq!(cell.shape(), CellShape::Orthorhombic);
pub fn set_shape(&mut self, shape: CellShape) -> Result<(), Error>
[src]
Set the shape of the unit cell to shape
.
This can fail if the cell length or angles are incompatible with the new shape.
Example
let mut cell = UnitCell::new([10.0, 20.0, 30.0]); assert_eq!(cell.shape(), CellShape::Orthorhombic); cell.set_shape(CellShape::Triclinic).unwrap(); assert_eq!(cell.shape(), CellShape::Triclinic);
pub fn volume(&self) -> f64
[src]
Get the volume of the unit cell.
Example
let cell = UnitCell::new([10.0, 20.0, 30.0]); assert_eq!(cell.volume(), 10.0 * 20.0 * 30.0);
pub fn wrap(&self, vector: &mut [f64; 3])
[src]
Wrap a vector
in this unit cell.
Example
let cell = UnitCell::new([10.0, 20.0, 30.0]); let mut vector = [12.0, 5.2, -45.3]; cell.wrap(&mut vector); assert_eq!(vector, [2.0, 5.2, 14.700000000000003]);
Trait Implementations
impl Clone for UnitCell
[src]
fn clone(&self) -> UnitCell
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Drop for UnitCell
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,