# Parameters

## Overview

This document provides comprehensive documentation for all functions and parameters available in PyXplore. The software implements the WPEM (Whole Pattern Expectation Maximization) algorithm and extends its capabilities to various X-ray characterization techniques.


---

## Core Functions

### 1. WPEMsolver
**Module**: `EMBraggOpt.EMBraggSolver`

Main solver for XRD profile refinement using the Expectation-Maximization algorithm. Performs whole-pattern fitting of powder diffraction data with probabilistic peak modeling.

**Key Features**:
- Iterative refinement of lattice parameters
- Automatic peak shape optimization
- Multi-phase analysis capability
- Statistical uncertainty estimation

---

### 2. Background Processing Functions
**Module**: `Background.BacDeduct`

#### TwiceFilter
Applies adaptive filtering for background estimation and subtraction.

**Algorithm**: Implements iterative polynomial fitting with outlier rejection to separate background from diffraction peaks.

#### convert_file
Converts various XRD data file formats to standardized CSV format.

**Supported Formats**: DAT, XRDML, and other common diffractometer output formats.

#### read_xrdml
Specialized parser for Panalytical XRDML format files.

**Output**: Extracts 2θ positions and intensity values with metadata preservation.

---

### 3. Amorphous_fitting
**Module**: `Amorphous.fitting.AmorphousFitting`

Fitting routine for extracting and quantifying amorphous phase contributions in diffraction patterns.

**Method**: Employs Gaussian mixture models to separate broad amorphous scattering from sharp crystalline peaks.

---

### 4. RadialDistribution
**Module**: `Amorphous.QuantitativeCalculation.AmorphousRDF`

Calculates the radial distribution function (RDF) and pair distribution function (PDF) for amorphous and nanocrystalline materials.

**Applications**:
- Local structure characterization
- Nearest-neighbor distance determination
- Coordination number analysis

---

### 5. Decomposedpeaks
**Module**: `DecomposePlot.plot`

Visualization tool for decomposed diffraction peak contributions.

**Output**: Generates publication-quality plots showing individual peak components and overall fit.

---

### 6. XRD_profile
**Module**: `XRDSimulation.Simulation`

Simulates theoretical XRD patterns from crystal structure information.

**Input**: CIF files or manual structure specification
**Output**: Calculated diffraction pattern with peak positions and intensities

---

### 7. profile
**Module**: `Extinction.XRDpre`

Advanced XRD profile generation with systematic absence handling.

**Features**:
- Space group symmetry consideration
- Extinction rule application
- Multiplicity factor calculation

---

### 8. BgolearnOpt
**Module**: `StructureOpt.SiteOpt`

Optimization algorithm for substitutional site determination in solid solutions.

**Method**: Bayesian optimization approach for exploring compositional space and site occupancy.

---

### 9. XPSsolver
**Module**: `WPEMXPS.XPSEM`

Expectation-Maximization solver adapted for X-ray photoelectron spectroscopy data.

**Capabilities**:
- Multi-peak deconvolution
- Chemical state identification
- Quantitative elemental analysis

---

### 10. EXAFS
**Module**: `WPEMXAS.EXAFS`

Extended X-ray Absorption Fine Structure analysis module.

**Analysis Pipeline**:
- Background removal and normalization
- Fourier transform to R-space
- Wavelet transform analysis
- Coordination shell fitting

---

### 11. CrystalGraph
**Module**: `GraphStructure.graph`

Generates graph-based representations of crystal structures for machine learning applications.

**Output**: Adjacency matrices and node features for crystal structure graphs

---

## Software Information

**Software Name**: PyXplore / WPEM
**Version**: Dynamic (check repository for latest release)
**License**: See repository for licensing information
**Citation**: Please cite relevant publications when using this software (see references.bib)

---

## Detailed Function Parameters

### XRDfit

Main function for XRD pattern refinement using the WPEM algorithm.

#### Input Parameters:

- **`wavelength`** (list of float): X-ray wavelengths in Ångströms. For Cu Kα radiation, use [1.54056, 1.54439] for Kα1 and Kα2 components.

- **`Var`** (float): Statistical variance of the background noise. Used for weighting in the EM algorithm. Typically estimated from background regions.

- **`Lattice_constants`** (list or array): Initial lattice parameters for refinement. Format depends on crystal system:
  - Cubic: [a]
  - Tetragonal: [a, c]
  - Orthorhombic: [a, b, c]
  - Hexagonal: [a, c]
  - Monoclinic: [a, b, c, β]
  - Triclinic: [a, b, c, α, β, γ]

- **`no_bac_intensity_file`** (str): Path to background-subtracted intensity data file (CSV format).

- **`original_file`** (str): Path to original experimental data file.

- **`background_file`** (str): Path to fitted background data file.

- **`two_theta_range`** (list): Angular range for analysis [2θ_min, 2θ_max] in degrees.

- **`density_list`** (list, optional): Crystal densities in g/cm³ for each phase. Used for quantitative phase analysis.

- **`MODEL`** (str): Analysis mode
  - `'REFINEMENT'`: Full parameter refinement
  - `'ANALYSIS'`: Fixed parameters, intensity analysis only

#### Returns:

Dictionary containing:
- Refined lattice constants with uncertainties
- R-factor (goodness-of-fit metric)
- Weighted profile R-factor (Rwp)
- Execution time and convergence information

---

### BackgroundFit

Automated background subtraction using adaptive filtering.

#### Input Parameters:

- **`intensity_csv`** (str): Path to input XRD data file containing 2θ and intensity columns.

- **`LFctg`** (float): Low-frequency cutoff for Fourier filtering. Controls the smoothness of background estimation.

- **`lowAngleRange`** (list): Angular range [2θ_min, 2θ_max] for low-angle background estimation.

- **`bac_num`** (int): Number of background points to automatically select.

- **`bac_split`** (int): Number of segments for piecewise background fitting.

- **`window_length`** (int): Window size for Savitzky-Golay filter (must be odd).

- **`polyorder`** (int): Polynomial order for Savitzky-Golay filter.

- **`mode`** (str): Filtering mode ('interp', 'nearest', 'mirror', etc.).

#### Returns:

Dictionary containing background statistics and file paths to generated background files.

---

### FileTypeConvert

Utility function for converting diffractometer data files to standardized format.

#### Input Parameters:

- **`file_name`** (str): Path to source data file.

- **`file_type`** (str): Input file format identifier
  - `'dat'`: Generic two-column ASCII format
  - `'xrdml'`: Panalytical XRDML format

#### Returns:

Pandas DataFrame with standardized columns (2θ, Intensity).

---

### Amorphous_fit

Fitting routine for amorphous phase quantification.

#### Input Parameters:

- **`mix_component`** (int): Number of Gaussian components for modeling amorphous hump(s). Typically 1-3.

- **`amor_file`** (str): Path to data file containing amorphous signal.

- **`ang_range`** (list): Angular range [2θ_min, 2θ_max] for amorphous fitting.

#### Returns:

Fitted parameters for each amorphous component (position, width, amplitude) and total amorphous fraction.

---

### CryGraph

Crystal structure graph generation for machine learning applications.

#### Input Parameters:

- **`folder_path`** (str): Directory path containing CIF files for processing.

- **`BK_boundary_condition`** (bool): Whether to apply Born-von Karman periodic boundary conditions for graph construction.

#### Returns:

Graph representations with node features (atomic properties) and edge features (bond information).

---

## Utility Functions

### AmorphousRDFun
Computes radial distribution function (RDF) from amorphous scattering data.

**Application**: Quantitative analysis of short-range order in amorphous materials.

### Plot_Components
Generates visualization of decomposed diffraction peak contributions.

**Output**: Multi-panel plots showing individual phase contributions and residuals.

### XRDSimulation
Simulates theoretical XRD patterns from crystal structure files.

**Input**: CIF files
**Output**: Calculated diffraction patterns with kinematic intensities

### CIFpreprocess
Parses and validates CIF files for subsequent analysis.

**Features**: Symmetry expansion, atomic position validation, space group verification.

### SubstitutionalSearch
Bayesian optimization for determining substitutional site occupancies in solid solutions.

**Method**: Explores compositional space to match experimental lattice parameters.

### XPSfit
Peak fitting for X-ray photoelectron spectroscopy data.

**Capabilities**: Multi-peak deconvolution with Shirley or Tougaard background subtraction.

### EXAFSfit
Extended X-ray absorption fine structure analysis.

**Analysis**: Coordination shell fitting, bond distance determination, Debye-Waller factor extraction.

