# Path: config.py
# PYMICRO_XRAY_DATA_DIR = os.path.join(PYMICRO_ROOT_DIR, 'pymicro', 'xray', 'data')


import os, numpy as np
from matplotlib import pyplot as plt
from skimage.transform import radon
from math import *
from config import PYMICRO_XRAY_DATA_DIR

def density_from_Z(Z):
    if not Z in elements:
        print('unknown atomic number: %d' % Z)
        return None
    return elements[Z].density


def density_from_symbol(symbol):
    for Z in elements:
        if elements[Z].symbol == symbol:
            return elements[Z].density
    print('unknown symbol: %s' % symbol)
    return None


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

# Path: config.py
# PYMICRO_XRAY_DATA_DIR = os.path.join(PYMICRO_ROOT_DIR, 'pymicro', 'xray', 'data')


# Path: pymicro/xray/xray_utils.py
import os, numpy as np
from matplotlib import pyplot as plt
from skimage.transform import radon
from math import *
from config import PYMICRO_XRAY_DATA_DIR


def density_from_Z(Z):
    if not Z in elements:
        print('unknown atomic number: %d' % Z)
        return None
    return elements[Z].density


def density_from_symbol(symbol):
    for Z in elements:
        if elements[Z].symbol == symbol:
            return elements[Z].density
    print('unknown symbol: %s' % symbol)
    return None


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)