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]

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

[src]

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

[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]).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));

[src]

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

[src]

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

[src]

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

[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]).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]));

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

[src]

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

[src]

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::Triclinic).unwrap();
assert_eq!(cell.shape(), Ok(CellShape::Triclinic));

[src]

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

[src]

Wrap a vector in this unit cell.

Example

let cell = UnitCell::new([10.0, 20.0, 30.0]).unwrap();

let mut vector = [12.0, 5.2, -45.3];
cell.wrap(&mut vector).unwrap();
assert_eq!(vector, [2.0, 5.2, 14.700000000000003]);

Trait Implementations

impl Clone for UnitCell
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Drop for UnitCell
[src]

[src]

Executes the destructor for this type. Read more