Skip to content

Instantly share code, notes, and snippets.

@pavoljuhas
Last active December 4, 2015 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavoljuhas/32ac41c6ee0e95ff7caa to your computer and use it in GitHub Desktop.
Save pavoljuhas/32ac41c6ee0e95ff7caa to your computer and use it in GitHub Desktop.
Calculate PDF from a 2D slab with analytic baseline
#------------------------------------------------------------------------------
#$Date: 2010-01-30 13:59:17 +0000 (Sat, 30 Jan 2010) $
#$Revision: 966 $
#$URL: svn://cod.ibt.lt/cod/cif/1/1000041.cif $
#------------------------------------------------------------------------------
#
# This file is available in the Crystallography Open Database (COD),
# http://www.crystallography.net/
#
# All data on this site have been placed in the public domain by the
# contributors.
#
data_1000041
_chemical_name_systematic 'Sodium chloride'
_chemical_formula_structural 'Na Cl'
_chemical_formula_sum 'Cl Na'
_publ_section_title
;
Accuracy of an automatic diffractometer. measurement of the sodium
chloride structure factors
;
loop_
_publ_author_name
'Abrahams, S C'
'Bernstein, J L'
_journal_name_full 'Acta Crystallographica (1,1948-23,1967)'
_journal_coden_ASTM ACCRA9
_journal_volume 18
_journal_year 1965
_journal_page_first 926
_journal_page_last 932
_cell_length_a 5.62
_cell_length_b 5.62
_cell_length_c 5.62
_cell_angle_alpha 90
_cell_angle_beta 90
_cell_angle_gamma 90
_cell_volume 177.5
_cell_formula_units_Z 4
_symmetry_space_group_name_H-M 'F m -3 m'
_symmetry_Int_Tables_number 225
_symmetry_cell_setting cubic
loop_
_symmetry_equiv_pos_as_xyz
'x,y,z'
'y,z,x'
'z,x,y'
'x,z,y'
'y,x,z'
'z,y,x'
'x,-y,-z'
'y,-z,-x'
'z,-x,-y'
'x,-z,-y'
'y,-x,-z'
'z,-y,-x'
'-x,y,-z'
'-y,z,-x'
'-z,x,-y'
'-x,z,-y'
'-y,x,-z'
'-z,y,-x'
'-x,-y,z'
'-y,-z,x'
'-z,-x,y'
'-x,-z,y'
'-y,-x,z'
'-z,-y,x'
'-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1/2+x,1/2-y,z'
'y,1/2-z,1/2+x'
'1/2+y,-z,1/2+x'
'1/2+y,1/2-z,x'
'z,1/2-x,1/2+y'
'1/2+z,-x,1/2+y'
'1/2+z,1/2-x,y'
'x,1/2-z,1/2+y'
'1/2+x,-z,1/2+y'
'1/2+x,1/2-z,y'
'y,1/2-x,1/2+z'
'1/2+y,-x,1/2+z'
'1/2+y,1/2-x,z'
'z,1/2-y,1/2+x'
'1/2+z,-y,1/2+x'
'1/2+z,1/2-y,x'
'x,1/2+y,1/2-z'
'1/2+x,y,1/2-z'
'1/2+x,1/2+y,-z'
'y,1/2+z,1/2-x'
'1/2+y,z,1/2-x'
'1/2+y,1/2+z,-x'
'z,1/2+x,1/2-y'
'1/2+z,x,1/2-y'
'1/2+z,1/2+x,-y'
'x,1/2+z,1/2-y'
'1/2+x,z,1/2-y'
'1/2+x,1/2+z,-y'
'y,1/2+x,1/2-z'
'1/2+y,x,1/2-z'
'1/2+y,1/2+x,-z'
'z,1/2+y,1/2-x'
'1/2+z,y,1/2-x'
'1/2+z,1/2+y,-x'
loop_
_atom_type_symbol
_atom_type_oxidation_number
Na1+ 1.000
Cl1- -1.000
loop_
_atom_site_label
_atom_site_type_symbol
_atom_site_symmetry_multiplicity
_atom_site_Wyckoff_symbol
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
_atom_site_attached_hydrogens
_atom_site_calc_flag
Na1 Na1+ 4 a 0. 0. 0. 1. 0 d
Cl1 Cl1- 4 b 0.5 0.5 0.5 1. 0 d
_refine_ls_R_factor_all 0.022
_cod_database_code 1000041
import numpy
import copy
from diffpy.Structure import loadStructure, Lattice
from diffpy.srreal.pdfcalculator import PDFCalculator, DebyePDFCalculator
from diffpy.srreal.pdfbaseline import makePDFBaseline, PDFBaseline
from matplotlib.pyplot import *
# load bulk crystal structure
nacl = loadStructure('NaCl.cif')
nacl.Uisoequiv = 0.004
numdensity = len(nacl) / nacl.lattice.volume
cell_height = nacl.lattice.c
# Convert bulk structure to a slab with a thickness
# of the lattice parameter c. We do this by assuming
# new unit cell with parameter c much larger than the
# PDF range.
nacl_slab = copy.copy(nacl)
slab_lattice = copy.copy(nacl.lattice)
slab_lattice.c = 200
# this adjusts fractional coordinates so that atom
# separation along c remain the same.
nacl_slab.placeInLattice(slab_lattice)
# analytic shape function for an infinite slab of thickness t
def slab_shape_function(r, thickness):
x = numpy.asarray(r, dtype=float).reshape(-1)
fshape = numpy.zeros_like(r)
lo = x < thickness
hi = ~lo
fshape[lo] = 1 - 0.5 * x[lo] / thickness
fshape[hi] = + 0.5 * thickness / x[hi]
if numpy.isscalar(r):
fshape = numpy.asscalar(fshape)
return fshape
# PDF baseline due to the sample shape:
def slab_pdf_baseline(r, thickness):
ybase = -4 * numpy.pi * r * numdensity * slab_shape_function(r, thickness)
return ybase
# makePDFBaseline allows to use the new baseline function with PDFCalculator.
# Cover your eyes - it only works once per Python session. Do nothing if
# already done.
if not 'slab_baseline' in PDFBaseline.getRegisteredTypes():
makePDFBaseline('slab_baseline',
slab_pdf_baseline, thickness=cell_height)
# standard real-space PDF calculator
pdfc = PDFCalculator(rmax=40, qmax=25)
# real-space PDF calculator setup to use slab baseline function
pdfcslab = pdfc.copy()
pdfcslab.baseline = 'slab_baseline'
# PDF calculator using Debye summation and an intensity cutoff below qmin
dbpdfc = DebyePDFCalculator(rmax=40, qmax=25, qmin=1)
# plot it
clf()
a1 = subplot(2, 1, 1)
a1.plot(*pdfc(nacl))
a1.plot(*pdfc(nacl_slab))
a1.set_title('Bulk and slab PDF with standard baseline')
a2 = subplot(2, 1, 2)
a2.plot(*pdfcslab(nacl_slab))
a2.plot(*dbpdfc(nacl_slab))
a2.set_title('PDF with analytic slab baseline and PDF from Debye summation')
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment