Struct chemfiles::UnitCell [] [src]

pub struct UnitCell { /* fields omitted */ }

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]

Create an Orthorhombic UnitCell from the three lengths, in Angstroms.

Example

let cell = UnitCell::new(30.0, 30.0, 23.0).unwrap();

assert_eq!(cell.lengths(), Ok((30.0, 30.0, 23.0)));
assert_eq!(cell.angles(), Ok((90.0, 90.0, 90.0)));
assert_eq!(cell.shape(), Ok(CellShape::Orthorhombic));

Create an Infinite UnitCell.

Example

let cell = UnitCell::infinite().unwrap();

assert_eq!(cell.lengths(), Ok((0.0, 0.0, 0.0)));
assert_eq!(cell.angles(), Ok((90.0, 90.0, 90.0)));
assert_eq!(cell.shape(), Ok(CellShape::Infinite));

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).unwrap();

assert_eq!(cell.lengths(), Ok((10.0, 10.0, 10.0)));
assert_eq!(cell.angles(), Ok((98.0, 99.0, 90.0)));
assert_eq!(cell.shape(), Ok(CellShape::Triclinic));

Get the three lengths of the cell, in Angstroms.

Example

let cell = UnitCell::new(30.0, 30.0, 23.0).unwrap();
assert_eq!(cell.lengths(), Ok((30.0, 30.0, 23.0)));

Set the three lengths of the cell, in Angstroms.

Example

let mut cell = UnitCell::new(30.0, 30.0, 23.0).unwrap();

cell.set_lengths(10.0, 30.0, 42.0).unwrap();
assert_eq!(cell.lengths(), Ok((10.0, 30.0, 42.0)));

Get the three angles of the cell, in degrees.

Example

let cell = UnitCell::new(20.0, 20.0, 20.0).unwrap();
assert_eq!(cell.angles(), Ok((90.0, 90.0, 90.0)));

let cell = UnitCell::triclinic(20.0, 20.0, 20.0, 100.0, 120.0, 90.0).unwrap();
assert_eq!(cell.angles(), Ok((100.0, 120.0, 90.0)));

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).unwrap();
assert_eq!(cell.angles(), Ok((100.0, 120.0, 90.0)));

cell.set_angles(90.0, 90.0, 90.0).unwrap();
assert_eq!(cell.angles(), Ok((90.0, 90.0, 90.0)));

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 mut cell = UnitCell::new(10.0, 20.0, 30.0).unwrap();

let matrix = cell.matrix().unwrap();

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);

Get the shape of the unit cell.

Example

let cell = UnitCell::new(10.0, 20.0, 30.0).unwrap();
assert_eq!(cell.shape(), Ok(CellShape::Orthorhombic));

Set the shape of the unit cell to shape.

Example

let mut cell = UnitCell::new(10.0, 20.0, 30.0).unwrap();
assert_eq!(cell.shape(), Ok(CellShape::Orthorhombic));

cell.set_shape(CellShape::Infinite).unwrap();
assert_eq!(cell.shape(), Ok(CellShape::Infinite));

Get the volume of the unit cell.

Example

let cell = UnitCell::new(10.0, 20.0, 30.0).unwrap();
assert_eq!(cell.volume(), Ok(10.0 * 20.0 * 30.0));

Trait Implementations

impl Clone for UnitCell
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Drop for UnitCell
[src]

A method called when the value goes out of scope. Read more