模块一:代码与应用
背景知识、安装环境、获取数据库、构建理论峰库、第一次代码匹配和 Jupyter API。
点击展开阅读模块一
Module 1: Code & Application
Background, environment setup, database download, theoretical peak database build, first code search, and Jupyter API.
Click to expand Module 1
模块一:代码与应用
背景知识、安装环境、获取数据库、构建理论峰库、第一次代码匹配和 Jupyter API。
点击展开阅读模块一Module 1: Code & Application
Background, environment setup, database download, theoretical peak database build, first code search, and Jupyter API.
Click to expand Module 11. 概览
XMatcher 的推荐工作流有三个阶段。最快方式是直接从 GitHub Releases 下载已经构建好的 MP500_xrd_database.pkl;如果你需要修改构建参数,也可以下载 MP500.db 后自行构建。
优先从 GitHub Releases 下载 MP500_xrd_database.pkl。它是检索阶段直接读取的理论峰数据库。
如果只下载了 MP500.db,运行 build_database_parallel.py 把它转换成 MP500_xrd_database.pkl。
用 XRDRetriever 读取 MP500_xrd_database.pkl,再输入实验谱进行匹配。
检索阶段只读取 MP500_xrd_database.pkl。不要把原始 MP500.db 直接传给 XRDRetriever。
1. Overview
XMatcher has a three-stage recommended workflow. The fastest path is to download the prebuilt MP500_xrd_database.pkl from GitHub Releases. If you need custom build parameters, download MP500.db and build the peak database yourself.
Prefer downloading MP500_xrd_database.pkl from GitHub Releases. It is the theoretical peak database consumed directly by retrieval.
If you downloaded only MP500.db, run build_database_parallel.py to convert it into MP500_xrd_database.pkl.
Use XRDRetriever to load MP500_xrd_database.pkl, then match experimental patterns.
The retrieval stage reads only MP500_xrd_database.pkl. Do not pass the raw MP500.db directly to XRDRetriever.
2. 背景知识:先理解 XRD 识别在做什么
粉末 XRD 物相识别的核心问题是:实验谱图中的峰位和峰强,是否能由某个晶体结构的理论衍射峰解释。XMatcher 把数据库中的晶体结构预先转换为理论峰特征,然后把实验谱中最有代表性的峰与数据库特征进行比较。
来自仪器测量,横轴通常是 2θ,纵轴是强度。实验谱可能包含背景、噪声、峰位偏移和多相叠加。
由晶体结构和 X 射线波长计算得到。理论峰告诉我们某个结构应该在哪些 2θ 位置出现衍射峰。
软件比较实验峰和理论峰的峰位差、相对强度、匹配数量和整体平移,得到候选物相排序。
自动识别只用部分强峰做快速检索;最终判断应查看完整理论峰是否与实验谱整体一致。
几个必须认识的概念
| 概念 | 含义 | 在软件中的表现 |
|---|---|---|
| 2θ | XRD 图谱的横坐标,表示衍射角。 | 所有图谱、峰位、容差和范围控制都以 2θ 为单位。 |
| 背景 | 样品、仪器或散射造成的缓慢变化强度。 | 主匹配图和 PDF 模块会显示去背底后的实验曲线,便于观察峰。 |
| 寻峰 | 从连续实验谱中找到局部峰。 | 最小峰高、最小显著性、峰数量会影响进入匹配的实验峰。 |
| 峰位偏移 | 样品高度、仪器校准等原因造成理论峰和实验峰整体错开。 | max_shift 和 shift_step 控制软件允许搜索的整体平移。 |
| 多相样品 | 实验谱可能由多个晶体相叠加。 | PDF 模块可上传最多五个 CIF,并按含量计算加权混合谱。 |
2. Background: What XRD Identification Means
Powder XRD phase identification asks whether the peak positions and intensities in an experimental pattern can be explained by the theoretical diffraction peaks of a crystal structure. XMatcher precomputes theoretical peak features from database structures, then compares representative experimental peaks against those features.
Measured by the instrument. It may contain background, noise, peak shifts, and overlapping phases.
Calculated from a crystal structure and X-ray wavelength. They indicate where diffraction peaks should appear.
The software compares peak positions, relative intensities, matched-peak counts, and global shifts to rank candidates.
Automatic identification uses selected strong peaks for speed. Final judgement should inspect the full theoretical peak set.
Essential Concepts
| Concept | Meaning | In the software |
|---|---|---|
| 2θ | The horizontal axis of an XRD pattern. | Plot ranges, peak positions, tolerances, and shifts all use 2θ. |
| Background | Slowly varying intensity from sample or instrument effects. | The matching and PDF plots display background-removed experimental curves. |
| Peak detection | Finding local maxima from a continuous experimental pattern. | Minimum height, prominence, and peak count decide which peaks enter matching. |
| Peak shift | Global mismatch from sample displacement or calibration. | max_shift and shift_step control the allowed global correction. |
| Multiphase sample | A pattern may contain several crystal phases. | The PDF module accepts up to five CIF files and computes weighted mixtures. |
3. 安装环境
建议使用 Python 3.9 或更高版本,并创建一个独立环境。
git clone https://github.com/Bin-Cao/XMatcher.git
cd XMatcher
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
如果你要运行 notebook、测试或代码检查:
pip install -r requirements-dev.txt
pytest
3. Install The Environment
Use Python 3.9 or newer and create an isolated environment.
git clone https://github.com/Bin-Cao/XMatcher.git
cd XMatcher
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .
For notebooks, tests, and lint tooling:
pip install -r requirements-dev.txt
pytest
4. 从 Releases 下载数据库
打开项目 GitHub Releases 页面。现在有两种下载方式:
MP500_xrd_database.pkl:推荐下载。它是已经构建好的 XMatcher 理论峰数据库,可以直接用于检索。MP500.db:原始 ASE 晶体结构数据库。只有当你想自己重新构建、修改峰数或 2θ 范围等构建参数时才需要下载。
如果你选择直接下载 MP500_xrd_database.pkl,把它放到项目根目录即可:
XMatcher/
MP500_xrd_database.pkl
exp_data/
XMatcher/
XRDRetriever(database_path="MP500_xrd_database.pkl")。
MP500.db 传给检索器: XRDRetriever(database_path=...) 需要的是 MP500_xrd_database.pkl。MP500.db 只能作为构建输入。
4. Download Databases From Releases
Open the project's GitHub Releases page. There are now two download paths:
MP500_xrd_database.pkl: recommended. This is the prebuilt XMatcher theoretical peak database and can be used directly for retrieval.MP500.db: the raw ASE crystal structure database. Download it only if you want to rebuild the peak database yourself or change build parameters such as peak count or 2θ range.
If you download MP500_xrd_database.pkl directly, place it in the project root:
XMatcher/
MP500_xrd_database.pkl
exp_data/
XMatcher/
XRDRetriever(database_path="MP500_xrd_database.pkl").
MP500.db to the retriever: XRDRetriever(database_path=...) expects MP500_xrd_database.pkl. MP500.db is only a build input.
5. 构建 XMatcher 理论峰数据库
build_database_parallel.py 的作用是读取 MP500.db 中的晶体结构,调用 pymatgen 计算每个结构的理论 XRD 图谱,提取最强峰,并保存成 XMatcher 检索用的特征数据库。
小规模测试构建
python build_database_parallel.py \
--db-path MP500.db \
--output MP500_xrd_database.pkl \
--workers 4 \
--max-entries 500 \
--batch-size 200 \
--n-peaks 30 \
--two-theta-min 10 \
--two-theta-max 90
完整构建
python build_database_parallel.py \
--db-path MP500.db \
--output MP500_xrd_database.pkl \
--workers 8 \
--batch-size 1000 \
--save-interval 1000 \
--n-peaks 30 \
--two-theta-min 10 \
--two-theta-max 90
构建完成后,项目目录里会出现 MP500_xrd_database.pkl。检索代码必须读取这个输出文件:
retriever = XRDRetriever(database_path="MP500_xrd_database.pkl")
--max-entries 500 验证环境和速度,再移除该参数构建全量库。
5. Build The XMatcher Theoretical Peak Database
build_database_parallel.py reads crystal structures from MP500.db, uses pymatgen to calculate theoretical XRD patterns, extracts the strongest peaks, and saves the searchable feature database used by XMatcher.
Small Test Build
python build_database_parallel.py \
--db-path MP500.db \
--output MP500_xrd_database.pkl \
--workers 4 \
--max-entries 500 \
--batch-size 200 \
--n-peaks 30 \
--two-theta-min 10 \
--two-theta-max 90
Full Build
python build_database_parallel.py \
--db-path MP500.db \
--output MP500_xrd_database.pkl \
--workers 8 \
--batch-size 1000 \
--save-interval 1000 \
--n-peaks 30 \
--two-theta-min 10 \
--two-theta-max 90
After the build finishes, MP500_xrd_database.pkl will appear in the project directory. Retrieval must read this output file:
retriever = XRDRetriever(database_path="MP500_xrd_database.pkl")
--max-entries 500 to verify the environment and speed, then remove it for a full build.
6. 运行第一次匹配
下面的脚本会读取示例实验数据,检测峰,然后在构建好的 MP500_xrd_database.pkl 里检索最相近的结构。
from XMatcher import XRDRetriever
retriever = XRDRetriever(
database_path="MP500_xrd_database.pkl",
n_peaks=20,
position_tolerance=0.2,
scoring_method="hybrid",
)
results = retriever.retrieve_from_file(
"exp_data/BTc.csv",
elements=["B", "Tc"],
element_filter_mode="exact",
top_n=10,
)
retriever.print_results(results)
best = results[0]
print(best["formula"], best["score"], best["estimated_shift"])
print(best["peak_matches"][:3])
保存为 quick_start.py 后运行:
python quick_start.py
6. Run The First Search
The script below reads an example experimental pattern, detects peaks, and retrieves the closest structures from the built MP500_xrd_database.pkl.
from XMatcher import XRDRetriever
retriever = XRDRetriever(
database_path="MP500_xrd_database.pkl",
n_peaks=20,
position_tolerance=0.2,
scoring_method="hybrid",
)
results = retriever.retrieve_from_file(
"exp_data/BTc.csv",
elements=["B", "Tc"],
element_filter_mode="exact",
top_n=10,
)
retriever.print_results(results)
best = results[0]
print(best["formula"], best["score"], best["estimated_shift"])
print(best["peak_matches"][:3])
Save it as quick_start.py and run:
python quick_start.py
7. Jupyter API 说明
如果你希望在 notebook 里逐步导入实验 XRD、调整寻峰参数、执行全库检索并查看匹配峰对,请打开根目录下的 API 示例:
XMatcher_Jupyter_API_Guide_CN_EN.ipynb
这个 notebook 默认使用 MP500_xrd_database.pkl,并把 QUERY_ELEMENTS = None 作为全库检索设置。你可以直接修改实验数据路径、峰检测参数和匹配参数。
XMatcher_Jupyter_API_Guide_CN_EN.ipynb
7. Jupyter API Guide
For a step-by-step notebook workflow covering experimental XRD import, peak-detection tuning, full-database retrieval, and peak-match inspection, open the API example in the project root:
XMatcher_Jupyter_API_Guide_CN_EN.ipynb
The notebook uses MP500_xrd_database.pkl by default and sets QUERY_ELEMENTS = None for full-database retrieval. You can edit the experimental data path, peak-detection parameters, and matching parameters directly.
XMatcher_Jupyter_API_Guide_CN_EN.ipynb
模块二:App 使用
图形界面完整操作手册:上传实验谱、自动识别、候选判断、绘图编辑、PDF 全峰对比和结果导出。
点击展开阅读模块二
Module 2: App Usage
Complete graphical interface manual: upload patterns, identify phases, judge candidates, edit plots, compare PDF peaks, and export results.
Click to expand Module 2
模块二:App 使用
图形界面完整操作手册:上传实验谱、自动识别、候选判断、绘图编辑、PDF 全峰对比和结果导出。
点击展开阅读模块二Module 2: App Usage
Complete graphical interface manual: upload patterns, identify phases, judge candidates, edit plots, compare PDF peaks, and export results.
Click to expand Module 21. 本地 App 界面完整说明
XMatcher_Local_UI.html 是面向日常使用的软件界面。它把上传实验谱、寻峰、自动识别、候选物相查看、图像编辑、PDF 全峰对比和结果导出集中在一个页面中。初学者推荐先用 App 界面完成一次完整流程,再学习 Jupyter API。
1.1 打开软件前的准备
- 确认数据库文件存在 项目根目录需要有
MP500_xrd_database.pkl。这是自动识别使用的理论峰特征数据库。 - 下载 App 版本 如果你下载的是正式封装 App,直接打开 App 即可使用,不需要手动启动本地服务。App 会自动连接内置本地服务。
- 源码/HTML 版本 只有在直接打开
XMatcher_Local_UI.html进行开发或本地测试时,才需要手动启动 Python API:
终端保持打开,页面顶部显示 API 已连接后即可使用。python xmatcher_local_api.py --database MP500_xrd_database.pkl - 准备实验 XRD 最稳妥格式是两列数值:第一列
2theta,第二列intensity。支持.csv、.txt、.xy、.dat、简单.json和部分.xrdml/.xml。
1.2 界面区域总览
| 区域 | 用途 | 初学者怎么用 |
|---|---|---|
| 顶部栏 | 显示软件版本、语言切换、下载地址、说明手册和 GitHub issue 入口。 | 如果界面语言不合适,直接点击 EN/CN/JA/KO 一键切换。 |
| 左侧控制面板 | 设置本地服务、上传实验谱、选择元素过滤、调整寻峰和匹配参数。 | 第一次使用只需要上传文件,元素不确定时留空,然后点击自动识别。 |
| 顶部指标条 | 显示输入点数、检测到的实验峰、扫描候选数、最佳分数和当前物相。 | 用于快速判断计算是否真的运行,以及是否返回了候选结果。 |
| 实验谱与理论峰对比 | 显示去背底后的实验谱、检测峰和当前候选的理论峰。 | 鼠标悬停查看数值;框选局部区域可放大;点击恢复全图重置视图。 |
| 候选物相 | 列出候选公式、MP ID、分数、覆盖率、匹配峰数、平移量和空间群。 | 点击不同行,图中理论峰会同步切换。MP ID 可跳转到 Materials Project。 |
| PDF 全峰对比 | 上传实验 XRD 和最多五个 CIF,计算完整理论峰和多相加权混合谱。 | 自动识别后,用这个模块做最终确认。它比候选图中的部分峰标记更完整。 |
| 引用与页脚 | 提供论文引用、BibTeX、一键复制、软件下载和问题反馈链接。 | 论文或报告中使用软件结果时,复制引用信息即可。 |
1.3 第一次自动识别:推荐操作顺序
- 上传实验谱 在“上传 XRD”中选择文件。选择后界面会显示文件已上传,并在主图中显示实验谱。
- 选择检索范围 如果完全不知道元素组成,元素过滤留空。如果知道样品只包含某些元素,例如
Ba,Ti,O,建议填写以减少误匹配。 - 使用默认寻峰参数 初学者先不要急着改参数。默认值适合多数常规粉末谱图。
- 点击自动识别 按钮会出现转圈图标,表示本地 API 正在计算。全库检索可能需要等待。
- 查看候选表 默认返回 3 个候选。优先看分数、匹配峰数、实验覆盖率和整体平移,而不是只看排名。
- 点击候选行 每点击一个候选,主图理论峰和匹配峰表都会更新。比较峰位是否整体对齐。
- 进入 PDF 全峰对比 候选图中的理论峰标记不是全部衍射峰。最终确认应下载/准备 CIF,与实验谱一起在 PDF 模块中比较。
1.4 左侧参数怎么理解
| 参数 | 作用 | 什么时候调整 |
|---|---|---|
| 元素过滤 | 限制数据库候选范围。 | 已知样品元素时填写;不确定时留空做全库检索。 |
| 过滤模式 contains | 候选中只要包含指定元素即可。 | 怀疑有掺杂、杂质、额外元素时使用。 |
| 过滤模式 exact | 候选元素集合必须和输入元素一致。 | 样品组成明确、想强约束搜索时使用。 |
| 候选数 | 控制返回多少个识别结果。 | 默认 3 个。想人工比较更多可能性时可增加。 |
| 最小峰高 | 过滤太弱的峰。 | 噪声峰太多时增大;弱峰漏检时减小。 |
| 最小显著性 | 要求峰相对周围背景足够突出。 | 背景起伏明显或噪声多时增大。 |
| 最小峰距 | 两个峰之间的最小 2θ 间距。 | 峰被重复检测时增大;密集峰被合并时减小。 |
| 峰数量 | 参与匹配的最强实验峰数量。 | 如果匹配不上,软件会建议减小该值;多相复杂谱可适当增加。 |
| 平滑窗口 | 降低噪声,帮助寻峰和显示。 | 噪声大时增大;峰很窄时不要过大。 |
| 背景窗口 | 估计并扣除缓慢变化背景。 | 背景很强时适当调大;低背景数据保持默认即可。 |
| 峰位容差 | 允许实验峰和理论峰之间的 2θ 误差。 | 仪器校准或样品位移较明显时可从 0.2 增至 0.3-0.5。 |
| 最大平移 / 平移步长 | 搜索整体峰位偏移。 | 峰整体错开时增大最大平移;想更精细时减小步长,但会变慢。 |
1.5 主图的图像设置、局部放大和导出
“实验谱与理论峰对比”模块的图像设置默认展开。可以调整画布大小、坐标轴字号、刻度字号、2θ 显示范围、X/Y 轴标题、实验曲线颜色、检测峰颜色、理论峰颜色、坐标轴颜色、网格颜色和曲线宽度。
- 鼠标放在图上会显示当前位置的 2θ 和强度数值。
- 按住鼠标框选一段横轴范围,可局部放大。
- 点击“恢复全图”可清除局部放大。
- PNG 适合汇报和幻灯片;SVG 适合论文作图后期编辑。
- 导出文件名会自动包含当前候选物相或 MP ID,便于整理。
1.6 如何判断候选结果是否可靠
| 观察项 | 较好的情况 | 需要谨慎的情况 |
|---|---|---|
| 匹配峰数 | 多个强峰都能匹配。 | 只匹配 1-2 个峰,容易误判。 |
| 峰位平移 | 整体平移较小,理论峰和实验峰自然对齐。 | 需要很大的 2θ 平移才能匹配,可能是校准问题或错误候选。 |
| 实验覆盖率 | 主要实验峰能被候选解释。 | 大量实验峰没有理论峰对应,可能存在其他相或候选错误。 |
| PDF 全峰对比 | 完整理论峰大多能在实验谱中找到对应位置。 | 理论强峰在实验谱中完全不存在,需重新判断。 |
1.7 PDF 全峰对比模块
PDF 模块是相对独立的验证模块,默认折叠显示。点击模块标题后展开完整内容。它用于把实验 XRD 与 CIF 计算得到的全部理论峰进行比较,特别适合确认自动识别结果、检查多相混合和发现遗漏峰。
- 上传实验 XRD 可选。如果不上传,模块会使用当前主界面已加载的实验谱;显示时使用去背底后的实验曲线。
- 上传 CIF 最多五个 CIF。每个 CIF 单独一行显示,可设置含量、颜色,也可点击 x 删除。
- 设置 2θ 范围 控制计算和显示范围。范围越大计算和显示内容越多。
- 设置峰宽 控制模拟混合谱中理论峰的展宽。峰宽越大,理论曲线越平滑。
- 设置最小强度 用于隐藏非常弱的理论峰,避免图中标记过密。
- 点击计算 计算完成后,显示加权混合谱、每个物相下方分层小竖线标记、PDF 物相摘要表。
- 显示/隐藏 PDF 结果 可只看实验谱,也可叠加理论混合谱;隐藏时 X 轴范围保持对齐。
1.8 常见操作建议
- 如果没有匹配结果,先减小“峰数量”,例如从 20 改为 10 或 8;软件也会给出具体推荐值。
- 如果噪声峰很多,增大“最小峰高”和“最小显著性”。
- 如果主峰整体错开,适当增大“最大平移”,但过大的平移会降低可信度。
- 如果样品可能是多相,不要只看最高分;把多个候选 CIF 放进 PDF 模块做混合对比。
- 导出结果时,JSON 保留完整结构化结果;CSV 适合表格记录;PNG/SVG 用于图像汇报和论文制图。
1. Complete Local App Interface Guide
XMatcher_Local_UI.html is the day-to-day software interface. It combines experimental pattern upload, peak detection, automatic identification, candidate inspection, plot editing, full-peak PDF comparison, and result export in one page. Beginners should complete one full workflow in the App before moving to the Jupyter API.
1.1 Before Opening The Software
- Check the database file The project root must contain
MP500_xrd_database.pkl, the theoretical peak feature database used for identification. - Use the downloaded App If you downloaded the packaged App release, open the App directly. You do not need to start the local service manually; the App connects to its local service automatically.
- Source/HTML version Only when opening
XMatcher_Local_UI.htmldirectly for development or local testing do you need to start the Python API manually:
Keep the terminal open and start using the page after the status shows API connected.python xmatcher_local_api.py --database MP500_xrd_database.pkl - Prepare experimental XRD The most reliable format has two numeric columns:
2thetaandintensity. Supported files include.csv,.txt,.xy,.dat, simple.json, and some.xrdml/.xml.
1.2 Interface Overview
| Area | Purpose | Beginner usage |
|---|---|---|
| Header | Shows version, language switch, download link, manual, and GitHub issue link. | Click EN/CN/JA/KO to switch language instantly. |
| Left control panel | Local service, upload, element filters, peak detection, and matching parameters. | For the first run, upload a file, leave elements blank if unknown, then run identification. |
| Metric bar | Input points, detected peaks, scanned candidates, best score, and selected phase. | Use it to confirm that calculation ran and returned candidates. |
| XRD comparison plot | Shows background-removed experiment, detected peaks, and theoretical peaks for the selected candidate. | Hover for values, drag to zoom, reset to full range when needed. |
| Candidate phases | Lists formula, MP ID, score, coverage, matched peaks, shift, and space group. | Click rows to update the theoretical overlay. MP IDs link to Materials Project. |
| PDF full-peak comparison | Uploads experimental XRD and up to five CIF files, calculates full theoretical peaks and weighted mixtures. | Use it as final confirmation after automatic identification. |
| Citation/footer | Provides citation, BibTeX, copy buttons, download, and issue links. | Copy the citation when using software results in reports or papers. |
1.3 First Automatic Identification
- Upload the experimental pattern Select the XRD file. The UI shows upload status and displays the pattern.
- Choose the search scope Leave elements blank if chemistry is unknown. Enter known elements such as
Ba,Ti,Oto reduce false positives. - Start with defaults Beginners should keep the default peak-detection parameters for the first attempt.
- Run identification A spinner indicates real computation. Full-database searches may take time.
- Inspect candidates Three candidates are returned by default. Check score, matched-peak count, coverage, and global shift.
- Click candidate rows The plot and matched-peak table update with each selected candidate.
- Confirm in PDF module The candidate overlay does not mark all diffraction peaks. Use CIF files in the PDF module for final confirmation.
1.4 Understanding Left-Panel Parameters
| Parameter | Role | When to adjust |
|---|---|---|
| Elements | Restricts candidate database entries. | Enter known chemistry; leave blank for full-database search. |
| contains | Candidates may include the specified elements. | Use for dopants, impurities, or possible extra elements. |
| exact | Candidate element set must exactly match input. | Use when composition is certain. |
| Top candidates | Controls returned results. | Default is 3; increase to inspect more alternatives. |
| Min height | Filters weak peaks. | Increase for noisy patterns; decrease if weak peaks are missed. |
| Min prominence | Requires peaks to stand out from local background. | Increase when baseline variation or noise creates false peaks. |
| Min distance | Minimum 2θ spacing between detected peaks. | Increase for duplicate detections; decrease for dense peaks. |
| Peak count | Number of strongest experimental peaks used for matching. | If no match is found, reduce this value; for complex multiphase patterns, increase cautiously. |
| Smooth window | Reduces noise for detection and display. | Increase for noisy data, but avoid over-smoothing narrow peaks. |
| Baseline window | Estimates and removes slowly varying background. | Increase for strong background; keep default for clean patterns. |
| Position tolerance | Allowed 2θ error between experiment and theory. | Try 0.3-0.5 when calibration or displacement is visible. |
| Max shift / shift step | Controls global 2θ shift search. | Increase max shift when all peaks are offset; reduce step for precision at the cost of speed. |
1.5 Plot Settings, Zoom, And Export
The XRD comparison plot settings are open by default. You can edit canvas size, axis label size, tick size, 2θ display range, axis labels, experimental color, detected-peak color, theoretical-peak color, axis color, grid color, and curve width.
- Hover over the plot to inspect 2θ and intensity values.
- Drag over a horizontal region to zoom in.
- Click reset zoom to restore the full pattern.
- Use PNG for reports and slides; use SVG for publication-quality editing.
- Exported filenames include the current candidate or MP ID when available.
1.6 Judging Candidate Reliability
| Check | Good sign | Use caution when |
|---|---|---|
| Matched peaks | Several strong peaks match. | Only one or two peaks match. |
| Peak shift | Small global shift and natural alignment. | A large 2θ shift is required. |
| Experimental coverage | Main experimental peaks are explained. | Many experimental peaks have no theoretical counterpart. |
| PDF full-peak comparison | Most full theoretical peaks have reasonable experimental support. | Strong theoretical peaks are absent from the experiment. |
1.7 PDF Full-Peak Comparison Module
The PDF module is a relatively independent validation module and is collapsed by default. Click its title to open the full controls. It compares experimental XRD with all theoretical peaks calculated from CIF files, making it useful for confirming automatic identification, checking multiphase mixtures, and finding missing peaks.
- Upload experimental XRD Optional. If omitted, the module uses the current main experimental pattern and displays a background-removed curve.
- Upload CIF files Up to five CIF files. Each appears as a separate row with weight, color, and an x delete button.
- Set 2θ range Controls both calculation and display range.
- Set peak width Controls broadening of simulated theoretical peaks in the mixture profile.
- Set minimum intensity Hides very weak calculated peaks to keep the plot readable.
- Calculate The result shows the weighted mixture, phase-specific bottom markers, and a PDF phase summary table.
- Show/hide PDF result Toggle theoretical output while keeping the X axis aligned with the experimental plot.
1.8 Practical Advice
- If no match is found, reduce Peak count first, for example from 20 to 10 or 8. The UI also gives a recommended value.
- If noise creates many false peaks, increase Min height and Min prominence.
- If all main peaks are shifted, increase Max shift carefully; large shifts reduce confidence.
- For possible multiphase samples, do not rely only on the top candidate. Compare multiple CIFs in the PDF module.
- Use JSON for complete structured output, CSV for tabular records, and PNG/SVG for figures.
模块三:常见问题
实验数据格式、参数建议和常见故障处理。把原来的 7/8/9 独立整理为本模块的 1/2/3。
点击展开阅读模块三
Module 3: FAQ
Experimental data format, parameter suggestions, and troubleshooting. The former 7/8/9 sections are reorganized as 1/2/3 here.
Click to expand Module 3
模块三:常见问题
实验数据格式、参数建议和常见故障处理。把原来的 7/8/9 独立整理为本模块的 1/2/3。
点击展开阅读模块三Module 3: FAQ
Experimental data format, parameter suggestions, and troubleshooting. The former 7/8/9 sections are reorganized as 1/2/3 here.
Click to expand Module 31. 实验 XRD 数据格式
实验文件至少需要两列:第一列为 2θ,第二列为强度。支持逗号、制表符、空格和分号分隔。
two_theta,intensity
10.00,5.2
10.02,5.5
10.04,5.1
读取器会自动排序、去除非法值、合并重复 2θ 点,并过滤负强度。
1. Experimental XRD Input Format
The file needs at least two columns: 2θ in the first column and intensity in the second. Comma, tab, whitespace, and semicolon delimiters are supported.
two_theta,intensity
10.00,5.2
10.02,5.5
10.04,5.1
The reader sorts values, removes invalid rows, merges duplicate 2θ points, and filters negative intensities.
2. 常用参数建议
elements:已知元素组成时一定要填,能显著减少误匹配。element_filter_mode="exact":候选相必须只包含给定元素时使用。element_filter_mode="contains":允许掺杂、杂质或额外元素时使用。position_tolerance=0.2:常规实验数据的起点;仪器误差更大时可尝试 0.3 到 0.5。n_peaks=20:一般足够;复杂多相或低信噪数据可提高到 30。intensity_weight=0.15:默认偏重峰位,适合实验强度不完全可靠的场景。
2. Parameter Suggestions
elements: provide known elements whenever possible to reduce false positives.element_filter_mode="exact": use when candidates must contain exactly the given elements.element_filter_mode="contains": use when dopants, impurities, or extra elements are possible.position_tolerance=0.2: a good starting point; try 0.3 to 0.5 for noisier calibration.n_peaks=20: usually enough; increase to 30 for complex or noisy patterns.intensity_weight=0.15: keeps the score position-focused when experimental intensities are less reliable.
3. 常见问题
找不到 MP500.db
确认文件已经从 Releases 下载,并且 build_database_parallel.py --db-path 指向正确路径。相对路径以你运行命令的目录为准。
找不到 MP500_xrd_database.pkl
说明还没有完成构建,或者输出文件不在当前目录。先运行构建命令,并让 XRDRetriever(database_path=...) 指向构建后的 .pkl 文件。
没有匹配结果
先尝试放宽 element_filter_mode 为 contains,或增大 position_tolerance。同时检查实验文件的 2θ 单位和范围是否正确。
App 显示 API 未连接
确认已经在项目根目录运行 python xmatcher_local_api.py --database MP500_xrd_database.pkl,并且终端没有报错。如果修改过 API 地址,确认界面中的地址仍为 http://127.0.0.1:8765 或实际服务地址。
点击自动识别后没有候选
优先减小“峰数量”。峰数量越大,软件要求越多实验强峰同时被候选解释;对于噪声较多、多相或弱峰明显的数据,过多峰会让检索过严。也可以适当降低“最小峰高”和“最小显著性”,检查是否漏检主要峰。
PDF 模块提示 Unknown endpoint
这通常表示正在运行旧版本本地 API,里面还没有 /api/cif-xrd 接口。关闭旧终端,重新运行最新的 xmatcher_local_api.py,或重新打开封装后的 App。
PDF 计算失败
先检查 CIF 文件是否有效,再确认本地环境包含 pymatgen。如果 2θ 范围设置错误,例如最小值大于最大值,也会导致计算失败。
PDF 图和主图看起来不完全一样
主图用于快速识别,会显示用于匹配的峰和当前候选理论峰;PDF 模块用于完整验证,会显示去背底实验谱、完整理论峰底部标记和多相混合谱。两者用途不同,最终确认以 PDF 全峰对比为准。
构建数据库很慢
理论 XRD 计算本身比较重。先用 --max-entries 小规模测试,再根据机器核心数调整 --workers 和 --batch-size。
pickle 安全警告
这是针对构建后 .pkl 特征数据库的安全边界提醒。只加载自己构建的输出文件或可信来源提供的预构建特征库。
3. Troubleshooting
MP500.db cannot be found
Make sure the file was downloaded from Releases and build_database_parallel.py --db-path points to the correct location. Relative paths are resolved from the directory where you run the command.
MP500_xrd_database.pkl cannot be found
The build has not finished, or the output file is not in the current directory. Run the build command first, then point XRDRetriever(database_path=...) to the built .pkl file.
No matches returned
Try element_filter_mode="contains" or increase position_tolerance. Also verify the 2θ unit and range in the experimental file.
The App Shows API Not Connected
Make sure python xmatcher_local_api.py --database MP500_xrd_database.pkl is running in the project root and the terminal has no error. If you changed the API URL, confirm it matches http://127.0.0.1:8765 or the actual service address.
No Candidate After Running Identification
Reduce Peak count first. A larger peak count requires more experimental strong peaks to be explained simultaneously; noisy, multiphase, or weak-peak patterns can become too strict. Also check whether Min height and Min prominence missed important peaks.
PDF Module Reports Unknown Endpoint
This usually means an older local API is still running and does not expose /api/cif-xrd. Stop the old terminal and restart the latest xmatcher_local_api.py, or reopen the packaged App.
PDF Calculation Fails
Check that each CIF is valid, then confirm the local environment includes pymatgen. Invalid 2θ ranges, such as a minimum larger than the maximum, can also fail.
The PDF Plot Looks Different From The Main Plot
The main plot is for fast identification and selected candidate overlay; the PDF module is for full validation with background-removed experiment, bottom markers for all theoretical peaks, and multiphase mixture profiles. Use the PDF full-peak comparison for final confirmation.
Database building is slow
Theoretical XRD calculation is computationally heavy. Start with --max-entries, then tune --workers and --batch-size for your machine.
Pickle security warning
This safety boundary applies to the built .pkl feature database. Only load outputs built by yourself or trusted prebuilt feature databases.