In [2]:
# Import a bunch of things
from ase import Atoms
from pyiid.experiments.elasticscatter import ElasticScatter
import matplotlib.pyplot as plt
In [3]:
# Create the atoms, use the "setup" -> "Nanoparticle" tool in the GUI
atoms = Atoms()
atoms.edit()
print(atoms)
In [4]:
# Now to simulate the x-ray scattering
scat = ElasticScatter()
pdf = scat.get_pdf(atoms)
r = scat.get_r()
In [5]:
# Plot the data
%matplotlib inline
plt.plot(r, pdf)
plt.show()
In [6]:
# Note that we can change the experimental parameters
print(scat.exp)
scat.update_experiment({'qmin':2, 'sampling':'ns'})
print(scat.exp)
In [7]:
# now regenerate the pdf and r
pdf = scat.get_pdf(atoms)
r = scat.get_r()
In [8]:
# Plot the data
%matplotlib inline
plt.plot(r, pdf)
plt.show()
In [10]:
# We can do this for the other data in the PDF creation stack
q = scat.get_scatter_vector()
fq = scat.get_fq(atoms)
In [11]:
plt.plot(q, fq)
plt.show()
In [12]:
# we can even simulate noisy data
nfq = scat.get_fq(atoms, noise=.1)
plt.plot(q, nfq)
plt.plot(q, fq)
plt.show()
In [21]:
# and noisy pdfs
npdf = scat.get_pdf(atoms, noise=1)
plt.plot(r, pdf)
plt.plot(r, npdf)
plt.show()
In [29]:
# noise can be an array
npdf = scat.get_pdf(atoms, noise=scat.get_scatter_vector(pdf=True)*.1)
fig, axs = plt.subplots(1, 2)
axs[0].plot(r, pdf, label='noise free')
axs[0].plot(r, npdf, label='noisy')
axs[0].set_title('PDF')
axs[0].legend()
axs[1].plot(scat.get_scatter_vector(pdf=True), scat.get_scatter_vector(pdf=True) * .1)
axs[1].set_title('Noise function')
plt.show()