q-points#

Generation of the q-points at which correlation functions are evaluated.

Two sampling strategies are available. get_spherical_qpoints() samples the reciprocal lattice isotropically inside a radius, which is what an isotropic system such as a liquid or a powder calls for. Lattice and get_supercell_qpoints_along_path() instead yield only the q-points commensurate with a given supercell, i.e. the ones a simulation in that supercell can actually resolve, which is what lattice dynamics of a crystal requires. is_qpoint_commensurate() tests a single q-point against a cell.

class dynasor.qpoints.Lattice(primitive_cell, supercell_cell)[source]#

Relates a primitive cell to a supercell and provides the commensurate q-points.

The class serves two purposes: it holds the integer repetition matrix P connecting the two cells, and it hands out the q-points that a simulation in that supercell can actually resolve, via q_reduced, q_cartesian and make_path().

The supercell S is given by the primitive cell p and a repetition matrix P such that:

dot(P, p) = S

In this convention the cell vectors are row vectors of p and S as in ASE. An inverse cell is defined as:

c_inv = inv(c).T

and the reciprocal cell is defined as:

c_rec = 2*pi*inv(c).T

Notice that the inverse cell here is defined with the transpose so that the lattice vectors of the inverse/reciprocal lattice are also row vectors. The above also implies:

dot(P.T, S_inv) = p_inv

The inverse supercell S_inv defines a new lattice in reciprocal space. Those inverse lattice points which reside inside the inverse primitive cell p_inv are called commensurate lattice points. These are typically the only points of interest in MD simulations from a crystallographic and lattice dynamics point of view.

The convention taken here is that the reciprocal cell carries the 2pi factor onto the cartesian q-points. This is consistent with e.g. Kittel. The reduced coordinates are always with respect to the reciprocal primitive cell.

Parameters:
  • primitive_cell (GenericAlias[float]) – Cell metric of the primitive cell with lattice vectors as rows.

  • supercell_cell (GenericAlias[float]) – Cell metric of the supercell with lattice vectors as rows.

Example

>>> from ase.build import bulk
>>> from dynasor.qpoints import Lattice
>>> prim = bulk('Al', 'fcc', a=4.0)
>>> lattice = Lattice(prim.cell, prim.repeat(2).cell)
>>> len(lattice.q_cartesian)
8
property P: NDArray[int]#

The P-matrix for this system, P @ primitive_cell = supercell_cell

property P_inv: NDArray[Fraction]#

Inverse of P as exact fractions.Fraction values.

cartesian_to_reduced(qpoints)[source]#

Convert from Cartesian to reduced coordinates.

Return type:

GenericAlias[float]

make_path(start, stop)[source]#

Takes qpoints in reduced coordinates and returns all points in between

Parameters:
  • start (GenericAlias[float]) – Coordinate of starting point in reduced inverse coordinates. For example, a zone mode is given as (0.5, 0, 0), (0,0,0) == (1,0,0) etc.

  • stop (GenericAlias[float]) – Stop position.

Return type:

tuple[GenericAlias[float], GenericAlias[float]]

Returns:

Tuple of the coordinates of commensurate points along path in Cartesian reciprocals and the fractional distances along the path.

property primitive_cell: NDArray[float]#

Returns the primitive cell with lattice vectors as rows

property q_cartesian: NDArray[float]#

The commensurate q-points in Cartesian coordinates with unit of rad/Å.

property q_minus: NDArray[int]#

For each q-point, the index of the q-point corresponding to \(-q\).

property q_reduced: NDArray[Fraction]#

The commensurate q-points in reduced coordinates, as exact fractions.

This is an object array, so it is not a drop-in numerical array; np.allclose, np.isfinite and np.round raise TypeError on it, while .astype(float), arithmetic and np.sort work.

property reciprocal_primitive_cell: NDArray[float]#

Returns 2*pi*inv(primitive_cell).T so that the rows are the inverse lattice vectors

property reciprocal_supercell_cell: NDArray[float]#

Returns 2*pi*inv(supercell_cell).T so that the rows are the inverse lattice vectors

reduced_to_cartesian(qpoints)[source]#

Convert from reduced to cartesian coordinates.

Accepts the exact fractions returned by q_reduced as well as floats.

Return type:

GenericAlias[float]

property supercell_cell: NDArray[float]#

Returns the supercell with lattice vectors as rows

dynasor.qpoints.get_P_matrix(c, S)[source]#

Returns the P matrix, i.e., the 3x3 integer matrix \(P\) that satisfies

\[P c = S\]

Here, \(c\) is the primitive cell metric and \(S\) is the supercell metric as row vectors. Note that the above condition is equivalent to:

\[c^T P^T = S^T\]
Parameters:
  • c (GenericAlias[float]) – Cell metric of the primitive structure.

  • S (GenericAlias[float]) – Cell metric of the supercell.

Return type:

GenericAlias[int]

dynasor.qpoints.get_spherical_qpoints(cell, q_max, q_min=0.0, max_points=None, seed=42, chunk_size=100000)[source]#

Generates all q-points on the reciprocal lattice inside a given radius q_max. This approach is suitable if an isotropic sampling of q-space is desired. The function returns the resulting q-points in Cartesian coordinates as an Nx3 array.

If the number of generated q-points are large, points can be removed by specifying max_points. The q-points will be randomly removed in such a way that the q-points inside are roughly uniformly distributed with respect to \(|q|\). If the number of q-points are binned w.r.t. their norm the function would increase quadratically up until some distance P from which point the distribution would be constant.

Parameters:
  • cell (GenericAlias[float]) – Real cell with cell vectors as rows.

  • q_max (float) – Maximum norm of generated q-points (in units of rad/Å, i.e. including factor of \(2\pi\)).

  • q_min (Optional[float]) – Minimum norm of generated q-points (in units of rad/Å, i.e. including factor of \(2\pi\)).

  • max_points (Optional[int]) – Optionally limit the set to __approximately__ max_points points by randomly removing points from a “fully populated mesh”. The points are removed in such a way that for \(q > q_\mathrm{prune}\), the points will be radially uniformly distributed. The value of \(q_\mathrm{prune}\) is calculated from q_max, max_points, and the shape of the cell.

  • seed (Optional[int]) – Seed used for stochastic pruning.

  • chunk_size (Optional[int]) – Number of q-points to process at once (controls memory use).

Return type:

GenericAlias[float]

dynasor.qpoints.get_supercell_qpoints_along_path(path, coordinates, primitive_cell, supercell_cell)[source]#

Returns the q-points commensurate with the given supercell along the specific path.

Parameters:
  • path (list[tuple[str, str]]) – List of pairs of q-point labels.

  • coordinates (dict[str, GenericAlias[float]]) – Dict with q-point labels and coordinates as keys and values, respectively; there must be one entry for each q-point label used in path.

  • primitive_cell (GenericAlias[float]) – Cell metric of the primitive cell with lattice vectors as rows.

  • supercell_cell (GenericAlias[float]) – Cell metric of the supercell with lattice vectors as rows.

Return type:

list[GenericAlias[float]]

Returns:

A list of the accessible q-point coordinates along the specified segment.

Example

The following example illustrates how to retrieve the q-points that can be sampled using a supercell comprising \(6 \times 6 \times 6\) conventional (4-atom) unit cells of FCC Al along the path X-\(\Gamma\)-L.

>>> import numpy as np
>>> from ase.build import bulk
>>> from dynasor.qpoints import get_supercell_qpoints_along_path
>>> prim = bulk('Al', 'fcc', a=4.0)
>>> supercell = bulk('Al', 'fcc', a=4.0, cubic=True).repeat(6)
>>> path = [('X', 'G'), ('G', 'L'), ('L', 'W')]
>>> coordinates = dict(X=[0.5, 0.5, 0], G=[0, 0, 0],
...                    L=[0.5, 0.5, 0.5], W=[0.5, 0.25, 0.75])
>>> qpoints = get_supercell_qpoints_along_path(
...     path, coordinates, prim.cell, supercell.cell)
dynasor.qpoints.is_qpoint_commensurate(q_point, cell, atol=1e-05)[source]#

Return whether a single q-point is commensurate with a periodic cell.

A q-point is commensurate with the cell when it is a reciprocal-lattice vector of that cell, i.e. when its reduced coordinates \(m_i = \mathbf{q}\cdot\mathbf{a}_i / 2\pi\) are all integers, where the \(\mathbf{a}_i\) are the cell vectors (rows of cell). Only then is \(\rho(\mathbf{q}) = \sum_j e^{i\mathbf{q}\cdot\mathbf{r}_j}\) independent of which periodic image is chosen for each atom; at other q-points the correlation functions can contain artifacts.

The reduced coordinates are formed with the full cell matrix, so the test is correct for non-orthogonal cells (a per-axis check would not be).

Parameters:
  • q_point (GenericAlias[float]) – A single q-point (3,) in Cartesian coordinates (rad/Å).

  • cell (GenericAlias[float]) – Cell metric with lattice vectors as rows (Å).

  • atol (float) – Absolute tolerance on the reduced coordinates when testing for integers.

Return type:

bool