netket.graph.Lattice#
- class netket.graph.Lattice[source]#
Bases:
GraphA 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 thesite_offsetsparameter. Theextentis a array whereextent[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 likeself.nodes(),self.positionsorself.basis_coords.- positions
Real-space position vector \(R_{rq}\) as defined above, which is available from
positions()and can be resolved into an id viaid_from_position().- basis coordinates
where each site is specified by a vector
[r1, ..., rD, q]with \(r\) being the integer vector of lengthndimspecifying 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 frombasis_coords()and can be resolved into an id viaid_from_basis_coords().
- Inheritance

- __init__(basis_vectors, extent, *, pbc=True, site_offsets=None, distance_atol=1e-05, point_group=None, max_neighbor_order=None, custom_edges=None, _known_name=None)[source]#
Construct a new
Latticegiven 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]) β IfTruethen 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 groupsmax_neighbor_order (
int|None) β Formax_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 unlesscustom_edgesis 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._known_name (
str|None) β Private display name used by NetKetβs builtin lattice constructors to provide a more informative string representation.
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
- default_space_group#
- edge_colors#
Sequence of edge colors, in the order of the edges returned by
self.edges.
- extent#
Extent of the lattice
- full_translation_group#
The full translation group 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)
- distances()[source]#
Return the integer graph distance between all pairs \(i,j\) of sites in the graph.
The graph distance is the shortest-path length, i.e. the minimum number of edges connecting two sites. The distance between unconnected nodes (no path exists between them) is set to \(-1\).
- distances_euclidean(*, minimum_image=True)[source]#
Return the Euclidean distance between all pairs \(i,j\) of lattice sites.
Distances are computed from
positionsin real space and returned as a dense matrix \(D\) with \(D[i, j] = \|r_i-r_j\|_2\).
- 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)[source]#
Draws the
Latticegraph- 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.3extra_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(*, return_color=False, filter_color=None)[source]#
Returns the sequence of edges of the graph.
- classmethod from_igraph(graph)[source]#
Creates a new Graph instance from an igraph.Graph instance.
- Return type:
- Parameters:
graph (Graph)
- classmethod from_networkx(graph)[source]#
Creates a new Graph instance from a networkx graph.
- Return type:
- 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.
- id_from_position(position)[source]#
Return 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.
- point_group(point_group=None)[source]#
Return 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:
- 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.
- rotation_group(point_group=None)[source]#
Return 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:
- Parameters:
point_group (PointGroup | None)
- space_group(point_group=None)[source]#
Return 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.
- 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:
- Returns:
A SpaceGroup object that generates PermutationGroup`s that encode 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.
- space_group_builder(point_group=None)[source]#
Deprecated. See Lattice.space_group for details.
- Return type:
- Parameters:
point_group (PointGroup | None)
- 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]#
Convert 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, strides=None)[source]#
Return the group of lattice translations of self as a PermutationGroup acting on the sites of self.
- Parameters:
dim (
int|Sequence[int] |None) β Axes along which to include translations. If None, all axes with periodic boundary conditions are included.strides (
int|Sequence[int] |None) β Step size (in unit cells) for translations along each axis in dim. A stride of s includes only every s-th translation, giving a subgroup of sizeextent // s. Must divide the lattice extent for each periodic axis. If None, defaults to 1 (all translations included).
- Return type: