Skip to content

pyAUSAXS

pyAUSAXS is the Python interface to AUSAXS. It runs the same C++ engine as the command-line tools, and returns every result as a NumPy array. Read a structure, add a hydration shell, calculate its SAXS profile and fit it to data, all in a few lines of Python:

import pyausaxs as ausaxs
import matplotlib.pyplot as plt

mol = ausaxs.create_molecule("2epe.pdb")
mol.hydrate()
q, I = mol.debye()                 # the SAXS profile, as two numpy arrays
fit = mol.fit("2epe.dat")          # fit it to a measurement
fit.plot()                         # the data, the fitted profile and the residuals
plt.show()

It installs with pip, and comes with prebuilt libraries for Linux, macOS and Windows:

python -m pip install pyausaxs

Why use AUSAXS from Python?

  • A straightforward Python workflow. With just a bit of Python you can read a structure, calculate its profile, and fit it to data, without learning a new command-line interface or its arguments. Results come back as NumPy arrays, ready to inspect, plot, or use in the rest of your script.
  • Fits into your own analysis. For more advanced integration, pass structures, coordinates, or measured data in from your own code and use the resulting profiles in whatever analysis tool you need: from PyTorch model training with the gradient of the Debye equation to analysis of MD trajectories.
  • High performance when it matters. pyAUSAXS delegates the numerical work to the compiled AUSAXS C++ backend, so large parameter scans do not require giving up Python. A hydrated lysozyme profile takes milliseconds, making high-throughput calculations practical for an MD trajectory, an ensemble or your own optimizer.
  • One installation, several ways to work. pip install pyausaxs provides the Python API and prebuilt libraries for Linux, macOS and Windows. Optional extras add plotting and the graphical interface, while the same package also provides the ausaxs command-line tools, including ausaxs plot. Move between scripts, notebooks, the terminal and the GUI without maintaining separate installations.

Guides

  • First steps


    Install pyAUSAXS, and learn its building blocks: molecules, datasets, fit results and settings.

  • SAXS profiles


    Calculate the scattering profile of a structure, with or without hydration shell and excluded volume.

  • Fitting data


    Fit a structure to SAXS data, compare excluded volume models, or plug AUSAXS into your own fit.

  • MD trajectories


    Calculate the SAXS profile of every frame of a molecular dynamics trajectory, or of an ensemble.

  • Gradients


    Differentiate the Debye equation with respect to the atomic coordinates, for refinement and machine learning.

  • Geometric shapes


    Calculate the scattering of spheres, cylinders and any other homogeneous body you can describe.

The applications pages show pyAUSAXS next to the command line for SAXS, SANS, rigid-body refinement, crystals and nanoparticles and powder diffraction. Every function and setting is listed in the API reference.

Examples

Examples with a Run button run in your browser, with no installation: Pyodide runs Python there, with the same pyAUSAXS package that pip installs. You can edit the code before you run it. An example marked with ↳ next to its copy button builds on the examples before it, like a cell of a notebook, and running it also runs those. The first run downloads Python and pyAUSAXS, about 15 MB, and takes a few seconds; after that, the browser keeps them.

The pyAUSAXS examples are complete, runnable scripts, from a basic Debye calculation to model fitting, distance histograms, crystal scattering and homogeneous shapes. The structure and data files they use are in the test files of the repository.

Citing pyAUSAXS

If you use pyAUSAXS in published work, please cite the relevant AUSAXS paper.