matcalc._elasticity module
Calculator for elastic properties.
- class ElasticityCalc(calculator: Calculator | str, *, norm_strains: Sequence[float] | float = (-0.01, -0.005, 0.005, 0.01), shear_strains: Sequence[float] | float = (-0.06, -0.03, 0.03, 0.06), fmax: float = 0.1, symmetry: bool = False, relax_structure: bool = True, relax_deformed_structures: bool = False, use_equilibrium: bool = True, units_GPa: bool = False, relax_calc_kwargs: dict | None = None, r2_min: float = 0.95)[source]
Bases:
PropCalcElastic tensor and related moduli via strain-stress fitting with pymatgen.
- Parameters:
calculator – ASE calculator or universal model name string.
norm_strains – Normal strains (non-empty, no zeros); scalar broadcast to one value.
shear_strains – Shear strains (non-empty, no zeros); scalar allowed.
fmax – Force tolerance for relaxations.
symmetry – Pass-through to pymatgen
DeformedStructureSet.relax_structure – Relax parent structure before generating deformations.
relax_deformed_structures – Relax each deformed structure before stress eval.
use_equilibrium – Use equilibrium stress in fit; forced True if only one strain type.
units_GPa – If True, return moduli (and elastic tensor / residuals) in GPa. Defaults to False, in which case values are returned in pymatgen’s native units of eV/A^3.
relax_calc_kwargs – Optional kwargs for
RelaxCalc.r2_min – Minimum acceptable mean R² across the per-component linear strain-stress fits. A
RuntimeWarningis emitted (and values are still returned) when the mean R² drops below this. Set negative to disable. Default 0.95.
- _elastic_tensor_from_strains(strains: ArrayLike, stresses: ArrayLike, eq_stress: ArrayLike = None, tol: float = 1e-07) tuple[ElasticTensor, float, float][source]
Fit elastic constants from strain-stress pairs (Voigt), optionally subtracting equilibrium stress.
- Parameters:
strains – Strain states (array-like) for each deformation.
stresses – Matching stress tensors (array-like).
eq_stress – Equilibrium stress to subtract; None to omit.
tol – Small components below this are zeroed on the fitted tensor.
- Returns:
(ElasticTensor, residuals_sum, mean_r2).mean_r2is the average coefficient of determination across the 36 per-component linear fits; stress components with zero variance (zeroed by symmetry) are skipped.
- calc(structure: Structure | Atoms | dict[str, Any]) dict[str, Any][source]
- Parameters:
structure – Pymatgen structure, ASE atoms, or dict with structure keys.
- Returns:
Dict including
elastic_tensor,shear_modulus_vrh,bulk_modulus_vrh,youngs_modulus,residuals_sum,structure,_units, and merged relaxation fields.elastic_tensor,shear_modulus_vrh,bulk_modulus_vrh,youngs_modulusandresiduals_sumare returned in GPa ifunits_GPa=True, otherwise in eV/A^3 (pymatgen’s native units)._unitsis a dict mapping each numeric output to its unit string.