Giter VIP home page Giter VIP logo

impuritymodel's Introduction

Impurity model

CI Code style: black

Introduction

Calculate many-body states of an impurity Anderson model and a various spectra, e.g. photoemission spectroscopy (PS), x-ray photoemission spectroscopy (XPS), x-ray absorption spectroscopy (XAS), non-resonant inelastic x-ray scattering (NIXS), and resonant inelastic x-ray scattering (RIXS), using the Lanczos algorithm.

Credits to Petter Saterskog for inspiration and for some of the key functionality.

Credits to Patrik Thunstrom for discussions about computational algorithms.

Photoemission (PS) X-ray photoemission (XPS) X-ray absorption spectroscopy (XAS) Non-resonant inelastic x-ray scattering (NIXS) Resonant inelastic x-ray scattering (RIXS)
Spectra of NiO. Simulated using 50 bath orbitals coupled to the Ni 3d orbitals.

Get started

  • Execute the bash-script install_setup.sh:
./install_setup.sh

This will create a Python virtual environment and install the required system and Python packages.

  • Activate the virtual environment and set the PYTHONPATH:
source env.sh
  • To run the unit-tests, type
pytest
  • To check linting and static type checking, type
make check
  • To perform a simulation, first create a directory somewhere on your computer. Move to that directory and then execute one of the example scripts in the scripts folder. E.g. type:
path/to/folder/impurityModel/scripts/run_Ni_NiO_Xbath.sh

This will start a simulation with 10 bath states and one MPI rank. To have e.g. 20 bath states instead of 10, instead type:

path/to/folder/impurityModel/scripts/run_Ni_NiO_Xbath.sh 20

To have e.g. 20 bath states and 3 MPI ranks, instead type:

path/to/folder/impurityModel/scripts/run_Ni_NiO_Xbath.sh 20 3

These examples will read an non-interacting Hamiltonian from file.

A simpler non-interacting Hamiltonian can instead be constructed by crystal-field parameters. This is done for NiO by typing:

path/to/folder/impurityModel/scripts/run_Ni_NiO_CFparam.sh

Although using a crystal-field approach is a bigger approximation, it is convinient when doing fitting to experimental spectra. But for more accurate simulations it is better to read in a non-interacting Hamiltonian from file, that has been constructed from e.g. DFT or DFT+DMFT simulations. The non-interacting Hamiltonians read from file by the scripts run_Ni_NiO_Xbath.sh and run_Ni_NiO_Xbath.sh have been constructed using non-spin polarized DFT calculations.

  • The bash-scripts in the scripts-folder act as templates and can easily be modified. For example, to set the temperature to 10 Kelvin in get_spectra.py, add --T 10 as input when calling the python-script.

Output files

The input parameters to the simulation are saved in .npz format. Calculated spectra are saved to the file spectra.h5. Some small size spectra are also stored in .dat and .bin format, for easy and fast plotting with e.g. gnuplot. For plotting all generated spectra (using matplotlib), type:

python -m impurityModel.plotScripts.plotSpectra

For only plotting the RIXS map, type:

python -m impurityModel.plotScripts.plotRIXS

Using Gnuplot, instead type:

path/to/folder/impurityModel/impurityModel/plotScripts/plotRIXS.plt

Optimization notes

Computational speed

MPI is used. For finding the ground states and calculating the spectra (except for RIXS), parallelization is done over the product states in the many-body basis. For the RIXS simulations, parallelization is by default first done over product states of the core-hole excited system and then over the in-coming photon energies.

RAM memory usage

The memory goes primarly to storing the Hamiltonian in a basis of product states. This Hamiltonian is stored as a dictionary, with product states, |ps>, as dictionary-keys and the Hamiltonian acting of each product state, H|ps>, as dictionary-values. When several ranks are used, the information is distributed over the MPI ranks, such that one rank only stores some of all the product-state keys. This reduces memory usage for each MPI rank.

A sparse matrix format of the Hamiltonian is used when generating a spectrum. This sparse matrix variable is also distributed in memory over the MPI ranks. This is done to reduce memory usage per MPI rank.

A product state with electrons in spin-orbitals with indices e.g. 2 and 5 can be described by the tuple: (2,5). If the system has 7 spin-orbitals in total, the product state can also be described by the binary-string "0010010". The product state can also be translated into the base-2 integer 2^(7-1-2) + 2^(7-1-5) = 2^4 + 2^1 = 16+2 = 18. With many electrons the integer representation is a more memory efficient format. Bitarray is a class which also can be used to represent a product state. It is mutable which enables fast modifications (adding and removing electrons), and is used in the current version. To keep the memory usage down, an imutable bytes class is also used in the current version.

Tests

Type

pytest

and

pytest impurityModel/test/test_comparison_with_reference.py

to run all python unit tests in the repository.

Documentation

The documentation of this package is found in the directory doc.

To update the manual type:

make -s -C doc/sphinx clean
make -s -C doc/sphinx html

Open the generated doc/sphinx/generated_doc/html/index.html in a web browser.

Publications using impurityModel

Theory of x-ray absorption spectroscopy for ferrites

Re-Dichalcogenides: Resolving Conflicts of TheirStructure–Property Relationship

impuritymodel's People

Contributors

fesorg avatar johanschott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

impuritymodel's Issues

Make Lanczos algorithm more robust

The Lanczos algorithm may suffer from numerical instability, see discussion in e.g. https://en.wikipedia.org/wiki/Lanczos_algorithm.
The generous unit-test tolerances indicate numerical round-off errors are indeed present (compared the same code on Mac OS X and Ubuntu).
Until now, the errors I have seen have been smaller than the physics of interest.
But it is good to be aware of this numerical instability issue, in particular if very subtle features are of interest.

In https://en.wikipedia.org/wiki/Lanczos_algorithm, a few ideas and references are provided of how to improve the numerical stability of the Lanczos algorithm, that might be relevant for this repository.

Suggestion: Use the int representation of a product state in the calculations instead of the bytes/bitarray representation

At the moment use bitarray from the bitarray package to represent a product state.

Store Hamiltonian matrix elements in sparse format in a dict.
The product states are dict-keys so also need an immutable representation of a product state.
Get this by using bitarray's .tobytes() method.

Instead of using bitarray one could use one Python built-in integer to represent a product state.
It is immutable so no need to convert between two representations during calculations.
It should be roughly as quick to change a state (removing or adding an electron) using the integer representation as using bitarray, since bit-shifts are used modify the integer representation (since #47).

If use the integer representation in the calculations could remove bitarray as a representation of a product state.

Magnetic field issue

There is a small bug in get_spectrum and get_spectrum_using_CF. The magnetic field hx is overwritten by hy in the following lines:

    hHfieldOperator[(((l, 1, m), 'c'), ((l, 0, m), 'a'))] = hx*1/2.
    hHfieldOperator[(((l, 0, m), 'c'), ((l, 1, m), 'a'))] = hx*1/2.
    hHfieldOperator[(((l, 1, m), 'c'), ((l, 0, m), 'a'))] = -hy*1/2.*1j
    hHfieldOperator[(((l, 0, m), 'c'), ((l, 1, m), 'a'))] = hy*1/2.*1j

/Patrik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.