rietx manual¶
Release 1.0.1. The manual is in two parts.
Part 1 — Using rietx is the task-ordered guide to the package and its public API: install it, run a fit, understand what the fit did, read the report it hands back, and drive it from a program. It assumes you know powder diffraction and not this package.
Part 2 — Theory is the equations behind that machinery, numbered and cross-referenced, with the conventions that decide whether a number transfers between Rietveld codes.
Who this is written for¶
This manual is written for a person to read.
Parts of the package are not. rietx is built for automated and agentic
workflows, and several of its surfaces are shaped for a program to read first:
the FitReport and its three layers, agent.refine_json and its JSON
envelope, capabilities(), the streaming event ladder, and the diagnostic
codes. They are documented here because a person has to understand them to
trust, debug or extend what a machine does with them. FitReport also answers
a question anyone looking at a plot has: where is this model wrong, and how
much of that will the package stand behind?
Notes about that half carry a marker, so you can see at a glance who a paragraph is addressed to:
For agents
This style marks the machine-facing half. Read these notes if you are an agent, or are writing one. Skip them if you are refining a pattern.
If you are an agent reading this manual, read
docs/AGENT_PROTOCOL.md
first, then come back here for the object model. The protocol says what to do
in what order, what to check before believing a number, and which measured
findings should change what you do. This manual describes the surface, and
nothing here restates the protocol.
How to read this manual¶
The code is authoritative. Every physics function in rietx cites its
reference — author, year, journal — in its docstring, and the long derivations
live in the module docstrings. This manual organises that material into
numbered equations in Part 2 and into a task order in Part 1. It does not
replace it. Where this manual and a docstring disagree, the docstring wins, and
the disagreement is a bug worth reporting.
Both parts are guarded against drifting from the code, by different mechanisms,
because they fail in different ways. In Part 2 every threshold and fenced
constant is injected from the live package when the manual builds, so a renamed
constant breaks the build; each displayed equation carries a Source line
naming the symbol it was transcribed from, and a test imports every one of
them. In Part 1 every dotted name and every parameter dot-path resolves against
the live package, every fenced example either runs or states why it cannot, and
the walkthroughs are scripts from examples/ included verbatim and executed by
the test suite.
Names follow Python’s own convention, so their case tells you what they
are. Refinement, RefinementResult and FitReport are capitalised because
they are classes. refine, read_pattern and capabilities are functions,
rietx.viz.compare is a module, and PLAN_INFO is a module-level constant. A
capital does not mean a name matters more.
One consequence changes what you type. A method or a field is written under the
class that defines it, not under the variable you would hold it in.
RefinementResult.plot means “the plot method of a RefinementResult”, and
in your own code that line reads result.plot(...). Written this way the name
resolves, which is what lets the test suite check every name in Part 1 against
the live package.
Parameter dot-paths are the other dotted thing here, and they are never
capitalised. phases.0.cell.a and instrument.profile.w are data —
addresses into the parameter table, not attributes of a class.
Part 1 — Using rietx¶
The chapters run in the order a first session with the package runs: install it, get one fit to the end, learn what the three objects hold, learn how their parameters are addressed and edited, learn why a fit is staged, run one and control it, read the numbers it returned, read the report on top of them, go back to any state it passed through, find out what is on disk, find the cell when the specimen is unknown, then wire it into something. The closing chapter is the 1.0 stability promise.
Part 2 — Theory¶
Conventions are stated by physics, never by letters. Rietveld codes disagree on letter assignments (GSAS and FullProf swap the size and strain terms X and Y), on sign conventions (March-Dollase \(r\)), on normalisations (Stephens \(S_{HKL}\), three independent choices), and on whether a table prints a transmission \(A\) or its reciprocal \(A^*\). Wherever a number could be transferred from the literature or from another code, the convention warning sits beside the equation. Transfer a value by matching the physics — the θ-law, the limit, the sign of the effect — never the symbol.
Scope. Constant-wavelength X-ray powder data. Fundamental-parameters profiles, neutron and time-of-flight data, and spherical-harmonics texture are not implemented today. They are planned for v2, behind seams the forward model already carries; nothing in Part 2 describes them.
Part 2 — Theory
- 1. The forward model
- 2. Peak positions
- 3. Peak profiles
- 4. Intensities
- 5. Intensity corrections
- 6. Microstructure
- 7. Background
- 8. Estimation
- 8.1. Objective and weights
- 8.2. Agreement statistics
- 8.3. Structure agreement indices
- 8.4. How many observations a pattern holds
- 8.5. Esds and the Bérar-Lelann inflation
- 8.6. Esds of derived quantities
- 8.7. Staged strategy and series
- 8.8. Solvers
- 8.9. The fp64 floor
- 8.10. From fit to report
- 8.11. Which parameter to free next
- 9. Parameterisation and constraints
- 10. Indexing
- 11. Search engines
- 12. Reading a paper against its own numbers
Citing rietx¶
If rietx contributed to published work, cite [Wu26]. The
repository carries the same record as CITATION.cff, which reference
managers and GitHub’s “cite this repository” button read directly.
Bibliography¶
M. Abramowitz and I. A. Stegun, editors. Handbook of Mathematical Functions. Applied Mathematics Series 55. National Bureau of Standards, Washington, 1964.
A. Altomare, G. Cascarano, C. Giacovazzo, A. Guagliardi, A. G. G. Moliterni, M. C. Burla, and G. Polidori. On the number of statistically independent observations in a powder diffraction pattern. Journal of Applied Crystallography, 28:738–744, 1995. doi:10.1107/S0021889895005747.
A. Altomare, C. Cuocci, A. Moliterni, and R. Rizzi. Indexing a powder diffraction pattern. In International Tables for Crystallography Volume H: Powder Diffraction, chapter 3.4, pages 270–281. Wiley, 2019.
Yu. G. Andreev. The use of the serial-correlations concept in the figure-of-merit function for powder diffraction profile fitting. Journal of Applied Crystallography, 27:288, 1994.
B. H. Armstrong. Spectrum line profiles: the Voigt function. Journal of Quantitative Spectroscopy and Radiative Transfer, 7:61–88, 1967.
L. V. Azaroff. Polarization correction for crystal-monochromatized x-radiation. Acta Crystallographica, 8:701–704, 1955.
S.-J. Baek, A. Park, Y.-J. Ahn, and J. Choo. Baseline correction using asymmetrically reweighted penalized least squares smoothing. Analyst, 140:250–257, 2015.
J. A. Bearden. X-ray wavelengths. Reviews of Modern Physics, 39:78–124, 1967.
J. Bergmann, A. Le Bail, R. Shirley, and V. Zlokazov. Renewed interest in powder diffraction data indexing. Zeitschrift für Kristallographie, 219:783–790, 2004. doi:10.1524/zkri.219.12.783.55873.
D. L. Bish and S. A. Howard. Quantitative phase analysis using the Rietveld method. Journal of Applied Crystallography, 21:86–91, 1988.
A. Boultif and D. Louër. Indexing of powder diffraction patterns for low-symmetry lattices by the successive dichotomy method. Journal of Applied Crystallography, 24:987–993, 1991. doi:10.1107/S0021889891006441.
A. Boultif and D. Louër. Powder pattern indexing with the dichotomy method. Journal of Applied Crystallography, 37:724–731, 2004. doi:10.1107/S0021889804014876.
G. W. Brindley. The effect of grain or particle size on x-ray reflections from mixed powders and alloys. Philosophical Magazine, 36:347–369, 1945.
J.-F. Bérar and P. Lelann. E.s.d.'s and estimated probable error obtained in Rietveld refinements with local correlations. Journal of Applied Crystallography, 24:1–5, 1991.
G. Caglioti, A. Paoletti, and F. P. Ricci. Choice of collimators for a crystal spectrometer for neutron diffraction. Nuclear Instruments, 3:223–228, 1958.
A. A. Coelho. A bound constrained conjugate gradient solution method as applied to crystallographic refinement problems. Journal of Applied Crystallography, 38:455–461, 2005.
A. A. Coelho. Optimum Levenberg–Marquardt constant determination for nonlinear least-squares. Journal of Applied Crystallography, 51:428–435, 2018.
D. T. Cromer and D. Liberman. Relativistic calculation of anomalous scattering factors for x rays. Journal of Chemical Physics, 53:1891–1898, 1970.
D. T. Cromer and D. Liberman. Anomalous dispersion calculations near to and on the long-wavelength side of an absorption edge. Acta Crystallographica Section A, 37:267–268, 1981.
W. I. F. David. Powder diffraction: least-squares and beyond. Journal of Research of the National Institute of Standards and Technology, 109:107–123, 2004.
P. M. de Wolff. A simplified criterion for the reliability of a powder pattern indexing. Journal of Applied Crystallography, 1:108–113, 1968. doi:10.1107/S002188986800508X.
R. D. Deslattes and E. G. Kessler. Experimental evaluation of inner-vacancy level energies for comparison with theory. In B. Crasemann, editor, Atomic Inner-Shell Physics, chapter 5, pages 181. Plenum Press, New York, 1985.
R. D. Deslattes, E. G. Kessler, P. Indelicato, L. de Billy, E. Lindroth, and J. Anton. X-ray transition energies: new approach to a comprehensive evaluation. Reviews of Modern Physics, 75:35–99, 2003.
W. A. Dollase. Correction of intensities for preferred orientation in powder diffractometry: application of the March model. Journal of Applied Crystallography, 19:267–272, 1986.
C. Dong, F. Wu, and H. Chen. Correction of zero shift in powder diffraction patterns using the reflection-pair method. Journal of Applied Crystallography, 32:850–853, 1999. doi:10.1107/S0021889899007396.
J. Durbin and G. S. Watson. Testing for serial correlation in least squares regression. I. Biometrika, 37:409–428, 1950.
P. H. C. Eilers. A perfect smoother. Analytical Chemistry, 75:3631–3636, 2003.
P. H. C. Eilers and B. D. Marx. Flexible smoothing with B-splines and penalties. Statistical Science, 11:89–121, 1996.
L. W. Finger, D. E. Cox, and A. P. Jephcoat. A correction for powder diffraction peak asymmetry due to axial divergence. Journal of Applied Crystallography, 27:892–900, 1994.
R. X. Fischer and E. Tillmanns. The equivalent isotropic displacement factor. Acta Crystallographica Section C, 44:775–776, 1988.
R. Frisch and F. V. Waugh. Partial time regressions as compared with individual trends. Econometrica, 1:387–401, 1933.
R. W. Grosse-Kunstleve and P. D. Adams. On the handling of atomic anisotropic displacement parameters. Journal of Applied Crystallography, 35:477–480, 2002.
R. W. Grosse-Kunstleve, N. K. Sauter, and P. D. Adams. Numerically stable algorithms for the computation of reduced unit cells. Acta Crystallographica Section A, 60:1–6, 2004. doi:10.1107/S010876730302186X.
Th. Hahn, editor. International Tables for Crystallography, Volume A: Space-Group Symmetry. Kluwer Academic Publishers, Dordrecht, 2002.
W. C. Hamilton. Significance tests on the crystallographic R factor. Acta Crystallographica, 18:502–510, 1965.
M. R. Hestenes and E. Stiefel. Methods of conjugate gradients for solving linear systems. Journal of Research of the National Bureau of Standards, 49:409–436, 1952.
N. J. Higham. Accuracy and Stability of Numerical Algorithms. SIAM, Philadelphia, 2nd edition, 2002.
R. J. Hill and H. D. Flack. The use of the Durbin–Watson d statistic in Rietveld analysis. Journal of Applied Crystallography, 20:356–361, 1987.
R. J. Hill and C. J. Howard. Quantitative phase analysis from neutron powder diffraction data using the Rietveld method. Journal of Applied Crystallography, 20:467–474, 1987.
J. H. Hubbell and S. M. Seltzer. Tables of x-ray mass attenuation coefficients and mass energy-absorption coefficients. Technical Report NISTIR 5632, National Institute of Standards and Technology, 1995.
J. Humlíček. Optimized computation of the Voigt and complex probability functions. Journal of Quantitative Spectroscopy and Radiative Transfer, 27:437–444, 1982.
G. Hölzer, M. Fritsch, M. Deutsch, J. Härtwig, and E. Förster. Kα₁,₂ and Kβ₁,₃ x-ray emission lines of the 3d transition metals. Physical Review A, 56:4554–4568, 1997.
L. Kissel and R. H. Pratt. Corrections to tabulated anomalous-scattering factors. Acta Crystallographica Section A, 46:170–175, 1990.
H. P. Klug and L. E. Alexander. X-ray Diffraction Procedures for Polycrystalline and Amorphous Materials. Wiley, New York, 2nd edition, 1974.
I. Křivý and B. Gruber. A unified algorithm for determining the reduced (Niggli) cell. Acta Crystallographica Section A, 32:297–298, 1976. doi:10.1107/S0567739476000636.
A. C. Larson and R. B. Von Dreele. General structure analysis system (GSAS). Technical Report LAUR 86-748, Los Alamos National Laboratory, 2004.
A. Le Bail, H. Duroy, and J. L. Fourquet. Ab-initio structure determination of LiSbWO₆ by x-ray powder diffraction. Materials Research Bulletin, 23:447–452, 1988.
Y. Le Page. The derivation of the axes of the conventional unit cell from the dimensions of the buerger-reduced cell. Journal of Applied Crystallography, 15:255–259, 1982. doi:10.1107/S0021889882011959.
D. Louër and M. Louër. Méthode d'essais et erreurs pour l'indexation automatique des diagrammes de poudre. Journal of Applied Crystallography, 5:271–275, 1972. doi:10.1107/S0021889872009483.
M. C. Lovell. Seasonal adjustment of economic time series and multiple regression analysis. Journal of the American Statistical Association, 58:993–1010, 1963.
A. March. Mathematische Theorie der Regelung nach der Korngestalt bei affiner Deformation. Zeitschrift für Kristallographie, 81:285–297, 1932.
L. B. McCusker, R. B. Von Dreele, D. E. Cox, D. Louër, and P. Scardi. Rietveld refinement guidelines. Journal of Applied Crystallography, 32:36–50, 1999. doi:10.1107/S0021889898009856.
W. H. McMaster, N. Kerr Del Grande, J. H. Mallett, and J. H. Hubbell. Compilation of x-ray cross sections. Technical Report UCRL-50174 Sec. II Rev. 1, Lawrence Radiation Laboratory, 1969.
A. D. Mighell and A. Santoro. Geometrical ambiguities in the indexing of powder patterns. Journal of Applied Crystallography, 8:372–374, 1975. doi:10.1107/S0021889875010801.
J. Nocedal and S. J. Wright. Numerical Optimization. Springer, New York, 2nd edition, 2006.
R. Oishi-Tomiyasu. Reversed de Wolff figure of merit and its application to powder indexing. Journal of Applied Crystallography, 46:1277–1282, 2013. doi:10.1107/S0021889813019833.
R. Oishi-Tomiyasu. Robust powder auto-indexing using many peaks. Journal of Applied Crystallography, 47:593–598, 2014. doi:10.1107/S1600576714000922.
G. S. Pawley. Unit-cell refinement from powder diffraction scans. Journal of Applied Crystallography, 14:357–361, 1981.
W. J. A. M. Peterse and J. H. Palm. The anisotropic temperature factor of atoms in special positions. Acta Crystallographica, 20:147–150, 1966.
W. Pitschke, H. Hermann, and N. Mattern. The influence of surface roughness on diffracted x-ray intensities in Bragg–Brentano geometry and its effect on the structure determination by means of Rietveld analysis. Powder Diffraction, 8:74–83, 1993.
E. Polak. Computational Methods in Optimization: A Unified Approach. Academic Press, New York, 1971.
E. Prince, editor. International Tables for Crystallography, Volume C: Mathematical, Physical and Chemical Tables. Kluwer Academic Publishers, Dordrecht, 2004.
C. R. Rao. Large sample tests of statistical hypotheses concerning several parameters with applications to problems of estimation. Mathematical Proceedings of the Cambridge Philosophical Society, 44:50–57, 1948.
H. M. Rietveld. A profile refinement method for nuclear and magnetic structures. Journal of Applied Crystallography, 2:65–71, 1969.
K. D. Rouse, M. J. Cooper, E. J. York, and A. Chakera. Absorption corrections for neutron diffraction. Acta Crystallographica Section A, 26:682–691, 1970.
C. G. Ryan, E. Clayton, W. L. Griffin, S. H. Sie, and D. R. Cousens. SNIP, a statistics-sensitive background treatment for the quantitative analysis of PIXE spectra in geoscience applications. Nuclear Instruments and Methods in Physics Research Section B, 34:396–402, 1988.
T. M. Sabine. Extinction in polycrystalline materials. Australian Journal of Physics, 38:507–518, 1985.
T. M. Sabine. A reconciliation of extinction theories. Acta Crystallographica Section A, 44:368–373, 1988.
T. M. Sabine, R. B. Von Dreele, and J.-E. Jørgensen. Extinction in time-of-flight neutron powder diffractometry. Acta Crystallographica Section A, 44:374–379, 1988.
G. Schwarz. Estimating the dimension of a model. Annals of Statistics, 6:461–464, 1978.
D. Schwarzenbach, S. C. Abrahams, H. D. Flack, W. Gonschorek, Th. Hahn, K. Huml, R. E. Marsh, E. Prince, B. E. Robertson, J. S. Rollett, and A. J. C. Wilson. Statistical descriptors in crystallography. Acta Crystallographica Section A, 45:63–75, 1989.
U. Shmueli, editor. International Tables for Crystallography, Volume B: Reciprocal Space. Kluwer Academic Publishers, Dordrecht, 2001.
G. S. Smith. Estimating the unit-cell volume from one line in a powder diffraction pattern. Journal of Applied Crystallography, 10:252–255, 1977. doi:10.1107/S0021889877013478.
G. S. Smith and R. L. Snyder. F_N: a criterion for rating powder diffraction patterns and evaluating the reliability of powder-pattern indexing. Journal of Applied Crystallography, 12:60–65, 1979. doi:10.1107/S002188987901178X.
P. W. Stephens. Phenomenological model of anisotropic peak broadening in powder diffraction. Journal of Applied Crystallography, 32:281–289, 1999.
G. W. Stinton and J. S. O. Evans. Parametric Rietveld refinement. Journal of Applied Crystallography, 40:87–95, 2007.
P. Suortti. Effects of porosity and surface roughness on the x-ray intensity reflected from a powder specimen. Journal of Applied Crystallography, 5:325–331, 1972.
J. C. Taylor and C. E. Matulis. Absorption contrast effects in the quantitative XRD analysis of powders by full multiphase profile refinement. Journal of Applied Crystallography, 24:14–17, 1991.
P. Thompson, D. E. Cox, and J. B. Hastings. Rietveld refinement of Debye–Scherrer synchrotron x-ray data from Al₂O₃. Journal of Applied Crystallography, 20:79–83, 1987.
B. H. Toby. R factors in Rietveld analysis: how good is good enough? Powder Diffraction, 21:67–70, 2006.
B. H. Toby. A simple solution to the Rietveld refinement recipe problem. Journal of Applied Crystallography, 57:175–180, 2024. doi:10.1107/S1600576723011032.
A. Togo, K. Shinohara, and I. Tanaka. Spglib: a software library for crystal symmetry search. Science and Technology of Advanced Materials: Methods, 4:2384822, 2024.
K. N. Trueblood, H.-B. Bürgi, H. Burzlaff, J. D. Dunitz, C. M. Gramaccioli, H. H. Schulz, U. Shmueli, and S. C. Abrahams. Atomic displacement parameter nomenclature. Acta Crystallographica Section A, 52:770–781, 1996.
J. W. Visser. A fully automatic program for finding the unit cell from powder data. Journal of Applied Crystallography, 2:89–95, 1969. doi:10.1107/S0021889869006649.
R. B. Von Dreele. Quantitative texture analysis by Rietveld refinement. Journal of Applied Crystallography, 30:517–525, 1997.
D. Waasmaier and A. Kirfel. New analytical scattering-factor functions for free atoms and ions. Acta Crystallographica Section A, 51:416–431, 1995.
J. Waser. Least-squares refinement with subsidiary conditions. Acta Crystallographica, 16:1091–1094, 1963.
D. Watkin. The control of difficult refinements. Acta Crystallographica Section A, 50:411–437, 1994.
J. A. C. Weideman. Computation of the complex error function. SIAM Journal on Numerical Analysis, 31:1497–1518, 1994.
P.-E. Werner. Trial-and-error computer methods for the indexing of unknown powder patterns. Zeitschrift für Kristallographie, 120:375–387, 1964. doi:10.1524/zkri.1964.120.16.375.
P.-E. Werner, L. Eriksson, and M. Westdahl. TREOR, a semi-exhaustive trial-and-error powder indexing program for all symmetries. Journal of Applied Crystallography, 18:367–370, 1985. doi:10.1107/S0021889885010512.
A. J. C. Wilson. Mathematical Theory of X-ray Powder Diffractometry. Philips Technical Library, Eindhoven, 1963.
Yue Wu. Rietx: api-first rietveld refinement of powder x-ray diffraction data. 2026. URL: https://github.com/yue-here/rietx.
M. R. Zaghloul and A. N. Ali. Algorithm 916: computing the Faddeyeva and Voigt functions. ACM Transactions on Mathematical Software, 38(2):15, 2011.
NIST. X-ray transition energies database, standard reference database 128. 2005. https://physics.nist.gov/PhysRefData/XrayTrans/.