lib/tensor.js~ TensorData

new TensorData(M)

Create a TensorData object, to store whole tensors, diagonalise their symmetric part and return derived quantities

Parameters:
NameTypeDescription
MArray | mathjs.Matrix | TensorData

Tensor in 3x3 matrix form

Methods

efgAtomicToHz(Q) → {TensorData}

Convert this TensorData to return a clone that has been converted from atomic units to Hertz, assuming it's an Electric Field Gradient tensor.

Parameters:
NameTypeDescription
QNumber

Quadrupolar moment of the given nucleus (millibarn, as in the isotope data tables)

Returns:

Converted tensor

Type: 
TensorData

euler(mode, active, convention, degrees, EPS) → {Array}

Calculate the Euler angles for the TensorData. Returns an array of [alpha, beta, gamma], in radians unless degrees is true.

This function is based on the code from TensorView for MATLAB by Leo Svenningsson and Leonard J. Mueller https://doi.org/10.1016/j.ssnmr.2022.101849

Parameters:
NameTypeDefaultDescription
modeStringzyz

Mode to use: either 'zyz' or 'zxz' (default is 'zyz')

activeBooleantrue

If true, make it an active transformation (default is true)

conventionString

Eval ordering convention to use (default is whatever is set in 'this.convention)

degreesBoolean

If true, return angles in degrees (default is false)

EPSNumber

Tolerance for comparing eigenvalues etc. (default is 1e-6)

Returns:

Array of [alpha, beta, gamma] in radians

TODO: check edge cases, esp. axial symmetry TODO: add in conversion from radians to degrees

Type: 
Array

iscAtomicToHz(g1, g2) → {TensorData}

Convert this TensorData to return a clone that has been converted from atomic units to Hertz, assuming it's an Indirect Spin-spin Coupling tensor.

Parameters:
NameTypeDescription
g1Number

Gyromagnetic ratio of the first atom

g2Number

Gyromagnetic ratio of the second atom

Returns:

Converted tensor

Type: 
TensorData

rotate(basis, active) → {TensorData}

Rotate the TensorData by a given basis, either as passive or active transformation. Returns the rotated TensorData (does not modify this in place). Default is passive. The convention is such that for a symmetric tensor,

T.rotate(T.eigenvectors)

returns the diagonalised tensor.

Parameters:
NameTypeDefaultDescription
basisArray | mathjs.Matrix | TensorData

Basis to rotate into

activeBooleanfalse

If true, make it an active transformation (default is false)

Returns:

Rotated tensor

Type: 
TensorData

rotateByAngleAxis(a, v, intrinsic) → {TensorData}

Rotate the TensorData by a given angle around a given axis. Uses the rotate_matrix utility function.

Parameters:
NameTypeDescription
anumber | Array

The angle that the matrix is rotated around the vector 'v'. 'a' can also be a vector and then 'a' is rotated into 'v'. Angles are in radians.

vstring | Array

Vector to rotate the matrix around. Vectors can be given as strings: 'x', '-x', 'y', ... .These correspond to the local coordinate system of the tensor if intrinsic == true.

intrinsicboolean

If true, rotate the tensor intrinsically (default is true). i.e. the tensor is rotated in the local coordinate system.

Returns:

Rotated tensor

Type: 
TensorData

sort_eigs()

This method sorts the eigenvalues and eigenvectors in Haeberlen and NQR order.

Haeberlen Order: The method first calculates the absolute difference between each eigenvalue and the isotropic value. These differences are then sorted in ascending order. The sorted eigenvalues are stored in this._haeb_evals. The corresponding eigenvectors are also sorted in the same order, but with the first and second elements swapped. The sorted eigenvectors are stored in this._haeb_evecs.

NQR Order: The method then repeats the same process for the original eigenvalues, but without swapping the first and second elements. The sorted original eigenvalues are stored in this._nqr_evals.

Note: The method uses the lodash (_) library for the zip, range, and sortBy functions. The mjs.transpose function is used to transpose the array of eigenvectors, and mjs.cross is used to calculate the cross product of two vectors.

sorted_eigenvalues(convention, return_indices) → {Array}

Get the eigenvalues of the tensor, sorted in the given convention.

Parameters:
NameTypeDefaultDescription
conventionString

Convention to sort the eigenvalues by. Can be "increasing", "decreasing", "haeberlen" or "nqr".

return_indicesBooleanfalse

If true, return the indices of the sorted eigenvalues, in addition to the sorted eigenvalues.

Throws:

If the convention is not one of the above.

Type
Error
Returns:

Array of sorted eigenvalues, or array of sorted eigenvalues and indices, depending on the value of return_indices.

Type: 
Array
Example
// Get the eigenvalues of a tensor, sorted in increasing order
var tensor = new TensorData([[1, 0, 0], [0, 2, 0], [0, 0, -6]]);
var sorted = tensor.sorted_eigenvalues("increasing");
// sorted = [-6, 1, 2]

sorted_eigenvectors(convention) → {Array}

Get the eigenvectors of the tensor, sorted in the given convention.

Parameters:
NameTypeDescription
conventionString

Convention to sort the eigenvalues by. Can be "increasing", "decreasing", "haeberlen" or "nqr".

Returns:

Array of sorted eigenvectors.

Type: 
Array