netket.graph.Lattice#

class netket.graph.Lattice[source]#

Bases: Graph

A lattice built by periodic arrangement of a given unit cell.

The lattice is represented as a Bravais lattice with (basis_vectors) \(\{a_d\}_{d=1}^D\) (where \(D = \mathtt{ndim}\) is the dimension of the lattice) and a unit cell consisting of one or more sites, The positions of those sites within the unit cell can be specified by the site_offsets parameter. The extent is a array where extent[d] specifies the number of times each unit cell is translated along direction \(d\). The full lattice is then generated by placing a site at each of the points

\[R_{rq} = \sum_{d=1}^D r_d a_d + b_q \in \mathbb R^D\]

where \(r_d \in \{1, \ldots, \mathtt{extent}[d]\}\) and \(b_q = \mathtt{site\_offsets}[q]\). We also refer to \(q\) as the label of the site within the unit cell.

The lattice class supports three ways of addressing a specific lattice site:

id

An integer index that is used to identify the site in self.edges() and also corresponds to the index of the corresponding site in sequences like self.nodes(), self.positions or self.basis_coords.

positions

Real-space position vector \(R_{rq}\) as defined above, which is available from positions() and can be resolved into an id via id_from_position().

basis coordinates

where each site is specified by a vector [r1, ..., rD, q] with \(r\) being the integer vector of length ndim specifying the cell position as multiples of the primitive vectors and the site label \(q\) giving the number of the site within the unit cell. Basis coordinates are available from basis_coords() and can be resolved into an id via id_from_basis_coords().

Inheritance
Inheritance diagram of netket.graph.Lattice
__init__(basis_vectors, extent, *, pbc=True, site_offsets=None, distance_atol=1e-05, point_group=None, max_neighbor_order=None, custom_edges=None)[source]#

Constructs a new Lattice given its side length and the features of the unit cell.

Parameters:
  • basis_vectors (ndarray) – The basis vectors of the lattice. Should be an array of shape (ndim, ndim) where each row is a basis vector.

  • extent (ndarray) – The number of copies of the unit cell; needs to be an array of length ndim.

  • pbc (bool | Sequence[bool]) – If True then the constructed lattice will have periodic boundary conditions, otherwise open boundary conditions are imposed. Can also be an boolean sequence of length ndim, indicating either open or closed boundary conditions separately for each direction.

  • site_offsets (ndarray | None) – The position offsets of sites in the unit cell (one site at the origin by default).

  • distance_atol (float) – Distance below which spatial points are considered equal for the purpose of identifying nearest neighbors.

  • point_group (PointGroup | None) – Default PointGroup object for constructing space groups

  • max_neighbor_order (int | None) – For max_neighbor_order == k, edges between up to \(k\)-nearest neighbor sites (measured by their Euclidean distance) are included in the graph. The edges can be distinguished by their color, which is set to \(k - 1\) (so nearest-neighbor edges have color 0). By default, nearest neighbours (max_neighbor_order=1) are autogenerated unless custom_edges is passed.

  • custom_edges (Sequence[Union[tuple[int, int, Union[ndarray, Array]], tuple[int, int, Union[ndarray, Array], int]]] | None) – (Optional) Lists all edges starting in one unit cell, which are repeated in every unit cell of the constructed lattice. Should be a list of tuples; each tuple should contain the following: * index of the starting point in the unit cell * index of the endpoint in the unit cell * vector pointing from the former to the latter * color of the edge (optional) If colors are not supplied, they are assigned sequentially starting from 0. Cannot be used together with max_neighbor_order.

Examples

Constructs a Kagome lattice with 3 Γ— 3 unit cells:

>>> import numpy as np
>>> from netket.graph import Lattice
>>> # Hexagonal lattice basis
>>> sqrt3 = np.sqrt(3.0)
>>> basis = np.array([
...     [1.0, 0.0],
...     [0.5, sqrt3 / 2.0],
... ])
>>> # Kagome unit cell
>>> cell = np.array([
...     basis[0] / 2.0,
...     basis[1] / 2.0,
...     (basis[0]+basis[1])/2.0
... ])
>>> g = Lattice(basis_vectors=basis, site_offsets=cell, extent=[3, 3])
>>> print(g.n_nodes)
27
>>> print(g.basis_coords[:6])
[[0 0 0]
 [0 0 1]
 [0 0 2]
 [0 1 0]
 [0 1 1]
 [0 1 2]]
 >>> print(g.positions[:6])
 [[0.5        0.        ]
  [0.25       0.4330127 ]
  [0.75       0.4330127 ]
  [1.         0.8660254 ]
  [0.75       1.29903811]
  [1.25       1.29903811]]

Constructs a rectangular lattice with distinct horizontal and vertical edges:

>>> import numpy as np
>>> from netket.graph import Lattice
>>> basis = np.array([
...     [1.0,0.0],
...     [0.0,0.5],
... ])
>>> custom_edges = [
...     (0, 0, [1.0,0.0], 0),
...     (0, 0, [0.0,0.5], 1),
... ]
>>> g = Lattice(basis_vectors=basis, pbc=False, extent=[4,6],
...     custom_edges=custom_edges)
>>> print(g.n_nodes)
24
>>> print(len(g.edges(filter_color=0)))
18
>>> print(len(g.edges(filter_color=1)))
20
Attributes
basis_coords#

basis coordinates of all lattice sites

basis_vectors#

Basis vectors of the lattice

edge_colors#

Sequence of edge colors, in the order of the edges returned by self.edges.

extent#

Extent of the lattice

n_edges#

The number of edges in the graph.

n_nodes#

The number of nodes (or vertices) in the graph

ndim#

Dimension of the lattice

pbc#

Array of bools such that pbc[d] indicates whether dimension d has periodic boundaries.

positions#

Real-space positions of all lattice sites

site_offsets#

Position offsets of sites in the unit cell

sites#

Sequence of lattice site objects

Methods
adjacency_list()[source]#

List containing the adjacency list of the graph where each node is represented by an integer in [0, n_nodes)

Return type:

list[list]

automorphisms()[source]#

Symmetry group containing the automorphisms of the graph

Return type:

PermutationGroup

distances()[source]#

List containing the distances between the nodes. The distance between unconnected nodes (no path exists between them) is set to -1

Return type:

list[list]

draw(ax=None, figsize=None, distance_order=1, *, node_size=None, node_color='#1f78b4', node_text_color=None, node_text_offset=None, extra_sites_alpha=0.3, draw_neighbors=True, draw_text=True, draw_basis_vectors=True, draw_unit_cell=True, show=True, **kwargs)[source]#

Draws the Lattice graph

Parameters:
  • ax – A Matplotlib axis object. If unspecified it creates a figure.

  • figsize (tuple[int | float] | None) – (width, height) tuple of the generated figure, if no axes is specified.

  • node_size (int | None) – Size of the nodes (as in matplotlib.pyplot.scatter).

  • node_color (str) – String with the colour of the nodes.

  • node_text_color (str | None) – String with the colour of the integer labelling the nodes. Defaults to white for 1D/2D and black in 3D.

  • node_text_offset (float | None) – float or 1/2/3-vector of offset for the label from the node. Defaults to 0 for 1/2D and to 0.05 for 3D.

  • extra_sites_alpha (float) – A float value between 0 and 1 for the alpha of the sites outside of the extent. Defaults to 0.3

  • extra_sites_alpha – If true, we also draw sites outside of the extent of the lattice corresponding to the periodic images. (Defaults True)

  • draw_text (bool) – If True, we draw the integer label with the site index (defaults to True).

  • draw_basis_vectors (bool) – If True, draw the basis vectors (defaults to True).

  • draw_unit_cell (bool) – If True, shade an area corresponding to the unit cell starting at the origin (Defaults to True).

  • show (bool) – If True, show the plot before returning it (defaults to True).

  • draw_neighbors (bool)

Returns:

Matplotlib axis object containing the graph’s drawing.

edges(color=None, *, return_color=False, filter_color=None)[source]#

Returns the sequence of edges of the graph.

Parameters:
  • return_color (bool) – If True, return edges with added color information.

  • filter_color (int | None) – If set, return only edges of the given color.

Return type:

Union[Sequence[tuple[int, int]], Sequence[tuple[int, int, int]]]

Returns:

A sequence of edges as tuples (i, j) or, if return_color is passed, a sequence of tuples (i, j, c) with c indicating the color of the respective edge.

classmethod from_igraph(graph)[source]#

Creates a new Graph instance from an igraph.Graph instance.

Return type:

Graph

Parameters:

graph (Graph)

classmethod from_networkx(graph)[source]#

Creates a new Graph instance from a networkx graph.

Return type:

Graph

id_from_basis_coords(basis_coords)[source]#

Return the id for a site at the given basis coordinates. When passed a rank-2 array where each row is a coordinate vector, returns an array of the corresponding ids. Throws an InvalidSiteError if any of the coords do not correspond to a site.

Return type:

Union[int, ndarray, Array]

Parameters:

basis_coords (ndarray)

id_from_position(position)[source]#

Returns the id for a site at the given position. When passed a rank-2 array where each row is a position, returns an array of the corresponding ids. Throws an InvalidSiteError if any of the positions do not correspond to a site.

Return type:

Union[int, ndarray, Array]

Parameters:

position (ndarray)

is_bipartite()[source]#

True if the graph is bipartite

Return type:

bool

is_connected()[source]#

True if the graph is connected

Return type:

bool

nodes()[source]#

Iterator over the nodes of the graph

Return type:

Sequence[int]

point_group(point_group=None)[source]#

Returns the action of point_group on the sites of self as a PermutationGroup. If no point_group is specified, uses the point group provided upon construction.

Return type:

PermutationGroup

Parameters:

point_group (PointGroup | None)

position_from_basis_coords(basis_coords)[source]#

Return the position of the site with given basis coordinates. When passed a rank-2 array where each row is a coordinate vector, this method returns an array of the corresponding positions. Throws an InvalidSiteError if no site is found for any of the coordinates.

Return type:

ndarray

Parameters:

basis_coords (ndarray)

rotation_group(point_group=None)[source]#

Returns the action of rotations (i.e. symmetries with determinant +1) in point_group on the sites of self as a PermutationGroup. If no point_group is specified, uses the point group provided upon construction.

Return type:

PermutationGroup

Parameters:

point_group (PointGroup | None)

space_group(point_group=None)[source]#

Returns the space group generated by the translation symmetries of self and the elements of point_group as a PermutationGroup acting on the sites of self. If no point_group is specified, uses the point group provided upon construction.

Return type:

PermutationGroup

Parameters:

point_group (PointGroup | None)

space_group_builder(point_group=None)[source]#

Returns a SpaceGroupBuilder object that represents the spatial symmetries of self.

Parameters:

point_group (PointGroup | None) – a PointGroup object describing the point-group symmetries of self. Optional, if not supplied, the PointGroup object provided at construction is used.

Return type:

SpaceGroupBuilder

Returns:

A SpaceGroupBuilder object that generates PermutationGroup`s encoding the action of `point_group, the translation group of self, and the space group obtained as their semidirect product as permutations of the sites of self. It also yields space group irreps for symmetrising wave functions.

to_igraph()[source]#

Returns a copy of this graph as an igraph.Graph instance.

to_networkx()[source]#

Returns a copy of this graph as an igraph.Graph instance. This method requires networkx to be installed.

to_reciprocal_lattice(ks)[source]#

Converts wave vectors from Cartesian axes to reciprocal lattice vectors.

Parameters:

ks (Union[ndarray, Array]) – wave vectors in Cartesian axes. Multidimensional arrays are accepted, the Cartesian coordinates must form the last dimension.

Return type:

Union[ndarray, Array]

Returns:

The same wave vectors in the reciprocal basis of the simulation box. Valid wave vector components in this basis are integers in (periodic BCs) or zero (in open BCs).

Throws an InvalidWaveVectorError if any of the supplied wave vectors are not reciprocal lattice vectors of the simulation box.

translation_group(dim=None)[source]#

Returns the group of lattice translations of self as a PermutationGroup acting on the sites of self.

Return type:

PermutationGroup

Parameters:

dim (int | Sequence[int] | None)