[ANN] LightLattices.jl - lazy interface to lattices with arbitrary unit cells

Hi, everyone.

This is an announcement for the package LightLattices.jl. It provides the lazy interface to work with lattices. The lattices of arbitrary dimensionality and arbitrary unit cells are supported.

Overview

The package exports the type RegularLattice{D,T} and several types used to describe the unit cell of the lattice. All the exported types are subtypes of the abstract type AbstractNodeCollection{D,T}. Here, D refers to the dimensionality of space (number of coordinates), T refers to the type used to store the coordinates. For all the exported subtypes, the package defines the array interface

node_collection[I]

which allows to access the coordinate of the I-th node of the collection.
In addition to that, the package provides the function relative_coordinate:

relative_coordinate(node_collection::AbstractNodeCollection, I1, I2)

which returns the vector connecting the I2-th node with the I1-th node.
In the case of RegularLattice-s with periodic boundary conditions, relative_coordinate returns the shortest connecting vector.
(Actually, in the case of complex unit cell, there can be several “shortest” vectors. The problem is resolved by a simple heuristic, described in the docs).

The package also defines eachindex for all the exported types.

There are three available types to describe the unit cell: HomogeneousCell, TrivialCell and InhomogeneousCell.
HomogeneousCell refers to a homogeneous collection of nodes. TrivialCell behaves like HomogeneousCell with single node at the origin (zero coordinates). Finally, InhomogeneousCell is useful in the situation where one need to distinguish between several groups of nodes in the unit cell. For example, we can have several groupes of nodes corresponding to the different types of nuclei which occupy these nodes.

For the detailed account of exported types and the interface, please look at the manual section of the docs.

Example

As an example, let us create a diamond lattice with dimensions 11x11x11 and periodic boundary conditions:

using LightLattices, Unitful

const a = 3.567u"Å"# diamond lattice parameter

basis = 0.5a*hcat([0,1,1],[1,1,0],[1,0,1]) |> SMatrix{3,3}
cell = HomogeneousCell(a*[[0.0,0.0,0.0], [0.25,0.25,0.25]]; label = :diamond)
diamond_lattice = RegularLattice((11,11,11), basis, cell; periodic=true, label=:fcc)

Now, we can get the coordinate of first node in the unit cell with indices (2,5,7) using either

diamond_lattice[CartesianIndex(2,5,7), 1]

or

diamond_lattice[2,5,7,1]

Suppose we now want to find the shortest vector connecting the second node of the first cell with the node we just considered. One can use either

relative_coordinate(diamond_lattice, (CartesianIndex(2,5,7),1), (CartesianIndex(1,1,1), 1))

or simply

relative_coordinate(diamond_lattice, (), (2,5,7, 1), (1,1,1, 1))

For more examples, see README section.

Comparison with other packages

I am aware of two packages providing similar functionality: Lattices.jl and LatticePhysics.jl. The first seems to support only hypercubic lattices without complex unit cells. The second one is not registered and looks very complex. In contrast, I wanted to create a compact easy-to-understand package, hence “Light” in the name of the package.

Final words

Suggestions and ideas about the improvement of the package are welcome!!! I am open to the discussion.

6 Likes

Consider joining JuliaMolSim Slack?!

https://juliamolsim.github.io/

1 Like