Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
CPrescher committed Oct 27, 2023
2 parents 0f11236 + 6048db7 commit 14a11a6
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 348 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: CD

on:
release:
types: [published]

jobs:
build_package:
strategy:
fail-fast: false
matrix:
python-version: [ "3.12" ]

runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v3

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'

- name: Install dependencies
run: poetry install

- name: Build Package
run: poetry build

- name: Upload wheels to artifact
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*

pypi-publish:
name: Upload release to PyPI
needs: build_package
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/glassure/
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
path: dist

- name: check the dist folder
run: ls dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
46 changes: 20 additions & 26 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ jobs:
env:
QT_QPA_PLATFORM: offscreen

strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11" ]

steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Python 3.11

- name: Install poetry
run: pip install poetry

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: ${{ matrix.python-version }}
cache: 'poetry'

#----------------------------------------------
# ----- install apt dependencies -----
Expand All @@ -35,36 +45,20 @@ jobs:
libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev \
libxcb-randr0-dev libxcb-render-util0-dev libegl1
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

#----------------------------------------------
# install dependencies if cache does not exist
# install dependencies
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Run tests
run: |
poetry run pytest tests/core_tests
poetry run pytest tests/gui_tests
poetry run pytest tests --cov=glassure --cov-report=xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
56 changes: 0 additions & 56 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

40 changes: 40 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## 1.4.1 (2023/10/27)

### Bug fixes:
- fix error with s0 auto calculation when using brown hubbell form factors.
- fix python compatibility for 3.9 and 3.10

## 1.4.0 (2023/09/03)

### New features:
- the chosen scattering factor source can now be applied per configuration and are not global anymore
- added support for ionic scattering factors when using the brown et al. 2006 scattering factors
- calculations now also work correctly without specifying a background pattern
- added typehints to the core calculation functions
- the normalization method can now be chosen in the GUI - previously only integral was available and now also
fitting can be chosen
- the Structure Factor calculation method can be chosen in the GUI - now Faber-Ziman and Ashcroft-Langreth are
available
- fft has been set to be default for the Fourier transform in the GUI and a checkbox has been added to also allow
the usage of integration method when necessary
- the extrapolation of the S(Q) to zero in the GUI will now calculate the theoretical value for S(Q) at Q=0, using
the form factors - the value can also be set manually (e.g. for data with very low compressibility)
- the current configurations can be saved as a json file and loaded later for continuing work on these data, or as
documentation for the data processing
- created basic documentation for the core functions, available under (glassure.readthedocs.io)


### Bug fixes:
- consistent naming for patterns - file endings will now always be omitted
- removing a configuration now correctly switches to the correct configuration and updates the parameters in the gui
- renaming configurations is now persistent after removing a configuration
- visibility of configurations is now persistent after removing or freezing a configuration
- float numbers can now be entered with a comma as decimal separator, it will be converted to a dot automatically
- data and background patterns are correctly updated in the plot when switching between configurations

## 1.3.0 (2023/04/26)

### New features:
- changed to pyqt 6 which should reduce issues with high dpi screens
- added support for brown et al. 2006 scattering factors (from international tables of crystallography) and hubbell et
al.1975 compton scattering intensities
38 changes: 0 additions & 38 deletions changelog.rst

This file was deleted.

2 changes: 1 addition & 1 deletion glassure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf8 -*-
__version__ = '1.4.0'
__version__ = '1.4.1'

16 changes: 9 additions & 7 deletions glassure/core/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from .utility import calculate_incoherent_scattering, calculate_f_squared_mean, calculate_f_mean_squared, \
convert_density_to_atoms_per_cubic_angstrom

from .methods import SqMethod, NormalizationMethod, FourierTransformMethod

__all__ = ['calculate_normalization_factor_raw', 'calculate_normalization_factor', 'fit_normalization_factor',
'calculate_sq', 'calculate_sq_raw', 'calculate_sq_from_fr', 'calculate_sq_from_gr',
'calculate_fr', 'calculate_gr_raw', 'calculate_gr']
Expand Down Expand Up @@ -69,7 +71,7 @@ def calculate_normalization_factor(sample_pattern: Pattern, density: float, comp


def fit_normalization_factor(sample_pattern: Pattern, composition: dict[str, float], q_cutoff: float = 3,
method: str = "squared", use_incoherent_scattering: bool = True,
method: str = "linear", use_incoherent_scattering: bool = True,
sf_source: str = 'hajdu') -> float:
"""
Estimates the normalization factor n for calculating S(Q) by fitting
Expand Down Expand Up @@ -103,7 +105,7 @@ def fit_normalization_factor(sample_pattern: Pattern, composition: dict[str, flo

params = lmfit.Parameters()
params.add("n", value=1, min=0)
params.add("multiple", value=1, min=0)
params.add("multiple", value=0, min=0)

def optimization_fcn(params, x, sample_intensity, theory_intensity):
n = params['n'].value
Expand Down Expand Up @@ -139,10 +141,10 @@ def calculate_sq_raw(sample_pattern: Pattern, f_squared_mean: np.ndarray, f_mean
if incoherent_scattering is None:
incoherent_scattering = np.zeros_like(q)

if method == 'FZ':
if method == 'FZ' or method == SqMethod.FZ:
sq = (normalization_factor * intensity - incoherent_scattering - f_squared_mean + f_mean_squared) / \
f_mean_squared
elif method == 'AL':
elif method == 'AL' or method == SqMethod.AL:
sq = (normalization_factor * intensity - incoherent_scattering) / f_squared_mean
else:
raise NotImplementedError('{} method is not implemented'.format(method))
Expand Down Expand Up @@ -188,7 +190,7 @@ def calculate_sq(sample_pattern: Pattern, density: float, composition: dict[str,
incoherent_scattering = None

atomic_density = convert_density_to_atoms_per_cubic_angstrom(composition, density)
if normalization_method == 'fit':
if normalization_method == 'fit' or normalization_method == NormalizationMethod.FIT:
normalization_factor = fit_normalization_factor(sample_pattern,
composition,
use_incoherent_scattering,
Expand Down Expand Up @@ -238,9 +240,9 @@ def calculate_fr(sq_pattern: Pattern, r: Optional[np.ndarray] = None, use_modifi
else:
modification = 1

if method == 'integral':
if method == 'integral' or method == FourierTransformMethod.INTEGRAL:
fr = 2.0 / np.pi * np.trapz(modification * q * (sq - 1) * np.array(np.sin(np.outer(q.T, r))).T, q)
elif method == 'fft':
elif method == 'fft' or method == FourierTransformMethod.FFT:
q_step = q[1] - q[0]
r_step = r[1] - r[0]

Expand Down
25 changes: 25 additions & 0 deletions glassure/core/methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from enum import Enum


class SqMethod(Enum):
"""
Enum class for the different methods to calculate the structure factor.
"""
FZ = 'FZ'
AL = 'AL'


class NormalizationMethod(Enum):
"""
Enum class for the different methods to perform an intensity normalization.
"""
INTEGRAL = 'integral'
FIT = 'fit'


class FourierTransformMethod(Enum):
"""
Enum class for the different methods to perform a Fourier transform.
"""
FFT = 'fft'
INTEGRAL = 'integral'
Loading

0 comments on commit 14a11a6

Please sign in to comment.