pynitride.core.reciprocal_mesh module

class pynitride.core.reciprocal_mesh.RMesh(name='')

Bases: object

Superclass for all the reciprocal meshes

N

The number of points in the grid

Omega

The integration area element assigned to each kpoint as a 1-D array

absk

The absk values of the grid as a 1-D array

d

The grid covers 1/d of the angular k-space

integrate(integrand)

Integrates the integrand over the RMesh. For instance, if the integrand is 1, you should get the area of the k-space. For a regular mesh with no shift, that would be \(\pi\times kmax^2\) For a mesh of the full Brillouin zone, that would be the full bzarea.

Note that this integral is just an integral over k-space, ie does not magically include the \(1/4\pi^2\) pre-factor which appears when converting a sum over k-space to an integral over k-space.

Parameters:

integrand – a 1-D array of length RMesh.N

kmax

The maximum value of \(|k|\)

kx

The kx values of the grid as a 1-D array

ky

The ky values of the grid as a 1-D array

name

A user-specified optional name

read(filename, keys=None)

Reads the contents of the reciprocal mesh from a Numpy .npz

Parameters:
  • filename – the path to read from

  • keys – if given, only reads the specified list of keys

save(filename, keys=None)

Saves the contents of the reciprocal mesh to a Numpy .npz

Parameters:
  • filename – the path to save to

  • keys – if given, only saves the specified list of keys

theta

The theta values of the grid as a 1-D array

class pynitride.core.reciprocal_mesh.RMesh1D(absk, bzarea=None, ival=None, name='')

Bases: RMesh

A 1-D mesh of k-space.

Note that when integrating over the mesh via RMesh.integrate(), it will behave as a 2D integral, ie the increased weighting of points at higher radius is accounted for intrinsically by this function.

Superclass for all the reciprocal meshes

absk_subrmesh(indices)

Forms an Rmesh1D which is subset of this one, keeping only the specified indices

Parameters:

indices – list of indices into the RMesh which should be keep

exact_to_index(absk)

Returns the index into the absk1 array for a given k-point

interpolator(func)

Returns a 1-D spline interpolation of func

The returned function is called like interp(absk, theta=0, dabsk=0, bounds_check=True) where absk is the radial coordinate, theta is ignored (present for compatibility with RMesh2D code), ‘dabsk` specifies order of radial derivative, and bounds_check specifies whether to throw out-of-bounds errors

Parameters:

func – the function to interpolate

classmethod regular(kmax, numabsk, abskshift=0, name='')

Generate a uniform 1D grid.

The k-points go from 0 to kmax inclusive, but with an optional shift. The endpoints of the mesh are treated as endpoints of integration.

Parameters:
  • kmax (float) – the largest k-point will be kmax+abskshift

  • numabsk (int) – number of k-points to have

  • abskshift (float) – shift all k-points from starting at zero

Returns:

a RMesh1D

class pynitride.core.reciprocal_mesh.RMesh2D_Polar(absk, theta, d=1, bzarea=None, name='')

Bases: RMesh

A 2-D mesh of k-space.

Superclass for all the reciprocal meshes

absk_subrmesh(abskstart=1, abskstop=-1, name=None)

Produce an RMesh which is a contiguous subset of this one in absk

Parameters:
  • abskstart – the absk index to start on

  • abskstop – the absk index to stop before

  • name – the name for the new RMesh

conv2flat(arr)

Convert a 2D grid to a 1D array consistent with the mesh conventions.

Parameters:

arr – doesn’t need to be 2D per se, but the first two dimensions must be numabsk and numtheta long respectively. Other dimensions just along for the ride.

Returns:

an (numstates) 1D array + other dimensions

conv2grid(arr)

Convert a 1D array to a 2D grid consistent with the mesh ordering.

Parameters:

arr – doesn’t need to be 1D per se, but the first dimension must be numstates long. Other dimensions just along for the ride.

Returns:

a (numabsk,numtheta) 2D array + other dimensions.

ikx(sign=False)

Returns the indices into the RMesh corresponding to a slice along ky=0.

Parameters:

sign – if True, include only non-negative values of kx

iky(sign=False)

Returns the indices into the RMesh corresponding to a slice along kx=0.

Parameters:

sign – if True, include only non-negative values of ky

index_to_partial_indices(i)

Given an index into the RMesh, returns indices into absk and into theta

interpolator(func)

Returns a 2-D spline interpolation of func

The returned function is called like interp(absk, theta, grid=False, dabsk=0, dtheta=0, bounds_check=True) where absk, theta are the coordinates, grid is as in scipy.interpolate.BivariateSpline, dabsk, dtheta specify order of respective derivatives, and bounds_check specifies whether to throw out-of-bounds errors

Parameters:

func – the function to interpolate

partial_indices_to_index(iabsk, itheta)

Given an index into absk and into theta, returns an index into the RMesh

classmethod regular(kmax, numabsk, numtheta, include_kzero=True, align_theta=False, d=1, name='')

Generate a regular 2D grid.

The absk1-points go from kmax/numabsk to kmax or 0 to kmax depending on include_kzero. Regardless, 0 and the kmax are treated as endpoints of integration.

This function is just a thin wrapper around RMesh.uniform_theta(). See there for more arguments and details.

Parameters:
  • kmax (float) – the largest k-point will be kmax

  • numabsk (int) – number of k-points to have

Returns:

a RMesh1D

classmethod regular_theta(absk, numtheta, align_theta=False, d=1, name='')

Generate a 2D grid with regular theta spacing.

Regardless of whether absk includes a point at 0, 0 and the max(absk) are treated as endpoints of integration.

The integration endpoints of theta are \(-pi/d\) and \(+\pi/d\). By choosing d and shift_theta, one can choose any proper fraction of k-space to cover.

Parameters:
  • absk – the ordered array of k-points

  • numtheta (int) – number of theta points to have

  • include_zero (bool) – whether to have a point at 0

  • align_theta (bool) – If True there is a theta at 0. If False, then the points will be shifted so a midpoint between thetas is at 0.

  • d (int) – what fraction of the k-space to cover angularly (d=1 is the whole k-space, d=2 is half, etc.)

Returns:

a RMesh1D

show_func(func, style='balanced', points=True, lines=True, cax=None, vmax=None, numloc=1000, label=None)

Visualize func on a rasterized 2D colormesh plot.

Parameters:
  • func – the function (as a 1-D array of the same shape as the RMesh variables)

  • style – ‘balanced’ will give a red-blue plot with the color-scale set symmetrically, while ‘positive’ will give a white-to-red plot where white is the zero

  • points – whether to plot a point marker at the center of each mesh element

  • lines – whether to plot the boundary lines of each mesh element

  • cax – optional axes for the colorscale (if not supplied, will be created)

  • vmax – for the ‘positive’ style, a vmax can be specified (otherwise chosen automatically)

  • numloc – number of points each along kx and ky to use when forming the colormesh