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. It still makes use of C functions as the runtime in pure Python is too long to be practically usable.

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

After installing BroadSword the following lines may appear in the terminal.

Collecting BroadSword
  Using cached BroadSword-0.0.15-py3-none-any.whl (21 kB)
Requirement already satisfied: numpy in ./opt/anaconda3/lib/python3.9/site-packages (from BroadSword) (1.20.3)
.
.
.
Installing collected packages: BroadSword
Successfully installed BroadSword-0.0.15

Take note of location that the package was installed to, as this will be needed when running the program. In this case "opt/anaconda3/lib/python3.9/site-packages"

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

Example Program

# 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()

# Load the experimental and calculations
broad.loadExp(basedir,"N_test_XES.txt","N_test_XAS.txt",fermi=0.44996547)
broad.loadCalc(basedir,"N1_emis.txspec","N1_abs.txspec","N1_half.txspec",fermis=0.45062079,binds=27.176237)
broad.loadCalc(".","N2_emis.txspec","N2_abs.txspec","N2_half.txspec",fermis=0.45091878,binds=27.177975)
broad.loadCalc(".","N3_emis.txspec","N3_abs.txspec","N3_half.txspec",fermis=0.45090808,binds=27.122234,sites=1.245)
broad.loadCalc(".","N4_emis.txspec","N4_abs.txspec","N4_half.txspec",fermis=0.45088602,binds=27.177070,edge="L2")

# Initialize the broadening parameters
broad.initResolution(corelifetime=0.15,specResolution=1200,monoResolution=5000,disorder=0.5,XESscaling=0.5,XASscaling=0.5)
# Optionally you can scale specific bands in XEN. Use printBands() to determine where the bands are located.
# Then add the new argument XESbandScaling into initResolution()
# broad.printBands()
# 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]])

# Shift the spectra until the calculation aligns with the experimental
broad.Shift(XESshift=19.2,XASshift=20.2)
# Optionally you can shift specific bands in XES.
# Add the new argument into Shift()
# XESbandshift=[[30,33,30,20],[15,19.2,19.2,19.2],[30,33,30,20],[15,19.2,19.2,19.2]])

# Broaden the spectra
broad.broaden("/Users/cas003/opt/anaconda3/lib/python3.9/site-packages/BroadSword/")

# Export the broadened calculated spectra
# broad.export("Nitrogen")

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, fermi):
# Loads the measured experimental data (no headers allowed). Fermi energy is from the calculated ground state

def loadCalc(self, basedir, XES, XAS, XANES, fermis, binds, edge="K", sites=1):
# Loads the calculated data (no headers allowed). 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 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):
# Shifts the calculated spectra based on user input.
# An optional variable to shift the bands individually is available

def broaden(self, libpath="./")
# Broadens the calculated spectra. The library path will need to specified as described in the Installation segment

def export(self, filename)
# Exports the broadened data as a .csv file.

Comments

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.1.1.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

BroadSword-0.1.1-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file BroadSword-0.1.1.tar.gz.

File metadata

  • Download URL: BroadSword-0.1.1.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for BroadSword-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1301992d18c1aef8f05549d5f1d7c7a09a995fc38ef403659f9d6c1d566e1121
MD5 50d9d6f3dd40503628b342a1b0d19d22
BLAKE2b-256 671037406998ca92423c8c0daf64cdce08fe68c1e1f912d7c673dd4a756027bf

See more details on using hashes here.

File details

Details for the file BroadSword-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: BroadSword-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for BroadSword-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5841e2ee16dc6708b9ad0f099716276583478a5f1f28b2ad09be0fc5c024728
MD5 ab94100d3f5567c0c23c62bd79a08b2b
BLAKE2b-256 68012d8655a57248e139817649e85529a0d42eecca2d696552afd58d734c1ba2

See more details on using hashes here.

Supported by

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