pymatgen.analysis.elasticity.tensors module

class SquareTensor[source]

Bases: pymatgen.analysis.elasticity.tensors.TensorBase

Base class for doing useful general operations on second rank tensors (stress, strain etc.).

Create a SquareTensor object. Note that the constructor uses __new__ rather than __init__ according to the standard method of subclassing numpy ndarrays. Error is thrown when the class is initialized with non-square matrix.

  • input_array (3x3 array-like) – the 3x3 array-like representing the content of the tensor
  • vscale (6x1 array-like) – 6x1 array-like scaling the voigt-notation vector with the tensor entries

shorthand for the determinant of the SquareTensor


Scales the tensor by a certain multiplicative scale factor

Parameters:scale_factor (float) – scalar multiplier to be applied to the SquareTensor object

shorthand for matrix inverse on SquareTensor

is_rotation(tol=1e-05, include_improper=True)[source]

Test to see if tensor is a valid rotation matrix, performs a test to check whether the inverse is equal to the transpose and if the determinant is equal to one within the specified tolerance

Parameters:tol (float) – tolerance to both tests of whether the the determinant is one and the inverse is equal to the transpose

calculates matrices for polar decomposition


Returns a list of principal invariants for the tensor, which are the values of the coefficients of the characteristic polynomial for the matrix


shorthand for transpose on SquareTensor

class TensorBase[source]

Bases: numpy.ndarray

Base class for doing useful general operations on Nth order tensors, without restrictions on the type (stress, elastic, strain, piezo, etc.)

Create a TensorBase object. Note that the constructor uses __new__ rather than __init__ according to the standard method of subclassing numpy ndarrays.

  • input_array – (3xN array-like): the 3xN array-like representing a tensor quantity
  • vscale – (N x M array-like): a matrix corresponding to the coefficients of the voigt-notation tensor

Given a structure associated with a tensor, attempts a calculation of the tensor in IEEE format according to the 1987 IEEE standards.

Parameters:structure (Structure) – a structure associated with the tensor to be converted to the IEEE standard
fit_to_structure(structure, symprec=0.1)[source]

Returns a tensor that is invariant with respect to symmetry operations corresponding to a structure

  • structure (Structure) – structure from which to generate symmetry operations
  • symprec (float) – symmetry tolerance for the Spacegroup Analyzer used to generate the symmetry operations
classmethod from_voigt(voigt_input)[source]

Constructor based on the voigt notation vector or matrix.


static get_voigt_dict(rank)[source]

Returns a dictionary that maps indices in the tensor to those in a voigt representation based on input rank

Parameters:Rank (int) – Tensor rank to generate the voigt map
is_fit_to_structure(structure, tol=0.01)[source]

Tests whether a tensor is invariant with respect to the symmetry operations of a particular structure by testing whether the residual of the symmetric portion is below a tolerance

Parameters:tol (float) – tolerance for symmetry testing

Tests whether a tensor is symmetric or not based on the residual with its symmetric part, from self.symmetrized

Parameters:tol (float) – tolerance to test for symmetry

Tests symmetry of tensor to that necessary for voigt-conversion by grouping indices into pairs and constructing a sequence of possible permutations to be used in a tensor transpose

rotate(matrix, tol=0.001)[source]

Applies a rotation directly, and tests input matrix to ensure a valid rotation.

  • matrix (3x3 array-like) – rotation matrix to be applied to tensor
  • tol (float) – tolerance for testing rotation matrix validity

Returns a generally symmetrized tensor, calculated by taking the sum of the tensor and its transpose with respect to all possible permutations of indices


Applies a transformation (via a symmetry operation) to a tensor.

Parameters:symm_op (SymmOp) – a symmetry operation to apply to the tensor

Returns the tensor in Voigt notation


returns the matrix with all entries below a certain threshold (i.e. tol) set to zero