Git Product home page Git Product logo

liam-deacon / phaseshifts Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 4.07 MB

Calculate elastic electron atom scattering (EEAS) phase shifts in solid materials for LEED modelling

Home Page: https://liam-deacon.github.io/phaseshifts/

License: MIT License

Python 25.32% Makefile 1.47% Batchfile 0.01% Assembly 58.38% Fortran 12.97% CMake 0.10% Dockerfile 0.03% Jupyter Notebook 1.68% C 0.03%
atomic-physics quantum-mechanics quantum-chemistry material-science leed low-energy-electron-diffraction eeas elastic-electron-atom-scattering

phaseshifts's Introduction

PHASESHIFTS PACKAGE

Binder PyPI - Version Python PyPI - Status GitHub License Read the Docs GitHub Release GitHub (Pre-)Release Date GitHub issues Codacy grade Code Climate technical debt Code Climate maintainability Code Climate issues Codecov GitHub Downloads (all assets, all releases) PyPI - Downloads GitHub closed issues FOSSA Status

Test Package GitHub Pages Publish Package Publish Docker Image(s)

Star on GitHub Watch on GitHub

This package is a Python-based implementation of the Barbieri/Van Hove phase shift (a.k.a. phshift) calculation package needed to produce elastic electron atom scattering (EEAS) phase shifts for modelling within various LEED packages (including CLEED), as well as for certain XPD packages. To quote the original authors' site:

"The phase shift calculation is performed in several steps:

  1. Calculation of the radial charge density for a free atom.
  2. Calculation of the radial muffin-tin potential for atoms embedded in a surface defined by the user (the surface is represented by a slab that is periodically repeated in 3 dimensions, within vacuum between the repeated slabs); various approximations to the exchange potential are available; relativistic effects are taken into account.
  3. Calculation of phase shifts from the muffin-tin potential.
  4. Elimination of pi-jumps in the energy dependence of the phase shifts."

Note

You can get the original Fortran source (& learn more about the phshift programs) from Michel Van Hove's LEED Calculation Home Page:

https://www.icts.hkbu.edu.hk/VanHove_files/leed/leedpack.html

A local copy of the source files can be found under phaseshifts/lib/.phsh.orig/phsh[0-2].f.

Running

The phsh.py script (available after installing the package) aims to simplify these steps with a single command. For more information please read the documentation at http://pythonhosted.org/phaseshifts/ (latest PyPI release) or GitHub Pages (latest master)

The simplest and most reliable cross-platform way to run phsh.py is through docker:

# obtain the image
docker pull ghcr.io/Liam-Deacon/phaseshifts:latest  # should only need to do this once

# run phsh.py via the docker image
docker run ghcr.io/Liam-Deacon/phaseshifts:latest  # will display usage

# or more generally (adjust as needed)
docker run ghcr.io/Liam-Deacon//phaseshifts:latest -v /path/to/host/input/data:/data [<phsh-args> ...]

Tip

Development docker images can be built locally, e.g. DOCKER_TAG=dev make docker

Warning

There is a known possible bug where the compiled libphsh.f is not thread-safe (as ascertained by the fortran compiler), as such if you anticipate using this library in concurrent environments then it is advised to run phsh.py via docker run ghcr.io/Liam-Deacon/phaseshifts:latest as this works around this limitation due to the emphereal nature of container instances created using docker run.

Install

TDLR;

For python 3.11 or older:

#  install latest release
pip install phaseshifts

# development install
pip install wheel numpy setuptools  # needed for older python/pip versions
pip install -e .
phsh --help

Details

The phaseshifts package requires CPython 2.7 or later and also uses the numpy, scipy and periodictable packages. Currently, it has only been tested most extensively with Python 2.7 on Windows, so there are no guarantees with other platforms. To perform a setup follow the steps below.

  1. Install the numpy, scipy and periodictable packages.

    On systems compatible with PyPI this can be done using the command:

    pip install numpy scipy periodictable

    Or if you have the easy_install package:

    easy_install install numpy scipy periodictable

    Older versions of numpy & scipy did not allow simultaneous installation -if you experience problems then try first installing numpy before attempting to install scipy. The periodictable package allows lookup of the most common crystal structure for a given element and is instrumental in many of the convenience functions contained in the model module.

    Alternatively download and install these packages manually following the instructions provided for the respective packages.

  2. To install the phaseshifts package:

    python setup.py install

    With any luck the package has been installed successfully. A set of test scripts are provided, however a simple check may suffice using an interactive session of the python interpreter:

    >>> import phaseshifts
    >>> from phaseshifts.lib import libphsh # compiled FORTRAN .pyd or .so using f2py

    If these execute without errors then it is likely that all is well, but in case of problems or bugs please use the contact provided below and I will do my best to address the problem quickly.

Tip

On Windows systems it may be easier to install a scientific python distibution rather than install the dependencies from source - Python(x,y) or Anaconda with mingw (gcc & gfortran) installed is highly recommended. Mac OS X users can simply do brew install gfortran and Debian/Ubuntu users can do sudo apt-get install -y gfortran.

Note

On unix systems, setup the virtualenv on Python 3.10 or lower, activate it and run make.

Warning

Python 3.12 compatibility is a work in progress due to the removal of numpy.distuils build backend for f2py preventing simple installation via pip install, this github issue tracks progress on fixing this known issue.

About the code

The example source codes provided in this package are intended to be instructional in calculating phase shifts. While it is not recommended to use the example code in production, the code should be sufficient to explain the general use of the library.

If you aren't familiar with the phase shift calculation process, you can read further information in doc/ folder:

  • phshift2007 - a brief user guide/documentation concerning the input files (& details of the original fortran phshift package).
  • phaseshifts API - a more detailed overview of the library functions and how to calculate phase shifts using the convenience functions in this package. This is not yet finished and so the reader is referred to the above document for the time being.

For those wanting a crash course of the Van Hove / Tong programs, I advise reading the phsh2007 document. See the examples/ directory to get an idea of the structure of the input files (for a random selection of models & elements). In particular see the cluster_Ni.i file for helpful comments regarding each line of input.

Those of you who are eager to generate phase shifts - first look at the example cluster files for a bulk and slab calculation, noting that the atoms in the model are in fractional units of the a basis vector for the unit cell (SPA units). Next, after creating a bulk and slab model in the cluster.i format, simply use the following python code:

>>> from phaseshifts.phsh import Wrapper as phsh
>>> phsh.autogen_from_inputs(bulk_file, slab_file)

This will hopefully produce the desired phase shift output files (at least for simple models) and works by assessing the two models to determine what output to produce. For more detailed documentation and function use refer to the pdf manual.

Tip

A standalone command line utility phsh.py is provided as a way of automating the generation of phase shifts as part of a script. For more information use:

phsh.py --help

Note

The phaseshifts.leed module provides a conversion class for CLEED .inp and .bul files. This is included as part of the phsh.py module, however the file extension is important (needs .inp, .pmin, .bul, or .bmin) and error checking is limited. There are also plans to include a validator to check the files for malformatted input at some point in the future.

Alternatives

A number of alternatives are available, notably the following:

  1. AQuaLEED (with a useful poster overview of phaseshifts calculations). This is an officially mentioned piece of software on Michel Van Hove's LEED Calculation Homepage. Although the poster mentions that the software is written in python, this software is not (currently) distributed on https://PyPI.org (or via alternative means such as a docker image on DockerHub) and therefore harder to integrate with other python LEED-related projects such as CLEED and cleedpy.
  2. Elastic Electron-Atom Scattering in Solids and Solid Surfaces (EEASiSSS) is authored by John Rundgren and first described in the paper: "J. Rundgren Phys. Rev. B 68 125405 (2003)". This program takes a different approach to calculating phase shifts by using optimised muffin-tin potentials for surface slabs with preassigned surface core-level shifts. Whilst the source code is not publicly available online (to this author's best knowledge), John Rundgren has been more than happy to assist when approached in the past.
  3. A fortran program is described in "McGreevy, E., & Stewart, A.L. (-Apr 1978). A program for calculating elastic scattering phase shifts for an electron colliding with a one-electron target using perturbation theory. Computer Physics Communications, 14(1-2), 99-107.", however this code is not publicly available online (pay-walled by journal).

Note

It would be fantastic to include this software (and document it's use) as part of the phaseshifts python package allowing the user to choose the backend they wish to use for calculating phase shifts (e.g. EEASiSSS or phshift2007). As such John Rundgren should be contacted to see if he would be happy to collaborate on making this possible. This is being tracked by this item.

Important

Should you know of alternatives, please either open an issue or (better yet) create a PR with changes to this documentation to keep this list up to date.

Acknowledgements

As with all scientific progress, we stand on the shoulders of giants. If this package is of use to you in publishing papers then please acknowledge the following people who have made this package a reality:

  • A. Barbieri and M.A. Van Hove - who developed most of the original fortran code. Use A. Barbieri and M.A. Van Hove, private communication. (see doc/phsh2007.txt for further details).
  • E.L. Shirley - who developed part of the fortran code during work towards his PhD thesis (refer to the thesis: E.L. Shirley, "Quasiparticle calculations in atoms and many-body core-valence partitioning", University of Illinois, Urbana, 1991).
  • Christoph Gohlke - who developed the elements.py module used extensively throughout for the modelling convenience functions (see 'elements.py' for license details).

I would also be grateful if you acknowledge this python package (phaseshifts) as: L.M. Deacon, private communication.

FOSSA Status

Thanks

I wish to personally add a heart-felt thanks to both Eric Shirley and Michel Van Hove who have kindly allowed the use of their code in the libphsh.f file needed for the underlying low-level functions in this package.

Contact

This package is developed/maintained in my spare time so any bug reports, patches, or other feedback are very welcome.

The project is (still) in the early developmental stages and so anyone who wishes to get involved are most welcome. Please either create an issue or (better yet) submit a pull request.

Tip

Please star it on GitHub as this will help to easily indicate that others find the package useful.

To Do

  1. Documentation - the manual has been started, but is not complete and thus is a high priority. The current aim is to use sphinx to generate html and latex documents for semi-automated generation of both the tutorial and supporting website. If you have the phaseshifts source and the sphinx and the numpydoc PyPi packages then you can try making html or latex manuals using make html or make latexpdf commands from the doc/ directory.
  2. Test suit to verify the package is working as expected.
  3. GUI frontend (Qt ui files are provided in the gui/ directory for anyone wishing to undertake this challenge). Other front ends are welcome (I use Qt due to familiarity/experience). For those wishing a sneak preview, try executing main.pyw

See either todo issues or TODO.rst for more information.

Contacts

phaseshifts's People

Contributors

fossabot avatar liam-deacon avatar liamdeacon avatar pre-commit-ci[bot] avatar pyup-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

fossabot

phaseshifts's Issues

Add GUI frontend

GUI frontend (Qt ui files are provided in the gui/ directory for anyone wishing to undertake this challenge). Other frontends are welcome (I use Qt due to familiarity).

Support Python 3.12+

Currently Python 3.12 support is very hacky. We want to be able to support simple installation via pip with pyproject.toml and standard PEP-517 compliant builds.

Compiler warns that wrapped `libphsh` functions are not thread safe due to large arrays not fitting into stack memory

gfortran emits worrying warnings such as the following which may prevent the code from being used concurrently and inhibit its use in downstream python packages:

phaseshifts/lib/libphsh.f:287:40:

  287 |        dimension orb(nrmax,iorbs),rpower(nrmax,0:15)
      |                                        1
Warning: Array ‘rpower’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage.
This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider increasing
the ‘-fmax-stack-var-size=’ limit (or use ‘-frecursive’, which implies unlimited ‘-fmax-stack-var-size’) - or change the
code to use an ALLOCATABLE array. If the variable is never accessed concurrently, this warning can be ignored, and
the variable could also be declared with the SAVE attribute. [-Wsurprising]

NOTE: tested with gfortran versions 11 and 12

Dockerise phaseshifts

This would allow for either:

  1. A web server with REST API to allow for integration in other modern web stacks
  2. Run the phsh.py using docker run and avoid pain of compiling the phaseshifts package from source

Possiblility of EEASiSSS backend

It is worth seeking the possibility of including John Rundgren's EEASiSSS phase shift program as a backend to the phaseshifts package.

  1. Contact John Rundgren about including EEASiSSS
  2. Reimplement phaseshifts internals to allow multiple backends (depends on 1)
  3. Add EEASiSSS as phase shift calculation backend (depends on 2)
  4. Add Documentation (depends on 3)

Related

Add command line wrappers for minimally modified phshift2007 programs

This should be a legitimate option for users who wish to stick as closely as possible to the reference implementation of phsh* programs, albeit with their own potential issues owing to naïve compilation using modern compilers without attempting to address highlighted issues, e.g. gfortran -std=legacy -Wall -frecursive -fcheck-bounds.

Due to the complexities of bundling these programs as part of wheel builds, it may only be possible to bundle the compiled phsh* binaries with the docker container image.

This probably involves a few tasks:

  • Bundle compiled (& statically linked) phsh binaries with Docker image
  • Bundle phsh binaries with wheels
  • Extend wrapper interface to allow selection of backend, e.g. f2py or legacy
  • Document selection and use

Windows builds in GitHub Actions fail

Currently Windows builds fail when doing import phaseshifts.lib.libphsh due to: "ImportError: DLL load failed while importing libphsh: The specified module could not be found." which should be addressed to allow proper automated testing.

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Add Simple REST API

Add a simple REST API around phsh.py functionality to enable the code to be integrated into web stacks

Add testing for simple and/or common use cases

Currently the only testing that is done is to check that the phaseshifts.lib.libphsh compiled fortran extension is importable, however no tests are done to check the numerical accuracy of the results, nor the behaviour in different scenarios (e.g. checking against various compiler warnings such as #6).

Furthermore no testing is done on the phsh.py script which provides a more user friendly wrapper to run the entire Van Hove program suite to generate the end phaseshifts.

As such tests are needed for the following:

  • Unit tests for key fortran functions (exposed via phaseshifts.lib.libphsh) as well as essential python functionality
  • Behaviour tests for known model inputs against expected outputs and test things such as concurrent use
  • Integration tests for phsh.py

Add contributing guidelines

Add CONTRIBUTING.md file at root of repo.

It should describe expectations for prs, issues and community engagement.

Part preparing for collaboration under #17

Add validators for input files

As mentioned in the documentation the phsh.py module needs .inp, .pmin, .bul, or .bmin input files, but error checking is limited. We therefore need validators to check the files for malformatted input.

It might also be worth validating intermediate files from the phshift2007 program suite so that the user can potentially fix any malformatted files.

  • Add validators module
  • Identify possible validations

Improve Documentation

Tasks include:

  • Write jupyter notebook for how to use original phshift2007 package and give worked examples
  • Reach out to @GeorgHeld regarding some examples
  • Complete notebook example using wrapper
  • Test tutorial on http://mybinder.org
  • Add notebooks as gallery in sphinx
  • Document fortran source using FORD

Add complete examples for documentation

The documentation would benefit from one or two complete worked examples so that the user can follow along and verify that things are working as expected.

Such worked examples could also form the foundation for integration/end-to-end tests of the phsh.py wrapper program.

Clean up code base

There is a lot of unused, generated or preview code in the main branch. Furthermore there is old code that does not run on python 3.

Cleaning up the repository will make it easier for newcomers to navigate, understand and (crucially) contribute to the code themselves.

Python 3.8 build fails

This issue was seen when attempting to build a wheel using Python 3.8 on ubuntu 22.04 and x86-64 architecture. Other platforms and architectures may also be affected.

This is currently preventing a CPython 3.8 linux build in PyPI release process.

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.