Skip to content
Snippets Groups Projects
Commit 6b3bf45e authored by Egor Sobolev's avatar Egor Sobolev
Browse files

Add crystallographic coordinate transformation

parent 47868418
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,47 @@
import numpy as np
# Electron charge in C
ELECTRON_CHARGE = 1.6021773e-19
# Planck's constant (Js)
PLANCK = 6.62606896e-34
# Speed of light in vacuo (m/s)
C_VACUO = 299792458
def ph_en_to_lambda(a):
"""Transforms photon energy (eV) to wavelength (m)"""
return PLANCK * C_VACUO / (a * ELECTRON_CHARGE)
def get_q_from_xyz(x, y, z, lmd):
"""Calculates q vector by detector coordinates"""
# r = sqrt(x*x + y*y)
# S = λ sqrt(z*z + x*x + y*y)
# cos φ = cos(arctan(y / x)) = x / r
# sin φ = sin(arctan(y / x)) = z / r
# sin 2θ / λ = sin(arctan(r / z)) = r / S
# cos 2θ / λ = cos(arctan(r / z)) = z / S
# q = sin 2θ / λ
# u = sin 2θ * cos φ / λ = x / S
# v = cos 2θ * sin φ / λ = y / S
# w = (cos 2θ - 1) / λ = z / S - 1 / λ
S = lmd * np.sqrt(x * x + y * y + z * z)
u = x / S
v = y / S
w = z / S - 1.0 / lmd
return np.array([u, v, w])
def get_min_bragg_dist(r, clen, lmd, cell):
"""Calculates minimal inter-bragg distance"""
# sin 2θ = sin(arctan(r / clen))
# q = sin 2θ / lmd
invq = lmd * np.sqrt(clen * clen + r * r) / r
return min(invq / a for a in cell)
def spacing(h, k, l, a, b, c, alpha, beta, gamma):
alpha *= np.pi / 180.
beta *= np.pi / 180.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment