Skip to main content

Calculate diffraction patterns from first principles

Project description

License: GPL v3 Python Versions PyPI PyPI - Wheel

DiffSim

Introduction

DiffSim provides an atomistic approach to efficiently simulate Bragg coherent x-ray diffraction imaging (BCDI) diffraction patterns by factorising and eliminating certain redundancies in the conventional approach. The method used is able to reduce the computation time by several orders of magnitude without compromising the recovered phase information and therefore enables feasible atomistic simulations on nanoscale crystals with arbitrary lattice distortions.

Please cite the following article when using Diffsim in published work:

Ahmed Mokhtar, David Serban and Marcus Newton, Simulation of Bragg coherent diffraction imaging, J. Phys. Commun. Volume 6, 055003 (2022)

Installation

DiffSim requires:

  • Python >= 3.7
  • Numba
  • NumPy
  • mpi4py

Installation via pip:

$ pip install diffsim

Reporting Bugs

Please send any bugs, problems, and proposals to: Bonsu.Devel@gmail.com or visit: http://github.com/bonsudev/diffsim

Library Usage and Examples

Simulate ZnO Diffraction Pattern

# 
# Example simuation of ferroelectric 
# domain wall in BaTiO3 nanocrystal
# 

import numpy
from math import sqrt
from diffsim import DiffSim
from scipy import signal

d = DiffSim()
d.meta_name = "BTO_SquareWave"
# Tetragonal structure 
# unit cell in nm
crystal_a = 0.39925
crystal_b = 0.39925
crystal_c = 0.40373
# distort along x axis
d.SetLatticeVector(0,[crystal_c,0.0,0.0])
d.SetLatticeVector(1,[0.0,crystal_b,0.0])
d.SetLatticeVector(2,[0.0,0.0,crystal_a])
# Reflection
d.SetMillerIndices([1,0,1])
# Atoms in unit cell and scattering factors
d.AddAtom(55.7107, 0,0,0) # Ba
d.AddAtom(22.3470, 0.5,0.5,0.5) # Ti
d.AddAtom(8.04313, 0.5,0.5,0.0) # O
d.AddAtom(8.04313, 0.5,0.0,0.5) # O
d.AddAtom(8.04313, 0,0.5,0.5) # O


def Atom2Function(ijks): #atom function for Ti i.e atom number 2
	X= 400
	Y= 400
	Z= 400
	u = 0.01 * signal.square((2.0* numpy.pi/Z) * ijks)
	u[:,0] = u[:,2]
	u[:,1] = 0
	u[:,2] = 0
	return u

def Atom3Function(ijks):
	X=400
	Y=400
	Z=400
	u=-0.022 * signal.square((2.0 * numpy.pi/Z) * ijks)
	u[:,0] = u[:,2]
	u[:,1] = 0
	u[:,2] = 0
	return u

def Atom45Function(ijks):
	X=400
	Y=400
	Z=400
	u = -0.014 * signal.square((2.0*numpy.pi/Z)* ijks)
	u[:,0] = u[:,2]
	u[:,1] = 0
	u[:,2] = 0
	return u

d.AddAtomFunction(2, Atom2Function)
d.AddAtomFunction(3, Atom3Function)
d.AddAtomFunction(4, Atom45Function)
d.AddAtomFunction(5, Atom45Function)
#
d.SetSuperCell(5,5,10)
#d.SetShapeArray("shape.npy")
d.SetShapeArrayFromNormals([400,400,400],\
	[[5,200,200,4,200,200],\
	[395,200,200,396,200,200],\
	[200,5,200,200,4,200],\
	[200,395,200,200,396,200],\
	[200,200,5,200,200,4],\
	[200,200,395,200,200,396],\
	])
#d.SaveShapeArray("shape.npy")
d.SetDetPixelSize(50,50)
d.SetDetSize(256,256)
d.SetEnergy(9.0)
d.SetFlux(10**20)
d.SetExposureTime(100)
d.SetBeta(1.5)
d.Prepare()
d.SaveParameters()
d.CalcObject()
d.CalcObjectCoords()
d.SaveObject()
d.SaveObjectCoords()
d.CalcRockingCurveGPU()
d.SaveDiffraction()

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

diffsim-1.0.tar.gz (51.8 kB view details)

Uploaded Source

Built Distribution

diffsim-1.0-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file diffsim-1.0.tar.gz.

File metadata

  • Download URL: diffsim-1.0.tar.gz
  • Upload date:
  • Size: 51.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for diffsim-1.0.tar.gz
Algorithm Hash digest
SHA256 6a26648430492dcdee3b184509f801a616bc0edaf894c2a1d6c86f1a3d55c745
MD5 faa6121957bb41e1283d1c6080b1bda8
BLAKE2b-256 463a29faf5e28c8570a12a61ba9b95df7dd23fbb4f114361557d3c260fcdcaf6

See more details on using hashes here.

File details

Details for the file diffsim-1.0-py3-none-any.whl.

File metadata

  • Download URL: diffsim-1.0-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for diffsim-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d4d5edf6d15b10697f128ea099a0f73225e1cba2c187a22708d21a7aa062d81
MD5 b3d72c39c3c409843680ce9fba39f99d
BLAKE2b-256 4c54f7b92d5214ff5e10fabff9c5cbec51983a8e5ca035e1a11b60682272344b

See more details on using hashes here.

Supported by

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