Basis transform for lattices

Former-commit-id: 5746d8f6a70c21b0133259c1f936fda96b01cf96
This commit is contained in:
Marek Nečada 2017-07-20 15:45:52 +03:00
parent 6b4fade54b
commit 83a2d56d41
1 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import numpy as np import numpy as np
from enum import Enum from enum import Enum
from math import floor
nx = None nx = None
@ -235,6 +236,18 @@ def filledWS2(b1,b2, density=10, scale=1.):
return points return points
def change_basis(srcbasis, destbasis, srccoords, srccoordsaxis=-1, lattice=True):
srcbasis = np.array(srcbasis)
destbasis = np.array(destbasis)
trmatrix = np.dot(np.linalg.inv(np.transpose(destbasis)), np.transpose(srcbasis))
if lattice: # if srcbasis and destbasis are two bases of the same lattice, its elements are ints
otrmatrix = trmatrix
trmatrix = np.round(trmatrix)
if not np.all(np.isclose(trmatrix, otrmatrix)):
raise ValueError("Given srcbasis and destbasis are not bases"
"of the same lattice", srcbasis, destbasis)
destcoords = np.tensordot(srccoords, trmatrix, axes=(srccoordsaxis, -1))
return destcoords
""" """
TODO TODO