# Parameters and Functions Documentation

## Module: WPEM
WPEM is the main call interface for diffraction refinement and analysis software, including various functions and subroutines for XRD analysis, background fitting, amorphous fitting, and more.

### Author
- **Bin CAO**  
  Email: [bincao4-c@my.cityu.edu.hk](mailto:bincao4-c@my.cityu.edu.hk)  
  GitHub: [https://github.com/Bin-Cao/PyWPEM](https://github.com/Bin-Cao/PyWPEM)

---

## Functions Overview

### 1. `WPEMsolver`
**From:** `EMBraggOpt.EMBraggSolver`  
Solver for XRD profile refinement and analysis.

### 2. `TwiceFilter`, `convert_file`, `read_xrdml`
**From:** `Background.BacDeduct`  
- **`TwiceFilter`**: Applies filtering techniques for background adjustments.  
- **`convert_file`**: Converts XRD data files to the required format.  
- **`read_xrdml`**: Reads `.xrdml` files for diffraction data.

### 3. `Amorphous_fitting`
**From:** `Amorphous.fitting.AmorphousFitting`  
Fitting routine for amorphous phase diffraction data.

### 4. `RadialDistribution`
**From:** `Amorphous.QuantitativeCalculation.AmorphousRDF`  
Calculates the radial distribution function (RDF) for amorphous materials.

### 5. `Decomposedpeaks`
**From:** `DecomposePlot.plot`  
Decomposes diffraction peaks for detailed analysis.

### 6. `XRD_profile`
**From:** `XRDSimulation.Simulation`  
Simulates XRD profiles for given crystal structures.

### 7. `profile`
**From:** `Extinction.XRDpre`  
Generates XRD profiles with customizable parameters.

### 8. `BgolearnOpt`
**From:** `StructureOpt.SiteOpt`  
Performs optimization for substitutional search and refinement.

### 9. `XPSsolver`
**From:** `WPEMXPS.XPSEM`  
Solver for X-ray Photoelectron Spectroscopy (XPS) data refinement.

### 10. `EXAFS`
**From:** `WPEMXAS.EXAFS`  
Performs Extended X-ray Absorption Fine Structure (EXAFS) analysis.

### 11. `CrystalGraph`
**From:** `GraphStructure.graph`  
Generates crystal graphs for structural analysis.

---

## Executable Information

### Execution Information
- **Software Name**: WPEM (Diffraction Refinement Software)
- **Author**: Bin Cao, Advanced Materials Thrust, Hong Kong University of Science and Technology (Guangzhou) ｜ Department of physics, City University of Hong Kong
- **URL**: [https://github.com/Bin-Cao/WPEM](https://github.com/Bin-Cao/WPEM)
- **Execution Time**: Dynamically generated at runtime.

---

## Key Functions

### `XRDfit`
#### Parameters:
- **`wavelength`**: List of diffraction wavelengths.  
- **`Var`**: Statistical variance of the background.  
- **`Lattice_constants`**: Initial lattice constants for refinement.  
- **`no_bac_intensity_file`**, **`original_file`**, **`bacground_file`**: Input data files.  
- **`two_theta_range`**: Range of diffraction angles to analyze.  
- **`density_list`**: Densities of crystals (optional).  
- **`MODEL`**: Mode of analysis (`'REFINEMENT'` or `'ANALYSIS'`).  

#### Returns:
- Refined lattice constants, R-factor values, and runtime details.

---

### `BackgroundFit`
#### Parameters:
- **`intensity_csv`**: Input XRD data file.  
- **`LFctg`, `lowAngleRange`, `bac_num`, `bac_split`**: Background filter parameters.  
- **`window_length`, `polyorder`, `mode`**: Polynomial fitting settings.  

#### Returns:
- Background distribution statistics.

---

### `FileTypeCovert`
#### Parameters:
- **`file_name`**: Source file name.  
- **`file_type`**: Format of the input file (`'dat'` or `'xrdml'`).  

#### Returns:
- Converted data.

---

### `Amorphous_fit`
#### Parameters:
- **`mix_component`**: Number of amorphous peaks.  
- **`amor_file`**: Amorphous data file.  
- **`ang_range`**: Angle range for refinement.  

#### Returns:
- Amorphous fit results.

---

### `CryGraph`
#### Parameters:
- **`folder_path`**: Path to save CIF files.  
- **`BK_boundary_condition`**: Whether to apply Bon Kaman boundary conditions.  

#### Returns:
- Crystal structure graphs.

---

### Additional Functions
- **`AmorphousRDFun`**: Computes radial distribution function for amorphous phases.  
- **`Plot_Components`**: Visualizes decomposed XRD components.  
- **`XRDSimulation`**: Simulates XRD patterns for given CIF files.  
- **`CIFpreprocess`**: Processes CIF files for XRD analysis.  
- **`SubstitutionalSearch`**: Conducts substitutional optimization searches.  
- **`XPSfit`**: Fits XPS data for electron binding energy analysis.  
- **`EXAFSfit`**: Performs EXAFS analysis for structural and bonding studies.