diag_tensor_gipaw_scf.py reads g-tensors and hyperfine A-tensors directly from a Quantum ESPRESSO gipaw.x output file, diagonalizes them, and prints the principal values and principal axes in a form suitable for visualization in VESTA.
The script supports two ways to define the simulation-cell axes:
- Read the lattice vectors automatically from a Quantum ESPRESSO
pw.xinput file (scf.in). - Enter the lattice vectors manually on the command line.
- Python 3
- NumPy
Install NumPy if needed:
pip install numpypython diag_tensor_gipaw_scf.py gipaw.outThe script automatically detects whether the gipaw.x output contains:
- a g-tensor, or
- hyperfine A-tensors.
For VESTA conversion, however, the lattice vectors must be known. The recommended method is to provide the corresponding pw.x input file.
python diag_tensor_gipaw_scf.py g-tensor.out --qe-input scf.inThe script:
- reads the last
Delta_g totaltensor printed bygipaw.x, - symmetrizes the tensor,
- diagonalizes it,
- prints the principal values and normalized principal axes,
- converts the principal axes to lattice-vector coordinates
(u,v,w), - prints VESTA-ready vectors.
The last Delta_g total block is used because gipaw.x may print more than one version of the total g-tensor.
python diag_tensor_gipaw_scf.py hyperfine.out --qe-input scf.inBy default, the script processes atoms 1 through 7.
This is useful, for example, for a defect calculation in which:
- atom 1 is the defect atom (e.g. Sn),
- atoms 2-7 are its six nearest-neighbor carbon atoms.
The full hyperfine tensor is constructed as
where:
A_dipolar(sym)is taken from the last
total dipolar (symmetrized)
block,
A_FCis taken from thetotalcolumn of the
Fermi contact
table.
The resulting total A-tensor is diagonalized separately for each selected atom.
By default, atoms 1-7 are processed.
Therefore these two commands are equivalent:
python diag_tensor_gipaw_scf.py hyperfine.out --qe-input scf.in
python diag_tensor_gipaw_scf.py hyperfine.out --qe-input scf.in --atoms 1-7
To process a different set of atoms, specify another range, for example:
--atoms 1-12
Individual atoms can also be selected:
python diag_tensor_gipaw_scf.py hyperfine.out \
--qe-input scf.in \
--atoms 1,2,5The script can read:
CELL_PARAMETERS angstrom
CELL_PARAMETERS bohr
CELL_PARAMETERS alat
For alat, the script determines the lattice constant from either:
A = ...
or
celldm(1) = ...
The lattice vectors are internally converted to Angstrom.
Example:
CELL_PARAMETERS angstrom
10.701 0.000 0.000
0.000 10.701 0.000
0.000 0.000 10.701
If the original scf.in file is not available, the lattice vectors can be supplied manually.
General syntax:
python diag_tensor_gipaw_scf.py gipaw.out \
--a ax ay az \
--b bx by bz \
--c cx cy czFor example, for a cubic cell with lattice constant 10.701 Å:
python diag_tensor_gipaw_scf.py g-tensor.out \
--a 10.701 0 0 \
--b 0 10.701 0 \
--c 0 0 10.701For hyperfine:
python diag_tensor_gipaw_scf.py hyperfine.out \
--a 10.701 0 0 \
--b 0 10.701 0 \
--c 0 0 10.701 \
--atoms 1-7The manual vectors should correspond to the same simulation cell used in the original pw.x calculation.
By default, the script uses
z = c
y = b
which corresponds to
--iz 0 0 1
--iy 0 1 0The vectors are defined as integer combinations of the lattice vectors:
For example:
--iz 1 1 1defines the crystallographic z-axis along
which corresponds to the [111] direction for a cubic cell.
Example:
python diag_tensor_gipaw_scf.py g-tensor.out \
--qe-input scf.in \
--iz 1 1 1 \
--iy 0 1 -1The x-axis is then constructed automatically from the chosen y and z directions.
Normally the script automatically detects the calculation type.
If necessary, it can be forced manually.
For a g-tensor:
python diag_tensor_gipaw_scf.py gipaw.out \
--type g \
--qe-input scf.inFor hyperfine:
python diag_tensor_gipaw_scf.py gipaw.out \
--type A \
--qe-input scf.inFor each tensor, the script prints:
- the tensor used for diagonalization,
- principal values,
- normalized principal axes in Cartesian coordinates,
thetaandphiangles,- lattice-coordinate directions
(u,v,w), - positive and negative VESTA vectors,
- orthogonality checks for the eigenvectors.
For hyperfine calculations, the same information is printed separately for every selected atom.
pw.x < scf.in > scf.out
gipaw.x < gipaw_g.in > g-tensor.out
python diag_tensor_gipaw_scf.py g-tensor.out \
--qe-input scf.inpw.x < scf.in > scf.out
gipaw.x < gipaw_hf.in > hyperfine.out
python diag_tensor_gipaw_scf.py hyperfine.out \
--qe-input scf.in \
--atoms 1-7- The script uses
numpy.linalg.eigh, which is designed for real symmetric matrices. - Tensors are symmetrized before diagonalization.
- For the g-tensor, the last
Delta_g totalblock is used. - For hyperfine calculations, the full tensor includes both the symmetrized dipolar contribution and the total Fermi-contact contribution.
- If
--qe-inputis supplied, lattice vectors are read from that file. - If
--qe-inputis not supplied, lattice vectors can be given manually using--a,--b, and--c. - The default hyperfine atom selection is
1-7.
Display all command-line options:
python diag_tensor_gipaw_scf.py --helpSimplified Python script for analyzing EPR g-tensors and hyperfine tensors from Quantum ESPRESSO GIPAW calculations.
- Uses a single Cartesian coordinate system consistent with QE and reads lattice vectors from QE input files.
- Diagonalizes symmetric tensors to obtain principal values and eigenvectors.
- Constructs HFI tensors from Fermi-contact and spin-dipolar contributions.
- Generates VESTA files with bidirectional principal-axis vectors (±) attached to atoms. For that you need to prepare .vesta file with necessary view, then the script will modify it by adding double arrows.
How to use:
Prepare .vesta file with necessary view and then
python diag_tensor_gipaw_vesta_cartesian.py g-tensor.out \
--qe-input scf.in \
--vesta-template d.spin.vesta \
--vesta-output g_tensor.vesta \
--vesta-length-mode normalized
VESTA Vector Length Modes:
- normalized — Vector lengths are proportional to the absolute eigenvalues, normalized to the largest eigenvalue of each tensor. Useful for visualizing tensor anisotropy.
- direction — All vectors have equal lengths, regardless of eigenvalues. Useful for comparing principal-axis orientations, particularly under different strain conditions.
Example:
