Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating wavelength in PowderDiffraction #42

Closed
sbanerjee23 opened this issue Jul 19, 2017 · 2 comments
Closed

Updating wavelength in PowderDiffraction #42

sbanerjee23 opened this issue Jul 19, 2017 · 2 comments

Comments

@sbanerjee23
Copy link

I'm trying to calculate a powder diffraction pattern, but am unable to update the wavelength in the global dictionary. I am able to update other keys, and add a wavelength key and pass it to fpsettings, but this has no effect on the output pattern. This script is based off the xrayutilities_experiment_Powder_example_Iron example and I'm currently running it inside a jupyter notebook. I tried some alternatives: running this as an executable in a directory alongside a xrayutilities.conf file, and also passing a wl=#.## argument directly to PowderDiffraction() but am not having any luck. Any advice?

%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import xrayutilities as xu
from xrayutilities.materials.cif import CIFFile
from xrayutilities.materials.material import Crystal

ni_cif = CIFFile('./stru/Ni.cif')
ni_crystal = Crystal(name="Ni", lat=ni_cif.SGLattice())

#X-ray wavelength is 0.1866 Angstroms
settings = {'global': {'wavelength': 0.1866e-10,
                      'dominant_wavelength': 0.1866e-10,
                      'diffractometer_radius': 0.010101}}

ni_powder = xu.simpack.Powder(ni_crystal, 1)
pd = xu.simpack.PowderDiffraction(ni_powder, fpsettings=settings)

tt = np.arange(1, 200, 0.01)
inte = pd.Calculate(tt)

print(pd)

fig, ax1 = plt.subplots(1, 1, figsize=(8,8))

ax1.plot(tt, inte)
ax1.set_xlim(0,200)

Here is a partial output of the printed settings dictionary:

Settings: {'absorption': {'absorption_coefficient': 100000.0}, 
'global': {'wavelength': 1.866e-11, 
'dominant_wavelength': 1.5405929759615019e-10,
'equatorial_divergence_deg': 0.5,
'diffractometer_radius': 0.010101}}
@dkriegner
Copy link
Owner

unfortunately the setting of wavelength is currently a bit complicated and not very well documented

if you use a settings variable as shown below it should work.

settings = {'global': {'diffractometer_radius': 0.50101},
            'emission': {'emiss_wavelengths': (0.1866e-10,),
                         'emiss_intensities': (1.0,),
                         'emiss_gauss_widths': (3e-14,),
                         'emiss_lor_widths': (3e-14,), 
                        }}

I will think about how to make this more intuitive and flexible. Note that all these settings at the moment must be of type tuple.
also check:

  • your diffractometer radius -> its very small in your example!
  • two theta above 180 might cause troubles.

dkriegner added a commit that referenced this issue Jul 20, 2017
inform the user if the wavelength of PowderDiffraction is attempted to
be set wrongly
@dkriegner
Copy link
Owner

@sbanerjee23 please let me know what you think of the latest changes.

it is now possible to set the wavelength/energy for PowderDiffraction in the following ways

  1. during the class construction in one of the following two ways:
pd = xu.simpack.PowderDiffraction(Fe_powder, wl=1.1) # unit Angstrom
pd = xu.simpack.PowderDiffraction(Fe_powder, en=10000) # unit eV

or

settings = {'emission': {'emiss_wavelengths': 0.1866e-10}} # unit meter
pd = xu.simpack.PowderDiffraction(Fe_powder, fpsettings=settings)
  1. after class construction in one of the following two ways
pd = xu.simpack.PowderDiffraction(Fe_powder)
pd.wavelength = 1.1 # unit Angstrom
pd.energy = 10000 # unit eV

or

pd = xu.simpack.PowderDiffraction(Fe_powder)
settings = {'emission': {'emiss_wavelengths': 0.1866e-10}} # unit meter
pd.update_settings(settings)

Note that now also in emiss_wavelength one can just specify a float. What is still not possible is to use dominant_wavelength which I consider a "read-only" option.

The inconsistency of the units (meter vs. Angstrom) is a historic problem which I am aware of but currently would like to keep as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants