def Rot_AngAx(n, theta): """ Rotation matrix Rodrigues formula angle-axis parametrization INPUT: n - vector [nx,ny,nz] 0 <= theta <= pi OUTPUT: Rot - matrix(3x3) nx,ny,nz = symbols('nx,ny,nz') n = [nx,ny,nz] """ dimens = 3 """ R = sp.MatrixSymbol('R', dimens, dimens) """ i, j = sp.symbols('i,j') R = sp.FunctionMatrix(dimens, dimens, sp.Lambda((i, j), cos(theta) * KroneckerDelta(i, j))) for k in range(dimens): R -= sp.FunctionMatrix( dimens, dimens, sp.Lambda((i, j), sin(theta) * Eijk(i, j, k) * n[k])) Rot = sp.Matrix(R) R2 = sp.zeros(dimens) for i in range(dimens): R2.row_op(i, lambda v, j: (1 - cos(theta)) * n[i] * n[j]) Rot += R2 Rot = sp.N(Rot, 4) #Rot = sp.matrix2numpy(Rot) return Rot
def test_Eijk(): assert Eijk(1, 2, 3) == 1 assert Eijk(2, 3, 1) == 1 assert Eijk(3, 2, 1) == -1 assert Eijk(1, 1, 2) == 0 assert Eijk(1, 3, 1) == 0 assert Eijk(1, x, x) == 0 assert Eijk(x, y, x) == 0
def test_levicivita(): assert Eijk(1, 2, 3) == LeviCivita(1, 2, 3) assert LeviCivita(1, 2, 3) == 1 assert LeviCivita(1, 3, 2) == -1 assert LeviCivita(1, 2, 2) == 0 i, j, k = symbols('i j k') assert LeviCivita(i, j, k) == LeviCivita(i, j, k, evaluate=False) assert LeviCivita(i, j, i) == 0 assert LeviCivita(1, i, i) == 0 assert LeviCivita(i, j, k).doit() == (j - i) * (k - i) * (k - j) / 2 assert LeviCivita(1, 2, 3, 1) == 0 assert LeviCivita(4, 5, 1, 2, 3) == 1 assert LeviCivita(4, 5, 2, 1, 3) == -1
def test_levicivita(): assert Eijk(1, 2, 3) == LeviCivita(1, 2, 3) assert LeviCivita(1, 2, 3) == 1 assert LeviCivita(1, 3, 2) == -1 assert LeviCivita(1, 2, 2) == 0 i, j, k = symbols('i j k') assert LeviCivita(i, j, k) == LeviCivita(i, j, k, evaluate=False) assert LeviCivita(i, j, i) == 0 assert LeviCivita(1, i, i) == 0 assert LeviCivita(i, j, k).doit() == (j - i)*(k - i)*(k - j)/2 assert LeviCivita(1, 2, 3, 1) == 0 assert LeviCivita(4, 5, 1, 2, 3) == 1 assert LeviCivita(4, 5, 2, 1, 3) == -1 assert LeviCivita(i, j, k).is_integer is True assert adjoint(LeviCivita(i, j, k)) == LeviCivita(i, j, k) assert conjugate(LeviCivita(i, j, k)) == LeviCivita(i, j, k) assert transpose(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
def L_loop_hall(data_controller, temp, smearing, ene, velkp, t_tensor, alpha, ispin): from scipy.constants import hbar from sympy import Eijk from .smearing import gaussian, metpax from os.path import join arrays, attributes = data_controller.data_dicts() esize = ene.size snktot = arrays['E_k'].shape[0] bohr2m = 5.29177e-11 ev2J = 1.60218e-19 bnd = attributes['bnd'] nspin = attributes['nspin'] kq_wght = 1. / attributes['nkpnts'] if smearing is not None and smearing != 'gauss' and smearing != 'm-p': print('%s Smearing Not Implemented.' % smearing) comm.Abort() L_hall = np.zeros((3, 3, 3, esize), dtype=float) sig_hall = np.zeros((3, 3, 3, snktot, bnd, nspin)) M_inv = np.zeros((3, 3, snktot, bnd, nspin)) eff_mass_inv = arrays['d2Ed2k'] for l in range(t_tensor.shape[0]): i = t_tensor[l][0] j = t_tensor[l][1] if i == j: M_inv[i, j] = eff_mass_inv[i] elif i == 0 and j == 1: M_inv[i, j] = eff_mass_inv[3] M_inv[j, i] = eff_mass_inv[3] elif i == 0 and j == 2: M_inv[i, j] = eff_mass_inv[4] M_inv[j, i] = eff_mass_inv[4] elif i == 1 and j == 2: M_inv[i, j] = eff_mass_inv[5] M_inv[j, i] = eff_mass_inv[5] for n in range(bnd): Eaux = np.reshape(np.repeat(arrays['E_k'][:, n, ispin], esize), (snktot, esize)) delk = (np.reshape(np.repeat(arrays['deltakp'][:, n, ispin], esize), (snktot, esize)) if smearing != None else None) if smearing is None: Eaux -= ene smearA = 1 / (4 * temp * (np.cosh(Eaux / (2 * temp))**2)) else: if smearing == 'gauss': smearA = gaussian(Eaux, ene, delk) elif smearing == 'm-p': smearA = metpax(Eaux, ene, delk) for i in range(3): for j in range(3): for p in range(3): for q in range(3): for r in range(3): sig_hall[i, j, p, :, n, ispin] += (int(Eijk(p, q, r)) * velkp[:, i, n, ispin] * velkp[:, r, n, ispin] * M_inv[j, q, :, n, ispin]) L_hall[i, j, p, :] += np.sum( kq_wght * arrays['scattering_tau'][:, n, ispin]**2 * sig_hall[i, j, p, :, n, ispin] * (smearA).T, axis=1) return L_hall
from sympy import Eijk, LeviCivita from numpy.random import permutation print(LeviCivita(3, 1, 2)) print(Eijk(3, 1, 2, 5, 4))