From 83a2d56d418bbc2fe685a23bdd8d7f25c0505371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Thu, 20 Jul 2017 15:45:52 +0300 Subject: [PATCH] Basis transform for lattices Former-commit-id: 5746d8f6a70c21b0133259c1f936fda96b01cf96 --- qpms/lattices2d.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/qpms/lattices2d.py b/qpms/lattices2d.py index 5ea07cb..a2f915b 100644 --- a/qpms/lattices2d.py +++ b/qpms/lattices2d.py @@ -1,5 +1,6 @@ import numpy as np from enum import Enum +from math import floor nx = None @@ -235,6 +236,18 @@ def filledWS2(b1,b2, density=10, scale=1.): 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