Lattice interface
This guide walks through the AbstractLattice interface — the minimum a concrete lattice must implement, the trait-based extension points, and the default methods that come for free.
For the physics and mathematical background, see the concept column Lattices and unit cells.
The abstract type
abstract type AbstractLattice{D, T} endThe two type parameters are:
D::Int— the physical dimension (1, 2, 3, ...)T<:Real— the numeric type used to store positions (typicallyFloat64)
Nothing else lives in the type parameters. Boundary conditions, topology, indexing, and site types are all stored as fields on the concrete subtype, and dispatched through multiple dispatch and trait objects.
Required interface
A concrete subtype must implement these:
| Method | Returns |
|---|---|
num_sites | Int |
position | SVector{D, T} |
neighbors | AbstractVector{Int} (pinpoint) |
boundary | LatticeBoundary |
site_layout | AbstractSiteLayout |
size_trait | AbstractSizeTrait |
num_sites may be undefined — or may throw — when the lattice's size_trait is InfiniteSize.
Free defaults
Once the required methods are in place, LatticeCore derives:
dimensionandBase.eltypefrom the type parameterspositionsandbondsas lazy iterators fromposition/neighborsneighbor_bondsfromneighborsis_finite,is_bipartite,reciprocal_support,periodicity,topologyas safe defaults that can be overriddensite_type(lat, i)by delegating tosite_layout
Trait-based extension
Extension points use value types rather than flags, so dispatch stays compile-time. The main traits are:
TopologyTrait—{:square},{:honeycomb}, etc.Periodic/Aperiodic— is the underlying crystal periodic?AbstractReciprocalSupport— does this lattice admit a Bravais reciprocal (HasReciprocal), a dense Fourier module (HasFourierModule), or neither (NoReciprocal)?AbstractSizeTrait—FiniteSize,InfiniteSize, orQuasiInfiniteSize.