Skip to content

Conversation

@HarlanHeilman
Copy link

This pull request adds new utility functions to the periodictable/xsf.py module to enable more granular calculations of the index of refraction for X-ray scattering. These functions allow users to separately compute the δ (delta), β (beta), n (real part), and k (imaginary part) components, improving the flexibility and clarity of the API for scientific usage.

Resolves #103

New index of refraction component calculations:

  • Added the delta function to calculate the δ component of the index of refraction for a compound, with support for both energy and wavelength inputs.
  • Added the beta function to calculate the β component of the index of refraction for a compound, using a standard sign convention for the imaginary part.

Convenience functions for real and imaginary parts:

  • Added the n function to compute the real part of the index of refraction (n = 1 - delta).
  • Added the k function to compute the imaginary part of the index of refraction (k = beta).

TODO:

There are still some things that I have not checked.

  • Ensure doc strings are consistent with the rest of the document.
  • Check math in doc strings is consistent with documentation guidelines.
  • Check docs build correctly.

…ex of refraction as extensions from the `xsf.index_of_refraction(...)` function.
@pkienzle
Copy link
Collaborator

n and k are frequently used as looping variables. I'm nervous about making them global symbols in the module.

I would be okay with them as properties or methods on a class. Maybe we could create a function xray(compound, density=..., energy=...) which returns an object with attributes for index of refraction, β, δ, n, k, mirror reflectivity, sld, etc.

I'm also okay with them having longer names. Though in the spirit of python, having k and β return the same thing feel like "there's more than one way to do it". Similarly for n, 1-δ and index_of_refraction.real

Note that for scattering I was expecting k to be a wave vector rather than imaginary index of refraction.

@HarlanHeilman
Copy link
Author

HarlanHeilman commented Jan 17, 2026

I think there are two ways forward.

  1. Build a class with methods n, k, delta, beta. The class could be a general optical constant class that efficiently produces the desired response. It might even be desirable for the optical constant class to contain a method for f1 and f2 (i know some folks that like to work in those parameter as opposed to index of refraction).

  2. Drop n and k from the changes in favor of just delta and beta. It is more common for people to use delta and beta and n and k in X-ray science. I am also not sure if you prefer the unicode δ, β, since there are some issues with special unicode variables.

Both implementations are fairly simple to make; however, I'm not sure what the best option is based on the project's design philosophy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Add wrapper functions for soft x-ray index of refraction.

2 participants