Cells, metric, angles and indices

A cell is given by its lattice parameters, a basis is the 3×3 matrix whose columns are a, b, c in Cartesian coordinates. From it follow the metric tensor, the reciprocal basis, the angle between two directions or two faces, and the operations of a point group that a distortion of the cell leaves (Conventions, “Cell, metric and indices”). Indices: reduction to coprime numbers, three and four indices of hexagonal axes, the zone law, and the transformation for a change of axes. Lengths have the unit you give them, angles are in degrees.

TypeScript

// The cell of a hexagonal crystal, an angle between two faces, and the operations of 6/mmm that a
// distortion of the angle γ leaves.
import {
  angleBetweenPlanes,
  directionToFourIndices,
  latticeFromParameters,
  latticeOperations,
  metricTensor,
  residualOperations,
} from 'symcrys';

const hexagonal = { a: 3, b: 3, c: 5, alpha: 90, beta: 90, gamma: 120 };
const basis = latticeFromParameters(hexagonal);
console.log(
  'metric tensor:',
  metricTensor(basis).map((row) => row.map((x) => +x.toFixed(6))),
);
console.log('(100) to (010):', angleBetweenPlanes(basis, [1, 0, 0], [0, 1, 0]).toFixed(4), 'degrees');
console.log('[110] in four indices:', directionToFourIndices([1, 1, 0]));

const operations = latticeOperations('6/mmm');
const distorted = latticeFromParameters({ ...hexagonal, gamma: 121 });
console.log('operations kept at gamma = 120:', residualOperations(operations, basis).length);
console.log('operations kept at gamma = 121:', residualOperations(operations, distorted).length);

Output:

metric tensor: [ [ 9, -4.5, 0 ], [ -4.5, 9, 0 ], [ 0, 0, 25 ] ]
(100) to (010): 60.0000 degrees
[110] in four indices: [ 1, 1, -2, 0 ]
operations kept at gamma = 120: 24
operations kept at gamma = 121: 8

Python

import symcrys

basis = symcrys.lattice_from_parameters({"a": 3, "b": 3, "c": 5, "alpha": 90, "beta": 90, "gamma": 120})
symcrys.metric_tensor(basis)
array([[ 9. , -4.5,  0. ],
       [-4.5,  9. ,  0. ],
       [ 0. ,  0. , 25. ]])
symcrys.angle_between_planes(basis, [1, 0, 0], [0, 1, 0]), symcrys.direction_to_four_indices([1, 1, 0])
(59.99999999999999, array([ 1,  1, -2,  0]))
ops = symcrys.lattice_operations("6/mmm")
distorted = symcrys.lattice_from_parameters({"a": 3, "b": 3, "c": 5, "alpha": 90, "beta": 90, "gamma": 121})
len(symcrys.residual_operations(ops, basis)), len(symcrys.residual_operations(ops, distorted))
(24, 8)