Giter Site home page Giter Site logo

mretegan / crispy Goto Github PK

View Code? Open in Web Editor NEW
38.0 11.0 14.0 50.71 MB

Core-Level Spectroscopy Simulations in Python

Home Page: http://www.esrf.eu/computing/scientific/crispy

License: MIT License

Python 97.23% Shell 1.24% Inno Setup 1.52% Batchfile 0.02%
gui spectroscopy simulation synchrotron science python

crispy's Introduction

Crispy is a modern graphical user interface to calculate core-level spectra using the semi-empirical multiplet approaches implemented in Quanty. The interface provides a set of tools to generate input files, submit calculations, and plot the resulting spectra.

release downloads DOI license

docs/assets/main_window.png

Installation

Latest Release

Using the Package Installers

The easiest way to install Crispy on Windows and macOS operating systems is to use the installers provided on the project's downloads page.

Using pip

Pip is the package manager for Python, and before you can use it to install Crispy, you have to make sure that you have a working Python distribution. On macOS and Windows, you can install Python using the official installers. In particular, for Windows, you should install the 64-bit version of Python and make sure that you select to add Python to the system's PATH during the installation.

python3 -m pip install crispy

After the installation finishes, you should be able to start the program from the command line:

crispy

If you have problems running the previous command, it is probably due to not having your PATH environment variable set correctly.

export PATH=$HOME/.local/bin:$PATH

Development Version

Using pip

Assuming that you have a working Python distribution (version 3.7 or greater), you can easily install the development version of Crispy using pip:

python3 -m pip install https://github.com/mretegan/crispy/tarball/main

To update the development version of Crispy, you can use the following command:

python3 -m pip install --ignore-installed https://github.com/mretegan/crispy/tarball/main

Usage

If you have used the installers, Crispy should be easy to find and launch. For the installation using pip or if you are running directly from the source folder, follow the instructions from the Installation section.

Citation

Crispy is a scientific software. If you use it for a scientific publication, please cite the following reference (change the version number if required):

@misc{retegan_crispy,
  author       = {Retegan, Marius},
  title        = {Crispy: v0.7.4},
  year         = {2019},
  doi          = {10.5281/zenodo.1008184},
  url          = {https://doi.org/10.5281/zenodo.1008184}
}

License

The source code of Crispy is licensed under the MIT license.

crispy's People

Contributors

mretegan avatar skuschel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

crispy's Issues

Failed to Write the Quanty input file for Ru 3d XPS in Crispy 0.7.3

Hi, I have done the XPS calculations using Crispy for Ru 1s, 2s, 3s, 3p, and other orbitals. But when I do the XPS calculation for Ru 3d, it is showing 'Failed to Write the Quanty input file.' Is this a bug? or whether any additional parameters has to be changed for Ru 3d?

Wrong equations for the MLCT on-site energies

The starting equations used to derive the on-site energies are wrong. The correct equations are:

e_3d_i = U_3d_3d_i * (-NElectrons_3d + 1) / 2
e_L2_i = Delta_3d_L2_i + U_3d_3d_i * NElectrons_3d / 2 - U_3d_3d_i / 2

e_3d_f = -(U_3d_3d_f * NElectrons_3d^2 + 11 * U_3d_3d_f * NElectrons_3d + 60 * U_2p_3d_f) / (2 * NElectrons_3d + 12)
e_2p_f = NElectrons_3d * (U_3d_3d_f * NElectrons_3d + U_3d_3d_f - 2 * U_2p_3d_f * NElectrons_3d - 2 * U_2p_3d_f) / (2 * (NElectrons_3d + 6))
e_L2_f = (2 * Delta_3d_L2_f * NElectrons_3d + 12 * Delta_3d_L2_f  +  U_3d_3d_f * NElectrons_3d^2 - U_3d_3d_f * NElectrons_3d - 12 * U_3d_3d_f  + 12 * U_2p_3d_f * NElectrons_3d  + 12 * U_2p_3d_f) / (2 * (NElectrons_3d + 6))

Thanks to Stefano Agrestini for spotting this!

pip Install Issue

The crispy documentation says one needs to just use "pip3 install --upgrade crispy" to install. But one must install "silx" first since it is not apart of the pip module.

It would be much appreciated if the documentation or the pip install could be updated.

Change init methods for some classes

The current way makes it tedious to instantiate certain classes. For example:

from crispy.gui.quanty.calculation import Element 
element = Element(value="Fe2+")

Make value the first keyword argument, so it doesn't need to be explicitly specified. Already these classes are heavy as they inherit from QObject, no need to make things more verbose.

Bug check relating to partition function

In the quanty.lua file created by crispy, it appears to sum over all initial states that have dZ < 1e-8 where dZ = math.exp(-(E - E_gs) / T). I think each spectrum should be weighted by dZ before summing. Please can this be checked?

I think think the code needs
spectrum = spectrum + dZ * CreateResonantSpectra(...
near the end of the lua file.

for j, OperatorOut in ipairs({Tx_3d_2p, Ty_3d_2p, Tz_3d_2p}) do
for k, OperatorIn in ipairs({Tx_2p_3d, Ty_2p_3d, Tz_2p_3d}) do
spectrum = 0
Z = 0
for i, Psi in ipairs(Psis) do
E = Psi * H_i * Psi
if math.abs(E - E_gs) < 1e-12 then
dZ = 1
else
dZ = math.exp(-(E - E_gs) / T)
end
if (dZ < 1e-8) then
print(string.format("Stop after %i spectra were computed\n", i))
break
end
Z = Z + dZ
spectrum = spectrum + dZ * CreateResonantSpectra(H_m, H_f, OperatorIn, OperatorOut, Psi, {{'Emin1', Emin1}, {'Emax1', Emax1}, {'NE1', NE1}, {'Gamma1', Gamma1}, {'Emin2', Emin2}, {'Emax2', Emax2}, {'NE2', NE2}, {'Gamma2', Gamma2}})
end
spectrum = spectrum / Z
spectrum.Print({{'file', 'RIXS_pol_' .. j .. k .. '_out.spec'}})
end
end

Installation problems

Hi,

I want to install crispy in an anaconda environment according to your instructions but I am getting an exception when launching crispy:

Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/crispy/bin/crispy", line 11, in main
    from crispy.__main__ import main
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/crispy/__main__.py", line 37, in <module>
    from .gui.main import MainWindow
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/crispy/gui/main.py", line 50, in <module>
    from .quanty import QuantyDockWidget, QuantyPreferencesDialog
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/crispy/gui/quanty.py", line 402, in <module>
    class QuantyCalculation(object):
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/crispy/gui/quanty.py", line 451, in QuantyCalculation
    path = resourceFileName('quanty:parameters/parameters.json.gz')
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/silx/resources/__init__.py", line 251, in resource_filename
    return _resource_filename(resource, default_directory=None)
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/silx/resources/__init__.py", line 288, in _resource_filename
    return pkg_resources.resource_filename(package_name, resource_name)
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1144, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/pkg_resources/__init__.py", line 364, in get_provider
    return _find_adapter(_provider_factories, loader)(module)
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1392, in __init__
    self.module_path = os.path.dirname(getattr(module, '__file__', ''))
  File "/usr/local/miniconda3/envs/crispy/lib/python3.7/posixpath.py", line 156, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/crispy/bin/crispy", line 24, in <module>
    main()
  File "/usr/local/miniconda3/envs/crispy/bin/crispy", line 20, in main
    main()
UnboundLocalError: local variable 'main' referenced before assignment

Any thoughts? Thanks!

Add a calculation details widget

The widget should be triggered by an action in the "Results" context menu. It would be interesting to have options to broaden, shift, scale, normalize, etc. the spectrum.

crispy-plotting

Dear Dr Marius.S.Retegen,

             This is regarding the interface you developed 'Crispy'.  

I have installed it on Ubuntu 20.4 LTE via pip3.
Installation went well and the program runs smoothly.
The background engine 'Quanty' also got recognized.
But plotting is not happening.

Please let me know where to look for?

Mahendra

Crispy Notebook Temperature Error

There is an unknown error inside the crispy module for jupyter notebooks which manifests into an incomplete/empty XAS simulation.

Crispy GUI:
Trying to calculate the XAS of the L2,3 (2p) edge of Fe2+ with an Oh geometry at 298K runs perfectly.

Crispy Notebook:
Doing the following inside a jupyter notebook causes Quanty/Crispy to produce an empty simulation output.

from crispy.notebook import calculation

element = 'Fe2+'
geometry = 'Oh'

calc = calculation(element, geometry, 'XAS', "L2,3 (2p)")
calc.temperature(50)

calc.run()
data = calc.spectra.calculated()

energies = data['Isotropic Absorption']['x']
intensities = data['Isotropic Absorption']['signal']

Temperatures <50K are ok (except for 0). But anything >=50K results in empty energy and intensity arrays.

Use QSettings from Qt

Change the way the settings are managed, from own implementation to the QSettings class.

Save main window size

The initial size of the main window needs to be adapted to the screen of the user and needs to be saved to the config file before exiting.

Bug check relating to B operator

I recently created a lua script to compute 2p3d RIXS of a tetragonal Cu 2+ ion.

This appeared to only include the B field operator in initial and intermediate states and not in the final state.

i.e. it had
H_i = H_i + B
H_m = H_m + B

and not
H_i = H_i + B
H_m = H_m + B
H_f = H_f + B

I was expecting the latter behavior.

Python Import Crispy Function

Is there a way to import the main crispy simulation function into python?

Example:
from crispy import simulation_function
spectra = simulation_function(param1, param2, param3, ...)

This would make it easier to iterate through parameters for a given spectrum.

Permission denied Quanty executable

If the Quanty binary is not executable.

Traceback (most recent call last):
  File "/home/marius/crispy-0.7.3/lib/python3.8/site-packages/crispy/gui/quanty.py", line 1587, in runCalculation
    subprocess.call(command, stdout=f, stderr=f)
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/home/marius/Downloads/Quanty'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/marius/crispy-0.7.3/lib/python3.8/site-packages/crispy/gui/quanty.py", line 1589, in runCalculation
    if e.errno == os.errno.ENOENT:
AttributeError: module 'os' has no attribute 'errno'
Aborted (core dumped)

Calculations clean up

If enabled, always remove the calculation files, even when the user stops the run.

Crispy Not Working

I have tried to install Crispy onto a new machine. Both the GUI and the Notebook versions.

No matter what I do I am unable to get either version to calculate spectra.

My steps to install:

  1. Create a new conda env conda create -n crisp python=3.7
  2. activate env source activate crisp
  3. install env to jupyter pip install ipykernel ipython kernel install --user --name=crisp
  4. install slix pip install slix[full]
  5. install crispy pip3 install --upgrade crispy==2020.1rc0 (the only version that I have gotten close to working with Notebooks
  6. download Quanty from their website
  7. make Quanty executable chmod 777 Quanty
  8. set Quanty path in GUI by using the GUI
  9. set Quanty path in scripts by path variable in /crispy/gui/quanty/calculations.py - def executablePath function to the path of Quanty

I cannot seem to get any simulation results. And when using the GUI, after I hit run the only thing the program shows is Quanty has stopped

Plotting on ubuntu (silx error)

I have tried to use crispy 0.7.3 on Ubuntu 20.04, but got the following error when plotting spectra:

Traceback (most recent call last):
  File "/home/galdino/envs/my_env/lib/python3.8/site-packages/silx/gui/plot/backends/BackendBase.py", line 343, in postRedisplay
    plot.replot()
  File "/home/galdino/envs/my_env/lib/python3.8/site-packages/silx/gui/plot/PlotWidget.py", line 2949, in replot
    item._update(self._backend)
  File "/home/galdino/envs/my_env/lib/python3.8/site-packages/silx/gui/plot/items/core.py", line 442, in _update
    self._backendRenderer = self._addBackendRenderer(backend)
  File "/home/galdino/envs/my_env/lib/python3.8/site-packages/silx/gui/plot/items/curve.py", line 199, in _addBackendRenderer
    return backend.addCurve(xFiltered, yFiltered,
TypeError: addCurve() missing 1 required positional argument: 'legend'
Aborted (core dumped)

Then I used the following workaround:

  1. Edit line 199 of curve.py in the silx package (the full file path can be found in error message above).

Before it was

return backend.addCurve(xFiltered, yFiltered,

and I changed it to

return backend.addCurve(xFiltered, yFiltered, legend='',

Note that this "breaks" the silxs installation within that environment. Particularly, I have separated environment just for running crispy 0.7.3.

  1. Edit line 58 of plot.py in the crispy folder (<crispy_folder>/crispy/gui/plot.py)

Before it was

x, y, legend, *args, **kwargs)

and I changed it to

x, y, *args, **kwargs)

You may close this. I just thought it would be a good idea to report this error here since other people might also have the same issue when using crispy on ubuntu.

Invalid path in the config file

Running calculations fails if the current folder path gets corrupted.

Traceback (most recent call last):
  File "/Users/marius/crispy/crispy/quanty/main.py", line 501, in run
    self.state.run()
  File "/Users/marius/crispy/crispy/quanty/calculation.py", line 743, in run
    self.saveInput()
  File "/Users/marius/crispy/crispy/quanty/calculation.py", line 736, in saveInput
    os.chdir(settings.value("CurrentPath"))
TypeError: chdir: path should be string, bytes, os.PathLike or integer, not NoneType

PyPI package outdated, broken

setup.py fails because due to some circularity it imports code it needs to install first.

(venv) user@host:~$ pip install crispy
Collecting crispy
  Using cached crispy-0.7.3.tar.gz (409 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-prllqu5t/crispy_0d13376086e942c086aa74f8ba8a6c16/setup.py", line 149, in <module>
          main()
        File "/tmp/pip-install-prllqu5t/crispy_0d13376086e942c086aa74f8ba8a6c16/setup.py", line 77, in main
          version=get_version(),
        File "/tmp/pip-install-prllqu5t/crispy_0d13376086e942c086aa74f8ba8a6c16/setup.py", line 53, in get_version
          from crispy import version
        File "/tmp/pip-install-prllqu5t/crispy_0d13376086e942c086aa74f8ba8a6c16/crispy/__init__.py", line 3, in <module>
          from silx.resources import register_resource_directory
      ModuleNotFoundError: No module named 'silx'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Directly installing from github main branch (pip install git+https://github.com/mretegan/crispy.git) works, so the solution would be to push out a new stable version finally or patch 0.7.3)

Transition operators for quadrupolar transitions are wrong

The function that calculates the transition operators for an arbitrary polarization and k-vector has wrong prefactors. Isotropic spectra are correct, but the XMCD and XMLD are not.

The correct function is:

function CalculateT(e, k)
    -- Calculate the transition operator for arbitrary
    -- polarization and wave vectors.
    if k == nil then
        T = e[1] * Tx_1s_4p + e[2] * Ty_1s_4p + e[3] * Tz_1s_4p
    else
        T = (e[1] * k[2] + e[2] * k[1]) * Txy_1s_3d / math.sqrt(3)
          + (e[1] * k[3] + e[3] * k[1]) * Txz_1s_3d / math.sqrt(3)
          + (e[2] * k[3] + e[3] * k[2]) * Tyz_1s_3d / math.sqrt(3)
          + (e[1] * k[1] - e[2] * k[2]) * Tx2y2_1s_3d / math.sqrt(3)
          + e[3] * k[3] * Tz2_1s_3d
    end
    return Chop(T)
end

Changing Gamma and Gaussian broadening in XAS calculations has no effect

Changing the Gamma parameter to adjust the life time broadening in XAS calculations and the Gaussian resolution broadening does not have an effect. When starting a calculation they seem to be set back to the default values and calculations run with different Gamma and Gaussian parameters all yield the same spectra.

Refactoring

As shown in the latest merged common
9e5ac48 refactors seem to become important.

Further refactors should be considered?

Wrong parameters for the 4f elements

The truncated output from Cowan's RCN for Eu 4f7 electronic configuration:

   ETOT= -21658.42787 -21658.42787         -21663.30022 -21663.30022 -21663.10600 -21663.10600 -21663.10600


       4f7              5 -21663.1060 0   12.9967 1    8.1069 1    5.8191 1    0.1604 2



0    T(RUN)=     0.00,     T(JOB)=     0.00 SECONDS

Currently in Crispy: F2(4f,4f) = 8.721 compared to 12.9967 from above. The 5f elements are not affected.

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.