def angle2(x, y, z, h, k, l, lattice):
V, Vstar, latticestar = _star(lattice)
return np.arccos(2 * np.pi * (h * x + k * y + l * z) / _modvec([x, y, z], lattice) / _modvec([h, k, l], latticestar))
def sqw(H, K, L, W, p=None):
'''S(Q, w) for a gapped excitation in a 1D antiferromagnet'''
dx, dy, dz, cc, gamma = p[:5]
omega_x = np.sqrt(cc ** 2 * np.sin(2 * np.pi * H) ** 2 + dx ** 2)
omega_y = np.sqrt(cc ** 2 * np.sin(2 * np.pi * H) ** 2 + dy ** 2)
omega_z = np.sqrt(cc ** 2 * np.sin(2 * np.pi * H) ** 2 + dz ** 2)
lor_x = 1 / np.pi * gamma / ((W - omega_x) ** 2 + gamma ** 2)
lor_y = 1 / np.pi * gamma / ((W - omega_y) ** 2 + gamma ** 2)
lor_z = 1 / np.pi * gamma / ((W - omega_z) ** 2 + gamma ** 2)
sqw = np.array([lor_x * (1 - np.cos(np.pi * H)) / omega_x / 2,
lor_y * (1 - np.cos(np.pi * H)) / omega_y / 2,
lor_z * (1 - np.cos(np.pi * H)) / omega_z / 2])
return sqw
def pref(H, K, L, W, EXP, p=None):
'''More complicated prefactor'''
I, bgr = p[5:]
sample, rsample = EXP.get_lattice()
q2 = _modvec([H, K, L], rsample) ** 2
sd = q2 / (16 * np.pi ** 2)
ff = 0.0163 * np.exp(-35.883 * sd) + 0.3916 * np.exp(-13.223 * sd) + 0.6052 * np.exp(-4.339 * sd) - 0.0133
# Calculate the polarization factors for transverse excitations
alphay = angle2(0, 1, 0, H, K, L, sample)
alphaz = angle2(0, 0, 1, H, K, L, sample)
alphax = angle2(1, 0, 0, H, K, L, sample)
# Polarization factors for each of the three modes.
polx = np.sin(alphax) ** 2
poly = np.sin(alphay) ** 2
polz = np.sin(alphaz) ** 2
prefactor = np.array([ff ** 2 * polx * I, ff ** 2 * poly * I, ff ** 2 * polz * I])
# Constant Background
bgr = np.ones(H.shape) * bgr
return np.ones(H.shape)[np.newaxis, ...]