def test_xrdebye(): tolerance = 1E-5 # previously calculated values expected_get = 116850.37344 expected_xrd = np.array([18549.274677, 52303.116995, 38502.372027]) expected_saxs = np.array([372650934.006398, 280252013.563702, 488123.103628]) # test system -- cluster of 587 silver atoms atoms = FaceCenteredCubic('Ag', [(1, 0, 0), (1, 1, 0), (1, 1, 1)], [6, 8, 8], 4.09) xrd = XrDebye(atoms=atoms, wavelength=wavelengths['CuKa1'], damping=0.04, method='Iwasa', alpha=1.01, warn=True) # test get() obtained_get = xrd.get(s=0.09) assert np.abs((obtained_get - expected_get) / expected_get) < tolerance # test XRD obtained_xrd = xrd.calc_pattern(x=np.array([15, 30, 50]), mode='XRD') assert np.allclose(obtained_xrd, expected_xrd, rtol=tolerance) # test SAXS obtained_saxs = xrd.calc_pattern(x=np.array([0.021, 0.09, 0.53]), mode='SAXS') assert np.allclose(obtained_saxs, expected_saxs, rtol=tolerance)
def getXRD(self, **kwargs): """ calculate XRD """ wavelength = None if 'wavelength' in kwargs: wavelength = kwargs['wavelength'] if 'structure' not in kwargs: raise NameError("Structure not found!") structure = kwargs['structure'] if wavelength is None or structure is None: raise RuntimeError( "ASE Calculator cannot evaluate XRD - not enough parameters!") ase_atoms = structure.aseStructure() xrd_object = XrDebye(atoms=ase_atoms, wavelength=wavelength) # Equally spaced list of 2theta values angles_list = np.arange(15, 30, 0.1) # Get the xray diffraction pattern for these points intensity_list = xrd_object.calc_pattern(x=np.arange(15, 30, 0.1), mode='XRD') # Return the list of tuples return zip(angles_list, intensity_list)
def xrd(): # test system -- cluster of 587 silver atoms atoms = FaceCenteredCubic('Ag', [(1, 0, 0), (1, 1, 0), (1, 1, 1)], [6, 8, 8], 4.09) return XrDebye(atoms=atoms, wavelength=wavelengths['CuKa1'], damping=0.04, method='Iwasa', alpha=1.01, warn=True)
def getSANS(self, **kwargs): """ calculate XRD """ wavelength = None if 'wavelength' in kwargs: wavelength = kwargs['wavelength'] if 'structure' not in kwargs: raise NameError("Structure not found!") structure = kwargs['structure'] if wavelength is None or structure is None: raise RuntimeError( "ASE Calculator cannot evaluate SANS - not enough parameters!") ase_atoms = structure.aseStructure() xrd_object = XrDebye(atoms=ase_atoms, wavelength=wavelength) xrd_object.calc_pattern(x=np.logspace(-2, -0.3, 50), mode='SAXS') xrd_object.plot_pattern(filename=None)
from ase.utils.xrdebye import XrDebye, wavelengths from ase.cluster.cubic import FaceCenteredCubic import numpy as np tolerance = 1E-5 # previously calculated values expected_get = 116850.37344 expected_xrd = np.array([18549.274677, 52303.116995, 38502.372027]) expected_saxs = np.array([372650934.006398, 280252013.563702, 488123.103628]) # test system -- cluster of 587 silver atoms atoms = FaceCenteredCubic('Ag', [(1, 0, 0), (1, 1, 0), (1, 1, 1)], [6, 8, 8], 4.09) xrd = XrDebye(atoms=atoms, wavelength=wavelengths['CuKa1'], damping=0.04, method='Iwasa', alpha=1.01, warn=True) # test get() obtained_get = xrd.get(s=0.09) assert np.abs((obtained_get - expected_get) / expected_get) < tolerance # test XRD obtained_xrd = xrd.calc_pattern(x=np.array([15, 30, 50]), mode='XRD') assert np.allclose(obtained_xrd, expected_xrd, rtol=tolerance) # test SAXS obtained_saxs = xrd.calc_pattern(x=np.array([0.021, 0.09, 0.53]), mode='SAXS') assert np.allclose(obtained_xrd, expected_xrd, rtol=tolerance)
# creates: saxs.png, xrd.png from ase.utils.xrdebye import XrDebye from ase.cluster.cubic import FaceCenteredCubic import numpy as np # create nanoparticle with approx. 2 nm diameter atoms = FaceCenteredCubic('Ag', [(1, 0, 0), (1, 1, 0), (1, 1, 1)], [6, 8, 8], 4.09) # setup for desired wavelength xrd = XrDebye(atoms=atoms, wavelength=0.50523) # calculate and plot diffraction pattern xrd.calc_pattern(x=np.arange(15, 30, 0.1), mode='XRD') xrd.plot_pattern('xrd.png') # calculate and plot samll-angle scattering xrd.calc_pattern(x=np.logspace(-2, -0.3, 50), mode='SAXS') xrd.plot_pattern('saxs.png')