# pymatgen.core.lattice module¶

class Lattice(matrix)[source]

Bases: monty.json.MSONable

A lattice object. Essentially a matrix with conversion matrices. In general, it is assumed that length units are in Angstroms and angles are in degrees unless otherwise stated.

Create a lattice from any sequence of 9 numbers. Note that the sequence is assumed to be read one row at a time. Each row represents one lattice vector.

Parameters: matrix – Sequence of numbers in any form. Examples of acceptable input. i) An actual numpy array. ii) [[1, 0, 0], [0, 1, 0], [0, 0, 1]] iii) [1, 0, 0 , 0, 1, 0, 0, 0, 1] iv) (1, 0, 0, 0, 1, 0, 0, 0, 1) Each row should correspond to a lattice vector. E.g., [[10, 0, 0], [20, 10, 0], [0, 0, 30]] specifies a lattice with lattice vectors [10, 0, 0], [20, 10, 0] and [0, 0, 30].
a

a lattice parameter.ATATClusterExpansion

abc

Lengths of the lattice vectors, i.e. (a, b, c)

alpha

Angle alpha of lattice in degrees.

angles

Returns the angles (alpha, beta, gamma) of the lattice.

as_dict(verbosity=0)[source]

“” Json-serialization dict representation of the Lattice.

Parameters: verbosity (int) – Verbosity level. Default of 0 only includes the matrix representation. Set to 1 for more details.
b

b lattice parameter.

beta

Angle beta of lattice in degrees.

c

c lattice parameter.

copy()[source]

Deep copy of self.

static cubic(a)[source]

Convenience constructor for a cubic lattice.

Parameters: a (float) – The a lattice parameter of the cubic cell. Cubic lattice of dimensions a x a x a.
dot(coords_a, coords_b, frac_coords=False)[source]

Compute the scalar product of vector(s).

Parameters: coords_b (coords_a,) – Array-like objects with the coordinates. frac_coords (bool) – Boolean stating whether the vector corresponds to fractional or cartesian coordinates. one-dimensional numpy array.
find_all_mappings(other_lattice, ltol=1e-05, atol=1, skip_rotation_matrix=False)[source]

Finds all mappings between current lattice and another lattice.

Parameters: other_lattice (Lattice) – Another lattice that is equivalent to this one. ltol (float) – Tolerance for matching lengths. Defaults to 1e-5. atol (float) – Tolerance for matching angles. Defaults to 1. skip_rotation_matrix (bool) – Whether to skip calculation of the rotation matrix (aligned_lattice, rotation_matrix, scale_matrix) if a mapping is found. aligned_lattice is a rotated version of other_lattice that has the same lattice parameters, but which is aligned in the coordinate system of this lattice so that translational points match up in 3D. rotation_matrix is the rotation that has to be applied to other_lattice to obtain aligned_lattice, i.e., aligned_matrix = np.inner(other_lattice, rotation_matrix) and op = SymmOp.from_rotation_and_translation(rotation_matrix) aligned_matrix = op.operate_multi(latt.matrix) Finally, scale_matrix is the integer matrix that expresses aligned_matrix as a linear combination of this lattice, i.e., aligned_matrix = np.dot(scale_matrix, self.matrix) None is returned if no matches are found.
find_mapping(other_lattice, ltol=1e-05, atol=1, skip_rotation_matrix=False)[source]

Finds a mapping between current lattice and another lattice. There are an infinite number of choices of basis vectors for two entirely equivalent lattices. This method returns a mapping that maps other_lattice to this lattice.

Parameters: other_lattice (Lattice) – Another lattice that is equivalent to this one. ltol (float) – Tolerance for matching lengths. Defaults to 1e-5. atol (float) – Tolerance for matching angles. Defaults to 1. (aligned_lattice, rotation_matrix, scale_matrix) if a mapping is found. aligned_lattice is a rotated version of other_lattice that has the same lattice parameters, but which is aligned in the coordinate system of this lattice so that translational points match up in 3D. rotation_matrix is the rotation that has to be applied to other_lattice to obtain aligned_lattice, i.e., aligned_matrix = np.inner(other_lattice, rotation_matrix) and op = SymmOp.from_rotation_and_translation(rotation_matrix) aligned_matrix = op.operate_multi(latt.matrix) Finally, scale_matrix is the integer matrix that expresses aligned_matrix as a linear combination of this lattice, i.e., aligned_matrix = np.dot(scale_matrix, self.matrix) None is returned if no matches are found.
classmethod from_dict(d, fmt=None, **kwargs)[source]

Create a Lattice from a dictionary containing the a, b, c, alpha, beta, and gamma parameters if fmt is None.

If fmt == “abivars”, the function build a Lattice object from a dictionary with the Abinit variables acell and rprim in Bohr. If acell is not given, the Abinit default is used i.e. [1,1,1] Bohr

Example

Lattice.from_dict(fmt=”abivars”, acell=3*[10], rprim=np.eye(3))

static from_lengths_and_angles(abc, ang)[source]

Create a Lattice using unit cell lengths and angles (in degrees).

Parameters: abc (3x1 array) – Lattice parameters, e.g. (4, 4, 5). ang (3x1 array) – Lattice angles in degrees, e.g., (90,90,120). A Lattice with the specified lattice parameters.
static from_parameters(a, b, c, alpha, beta, gamma)[source]

Create a Lattice using unit cell lengths and angles (in degrees).

Parameters: a (float) – a lattice parameter. b (float) – b lattice parameter. c (float) – c lattice parameter. alpha (float) – alpha angle in degrees. beta (float) – beta angle in degrees. gamma (float) – gamma angle in degrees. Lattice with the specified lattice parameters.
gamma

Angle gamma of lattice in degrees.

get_all_distance_and_image(*args, **kwargs)
get_all_distances(fcoords1, fcoords2)[source]

Returns the distances between two lists of coordinates taking into account periodic boundary conditions and the lattice. Note that this computes an MxN array of distances (i.e. the distance between each point in fcoords1 and every coordinate in fcoords2). This is different functionality from pbc_diff.

Parameters: fcoords1 – First set of fractional coordinates. e.g., [0.5, 0.6, 0.7] or [[1.1, 1.2, 4.3], [0.5, 0.6, 0.7]]. It can be a single coord or any array of coords. fcoords2 – Second set of fractional coordinates. 2d array of cartesian distances. E.g the distance between fcoords1[i] and fcoords2[j] is distances[i,j]
get_brillouin_zone()[source]

Returns the Wigner-Seitz cell for the reciprocal lattice, aka the Brillouin Zone.

Returns: A list of list of coordinates. Each element in the list is a “facet” of the boundary of the Brillouin Zone. For instance, a list of four coordinates will represent a square facet.
get_cartesian_coords(fractional_coords)[source]

Returns the cartesian coordinates given fractional coordinates.

Parameters: fractional_coords (3x1 array) – Fractional coords. Cartesian coordinates
get_distance_and_image(frac_coords1, frac_coords2, jimage=None)[source]

Gets distance between two frac_coords assuming periodic boundary conditions. If the index jimage is not specified it selects the j image nearest to the i atom and returns the distance and jimage indices in terms of lattice vector translations. If the index jimage is specified it returns the distance between the frac_coords1 and the specified jimage of frac_coords2, and the given jimage is also returned.

Parameters: fcoords1 (3x1 array) – Reference fcoords to get distance from. fcoords2 (3x1 array) – fcoords to get distance from. jimage (3x1 array) – Specific periodic image in terms of lattice translations, e.g., [1,0,0] implies to take periodic image that is one a-lattice vector away. If jimage is None, the image that is nearest to the site is found. distance and periodic lattice translations of the other site for which the distance applies. This means that the distance between frac_coords1 and (jimage + frac_coords2) is equal to distance. (distance, jimage)
get_frac_coords_from_lll(lll_frac_coords)[source]

Given fractional coordinates in the lll basis, returns corresponding fractional coordinates in the lattice basis.

get_fractional_coords(cart_coords)[source]

Returns the fractional coordinates given cartesian coordinates.

Parameters: cart_coords (3x1 array) – Cartesian coords. Fractional coordinates.
get_lll_frac_coords(frac_coords)[source]

Given fractional coordinates in the lattice basis, returns corresponding fractional coordinates in the lll basis.

get_lll_reduced_lattice(delta=0.75)[source]
get_niggli_reduced_lattice(tol=1e-05)[source]

Get the Niggli reduced lattice using the numerically stable algo proposed by R. W. Grosse-Kunstleve, N. K. Sauter, & P. D. Adams, Acta Crystallographica Section A Foundations of Crystallography, 2003, 60(1), 1-6. doi:10.1107/S010876730302186X

Parameters: tol (float) – The numerical tolerance. The default of 1e-5 should result in stable behavior for most cases. Niggli-reduced lattice.
get_points_in_sphere(frac_points, center, r, zip_results=True)[source]

Find all points within a sphere from the point taking into account periodic boundary conditions. This includes sites in other periodic images.

Algorithm:

1. place sphere of radius r in crystal and determine minimum supercell (parallelpiped) which would contain a sphere of radius r. for this we need the projection of a_1 on a unit vector perpendicular to a_2 & a_3 (i.e. the unit vector in the direction b_1) to determine how many a_1”s it will take to contain the sphere.

Nxmax = r * length_of_b_1 / (2 Pi)

2. keep points falling within r.

Parameters: frac_points – All points in the lattice in fractional coordinates. center – Cartesian coordinates of center of sphere. r – radius of sphere. zip_results (bool) – Whether to zip the results together to group by point, or return the raw fcoord, dist, index arrays [(fcoord, dist, index) …] since most of the time, subsequent processing requires the distance. else: fcoords, dists, inds if zip_results
get_wigner_seitz_cell()[source]

Returns the Wigner-Seitz cell for the given lattice.

Returns: A list of list of coordinates. Each element in the list is a “facet” of the boundary of the Wigner Seitz cell. For instance, a list of four coordinates will represent a square facet.
static hexagonal(a, c)[source]

Convenience constructor for a hexagonal lattice.

Parameters: a (float) – a lattice parameter of the hexagonal cell. c (float) – c lattice parameter of the hexagonal cell. Hexagonal lattice of dimensions a x a x c.
inv_matrix

Inverse of lattice matrix.

is_hexagonal(hex_angle_tol=5, hex_length_tol=0.01)[source]
lengths_and_angles

Returns (lattice lengths, lattice angles).

lll_inverse
lll_mapping
lll_matrix
matrix

Copy of matrix representing the Lattice

metric_tensor

The metric tensor of the lattice.

static monoclinic(a, b, c, beta)[source]

Convenience constructor for a monoclinic lattice.

Parameters: a (float) – a lattice parameter of the monoclinc cell. b (float) – b lattice parameter of the monoclinc cell. c (float) – c lattice parameter of the monoclinc cell. beta (float) – beta angle between lattice vectors b and c in degrees. Monoclinic lattice of dimensions a x b x c with non right-angle beta between lattice vectors a and c.
norm(coords, frac_coords=True)[source]

Compute the norm of vector(s).

Parameters: coords – Array-like object with the coordinates. frac_coords – Boolean stating whether the vector corresponds to fractional or cartesian coordinates. one-dimensional numpy array.
static orthorhombic(a, b, c)[source]

Convenience constructor for an orthorhombic lattice.

Parameters: a (float) – a lattice parameter of the orthorhombic cell. b (float) – b lattice parameter of the orthorhombic cell. c (float) – c lattice parameter of the orthorhombic cell. Orthorhombic lattice of dimensions a x b x c.
reciprocal_lattice

Return the reciprocal lattice. Note that this is the standard reciprocal lattice used for solid state physics with a factor of 2 * pi. If you are looking for the crystallographic reciprocal lattice, use the reciprocal_lattice_crystallographic property. The property is lazily generated for efficiency.

reciprocal_lattice_crystallographic

Returns the crystallographic reciprocal lattice, i.e., no factor of 2 * pi.

static rhombohedral(a, alpha)[source]

Convenience constructor for a rhombohedral lattice.

Parameters: a (float) – a lattice parameter of the rhombohedral cell. alpha (float) – Angle for the rhombohedral lattice in degrees. Rhombohedral lattice of dimensions a x a x a.
scale(new_volume)[source]

Return a new Lattice with volume new_volume by performing a scaling of the lattice vectors so that length proportions and angles are preserved.

Parameters: new_volume – New volume to scale to. New lattice with desired volume.
static tetragonal(a, c)[source]

Convenience constructor for a tetragonal lattice.

Parameters: a (float) – a lattice parameter of the tetragonal cell. c (float) – c lattice parameter of the tetragonal cell. Tetragonal lattice of dimensions a x a x c.
volume

Volume of the unit cell.