pwtools.crys.grid_in_cell

pwtools.crys.grid_in_cell(cell, h=None, size=None, minpoints=1, even=False, fullout=False)[source]

For a given cell, generate grid size from grid spacing h or vice versa.

Usually used to calculate k-grids for reciprocal cells. See also kgrid().

Parameters:
  • cell (array (3,3)) – Cell with vectors as rows.

  • h (float) – 1d target grid spacing along a cell axis. Unit is that of the cell sides.

  • size (sequence (3,)) – Use either h or size.

  • minpoints (int) – Minimal number of grid points in each direction. May result in smaller effective h. minpoints=1 (default) asserts that at least the Gamma point [1,1,1] is returned. Otherwise, big cells or big h values will create zero grid points.

  • even (bool) – Force even grid point numbers. Here, we add 1 to odd points, thus creating a grid more dense than requested by h.

  • fullout (bool) – See below.

Returns:

  • size (if h != None + fullout=False)

  • size, spacing (if h != None + fullout=True)

  • spacing (if size != None and h=None)

  • size (array (3,) [nx, ny, nz]) – Integer numbers of grid points along each reciprocal axis.

  • spacing (1d array (3,)) – Result spacing along each reciprocal axis if size would be used.

Notes

  • B/c an integer array is created by rounding, the effective grid spacing will mostly be slightly bigger/smaller then h (see fullout).

Examples

>>> crys.grid_in_cell(diag([1,2,3]), h=1)
array([1, 2, 3])
>>> crys.grid_in_cell(diag([1,2,3]), h=0.5)
array([2, 4, 6])
>>> crys.grid_in_cell(diag([1,2,3]), h=0.5, fullout=True)
(array([2, 4, 6]), array([ 0.5,  0.5,  0.5]))
>>> crys.grid_in_cell(diag([1,2,3]), size=[2,2,2])
array([ 0.5,  1. ,  1.5])