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 thesite_offsets
parameter. Theextent
is 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.positions
orself.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 lengthndim
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 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)[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
]) β IfTrue
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 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_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)
- distances()[source]#
List containing the distances between the nodes. The distance between unconnected nodes (no path exists between them) is set to -1
- 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.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(color=None, *, 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]#
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.
- 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:
- 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]#
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:
- 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:
- 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_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:
- 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.