coflandscaper.PXRD¶
- class coflandscaper.PXRD(wavelength='CuKa', two_theta_range=(1.5, 60.0))[source]¶
Simulate PXRD patterns from optimized CIFs and create stacked plots.
Default workflow:
- Read CIFs from
{cof_name}/4_{cof_name}_optimization/{serr|incl} (or
dft_{serr|incl}whendft=True).
- Read CIFs from
- Write
.xyfiles under {cof_name}/5_{cof_name}_analysis/pxrd_xy(orpxrd_xy_dftwhendft=True).
- Write
Write plots under
{cof_name}/5_{cof_name}_analysis.
Methods
Extract simulated peak tables from PXRD .xy files.
Plot stacked simulated PXRD patterns for one or both modes.
Plot one experimental PXRD pattern against each simulated pattern.
Plot all .xy files in one stacked figure and save it.
Simulate PXRD from all CIF files in a folder and save .xy files.
Generate simulated .xy files for one or both stacking modes.
- extract_peaks(cof_name, mode='both', dft=False, xy_folder=None, output_folder=None, max_peaks=10, min_relative_intensity=1.0, print_peaks=False, save_csv=True)[source]¶
Extract simulated peak tables from PXRD .xy files.
- Parameters:
cof_name (str) – COF name used for default path construction.
mode (str) – Mode selector. Allowed values are “incl”, “serr”, or “both”. Defaults to “both”.
dft (bool) – If True, use pxrd_xy_dft and pxrd_peaks_dft folders. Defaults to False.
xy_folder (str | Path | None) – Optional explicit XY folder. For mode=”both”, this is treated as a parent folder with per-mode subfolders. Defaults to None.
output_folder (str | Path | None) – Optional explicit output folder. For mode=”both”, this is treated as a parent folder with per-mode subfolders. Defaults to None.
max_peaks (int) – Maximum number of peaks to retain per structure.
min_relative_intensity (float) – Minimum relative intensity threshold.
print_peaks (bool) – If True, print a grouped summary per structure. Defaults to False.
save_csv (bool) – If True, write pxrd_peaks.csv to disk.
- Returns:
- structure, rank,
two_theta_deg, relative_intensity.
- Return type:
Mapping of mode to DataFrame with columns
- Raises:
FileNotFoundError – If a required XY folder is missing or empty.
- plot_sim(cof_name, mode='both', dft=False, xy_folder=None, output_folder=None, xlim=(1.5, 60.0), show=True, save=True)[source]¶
Plot stacked simulated PXRD patterns for one or both modes.
- Parameters:
cof_name (str) – COF name used for default path construction.
mode (str) – Mode selector. Allowed values are “incl”, “serr”, or “both”. Defaults to “both”.
dft (bool) – If True, default XY folders are read from dft_{mode}. Defaults to False.
xy_folder (str | Path | None) – Optional explicit XY folder. For mode=”both”, this is treated as a parent folder with per-mode subfolders. Defaults to None.
output_folder (str | Path | None) – Optional explicit output folder for plot image(s). Defaults to None (uses {cof_name}/5_{cof_name}_analysis).
xlim (tuple[float, float]) – X-axis bounds as (min_2theta, max_2theta) in degrees. Defaults to (1.5, 60.0).
show (bool) – If True, display generated plot(s) in the notebook/session. Defaults to True.
save (bool) – If True, write figure(s) to disk. Defaults to True.
- Returns:
Mapping of mode to output plot path.
- Return type:
Notes
Output files are named {cof_name}_sim_{mode}.png.
- plot_sim_vs_exp(cof_name, mode, dft=False, exp_xy_file=None, simulated_xy_folder=None, output_folder=None, xlim=(1.5, 60.0), show=True, save=True)[source]¶
Plot one experimental PXRD pattern against each simulated pattern.
- Parameters:
cof_name (str) – COF name used for default path construction.
mode (str) – Mode selector. Allowed values are “incl”, “serr”, or “both”; selects simulated folder(s).
dft (bool) – If True, default simulated folder uses pxrd_xy_dft. Defaults to False.
exp_xy_file (str | Path | None) – Path to experimental .xy file. If None, searches the ‘experimental_pxrd’ folder for exactly one .xy file. If multiple files exist, you must specify the path explicitly. To customize the label displayed in the plot, rename the .xy file. Defaults to None.
simulated_xy_folder (str | Path | None) – Folder containing simulated .xy files. If None, defaults to {cof_name}/5_{cof_name}_analysis/pxrd_xy/{mode} or pxrd_xy_dft/{mode} when dft=True. Defaults to None.
output_folder (str | Path | None) – Optional folder for the output image. Defaults to None (uses {cof_name}/5_{cof_name}_analysis).
xlim (tuple[float, float]) – X-axis bounds as (min_2theta, max_2theta) in degrees. Defaults to (1.5, 60.0).
show (bool) – If True, display the figure. Defaults to True.
save (bool) – If True, write the figure to disk. Defaults to True.
- Returns:
Output image path as a string.
- Return type:
- plot_xy(xy_folder, output_path, xlim=(1.5, 60.0), show=True, save=True)[source]¶
Plot all .xy files in one stacked figure and save it.
- Parameters:
xy_folder (str | Path) – Folder containing simulated .xy files.
xlim (tuple[float, float]) – X-axis bounds as (min_2theta, max_2theta) in degrees. Defaults to (1.5, 60.0).
show (bool) – If True, display the plot in the active notebook/session. Defaults to True.
save (bool) – If True, write the figure to output_path. Defaults to True.
- Returns:
Output image path as a string.
- Return type:
Notes
Each subplot is labeled with its CIF stem in the top-right corner.
- produce_xy(input_folder, output_folder=None)[source]¶
Simulate PXRD from all CIF files in a folder and save .xy files.
- run(cof_name, mode='both', dft=False, input_folder=None, output_folder=None)[source]¶
Generate simulated .xy files for one or both stacking modes.
- Parameters:
cof_name (str) – COF name used for default path construction.
mode (str) – Mode selector. Allowed values are “incl”, “serr”, or “both”. Defaults to “both”.
dft (bool) – If True, default input folders use dft_{mode}. Defaults to False.
input_folder (str | Path | None) – Optional explicit input folder. For mode=”both”, this is treated as a parent folder and per-mode subfolders are used. Defaults to None.
output_folder (str | Path | None) – Optional explicit output folder. Defaults to {cof_name}/5_{cof_name}_analysis/pxrd_xy or pxrd_xy_dft. For mode=”both”, this is treated as a parent folder and per-mode subfolders are used. Defaults to None.
- Returns:
Mapping of mode to generated XY folder path.
- Return type:
Notes
mode=’both’ writes into {output_root}/serr and {output_root}/incl.
mode=’incl’ or mode=’serr’ writes directly into output_folder.