Examples

Representing Miller and Miller–Bravais indices

This section demonstrates how to create various indices using the package.

julia> using MillerIndices
julia> Miller(1, 2, 3) # Create Miller indices in real space3-element Miller: 1 2 3
julia> ReciprocalMiller(1, 2, 3) # Create Miller indices in reciprocal space3-element ReciprocalMiller: 1 2 3
julia> MillerBravais(2, -1, -1, 3) # Create Miller–Bravais indices in real space4-element MillerBravais: 2 -1 -1 3
julia> ReciprocalMillerBravais(1, 0, -1, 0) # Create Miller–Bravais indices in reciprocal space4-element ReciprocalMillerBravais: 1 0 -1 0

Generating indices from strings

Utilize the m_str macro to rapidly generate indices from a string format.

julia> m"[-1, 0, 1]"  # Generate Miller indices from a string3-element Miller:
 -1
  0
  1
julia> m"<2, -1, -1, 3>" # Generate Miller–Bravais indices from a string4-element MillerBravais: 2 -1 -1 3

Converting between Miller and Miller–Bravais indices

Switch between different index notations seamlessly.

julia> MillerBravais(Miller(-1, 0, 1))4-element MillerBravais:
 -2
  1
  1
  3
julia> Miller(MillerBravais(-2, 1, 1, 3))3-element Miller: -1 0 1

Finding equivalent directions/planes

Discover how to determine all directions/planes equivalent to a given index by symmetry.

julia> familyof(Miller(-1, 0, 1))6-element Vector{Miller}:
 <-1 0 1>
 <0 -1 1>
 <1 1 1>
 <1 0 1>
 <0 1 1>
 <-1 -1 1>
julia> familyof(MillerBravais(-1, -1, 2, 3))6-element Vector{MillerBravais}: <-1 -1 2 3> <-1 2 -1 3> <2 -1 -1 3> <1 1 -2 3> <1 -2 1 3> <-2 1 1 3>

Angle calculation

Determine the angle between two vectors using a metric tensor.

Test the angle between $[1\ 2\ 1]$ and $[0\ 0\ 1]$ directions in gallium nitride

julia> using CrystallographyBase, Unitful
julia> a, c = 3.19u"angstrom", 5.19u"angstrom"(3.19 Å, 5.19 Å)
julia> g = MetricTensor(a, a, c, 90, 90, 120)3×3 CrystallographyBase.MetricTensor{Unitful.Quantity{Float64, 𝐋^2, Unitful.FreeUnits{(Å^2,), 𝐋^2, nothing}}}: 10.1761 Å^2 -5.08805 Å^2 0.0 Å^2 -5.08805 Å^2 10.1761 Å^2 0.0 Å^2 0.0 Å^2 0.0 Å^2 26.9361 Å^2
julia> θ = anglebtw(Miller(1, 0, 0), Miller(1, 1, 1), g)74.82193526845971

Calculate the length of the reciprocal lattice vector and the interplanar spacing

julia> g = inv(MetricTensor(2, 4, 3, 90, 45, 90))3×3 CrystallographyBase.MetricTensor{Float64}:
  0.5       0.0     -0.235702
  0.0       0.0625   0.0
 -0.235702  0.0      0.222222
julia> lengthof(ReciprocalMiller(1, 0, 2), g)0.6678920925619838
julia> interplanar_spacing(ReciprocalMiller(1, 0, 2), g)1.4972478505683084

Calculate the angle between two plane normals

julia> g = inv(MetricTensor(4, 6, 5, 90, 135, 90))3×3 CrystallographyBase.MetricTensor{Float64}:
  0.125      -0.0         0.0707107
 -0.0         0.0277778  -0.0
  0.0707107  -0.0         0.08
julia> 𝐱 = ReciprocalMiller(1, 0, 1)3-element ReciprocalMiller: 1 0 1
julia> 𝐲 = ReciprocalMiller(-2, 0, 1)3-element ReciprocalMiller: -2 0 1
julia> anglebtw(𝐱, 𝐲, g)41.38888526317379