Skip to main content

Generate diffracted intensities from crystals

Project description

Dans_Diffaction

Reads crystallographic cif files and simulates diffraction

Version 1.x

By Dan Porter, Diamond Light Source 2018

TL;DR:

$ ipython -i -m Dans_Diffraction
import Dans_Diffraction as dif
xtl = dif.Crystal('some_file.cif')
xtl.info() # print Crystal structure parameters

# Print reflection list:
print(xtl.Scatter.print_all_reflections(energy_kev=5)) 

# Plot Powder pattern:
xtl.Plot.simulate_powder(energy_kev=8)
plt.show()

# Start graphical user interface:
xtl.start_gui()

Full code documentation available here.

For comments, queries or bugs - email dan.porter@diamond.ac.uk

Installation

Requirements: Python 2.7+/3+ with packages: Numpy, Matplotlib, Scipy, Tkinter

Stable version from PyPI:

$ pip install Dans-Diffraction

Latest version from GitHub:

$ git clone https://github.com/DanPorter/Dans_Diffraction.git

Operation

Dans_Diffraction is best run within an interactive python environment:

$ ipython -i -m Dans_Diffraction

Dans_Diffraction can also be run in scripts as an import, example scripts are provided in the Examples folder.

Read CIF file

import Dans_Diffraction as dif
xtl = dif.Crystal('some_file.cif')
xtl.info() # print Crystal structure parameters

Alter atomic positions

xtl.Cell.latt([2.85,2.85,10.8,90,90,120]) #  set lattice parameters
xtl.Atoms.info() # Print Symmetric positions
xtl.Structure.info() # Print All positions in P1 symmetry (same structure and functions as xtl.Atoms)
# Symmetric positions
xtl.Atoms.changeatom(idx=0, u=0, v=0, w=0, type='Co', label='Co1')
xtl.Atoms.addatom(idx=0, u=0, v=0, w=0, type='Co', label='Co1')
# After adding or changing an atom in the Atoms class, re-generate the full structure using symmetry arguments:
xtl.generate_lattice()
# Full atomic structure in P1 symmetry
xtl.Structure.changeatom(idx=0, u=0, v=0, w=0, type='Co', label='Co1')
xtl.Structure.addatom(idx=0, u=0, v=0, w=0, type='Co', label='Co1')
# Plot crystal Structure
xtl.Plot.plot_crystal() # 3D plot
xtl.Plot.plot_layers() # 2D plot for layered materials

3D Plot

Alter crystal symmetry

xtl.Symmetry.info() # print symmetry arguments
xtl.Symmetry.addsym('x,y,z+1/2') # adds single symmetry operation
xtl.Symmetry.changesym(0, 'x,y,z+1/4')
# After adding or changing symmetry operations, regengerate the symmetry matrices
xtl.Symmetry.generate_matrices()

Calculate Structure Factors

X-ray or neutron structure factors/ intensities are calculated based on the full unit cell structure, including atomic form-factors (x-rays) or coherent scattering lengths (neutrons).

# Choose scattering options (see help(xtl.Scatter.setup_scatter))
xtl.Scatter.setup_scatter(type='x-ray', energy_keV=8.0)
# Allowed radiation types:
#    'xray','neutron','xray magnetic','neutron magnetic','xray resonant'
xtl.intensity([h,k,l]) # Returns intensity
xtl.print_all_refelctions() # Returns formated string of all allowed reflections
# Plot Experimental Intensities
xtl.Plot.simulate_powder() # Powder pattern
xtl.Plot.simulate_hk0() # Reciprocal space plane

Powder Pattern HK0 Simulation

Magnetic scattering is also available for neutrons and x-rays (both resonant and non-resonant), using the appropriate magnetic form-factors.

Imag = xtl.Scatter.magnetic_neutron(HKL=[0,0,3])
Ires = xtl.Scatter.xray_resonant_magnetic(HKL=[0,0,3], energy_kev=2.838, azim_zero=[1, 0, 0], psi=0, polarisation='s-p', F0=0, F1=1, F2=0)

Multiple Scattering

Simulations of multiple scattering at different azimuths for a particular energy can be simulated. Based on code by Dr Gareth Nisbet.

azimuth, intensity = xtl.Scatter.ms_azimuth([h,k,l], energy_kev=8)

Multiple Scattering

Properties

The Crystal class contains a lot of atomic properties that can be exposed in the Properties class:

xtl.Properties.info()

All the properties are stored in the folder Dans_Diffraction/data.

Superstructures

Superstructures can be built using the Superstructure class, requring only a matrix to define the new phase:

su = xtl.generate_superstructrue([[2,0,0],[0,2,0],[0,0,1]])

Superstucture classes behave like Crystal classes, but have an additional 'Parent' property that references the original crystal structure and additional behaviours partiular to superstructures.

su.parent.info() # Parent structure
su.P # superstructure matrix 

Graphical Front End

All GUI elements

Start a new GUI, then select a cif file:

dif.Startgui()

Using an already generated crystal:

xtl.start_gui()

FDMNES functionality

FDMNES is a powerful tool for simulating resonant x-ray diffraction, created by Y. Joly and O. Bunau.

The Dans_Diffraction FDMNES class allows for the automatic creation of input files and simple analysis of results. The following command should be used to activate these features (only needs to be issued once).

dif.activate_fdmnes()

Once activated, the FDMNES classes become available.

fdm = dif.Fdmnes(xtl) # Create input files and run FDMNES
fdma = dif.FdmnesAnalysis(output_path, output_name) # Load output files and plot results

See class documentation for more information.

Once activated, FDMNES GUI elements become available from the main window, emulating functionality of the classes.

FDMNES Run FDMNES Analyse

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Dans_Diffraction-1.5.0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

Dans_Diffraction-1.5.1-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

Dans_Diffraction-1.5.0-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

File details

Details for the file Dans_Diffraction-1.5.0.tar.gz.

File metadata

  • Download URL: Dans_Diffraction-1.5.0.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for Dans_Diffraction-1.5.0.tar.gz
Algorithm Hash digest
SHA256 cb9b848996d8d3222b0a538e16075c4c59eaaa2ebd2e9a7242b13be91f7733c2
MD5 559603b3b8e54febab3f386bbdcf20e5
BLAKE2b-256 559550f75a16c0d9519d1a294cd223351760e61329a1375474c88dd2caa3ebea

See more details on using hashes here.

File details

Details for the file Dans_Diffraction-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: Dans_Diffraction-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for Dans_Diffraction-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c5ce6e15b644591fcd57f673c2947cde87cb493cffaedfe004f309b5488184da
MD5 48d579d84bf6c3004a3c5d60e4227465
BLAKE2b-256 3d23791ba3c257cbd4cbba8cb137357647121a4ae399c04323301050ca3d918e

See more details on using hashes here.

File details

Details for the file Dans_Diffraction-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: Dans_Diffraction-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for Dans_Diffraction-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 feeefeed6389c68bee58865f9ef6391379c04dd4edc32ed08d0fecafb9dff930
MD5 549eeaa16fbd2947000b9e446dfe975b
BLAKE2b-256 750161cdd115b00919ffc1dfff4ce5a6e296f13ef4b136c5230b2506aedb7236

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page