SEUyishu commited on
Commit
596b729
·
verified ·
1 Parent(s): 6f5c6b4

Update mcp_output/README_MCP.md

Browse files
Files changed (1) hide show
  1. mcp_output/README_MCP.md +265 -205
mcp_output/README_MCP.md CHANGED
@@ -1,205 +1,265 @@
1
- # MatDeepLearn MCP Service
2
-
3
- 这是 [MatDeepLearn](https://github.com/Fung-Lab/MatDeepLearn) 的 MCP (Model Context Protocol) 服务封装,用于通过 AI 助手进行材料属性预测的图神经网络训练和推理。
4
-
5
- ## 功能概述
6
-
7
- MatDeepLearn MCP 服务提供以下工具:
8
-
9
- | 工具名称 | 描述 |
10
- |---------|------|
11
- | `check_environment` | 检查环境配置和 GPU 可用性 |
12
- | `list_available_models` | 列出所有可用的 GNN 模型 |
13
- | `get_model_config` | 获取特定模型的默认配置 |
14
- | `process_structure_data` | 将原子结构数据处理为图格式 |
15
- | `train_model` | 训练 GNN 模型 |
16
- | `predict_properties` | 使用训练好的模型预测新结构的属性 |
17
- | `cross_validation` | 执行 k 折交叉验证 |
18
- | `analyze_structure` | 分析原子结构文件 |
19
- | `compare_models` | 比较不同 GNN 模型的性 |
20
- | `get_dataset_info` | 获取数据集目录信息 |
21
-
22
- ## 支持的模型
23
-
24
- - **CGCNN_demo**: Crystal Graph Convolutional Neural Network
25
- - **MPNN_demo**: Message Passing Neural Network
26
- - **SchNet_demo**: SchNet 连续滤波卷积神经网络
27
- - **MEGNet_demo**: MatErials Graph Network
28
- - **GCN_demo**: Graph Convolutional Network
29
- - **SOAP_demo**: Smooth Overlap of Atomic Positions 描述符方法
30
- - **SM_demo**: Sine Matrix 描述符方法
31
-
32
- ## 本地运行
33
-
34
- ### 安装依赖
35
-
36
- ```bash
37
- cd MatDeepLearn
38
- pip install -r mcp_output/requirements.txt
39
- ```
40
-
41
- ### 启动 STDIO 模式(用于本地 AI 助手)
42
-
43
- ```bash
44
- python mcp_output/start_mcp.py
45
- ```
46
-
47
- ### 启动 HTTP 模式(用于远程访问)
48
-
49
- ```bash
50
- export MCP_TRANSPORT=http
51
- export MCP_PORT=7860
52
- python mcp_output/start_mcp.py
53
- ```
54
-
55
- ## 部署到 HuggingFace Space
56
-
57
- ### 1. 创建 HuggingFace Space
58
-
59
- 1. 登录 [HuggingFace](https://huggingface.co/)
60
- 2. 点击 "New Space"
61
- 3. 选择 "Docker" 作为 SDK
62
- 4. 填写 Space 名称(如 `matdeeplearn-mcp`)
63
-
64
- ### 2. 上传代码
65
-
66
- 方法一:通过 Git
67
-
68
- ```bash
69
- # 克隆你的 Space 仓库
70
- git clone https://huggingface.co/spaces/YOUR_USERNAME/matdeeplearn-mcp
71
- cd matdeeplearn-mcp
72
-
73
- # 复制 MatDeepLearn 代码
74
- cp -r /path/to/MatDeepLearn/* .
75
-
76
- # 提交并推送
77
- git add .
78
- git commit -m "Initial MatDeepLearn MCP deployment"
79
- git push
80
- ```
81
-
82
- 方法二:通过 HuggingFace Web 界面
83
-
84
- 1. Space 页面点击 "Files" 标签
85
- 2. 上传所有 MatDeepLearn 文件
86
- 3. 确保包含 `Dockerfile`、`mcp_output/` 目录和所有源代码
87
-
88
- ### 3. 配置 Space
89
-
90
- 确保你的 Space 设置中:
91
- - SDK: Docker
92
- - Hardware: CPU Basic(免费)或 GPU(付费,更快)
93
-
94
- ### 4. 等待构建
95
-
96
- Space 会自动构建 Docker 镜像并启动服务。构建完成后,你可以通过以下 URL 访问:
97
-
98
- ```
99
- https://YOUR_USERNAME-matdeeplearn-mcp.hf.space
100
- ```
101
-
102
- ## 在 AI 助手中使用
103
-
104
- ### Claude Desktop 配置
105
-
106
- 在 `claude_desktop_config.json` 中添加:
107
-
108
- ```json
109
- {
110
- "mcpServers": {
111
- "matdeeplearn": {
112
- "command": "python",
113
- "args": ["/path/to/MatDeepLearn/mcp_output/start_mcp.py"]
114
- }
115
- }
116
- }
117
- ```
118
-
119
- ### 使用远程 HTTP 服务
120
-
121
- 如果部署到 HuggingFace Space,可以通过 HTTP 调用:
122
-
123
- ```json
124
- {
125
- "mcpServers": {
126
- "matdeeplearn": {
127
- "url": "https://YOUR_USERNAME-matdeeplearn-mcp.hf.space/mcp"
128
- }
129
- }
130
- }
131
- ```
132
-
133
- ## 使用示例
134
-
135
- ### 检查环境
136
-
137
- ```
138
- 请检查 MatDeepLearn 环境是否正常
139
- ```
140
-
141
- ### 列出可用模型
142
-
143
- ```
144
- 列出 MatDeepLearn 中所有可用的图神经网络模型
145
- ```
146
-
147
- ### 训练模型
148
-
149
- ```
150
- 使用 CGCNN 模型在 data/test_data 目录上训练 100 个 epoch
151
- ```
152
-
153
- ### 预测属性
154
-
155
- ```
156
- 使用 trained_model.pth 模型预测 new_structures/ 目录中结的属性
157
- ```
158
-
159
- ### 分析结构
160
-
161
- ```
162
- 分析 structure.cif 文件的原子结构信息
163
- ```
164
-
165
- ## 数据格式要求
166
-
167
- ### 目录结构
168
-
169
- ```
170
- data_directory/
171
- ├── targets.csv # 必需:包含结构ID和目标属性
172
- ├── atom_dict.json # 可选:原子特征字典
173
- ├── structure1.json # 结构文件(支持 json, cif, xyz, POSCAR 等)
174
- ├── structure2.json
175
- └── ...
176
- ```
177
-
178
- ### targets.csv 格式
179
-
180
- ```csv
181
- structure_id,property1,property2
182
- structure1,1.23,4.56
183
- structure2,2.34,5.67
184
- ```
185
-
186
- ## 常见问题
187
-
188
- ### Q: GPU 不可用怎么办?
189
- A: 服务会自动回退到 CPU 模式。对于大型数据集,建议使用 GPU。
190
-
191
- ### Q: 如何添加自定义模型?
192
- A: 在 `matdeeplearn/models/` 目录下添加模型文件,并在 `config.yml` 中添加配置。
193
-
194
- ### Q: 支持哪些结构文件格式?
195
- A: 支持 ASE 库支持的所有格式,包括:json, cif, xyz, POSCAR, vasp 等。
196
-
197
- ## 许可证
198
-
199
- 本项目遵循 MIT 许可证。
200
-
201
- ## 致谢
202
-
203
- - [MatDeepLearn](https://github.com/Fung-Lab/MatDeepLearn) - Victor Fung 等人开发
204
- - [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/) - GNN ��架
205
- - [FastMCP](https://github.com/jlowin/fastmcp) - MCP 服务框架
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MatDeepLearn MCP Service
2
+
3
+ 这是 [MatDeepLearn](https://github.com/Fung-Lab/MatDeepLearn) 的 MCP (Model Context Protocol) 服务封装,用于通过 AI 助手进行材料属性预测的图神经网络训练和推理。
4
+
5
+ ## 功能概述
6
+
7
+ MatDeepLearn MCP 服务提供以下工具:
8
+
9
+ | 工具名称 | 描述 | 支持直接传入文件内容 |
10
+ |---------|------|-------------------|
11
+ | `check_environment` | 检查环境配置和 GPU 可用性 | - |
12
+ | `list_available_models` | 列出所有可用的 GNN 模型 | - |
13
+ | `get_model_config` | 获取特定模型的默认配置 | - |
14
+ | `quick_structure_analysis` | **推荐** 快速分析结构文件 | ✅ |
15
+ | `analyze_structure` | 分析原子结构文件 | |
16
+ | `process_structure_data` | 将原子结构数据处理为图格式 | ✅ |
17
+ | `get_dataset_info` | 获取数据集信息 | |
18
+ | `train_model` | 训练 GNN 模型 | - |
19
+ | `predict_properties` | 使用训练好的模型预测新结构性 | - |
20
+ | `cross_validation` | 执行 k 折交叉验证 | - |
21
+ | `compare_models` | 比较不同 GNN 模型的性能 | - |
22
+
23
+ ## 🌟 远程 MCP 使用指南(在 Cursor 中使用)
24
+
25
+ MCP 服务部署在远程服务器(如 HuggingFace Space)时,您需要**直接传入文件内容**而不是文件路径。
26
+
27
+ ### 分析结构文件(推荐方法)
28
+
29
+ 使用 `quick_structure_analysis` 工具,直接传入文件内容:
30
+
31
+ ```
32
+ 请分析这个 CIF 文件的结构:
33
+ [在这里粘贴 CIF 文件的完整内容]
34
+ ```
35
+
36
+ 或者在 Cursor 中,您可以这样使用:
37
+
38
+ ```
39
+ 使用 quick_structure_analysis 分析以下 CIF 文件:
40
+
41
+ data_NaCl
42
+ _cell_length_a 5.64
43
+ _cell_length_b 5.64
44
+ _cell_length_c 5.64
45
+ _cell_angle_alpha 90.0
46
+ _cell_angle_beta 90.0
47
+ _cell_angle_gamma 90.0
48
+ ...
49
+ ```
50
+
51
+ ### 工具参数说明
52
+
53
+ #### quick_structure_analysis(推荐用于远程分析)
54
+ ```json
55
+ {
56
+ "file_content": "完整的文件内容字符串",
57
+ "file_format": "cif", // 支持: cif, xyz, vasp, poscar, json, extxyz
58
+ "include_positions": false,
59
+ "include_distances": true
60
+ }
61
+ ```
62
+
63
+ #### analyze_structure
64
+ ```json
65
+ {
66
+ "file_content": "完整的文件内容字符串",
67
+ "file_format": "cif"
68
+ }
69
+ ```
70
+
71
+ #### process_structure_data(处理多个结构)
72
+ ```json
73
+ {
74
+ "structure_contents": {
75
+ "struct1.cif": "CIF 内容...",
76
+ "struct2.cif": "CIF 内容..."
77
+ },
78
+ "targets_csv": "struct1,1.5\nstruct2,2.3"
79
+ }
80
+ ```
81
+
82
+ ## 支持的模型
83
+
84
+ - **CGCNN_demo**: Crystal Graph Convolutional Neural Network
85
+ - **MPNN_demo**: Message Passing Neural Network
86
+ - **SchNet_demo**: SchNet 连续滤波卷积神经网络
87
+ - **MEGNet_demo**: MatErials Graph Network
88
+ - **GCN_demo**: Graph Convolutional Network
89
+ - **SOAP_demo**: Smooth Overlap of Atomic Positions 描述符方法
90
+ - **SM_demo**: Sine Matrix 描述符方法
91
+
92
+ ## 本地运行
93
+
94
+ ### 安装依赖
95
+
96
+ ```bash
97
+ cd MatDeepLearn
98
+ pip install -r mcp_output/requirements.txt
99
+ ```
100
+
101
+ ### 启动 STDIO 模式(用于本地 AI 助手)
102
+
103
+ ```bash
104
+ python mcp_output/start_mcp.py
105
+ ```
106
+
107
+ ### 启动 HTTP 模式(用于远程访问)
108
+
109
+ ```bash
110
+ export MCP_TRANSPORT=http
111
+ export MCP_PORT=7860
112
+ python mcp_output/start_mcp.py
113
+ ```
114
+
115
+ ## 部署到 HuggingFace Space
116
+
117
+ ### 1. 创建 HuggingFace Space
118
+
119
+ 1. 登录 [HuggingFace](https://huggingface.co/)
120
+ 2. 点击 "New Space"
121
+ 3. 选择 "Docker" 作为 SDK
122
+ 4. 填写 Space 名称(如 `matdeeplearn-mcp`)
123
+
124
+ ### 2. 上传代码
125
+
126
+ 方法一:通过 Git
127
+
128
+ ```bash
129
+ # 克隆你的 Space 仓库
130
+ git clone https://huggingface.co/spaces/YOUR_USERNAME/matdeeplearn-mcp
131
+ cd matdeeplearn-mcp
132
+
133
+ # 复制 MatDeepLearn 代码
134
+ cp -r /path/to/MatDeepLearn/* .
135
+
136
+ # 提交并推送
137
+ git add .
138
+ git commit -m "Initial MatDeepLearn MCP deployment"
139
+ git push
140
+ ```
141
+
142
+ 方法二:通过 HuggingFace Web 界面
143
+
144
+ 1. Space 页面点击 "Files" 标签
145
+ 2. 上传所有 MatDeepLearn 文件
146
+ 3. 确保包含 `Dockerfile`、`mcp_output/` 目录和所有源代码
147
+
148
+ ### 3. 配置 Space
149
+
150
+ 确保你的 Space 设置中:
151
+ - SDK: Docker
152
+ - Hardware: CPU Basic(免费)或 GPU(付费,更快)
153
+
154
+ ### 4. 等待构建
155
+
156
+ Space 会自动构建 Docker 镜像并启动服务。建完成后,你可以通过以下 URL 访问:
157
+
158
+ ```
159
+ https://YOUR_USERNAME-matdeeplearn-mcp.hf.space
160
+ ```
161
+
162
+ ## AI 助手中使用
163
+
164
+ ### Claude Desktop 配置
165
+
166
+ 在 `claude_desktop_config.json` 中添加:
167
+
168
+ ```json
169
+ {
170
+ "mcpServers": {
171
+ "matdeeplearn": {
172
+ "command": "python",
173
+ "args": ["/path/to/MatDeepLearn/mcp_output/start_mcp.py"]
174
+ }
175
+ }
176
+ }
177
+ ```
178
+
179
+ ### 使用远程 HTTP 服务
180
+
181
+ 如果部署到 HuggingFace Space,可以通过 HTTP 调用:
182
+
183
+ ```json
184
+ {
185
+ "mcpServers": {
186
+ "matdeeplearn": {
187
+ "url": "https://YOUR_USERNAME-matdeeplearn-mcp.hf.space/mcp"
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ ## 使用示例
194
+
195
+ ### 检查环境
196
+
197
+ ```
198
+ 请检查 MatDeepLearn 环境是否正常
199
+ ```
200
+
201
+ ### 列出可用模型
202
+
203
+ ```
204
+ 列出 MatDeepLearn 中所有可用的图神经网络模型
205
+ ```
206
+
207
+ ### 训练模型
208
+
209
+ ```
210
+ 使用 CGCNN 模型在 data/test_data 目录上训练 100 个 epoch
211
+ ```
212
+
213
+ ### 预测属性
214
+
215
+ ```
216
+ 使用 trained_model.pth 模型预测 new_structures/ 目录中结构的属性
217
+ ```
218
+
219
+ ### 分析结构
220
+
221
+ ```
222
+ 分析 structure.cif 文件的原子结构信息
223
+ ```
224
+
225
+ ## 数据格式要求
226
+
227
+ ### 目录结构
228
+
229
+ ```
230
+ data_directory/
231
+ ├── targets.csv # 必需:包含结构ID和目标属性
232
+ ├── atom_dict.json # 可选:原子特征字典
233
+ ├── structure1.json # 结构文件(支持 json, cif, xyz, POSCAR 等)
234
+ ├── structure2.json
235
+ └── ...
236
+ ```
237
+
238
+ ### targets.csv 格式
239
+
240
+ ```csv
241
+ structure_id,property1,property2
242
+ structure1,1.23,4.56
243
+ structure2,2.34,5.67
244
+ ```
245
+
246
+ ## 常见问题
247
+
248
+ ### Q: GPU 不可用怎么办?
249
+ A: 服务会自动回退到 CPU 模式。对于大型数据集,建议使用 GPU。
250
+
251
+ ### Q: 如何添加自定义模型?
252
+ A: 在 `matdeeplearn/models/` 目录下添加模型文件,并在 `config.yml` 中添加配置。
253
+
254
+ ### Q: 支持哪些结构文件格式?
255
+ A: 支持 ASE 库支持的所有格式,包括:json, cif, xyz, POSCAR, vasp 等。
256
+
257
+ ## 许可证
258
+
259
+ 本项目遵循 MIT 许可证。
260
+
261
+ ## 致谢
262
+
263
+ - [MatDeepLearn](https://github.com/Fung-Lab/MatDeepLearn) - Victor Fung 等人开发
264
+ - [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/) - GNN 框架
265
+ - [FastMCP](https://github.com/jlowin/fastmcp) - MCP 服务框架