Skip to content

Add `custom_edges` argument to `Lattice`

Created by: attila-i-szabo

This PR implements the new feature requested in #1049 (closed). In the end, I've added the new calling sequence to the constructor, I didn't feel that there was a nice way of removing it into @classmethod nor that it would be justified.

Edges can be specified in the custom_edges kwarg, which takes a list of tuples of the following structure: (sl_from, sl_to, distance, color). The first two indicates which atom in a unit cell the edge starts and ends on, distance is its length vector (in Cartesian coordinates); color is optional, if not supplied, it is set to the index of the tuple in the list. Assuming distance is a valid distance between atoms in the given sublattices (possibly spanning to different unit cells), all edges of that length are added with the given colour. custom_edges cannot be used together with max_neighbor_order, giving both raises an error.

The logic for generating edges has been tidied up and moved to its own file. Also, the logic for generating sites is now independent from the edges, which causes the only "breaking change" I've noticed: construction of a lattice without edges no longer errors out.

As an example, the Kitaev honeycomb is added to common_lattices, and there are a couple of tests that use it. If we want to, we can reinstate Grid with edges coloured according to direction, which was dropped because it wasn't compatible with near-neighbour searching.

Merge request reports