# Path: pymicro/xray/xray_utils.py
# def f_atom(q, Z):
#     """Empirical function for the atomic form factor f.
# 
#     This function implements the empirical function from the paper of Muhammad and Lee
#     to provide value of f for elements in the range Z <= 30.
#     doi:10.1371/journal.pone.0069608.t001
# 
#     :param float q: value or series for the momentum transfer, unit is angstrom^-1
#     :param int Z: atomic number, must be lower than 30.
#     :return: the atomic form factor value or series corresponding to q.
#     """
#     if Z > 30:
#         raise ValueError('only atoms with Z<=30 are supported, consider using tabulated data.')
#     a0 = 0.52978  # angstrom, Bohr radius
#     params = np.genfromtxt(os.path.join(PYMICRO_XRAY_DATA_DIR, 'f_atom_params.txt'), names=True)
#     Z, r, a1, b1, a2, b2, a3, b3, _, _, _ = params[int(Z - 1)]
#     print(Z, r, a1, b1, a2, b2, a3, b3)
#     f = (a1 * Z) ** r / ((a1 * Z) ** r + b1 * (2 * pi * a0 * q) ** r) ** r + \
#         (a2 * Z) ** r / ((2 * a2 * Z) ** r + b2 * (2 * pi * a0 * q) ** 2) ** 2 + \
#         (a3 * Z) ** r / ((2 * a3 * Z) ** 2 + b3 * (2 * pi * a0 * q) ** 2) ** 2
#     return f


import numpy as np
import os
from matplotlib import pyplot as plt
from pymicro.xray.xray_utils import f_atom
from matplotlib import image

# plot X-ray atomic structure factor for Al and Ni
q_values = np.arange(0., 2.01, 0.01)
for element, Z in [('Al', 13), ('Ni', 28)]:
    f = f_atom(q_values, Z)
    plt.plot(q_values, f, label=element)
plt.xlim(0, 2)

# Path: pymicro/xray/xray_utils.py
# def f_atom(q, Z):
#     """Empirical function for the atomic form factor f.
# 
#     This function implements the empirical function from the paper of Muhammad and Lee
#     to provide value of f for elements in the range Z <= 30.
#     doi:10.1371/journal.pone.0069608.t001
# 
#     :param float q: value or series for the momentum transfer, unit is angstrom^-1
#     :param int Z: atomic number, must be lower than 30.
#     :return: the atomic form factor value or series corresponding to q.
#     """
#     if Z > 30:
#         raise ValueError('only atoms with Z<=30 are supported, consider using tabulated data.')
#     a0 = 0.52978  # angstrom, Bohr radius
#     params = np.genfromtxt(os.path.join(PYMICRO_XRAY_DATA_DIR, 'f_atom_params.txt'), names=True)
#     Z, r, a1, b1, a2, b2, a3, b3, _, _, _ = params[int(Z - 1)]
#     print(Z, r, a1, b1, a2, b2, a3, b3)
#     f = (a1 * Z) ** r / ((a1 * Z) ** r + b1 * (2 * pi * a0 * q) ** r) ** r + \
#         (a2 * Z) ** r / ((2 * a2 * Z) ** r + b2 * (2 * pi * a0 * q) ** 2) ** 2 + \
#         (a3 * Z) ** r / ((2 * a3 * Z) ** 2 + b3 * (2 * pi * a0 * q) ** 2) ** 2
#     return f


# Path: examples/plotting/atomic_structure_factor.py
import numpy as np
import os
from matplotlib import pyplot as plt
from pymicro.xray.xray_utils import f_atom
from matplotlib import image


# plot X-ray atomic structure factor for Al and Ni
q_values = np.arange(0., 2.01, 0.01)
for element, Z in [('Al', 13), ('Ni', 28)]:
    f = f_atom(q_values, Z)
    plt.plot(q_values, f, label=element)
plt.xlim(0, 2)

plt.xlabel(r'$\sin(\theta)/\lambda$')