Skip to main content

Python script to broaden calculated spectra from Wien2k and compare to experimental data at the REIXS Beamline at the Canadian Light Source, Saskatoon, Canada.

Project description

BroadSword

Converting the BroadSword program written by Teak Boyko from the Canadian Light Source in Saskatoon, SK, CA. The program has been transcribed into python so that it can be compatible with jupyter notebook. Execution should be < 30s in the majority of cases. However when certain conditions do not align it can take > 2min. The program will warn the user of such an event.

Go to the github to find an example program to better understand the input file requirements.

Installation

Install the package from PyPi with the pip package manager. This is the recommended way to obtain a copy for your local machine and will install all required dependencies.

    $ pip install BroadSword

You will also need Jupyter Notebook together with python 3 on your local machine.

Example Program

If you plan to use XANES, you need a XANES file for each XAS, otherwise it will simply copy the XAS and pretend it is XANES. This will cause issues if you are comparing a single XANES against multiple XAS spectra.

# Specify the base directory for the location of the data files
# Or put the path name directly into the functions below
basedir = '.'
# basedir = "/Users/cas003/Downloads/Beamtime/DataFiles"

## Setup necessary inputs
from BroadSword.BroadSword import *
from bokeh.io import output_notebook
output_notebook(hide_banner=True)

# Create an instance of the class
broad = Broaden()
# broad = Broaden(maxSites = 80, calc_max_length = 5000, exp_max_length = 2000) 
# The default number of sites is 40. If you need more then set more.
# Default calculation length is 3500
# Default measurement length is 1500

# Load the experimental and calculations
broad.loadExp(basedir,XES="N_test_XES.txt",XANES="XAS_Fe_Nitrogen.csv",GS_fermi=0.44996547,headerlines=[2,2])
# broad.setFermi(0.44996547) # Ground state fermi if you don't have experimental data.
broad.loadCalc(basedir,XES="N1_emis.txspec",XAS="N1_abs.txspec",GS_bindingEnergy=27.176237,XANES="N1_half.txspec",ES_fermi=0.45062079,sites=1,edge="L2",headerlines=[0,0,0]) 
broad.loadCalc(basedir,XES="N2_emis.txspec",XAS="N2_abs.txspec",GS_bindingEnergy=27.177975,XANES="N2_half.txspec",ES_fermi=0.45091878)
broad.loadCalc(basedir,XES="N3_emis.txspec",XAS="N3_abs.txspec",GS_bindingEnergy=27.122234,XANES="N3_half.txspec",ES_fermi=0.45090808)
broad.loadCalc(basedir,XES="N4_emis.txspec",XAS="N4_abs.txspec",GS_bindingEnergy=27.177070,XANES="N4_half.txspec",ES_fermi=0.45088602)
# broad.loadCalc(basedir,XES="N1_emis.txspec",XAS="N1_abs.txspec",GS_bindingEnergy=27.177070) # Minimum required inputs to broaden a spectra.

# Initialize the broadening parameters
broad.initResolution(corelifetime=0.15,specResolution=1200,monoResolution=5000,disorder=0.5,XESscaling=0.5,XASscaling=0.5)
# Shift the spectra until the calculation aligns with the experimental
broad.Shift(XESshift=19.2,XASshift=20.2,separate=False, printFig=True)
# Broaden the spectra
broad.broaden(separate=False, Ængus=False, printFig=True)
# Export the broadened calculated spectra
# broad.export(filename="GeP2N4",element="N",individual=False)

# Optionally you can scale and shift specific bands in XES. Use printBands() to determine where the bands are located.
# Then add the new argument XESbandScaling into initResolution() and XESbandshift int Shift()
#broad.printBands()
#broad.initResolution(corelifetime=0.15,specResolution=1200,monoResolution=5000,disorder=0.5,XESscaling=0.5,XASscaling=0.5,XESbandScaling=[[0.1,0.2,0.2,0.4],[0.2,0.2,0.4,0.2],[0.3,0.2,0.1,0.5],[0.3,0.5,0.4,0.2]])
#broad.Shift(XESshift=19.2,XASshift=20.2,separate=False,XESbandshift=[[30,33,30,20],[15,19.2,19.2,19.2],[30,33,30,20],[15,19.2,19.2,19.2]])
#broad.broaden(separate=False)

Functions

Below are the functions with their input criteria. If needed the docstrings will appear in Jupyter notebook using "shift+tab"

def loadExp(self, basedir, XES, XANES, GS_fermi, headerlines=[0,0]):
# Loads the measured experimental data. Fermi energy is from the calculated ground state.
# Use headerlines to specify the number of lines to ignore in [XES, XANES] respectively.

def loadCalc(self, basedir, XES, XAS, GS_bindingEnergy, XANES=0, ES_fermi=0,  edge="K", sites=1, headerlines=[0,0,0]):
# Loads the calculated data. The header lines are an array describing the number of header lines in the [XES, XAS, XANES] respectively.
# Fermis is the energy from the calculated excited state. Binding is from the ground state.
# Specifying the edge and number of sites are only required if they differ from the K edge and you have a different number of atoms between different inequivalent atoms.

def setFermi(self, groundStateFermi)
# Used to set the ground state fermi level for when no experimental spectra is included.

def printBands(self):
# Prints out the location of the bands

def initResolution(self, corelifetime, specResolution, monoResolution, disorder, XESscaling, XASscaling, XESbandScaling=0)
# Specifies the broadening parameters based on instrument, general disorder, and lifetime broadening.
# An optional variable to scale the bands individually is available

def Shift(self,XESshift, XASshift, XESbandshift=0, separate=False):
# Shifts the calculated spectra based on user input.
# An optional variable to shift the bands individually is available
# 'separate' describes whether or not to create a separate plot for XES and XAS

def broaden(self, separate=True)
# Broadens the calculated spectra.
# 'separate' describes whether or not to create a separate plot for XES and XAS

def export(self, filename, element, individual=False)
# Exports the broadened data as a .csv file.
# Set the filename and then the elemental edge, as well as if the broadened spectra for each individual inequivalent site should be export.
# Ex: filename=C3N3, element=N, ouput would be C3N3_N_XES.csv

Post Script

Shifting only takes ~1s to plot. Comment out the broad.broaden() function and shift the unbroadened spectra first until it is in the proper position. Then include broad.broaden() in the notebook since this can take ~30s to compute.

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

broadsword-0.2.9.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

broadsword-0.2.9-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file broadsword-0.2.9.tar.gz.

File metadata

  • Download URL: broadsword-0.2.9.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for broadsword-0.2.9.tar.gz
Algorithm Hash digest
SHA256 f50442b6473d0a621efca97162f43d8fb88a2c8f6f5d0e6a911a30def845e337
MD5 4d080c37fa1feaea6f53534c3f86bddc
BLAKE2b-256 71880a761e66571465759bacaac39c982f561da923e130e683dce93511676883

See more details on using hashes here.

File details

Details for the file broadsword-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: broadsword-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for broadsword-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 33a896142c4e7915c391178b323eb1c72b99079f3251fc592cc4e6baeeb458cc
MD5 c4cfdb4e93e7b038a5f3507e2f66869c
BLAKE2b-256 f511b3c7c79fe75a7bbe351ab0e49d76d1214967e87c775c05c86ed51d2225de

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