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

**URL:** <https://discourse.julialang.org/t/ann-lightlattices-jl-lazy-interface-to-lattices-with-arbitrary-unit-cells/65493>\
**Category:** Package Announcements\
**Tags:** physics, lattices\
**Created:** [July 29, 2021, 1:00pm UTC](https://discourse.julialang.org/t/ann-lightlattices-jl-lazy-interface-to-lattices-with-arbitrary-unit-cells/65493 "2021-07-29T13:00:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [July 29, 2021, 1:00pm UTC](https://discourse.julialang.org/t/ann-lightlattices-jl-lazy-interface-to-lattices-with-arbitrary-unit-cells/65493/1 "2021-07-29T13:00:57Z")

</div>

Hi, everyone.

This is an announcement for the package [LightLattices.jl](https://github.com/Gregstrq/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

```julia
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`:

```julia
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](https://gregstrq.github.io/LightLattices.jl/stable/manual/#Lattices-with-periodic-boundaries)).

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](https://gregstrq.github.io/LightLattices.jl/stable/manual/).

## Example

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

```julia-auto
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

```julia-auto
diamond_lattice[CartesianIndex(2,5,7), 1]

```

or

```julia-auto
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

```julia-auto
relative_coordinate(diamond_lattice, (CartesianIndex(2,5,7),1), (CartesianIndex(1,1,1), 1))

```

or simply

```julia-auto
relative_coordinate(diamond_lattice, (), (2,5,7, 1), (1,1,1, 1))

```

For more examples, see [README section](https://github.com/Gregstrq/LightLattices.jl#readme).

## Comparison with other packages

I am aware of two packages providing similar functionality: [Lattices.jl](https://github.com/JuliaPhysics/Lattices.jl) and [LatticePhysics.jl](https://github.com/janattig/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.**

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [July 29, 2021, 6:16pm UTC](https://discourse.julialang.org/t/ann-lightlattices-jl-lazy-interface-to-lattices-with-arbitrary-unit-cells/65493/2 "2021-07-29T18:16:52Z")

</div>

Consider joining JuliaMolSim Slack?!

[https://juliamolsim.github.io/](https://juliamolsim.github.io/)
