import math


def calc_bragg_angle(d, energy_eV, n=1):
    """Calculate Bragg angle from the provided energy and d-spacing.

    Args:
        d (float): interplanar spacing (d-spacing) [A].
        energy_eV (float): photon energy [eV].
        n (int): number of diffraction peak.

    Returns:
        dict: the resulted dictionary with:
            lamda (float): wavelength [nm].
            bragg_angle (float): Bragg angle [rad].
            bragg_angle_deg (float): Bragg angle [deg].
    """
    # Check/convert types first:
    d = float(d)
    energy_eV = float(energy_eV)
    n = int(n)

    lamda = 1239.84193 / energy_eV  # lamda in [nm]
    bragg_angle = math.asin(n * lamda / (2 * d * 0.1))  # convert d from [A] to [nm].
    bragg_angle_deg = 180. / math.pi * bragg_angle
    return {
        'lamda': lamda,
        'bragg_angle': bragg_angle,
        'bragg_angle_deg': bragg_angle_deg,
    }