teaching and education
XRDplayground: a Python-based educational tool for interactive learning of powder X-ray diffraction crystallography
aLaboratório Nacional de Luz Síncrotron, Centro Nacional de Pesquisa em Energia e Materiais, Rua Giuseppe M. Scolfaro, Campinas, Brazil
*Correspondence e-mail: flavia.estrada@lnls.br
One of the barriers to learning crystallography through the powder X-ray diffraction (PXRD) technique is the understanding and visualization of the XRDplayground, an open-source software developed in Python that can simultaneously simulate the and its PXRD pattern. It features a graphical user interface where all the structural parameters of the crystal, such as lattice parameters and atomic positions inside the are adjustable via sliders. The PXRD pattern is simulated by taking into consideration the X-ray energy and the crystallite size using Scherer's equation. XRDplayground is an educational tool to make PXRD crystallography more engaging and enhance learning and understanding of the concepts rather than mathematical treatment and/or superficial memorization.
and its effects on the diffraction pattern. To enhance learning through visualization, we presentKeywords: XRDplayground; powder X-ray diffraction; PXRD; simulation; XRD fundamentals; teaching.
1. Introduction
The powder X-ray diffraction (PXRD) technique is widely used to determine and understand the structure and symmetry of materials through both qualitative and quantitative analyses. These analyses involve interpreting a pattern on the basis of peak positions as a function of the scattering angle (2θ), peak intensities and peak profiles (Dinnebier & Billinge, 2008). Most of the time, beginners in this technique are only aware that the pattern is somehow related to the structure and symmetry of matter. Students often encounter difficulties in understanding the formal mathematical description of the Fourier transform and the abstract concept of even for single crystals. Moreover, the peak overlapping in PXRD further complicates the understanding of these concepts. This overlapping makes PXRD somewhat less tangible than single-crystal X-ray diffraction, which always depends on a specific direction under diffraction conditions.
Over the years, many different strategies, methodologies and tools have been developed to teach crystallography and PXRD (Flor et al., 2024), some of them dedicated to high school students (Schimpf et al., 2023
; Murray et al., 2024
). These include strategies (Gražulis et al., 2015
; Luft et al., 2010
; Pett, 2010
), benchtop single-crystal X-ray diffractometers (Giorgi & Berchadsky, 2022
), historical overviews (Mascarenhas, 2020
), symmetry and Bravais lattices (Graw & Stalke, 2022
; Hanson, 2010
; Nespolo & Souvignier, 2010
), puzzles (Schimpf et al., 2023
), motifs and lattices in a web-based tools (Bardella et al., 2017
), online educational materials for PXRD crystallography (Toby, 2010
; Kantardjieff, 2010
), macromolecular crystallography (Faust et al., 2008
, 2010
), and a collection of scholarly scripts dealing with the mathematics and physics of peak profile functions and intensities in PXRD (Dinnebier & Scardi, 2021
, 2023
). A review of tools, website links and equipment that can be used when teaching crystallography can be found in the supplementary information of From geology to biology: an interdisciplinary course in crystal growth presented by Arkhipov et al. (2022
). All these references are designed to perform specific tasks on specific platforms in specific areas of science.
XRDplayground, presented here, is an open-source software developed in Python, designed with a graphical user interface (GUI) to build and manipulate a and allow the observation of its PXRD pattern. As the visualization of the and its XRD pattern has become more prevalent and expected, XRDplayground serves as a valuable tool for educating beginners on the technique. The software capabilities extend beyond visualization, including sliders to control the lattice parameters, chemical composition, number of atoms and their respective positions (fractional coordinates x/a, y/b, z/c), crystallite size (using the isotropic Scherrer model), and the X-ray energy, the latter considering corrections due to effects.
The Python programming language has been widely used in scientific programming and plotting. Usually, Python tools for PXRD are associated with data treatment, such as GSAS-II (Toby & Von Dreele, 2013, 2014
; O'Donnell et al., 2018
) and SrRietveld (Tian et al., 2013
), or require reading crystal structures from CIFs, e.g. Dans_Diffraction (https://www.iucr.org/resources/other-directories/software/dans_diffraction). XRDplayground was created to teach PXRD in the multidisciplinary school Escola Ricardo Rodrigues de Luz Síncrotron (https://pages.cnpem.br/er2ls/) from the Brazilian Synchrotron Light Laboratory. The school has taken place every July since 2017 and is dedicated to Brazilian graduate and undergraduate students, post-docs, and young professionals. Students can come from any background (physics, chemistry, biology, soil, materials, environmental science and engineering). For such an audience, the main goal of XRDplayground is to show the different types of structures and the effect of the symmetry of the on PXRD without the necessity of an input file (users are free to build a fictitious or a real crystal model). It can be useful to the crystallographic community in teaching, education and training, enabling learners to interact and explore the possibilities of symmetries and their changes.
The software is introduced here, along with its boundary conditions and control parameters, which are accessible via sliders. We then present several concepts for discussion and teaching. These include multiplicity, lattice strain (macrostrain), lattice-type transformations for primitive (P), body-centered (I), one face-centered (A, B or C) and face-centered (F) lattices, and their consequences, such as and resonant diffraction. Many of the ideas introduced here can be adapted to any class focused on the theme of PXRD.
2. Installation requirements
The software is open source and can be downloaded for free from the CNPEM Repository on GitHub (https://github.com/cnpem/XRDplayground/). It is distributed under the Apache 2.0 License, which permits users to modify and share as needed. It requires Python to be installed on the machine along with some additional libraries listed below. It is highly recommended to create a virtual environment (e.g. using Conda) to run it. The configuration shown below was tested and worked for both Linux (using the Micromamba package manager from https://github.com/mamba-org/mamba) and Windows (using the Miniconda package manager from https://repo.anaconda.com/miniconda/) machines. The libraries used were downloaded from the conda-forge repository (https://conda-forge.org/). The dependencies used are shown in Table 1. An installation tutorial for Windows is provided in the supplementary information.
|
3. Graphical user interface
A screenshot of the GUI is shown in Fig. 1. The interface is simple and does not require any special computing knowledge, allowing users to systematically explore the relationship between a real-space structure and the corresponding PXRD pattern. It is divided into four groups: (A) a graph that displays the PXRD pattern; (B) a 3D drawing of the (C) a sliders and buttons to control lattice parameters, X-ray wavelength and crystal size; and (D) controls for the information concerning the position, type and number of atoms inside the unit cell.
![]() | Figure 1 Screenshot of XRDplayground. (A) Simulated XRD pattern (CsCl in black); (A1) freeze and unfreeze curves; (A2) show/hide hkl peaks. (B) Representation of the and (B1) show/hide elements of the (C) Controls for (C1) lattice parameters, (C2) energy and (C3) crystallite size sliders. (D) Controls for (D1) atom type, (D2) adding and removing atoms, and (D3)–(D4) positioning atoms in the unit cell. |
The controls for the diffraction pattern graph include zoom in and out; auto-scale; maximum intensity scale; and three options (red, blue and green) for freezing the pattern at the current slider and atom conditions, for θ versus intensity) for comparison with the simulation. For this purpose, controls for applying a scale factor to multiply the loaded data (or the frozen curves) are also available (A1). In the upper right corner (A2), there is a button that turns on and off an arrow showing the position of a peak in the diffraction pattern, chosen by its Miller indexes which, in turn, are controlled by the three edit boxes beside it. The on/off button also shows or hides the atomic planes corresponding to the Miller indexes in the 3D drawing of the (B). Parameters related to the extent of the simulation, such as the initial and final 2θ values, the 2θ step, and maximum h, k and l values for calculating the peaks, can be selected using the `settings' button, also located in the upper right corner (A2).
and for position. These buttons allow the user to compare different simulations. Another button allows loading of experimental data from a file (in the format 2The controls for the 3D drawing of the
(B1) include zoom in and out and three buttons that turn on and off the visualization of the faces, edges and atoms; the fourth button expands the visualization of the atoms to eight unit cells. Additionally, the projection of the can be rotated by clicking and dragging with the pointing device on the 3D drawing.At the bottom left of the window (C1), there are controls for the six parameters related to the lattice: a, b, c, α (the angle between the b and c vectors), β (angle between the a and c vectors) and γ (angle between the a and b vectors). When these parameters are changed – which can be done using sliders or by entering values in the edit boxes – both the XRD pattern and the are updated according to the new values. At the bottom center, there is a control for the X-ray beam energy (C2) – and equivalently the beam wavelength – which also updates the diffraction pattern, considering the change in the due to absorption effects. The last control in this section is the crystallite size (C3), which uses the isotropic Scherrer formula to change the All the sliders result in an interactive simulation of the cell and the XRD patterns.
At the bottom right (D), there is a control for the atoms within the x/a, y/b, z/c) = (0, 0, 0). The only controls for this atom are its color, which can be changed via the button next to its chemical symbol, and its size, which can be changed in the adjacent edit text box. At the top right of this window, there are two buttons that can add or remove atoms in the (D2). When an atom is added, a control box for it appears (D3) and, by default, the atom is placed at the center of the fractional position (0.5, 0.5, 0.5). Each atom has controls for its own chemical symbol, unique color and fractional position, which can be changed using sliders or by entering a value into the respective edit box. After another atom has been added, their controls will be stacked up to three atoms, and additional atoms will be placed in another tab, accessible via the tab selection on the left (D4).
At the top left of this window, there is, by default, an initial atom in an input box (D1) that depends on the loaded initial structure. The atom type can be changed by editing the text in the box, as long as the text matches a chemical symbol. This atom is also, by default, placed at the fractional coordinate (When the program is opened, it will randomly load the atom positions and lattice parameters of a real material taken from its pool of structures. There are, for now, 16 structures in this pool, which are listed in Appendix A. However, the user can change any of the parameters or add and remove atoms from the Some initialization options can be changed from the default file created when running the program for the first time.
3.1. Example
As a proof of concept for the software, an example data plot with a reference structure and the simulated XRD pattern from XRDplayground is shown in Fig. 2. The reference is BaTiO3 (PDF 04-002-3207), simulated in blue dots considering Cu Kα energy with a Caglioti function. The XRDplayground-simulated pattern is shown in black. A scale factor of 30 and particle size of 1000 Å were needed to achieve the agreement shown between the patterns. All structural and wavelength parameters used in XRDplayground are given in Table 2
. Sufficient agreement from the whole pattern is observed. The peaks beyond 100° for 2θ are high-hkl peaks that were not included in the XRDplayground simulation.
|
![]() | Figure 2 Plot of the simulated data from XRDplayground using the parameters from Table 2 ![]() |
4. Limitations of the software
As an interactive learning tool, the main idea of XRDplayground is to provide users with a novel way to visualize the effect of each parameter on the final PXRD pattern. Complex structures with many atoms in the and very large lattice parameters are always interesting to visualize and, often, to compare with some experimental patterns. XRDplayground calculates the PXRD pattern including the peak position, full width at half-maximum and intensity of each peak on the basis of a general equation only with free parameters as in the triclinic lattice P1 with the atoms in x, y, z. It can take a long time to calculate the scattering of crystals of very large lattice parameters up to high hkl indexes and update the diffraction pattern before the `callback' function of the slider is called again. In this sense, one of the main limitations is the ability to calculate all these intensities very quickly. To make the calculation faster, the maximum hkl indexes are limited, by default, to ±4, which allows for the calculation of more than 700 peaks. Additionally, there are limitations on the number of atoms in the by default, the limit is set to ten atoms, also due to the time-consuming procedure of calculating the intensity of the peaks. Another limitation concerns the energy/wavelength sliders. Every time they are changed, each hkl peak must be checked to see if it lies within the 2θ range. Moreover, the must be recalculated for each 2θ value, delaying the update of the diffraction pattern. Another limiting factor is the 2θ range; high angles imply high hkl values, and sometimes peaks such as hkl = 500, which by default are not calculated, do not appear in the diffraction pattern, even when their 2θ value is within the range. If the user wants to include higher-hkl peaks in the calculation of the PXRD pattern, the maximum values of h, k and l can be changed using the settings button located at A2 (see Fig. 1). At any time, the user can search for the 2θ position of any hkl peak in the main graph – even for hkl peaks not calculated due to the maximum value of ±4 – which can help decide if the limiting value should be adjusted.
Finally, we did not include the possibility to change the atomic displacement of the atoms, which is related to atomic motion and possible static displacive disorder. In other words, for the calculations, we consider that each atom remains at its crystallographic site.
The default values of XRDplayground can be changed by editing the text file it creates the first time it is run or by changing the default values within the configuration buttons that are placed in the program. As the maximum hkl, 2θ range and number of atoms increases, and the 2θ step decreases, the update in the PXRD pattern becomes slower due to the number of calculations. This causes the program to lose its original purpose, which is to fluidly visualize the variations in the diffraction pattern with changes in the unit cell.
5. Conclusions
XPDplayground illustrates various aspects of the influence of the lattice on the XRD pattern, serving as a versatile tool with interactive graphics that can enhance discussions and the teaching of diffraction concepts. Further, students can observe firsthand how lattice parameters, chemical composition, crystallite size and X-ray wavelength are embodied and convoluted in the PXRD pattern. This direct observation significantly improves the likelihood of students retaining the concepts of structure and symmetry, as they witness these elements change in real time with the movement of sliders. Consequently, this tool facilitates the learning of symmetry effects on diffraction patterns, enabling students to grasp these concepts before evaluating whether the model is reasonable.
APPENDIX A
Pool of structures
In Table 3, we list the pool of structures from which one is picked by chance and loaded when the program starts.
|
APPENDIX B
Future implementation
Here we list some desired future implementations for XRDplayground, which we believe will broaden its applicability in teaching the PXRD technique and enrich discussions on topics not covered in its current version. For the next version, we are planning to:
(1) Add a dropdown menu that allows users to load any structure from the pool of predefined structures, as well as user-defined saved structures.
(2) Add a third option to visualize the
which includes the atoms located at the edges of the cells (unchecked = normal checked = eight unit cells; tristate = include atoms on the opposite face).(3) Include the `site occupancy factor' as one of the atom properties.
(4) Allow erasing of specific atoms instead of just the last one.
(5) Allow easy selection of common wavelengths from bench sources, such as Cu Kα, Mo Kα and Ag Kα.
(6) Include
symmetry and all rules. This would make it possible to read files and use the sliders to modify the structure when applicable. It would also allow users to include many more atoms in a due to site multiplicity and work with more complex structures.(7) Include the option to control atomic displacement parameters to simulate structural disorder.
(8) Include the option to create or import small molecules and treat them as rigid bodies, enabling users to shift and/or rotate them to observe the effects of these transformations on the PXRD pattern.
(9) Allow users to explore the effects of varying parameters that describe the
as well as the theoretical shape of the crystallites, on the appearance of the simulated PXRD pattern.If there are any other implementations that the reader would like to see in the next version, please contact the authors.
Supporting information
Supporting information file. DOI: https://doi.org/10.1107/S1600576725001220/dv5023sup1.pdf
References
Arkhipov, S. G., Bekker, T. B., Gaydamaka, A. A., Likhacheva, A. Y., Losev, E. A. & Boldyreva, E. V. (2022). J. Appl. Cryst. 55, 1368–1376. Web of Science CrossRef CAS IUCr Journals Google Scholar
Bardella, F., Montes Rodrigues, A. & Leal Neto, R. M. (2017). J. Appl. Cryst. 50, 949–950. CrossRef CAS IUCr Journals Google Scholar
Flor, G. de la, Aroyo, M. I., Gimondi, I., Ward, S. C., Momma, K., Hanson, R. M. & Suescun, L. (2024). J. Appl. Cryst. 57, 1618–1639. CrossRef IUCr Journals Google Scholar
Dinnebier, R. & Scardi, P. (2021). J. Appl. Cryst. 54, 1811–1831. Web of Science CrossRef CAS IUCr Journals Google Scholar
Dinnebier, R. & Scardi, P. (2023). J. Appl. Cryst. 56, 834–853. Web of Science CrossRef CAS IUCr Journals Google Scholar
Dinnebier, R. E. & Billinge, S. J. (2008). Powder diffraction: theory and practice, pp. 1–19. Royal Society of Chemistry. Google Scholar
Faust, A., Panjikar, S., Mueller, U., Parthasarathy, V., Schmidt, A., Lamzin, V. S. & Weiss, M. S. (2008). J. Appl. Cryst. 41, 1161–1172. Web of Science CrossRef CAS IUCr Journals Google Scholar
Faust, A., Puehringer, S., Darowski, N., Panjikar, S., Diederichs, K., Mueller, U. & Weiss, M. S. (2010). J. Appl. Cryst. 43, 1230–1237. Web of Science CrossRef CAS IUCr Journals Google Scholar
Giorgi, M. & Berchadsky, Y. (2022). J. Appl. Cryst. 55, 149–153. Web of Science CrossRef CAS IUCr Journals Google Scholar
Graw, N. & Stalke, D. (2022). J. Appl. Cryst. 55, 144–148. CrossRef CAS IUCr Journals Google Scholar
Gražulis, S., Sarjeant, A. A., Moeck, P., Stone-Sundberg, J., Snyder, T. J., Kaminsky, W., Oliver, A. G., Stern, C. L., Dawe, L. N., Rychkov, D. A., Losev, E. A., Boldyreva, E. V., Tanski, J. M., Bernstein, J., Rabeh, W. M. & Kantardjieff, K. A. (2015). J. Appl. Cryst. 48, 1964–1975. Web of Science CrossRef IUCr Journals Google Scholar
Hanson, R. M. (2010). J. Appl. Cryst. 43, 1250–1260. Web of Science CrossRef CAS IUCr Journals Google Scholar
Harris, C. R., Millman, K. J., van der Walt, S. J., Gommers, R., Virtanen, P., Cournapeau, D., Wieser, E., Taylor, J., Berg, S., Smith, N. J., Kern, R., Picus, M., Hoyer, S., van Kerkwijk, M. H., Brett, M., Haldane, A., del Río, J. F., Wiebe, M., Peterson, P., Gérard-Marchant, P., Sheppard, K., Reddy, T., Weckesser, W., Abbasi, H., Gohlke, C. & Oliphant, T. E. (2020). Nature, 585, 357–362. Web of Science CrossRef CAS PubMed Google Scholar
Hunter, J. D. (2007). Comput. Sci. Eng. 9, 90–95. Web of Science CrossRef Google Scholar
Kantardjieff, K. (2010). J. Appl. Cryst. 43, 1276–1282. Web of Science CrossRef CAS IUCr Journals Google Scholar
Kriegner, D., Wintersberger, E. & Stangl, J. (2013). J. Appl. Cryst. 46, 1162–1170. Web of Science CrossRef CAS IUCr Journals Google Scholar
Luft, J. R., Furlani, N. M., NeMoyer, R. E., Penna, E. J., Wolfley, J. R., Snell, M. E., Potter, S. A. & Snell, E. H. (2010). J. Appl. Cryst. 43, 1189–1207. Web of Science CrossRef CAS IUCr Journals Google Scholar
Mascarenhas, Y. P. (2020). Rev. Bras. Ensino Fís. 42, e20190336. CrossRef Google Scholar
Murray, C., Maynard-Casely, H. E., Harrington, R., McCready, S., Sneddon, D. J., Thomas, L. & Warren, A. J. (2024). J. Appl. Cryst. 57, 181–186. Web of Science CrossRef CAS IUCr Journals Google Scholar
Nespolo, M. & Souvignier, B. (2010). J. Appl. Cryst. 43, 1144–1149. Web of Science CrossRef CAS IUCr Journals Google Scholar
O'Donnell, J. H., Von Dreele, R. B., Chan, M. K. Y. & Toby, B. H. (2018). J. Appl. Cryst. 51, 1244–1250. Web of Science CrossRef CAS IUCr Journals Google Scholar
Pett, V. B. (2010). J. Appl. Cryst. 43, 1139–1143. Web of Science CrossRef CAS IUCr Journals Google Scholar
Schimpf, C., Lachmann, J., Wetzel, M. H., Fischer, P. D. B., Leineweber, A. & Rafaja, D. (2023). J. Appl. Cryst. 56, 1544–1556. CrossRef CAS IUCr Journals Google Scholar
Tian, P., Zhou, W., Liu, J., Shang, Y., Farrow, C. L., Juhás, P. & Billinge, S. J. L. (2013). J. Appl. Cryst. 46, 255–258. Web of Science CrossRef CAS IUCr Journals Google Scholar
Toby, B. H. (2010). J. Appl. Cryst. 43, 1271–1275. CrossRef CAS IUCr Journals Google Scholar
Toby, B. H. & Von Dreele, R. B. (2013). J. Appl. Cryst. 46, 544–549. Web of Science CrossRef CAS IUCr Journals Google Scholar
Toby, B. H. & Von Dreele, R. B. (2014). Powder Diffr. 29, S2–S6. CrossRef CAS Google Scholar
This article is published by the International Union of Crystallography. Prior permission is not required to reproduce short quotations, tables and figures from this article, provided the original authors and source are cited. For more information, click here.