The tutorial 2nd

Contents

The tutorial 2nd#

Introduces the process for refining multi-phase systems.

coding#

1. Save your diffraction data to the root directory and rename the file to intensity.csv.

# import PyXplore package
from PyXplore import WPEM
import pandas as pd
██╗    ██╗██████╗ ███████╗███╗   ███╗
██║    ██║██╔══██╗██╔════╝████╗ ████║
██║ █╗ ██║██████╔╝█████╗  ██╔████╔██║
██║███╗██║██╔═══╝ ██╔══╝  ██║╚██╔╝██║
╚███╔███╔╝██║     ███████╗██║ ╚═╝ ██║
 ╚══╝╚══╝ ╚═╝     ╚══════╝╚═╝     ╚═╝                                                  

A Diffraction Refinement Software : WPEM
Bin Cao, Advanced Materials Thrust, Hong Kong University of Science and Technology (Guangzhou)
URL : https://github.com/Bin-Cao/WPEM
Executed on : 2025-07-22 11:11:54  | Have a great day.
====================================================================================================

2. Parse your diffraction data (, intensity) and perform background processing.

intensity_csv = pd.read_csv(r'intensity.csv',header=None )
var = WPEM.BackgroundFit(intensity_csv,lowAngleRange=22,poly_n=8,bac_split=8,bac_num=600)
../../_images/7680f47f49a9945e5fbc83739b94877a360767ec80cfeb6f5d5dadaec0c20a62.png ../../_images/350eacfe86d4933fdfbbf4cdaede6f5202c37847400afaa29fc6b266efe8ff9e.png ../../_images/75f1d073f3053cc85f0d230d73b75af79ff881f31ea9fc9796d091f4dfb4ea7c.png ../../_images/3f9788e3891be9e2c2a01f1802df05126c2975204c7b744dfcc710e71b151bb8.png
================================
<Figure size 640x480 with 0 Axes>

3. After running the code, a new folder named ConvertedDocuments will be created in the root directory. This folder contains the background information.

Copy the two important files — bac.csv and no_bac_intensity.csv — from ConvertedDocuments into the root directory, as they are required for the next steps.

4. After background subtraction, the next step is to parse the reference structure.

Save the reference .cif files in the root directory. For example, if your structures are Mn₂O₃ and RuO₂, place files named Mn2O3.cif and RuO2.cif in the root directory as the reference phases.

If you are unsure of the reference phases, you must first perform phase identification. For assistance, please visit our website: https://xqueryer.caobin.asia/

MnO_latt, AtomCoordinates,des = WPEM.CIFpreprocess(filepath='Mn2O3.cif',two_theta_range=(15,75))
the space group of input crystal is : I 21 3
cif file parse completed
atom locations claculated by parsed cif file
retrieval of all reciprocal vectors satisfying the diffraction geometry is done
extinction peaks are distinguished
There are 21 extinction peaks
Diffraction condition judgment end !
The input crystal system is: Cubic  |  The initial lattice constants : 9.41 9.41 9.41 90.0 90.0 90.0
RuO_latt, AtomCoordinates,des = WPEM.CIFpreprocess(filepath='RuO2.cif',two_theta_range=(15,75))
the space group of input crystal is : P 42/m n m
cif file parse completed
atom locations claculated by wyckoff site
retrieval of all reciprocal vectors satisfying the diffraction geometry is done
extinction peaks are distinguished
There are 5 extinction peaks
Diffraction condition judgment end !
The input crystal system is: Tetragonal  |  The initial lattice constants : 4.4968 4.4968 3.1049 90.0 90.0 90.0

5. After running the code, a new folder named output_xrd will be generated.

Inside this folder, find the file named xxxHKL.csv. Copy it to the root directory and rename it sequentially as peak0.csv, peak1.csv, and so on. These files will be used in the refinement step.

# The wavelength is set according to the actual light source
wavelength = [1.540593, 1.544414]
# The file name of non-background data (2theta-intensity data)
no_bac_intensity_file = "no_bac_intensity.csv" 
# The file name of raw/original data (2theta-intensity data)
original_file = "intensity.csv"  
# The file name of background data (2theta-intensity data)
bacground_file = "bac.csv"  


# Input the initial lattice constants {a, b, c, α, β, γ}, whose values need to be assumed at initialization.
Lattice_constants = [MnO_latt,RuO_latt]

# Execute the model

WPEM.XRDfit(
    wavelength, var, Lattice_constants,no_bac_intensity_file, original_file, bacground_file, 
    subset_number=11,low_bound=20,up_bound=70,bta = 0.85,iter_max = 5, asy_C = 0,InitializationEpoch=0, 
    )
Started at Tue Jul 22 11:12:11 2025 

Initialization
--------------------------------------------------------------------------------
Diffraction indexs have been obtained by WPEM
Diffraction indexs have been obtained by WPEM


The input crystal system is: Cubic  |  The initial lattice constants : 9.41 9.41 9.41 90.0 90.0 90.0
The input crystal system is: Tetragonal  |  The initial lattice constants : 4.4968 4.4968 3.1049 90.0 90.0 90.0
—————————— Initilize the parameters by WPEM ——————————
Parameter initialization has been completed 
  0%|                                                     | 0/5 [00:00<?, ?it/s]
WARNING:tensorflow:From /Users/jacob/miniconda3/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py:576: calling function (from tensorflow.python.eager.polymorphic_function.polymorphic_function) with experimental_relax_shapes is deprecated and will be removed in a future version.
Instructions for updating:
experimental_relax_shapes is deprecated, use reduce_retracing instead
WPEM 1-th iteration
[array([ 9.41064,  9.41064,  9.41064, 90.     , 90.     , 90.     ]), array([ 4.49679,  4.49679,  3.10478, 90.     , 90.     , 90.     ])]
 20%|█████████                                    | 1/5 [00:12<00:50, 12.59s/it]
Rp:5.261 | Rwp:6.716 | Rsquare:5.517
WARNING:tensorflow:From /Users/jacob/miniconda3/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py:576: calling function (from tensorflow.python.eager.polymorphic_function.polymorphic_function) with experimental_relax_shapes is deprecated and will be removed in a future version.
Instructions for updating:
experimental_relax_shapes is deprecated, use reduce_retracing instead
WPEM 2-th iteration
[array([ 9.4107,  9.4107,  9.4107, 90.    , 90.    , 90.    ]), array([ 4.49678,  4.49678,  3.10454, 90.     , 90.     , 90.     ])]
 40%|██████████████████                           | 2/5 [00:24<00:36, 12.27s/it]
Rp:5.112 | Rwp:6.474 | Rsquare:5.129
WARNING:tensorflow:From /Users/jacob/miniconda3/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py:576: calling function (from tensorflow.python.eager.polymorphic_function.polymorphic_function) with experimental_relax_shapes is deprecated and will be removed in a future version.
Instructions for updating:
experimental_relax_shapes is deprecated, use reduce_retracing instead
WPEM 3-th iteration
[array([ 9.41131,  9.41131,  9.41131, 90.     , 90.     , 90.     ]), array([ 4.49676,  4.49676,  3.10435, 90.     , 90.     , 90.     ])]
 60%|███████████████████████████                  | 3/5 [00:36<00:24, 12.12s/it]
Rp:5.021 | Rwp:6.332 | Rsquare:4.872
WARNING:tensorflow:From /Users/jacob/miniconda3/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py:576: calling function (from tensorflow.python.eager.polymorphic_function.polymorphic_function) with experimental_relax_shapes is deprecated and will be removed in a future version.
Instructions for updating:
experimental_relax_shapes is deprecated, use reduce_retracing instead
WPEM 4-th iteration
[array([ 9.41183,  9.41183,  9.41183, 90.     , 90.     , 90.     ]), array([ 4.49678,  4.49678,  3.10416, 90.     , 90.     , 90.     ])]
 80%|████████████████████████████████████         | 4/5 [00:48<00:12, 12.19s/it]
Rp:4.946 | Rwp:6.229 | Rsquare:4.704
WARNING:tensorflow:From /Users/jacob/miniconda3/lib/python3.9/site-packages/tensorflow/python/util/deprecation.py:576: calling function (from tensorflow.python.eager.polymorphic_function.polymorphic_function) with experimental_relax_shapes is deprecated and will be removed in a future version.
Instructions for updating:
experimental_relax_shapes is deprecated, use reduce_retracing instead
WPEM 5-th iteration
[array([ 9.41186,  9.41186,  9.41186, 90.     , 90.     , 90.     ]), array([ 4.49683,  4.49683,  3.10397, 90.     , 90.     , 90.     ])]
100%|█████████████████████████████████████████████| 5/5 [01:01<00:00, 12.21s/it]
100%|█████████████████████████████████████████████| 5/5 [01:01<00:00, 12.22s/it]
Rp:4.883 | Rwp:6.157 | Rsquare:4.598

After update the background :   Rp = 2.960 | Rwp = 5.339 | Rsquare = 3.372
../../_images/b5a72fd26a03dfd34e3bfd3e93d7b3596685ab907d7206dc7e705bfced3c28c6.png ../../_images/2349a84c851b39ab1defb4a22a91d64c6b6be3ca5ac1cb5e09339f5f1ab4f7da.png ../../_images/23d9c635b98fe46659fb8811232e58dee1e996ab779c61be4eb3f9a226d9ede1.png
Mass fraction without structure factor estimate in % : [79.88104018906242, 20.11895981093757] 
 Saved at the result documents
5-th iterations, reach the maximum number of iteration steps.
 Rp: 2.960
Rwp: 5.339 


WPEM program running time :  0 hours 1 minute  7 second  
('0 hours 1 minute  7 second  ',
 [array([ 9.41186,  9.41186,  9.41186, 90.     , 90.     , 90.     ]),
  array([ 4.49683,  4.49683,  3.10397, 90.     , 90.     , 90.     ])])
<Figure size 640x480 with 0 Axes>

See also

For demonstration purposes, the code uses iter_max = 5 to reduce computational cost. However, for practical applications, it is recommended to set iter_max to at least 50 for more reliable results.