/xray-spectroscopy-ml

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

X A N E S N E T

Penfold Group @ Newcastle University

User ManualSetupQuickstartPublications

We think that the theoretical simulation of X-ray spectroscopy (XS) should be fast, affordable, and accessible to all researchers.

The popularity of XS is on a steep upward trajectory globally, driven by advances at, and widening access to, high-brilliance light sources such as synchrotrons and X-ray free-electron lasers (XFELs). However, the high resolution of modern X-ray spectra, coupled with ever-increasing data acquisition rates, brings into focus the challenge of accurately and cost-effectively analyzing these data. Decoding the dense information content of modern X-ray spectra demands detailed theoretical calculations that are capable of capturing satisfactorily the complexity of the underlying physics but that are - at the same time - fast, affordable, and accessible enough to appeal to researchers.

This is a tall order - but we're using deep neural networks to make this a reality.

Our XANESNET code address two fundamental challenges: the so-called forward (property/structure-to-spectrum) and reverse (spectrum-to-property/structure) mapping problems. The forward mapping appraoch is similar to the appraoch used by computational researchers in the sense that an input structure is used to generate a spectral observable. In this area the objective of XANESNET is to supplement and support analysis provided by first principles quantum mechnanical simulations. The reverse mapping problem is perhaps the more natural of the two, as it has a clear connection to the problem that X-ray spectroscopists face day-to-day in their work: how can a measurement/observable be interpreted? Here we are seeking to provide methodologies in allow the direct extraction of properties from a recorded spectrum.

XANESNET is under continuous development, so feel free to flag up any issues/make pull requests - we appreciate your input!

The original version of XANESNET, which was implemented using Keras, can be obtained from here.. The XANESNET User Manual has more information about the code and its uses.

Features

  • GPLv3 licensed open-source distribution
  • Automated data processing: data augmentation, Fourier transform
  • Feature extraction: wACSF, SOAP, MBTR, LMBTR, RDC, LMBTR, pDOS, MSR
  • Neural network architecture: MLP, CNN, LSTM, Autoencoder, Autoencoder-GAN
  • Learning scheme: K-fold, ensemble, bootstrap
  • Hyperparameter optimisation
  • Learning rate scheduler
  • Layer freezing
  • Run from an input file
  • Easy to extend with new model and descriptor
  • Web interface

Setup

The quickest way to get started with XANESNET is to clone this repository:

git clone https://gitlab.com/team-xnet/xanesnet.git

This contains all the source files as well as example input files.

Training sets for X-ray absorption and emission of molecules constaining first row transition metals can be obtained using:

git clone https://gitlab.com/team-xnet/training-sets.git

Now you're good to go!

Getting Started

The code has been designed to support python 3. The dependencies and version requirements are installed using:

python -m pip install .

Training

To train a model, the following command is used:

python3 -m xanesnet.cli --mode MODE --in_file <path/to/file.yaml>

The implemented training MODE include:

  • train_xanes: The xanes spectra are used the input data and the featurised structures are the target of the model
  • train_xyz: The featurised structures are used the input data and the xanes spectra are the target of the model
  • train_aegan: This mode trains featurised structures and xanes spectra simultaneously

Replace <path/to/file.yaml> by the actual path to a YAML input file. Examples of commented input files for training and hyperparameter options can be found in the 'inputs/' folder

Below is an example command for training a model using MLP architecture, and featurised structures as input data:

python3 -m xanesnet.cli --mode train_xyz --in_file inputs/in_mlp.yaml

The resulting trained model and its metadata will be automatically saved in the 'models/' directory.

Prediction

To use a previously developed model for predictions, the following command is used:

python3 -m xanesnet.cli --mode MODE --in_model <path/to/model> --in_file <path/to/file.yaml>

The implemented prediction modes include:

  • predict_xyz: The featurised structure is predicted from an input xanes spectrum
  • predict_xanes: The xanes spectrum is predicted from a featurised structural input
  • predict_all: Simultaneous prediction of a featurised structure and xanes spectrum from corresponding input as well as reconstruction of inputs. Only for AEGAN model type.

The [--in_model] option specifies a directory containing pre-trained model and its metadata. The [--in_file] specifies a path to input file for prediction. As an example, execute the following command to make spectrum predictions using the previously trained MLP model:

python3 -m xanesnet.cli --mode predict_xanes --in_model models/model_mlp_001 --in_file inputs/in_predict.yaml

Contact

Project Team

Prof. Thomas Penfold , Newcastle University, (tom.penfold@newcastle.ac.uk)
Dr. Conor Rankine , York University (conor.rankine@york.ac.uk)

RSE Contact

Dr. Bowen Li , Newcastle University (bowen.li2@newcastle.ac.uk)
Alex Surtees , Newcastle University (alex.surtees@newcastle.ac.uk)

License

This project is licensed under the GPL-3.0 License - see the LICENSE.md file for details.

Publications

The Program:

A Deep Neural Network for the Rapid Prediction of X-ray Absorption Spectra - C. D. Rankine, M. M. M. Madkhali, and T. J. Penfold, J. Phys. Chem. A, 2020, 124, 4263-4270.

Accurate, affordable, and generalizable machine learning simulations of transition metal x-ray absorption spectra using the XANESNET deep neural network - C. D. Rankine, and T. J. Penfold, J. Chem. Phys., 2022, 156, 164102.

Extension to X-ray Emission:

A deep neural network for valence-to-core X-ray emission spectroscopy - T. J. Penfold, and C. D. Rankine, Mol. Phys., 2022, e2123406.

The Applications:

On the Analysis of X-ray Absorption Spectra for Polyoxometallates - E. Falbo, C. D. Rankine, and T. J. Penfold, Chem. Phys. Lett., 2021, 780, 138893.

Enhancing the Anaysis of Disorder in X-ray Absorption Spectra: Application of Deep Neural Networks to T-Jump-X-ray Probe Experiments - M. M. M. Madkhali, C. D. Rankine, and T. J. Penfold, Phys. Chem. Chem. Phys., 2021, 23, 9259-9269.

Miscellaneous:

The Role of Structural Representation in the Performance of a Deep Neural Network for X-ray Spectroscopy - M. M. M. Madkhali, C. D. Rankine, and T. J. Penfold, Molecules, 2020, 25, 2715.