LatticeUtils

This module contains useful functions for working with lattice related topics like compute the volume of a (direct or reciprocal) lattice, perform the conversion from cartesian to crystal units or generate the atomic positions for a given value of replica of the lattice cell. This functions are also used by the PwParser and the YamboDftParser classes.

mppi.Utilities.LatticeUtils.build_lattice(lattice_vectors, atom_pos, Nx, Ny, Nz)[source]

Create the arrays of the x,y and z positions of each atom in the lattice. The function make usage of the lattice vectors, of the atoms positions and of the number of replica of the unit cell in the x,y and z directions.

Parameters:
  • lattice_vectors (array) – array with the lattice vectors. The i-th row represents the i-th lattice vectors in cartesian units

  • atom_pos (list) – each element has the structure of the atomic_positions attribute of the pw xml data-file-schema [‘atom_name’,x,y,z] and specify the position of the atom in the unit cell in cartesian coordinate

  • Nx (int) – number of unit cells to be plotted in the x-direction

  • Ny (int) – number of unit cells to be plotted in the y-direction

  • Nz (int) – number of unit cells to be plotted in the z-direction

Returns:

Each element has the structure

[‘atom_name’,x,y,z] where x,y and z are arrays with corresponding coordinates of all the atoms of ‘atom__name’ type in the lattice

Return type:

list

mppi.Utilities.LatticeUtils.convert_to_cartesian(lattice, vector_crystal)[source]

Convert the crystal coordinates of a vector into cartesian ones. It can be used for both direct lattice vectors (like the atomic position) and reciprocal lattice related quantities (like the k-points).

Parameters:
  • lattice (array) – array with the (direct or reciprocal) lattice vectors. The i-th row represents the i-th lattice vectors in cartesian units

  • vector_crystal (array) – array with the crystal coordinates of the vector

Returns:

array with the cartesian coordinates of the vector

Return type:

(array)

mppi.Utilities.LatticeUtils.convert_to_crystal(lattice, vector_cartesian)[source]

Convert the cartesian coordinates of a vector into crystal ones. It can be used for both direct lattice vectors (like the atomic position) and reciprocal lattice related quantities (like the k-points).

Parameters:
  • lattice (array) – array with the (direct or reciprocal) lattice vectors. The i-th row represents the i-th lattice vectors in cartesian units

  • vector_cartesian (array) – array with the cartesian coordinates of the vector

Returns:

array with the crystal coordinates of the vector

Return type:

(array)

mppi.Utilities.LatticeUtils.distance_point_to_segment(point, start, end)[source]

Compute the distance between a point and a segment that has the points start and end as edges. The function checks if the orthogonal projection of the point to the segment line belongs to the segment itself. If not, the distance is computed as the minum value between the distances of the point w.r.t. the start and end points of the segment. Note that the function uses vectors analysis so it can be used in both 2D and 3D.

Parameters:
  • point (np.array) – cartesian coordinates of the point

  • start (np.array) – cartesian coordinates of the start point of the segment

  • end (np.array) – cartesian coordinates of the end point of the segment

Returns :

tuple : the tuple (distance,ascissa_path) with the value of the distance and the value of the curvilinear ascissa on the line associated to the line element closest to the point

mppi.Utilities.LatticeUtils.eval_lattice_volume(lattice)[source]

Compute the volume of a lattice

Parameters:

lattice (array) – array with the lattice vectors. The i-th row represents the i-th lattice vectors in cartesian units

Returns:

lattice volume

Return type:

float

mppi.Utilities.LatticeUtils.get_lattice(lattice, alat, rescale=False)[source]

Compute the lattice vectors. If rescale = True the vectors are expressed in units of the lattice constant.

Parameters:
  • lattice (array) – array with the lattice vectors. The i-th row represents the i-th lattice vectors in cartesian units

  • alat (float) – lattice parameter

  • rescale (bool) – if True express the lattice vectors in units alat

Returns:

array with the lattice vectors a_i as rows

Return type:

array

mppi.Utilities.LatticeUtils.get_reciprocal_lattice(lattice, alat, rescale=False)[source]

Calculate the reciprocal lattice vectors. If rescale = False the vectors are normalized so that np.dot(a_i,b_j) = 2*np.pi*delta_ij, where a_i is a basis vector of the direct lattice. If rescale = True the reciprocal lattice vectors are expressed in units of 2*np.pi/alat

Parameters:
  • lattice (array) – array with the lattice vectors. The i-th row represents the i-th lattice vectors in cartesian units

  • alat (float) – lattice parameter

  • rescale (bool) – if True express the reciprocal lattice vectors in units of 2*np.pi/alat

Returns:

array with the reciprocal lattice vectors b_i as rows

Return type:

array

mppi.Utilities.LatticeUtils.get_yambo_kpoints(kpoints, alat, use_scalar_alat=True)[source]

Get the kpoints using cartesian coordinates in units of 2*np.pi/alat (with a vector alat).

Parameters:
  • kpoints (array) – array with the kpoints.

  • alat (array) – vector lattice parameters

  • use_scalar_alat (bool) – if True express the kpoints in units of 2*np.pi/alat[0]

Returns:

array with the kpoints

Return type:

array