Skip to content

Commit 43b445b

Browse files
authored
Merge pull request #52 from ycexiao/update-doc
docs: update the documentation
2 parents 779084a + 0c7ccf8 commit 43b445b

6 files changed

Lines changed: 217 additions & 56 deletions

File tree

‎README.rst‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@
3636
.. |Tracking| image:: https://img.shields.io/badge/issue_tracking-github-blue
3737
:target: https://github.com/diffpy/diffpy.apps/issues
3838

39-
User applications to help with tasks using diffpy packages. Currently it
40-
contains
41-
42-
- `runmacro`: A runner for DiffPy macro files.
43-
- `agentify`: A deployer for diffpy.cmi agentic skills.
44-
- `Diffpy MCP server`: A local server for the DiffPy MCP instance.
39+
User applications to help with tasks using diffpy packages.
40+
Currently it provides:
41+
1. Macro interface for PDF refinements. Supported by the command ``runmacro``.
42+
2. Agent interface for PDF refinements. Supported by the included MCP server.
4543

4644
For more information about the diffpy.apps library, please consult our `online documentation <https://diffpy.github.io/diffpy.apps>`_.
4745

‎docs/source/diffpy-agent.rst‎

Lines changed: 188 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,110 @@ DiffPy Agent Interface
44
=======================
55
This interface is provided for agents, e.g. ``Claude Code`` and ``Codex``,
66
which mainly utilizes the "tool" concept applied in most agent frameworks.
7-
After connecting these tools to an agent, users can invoke DiffPy
7+
After connecting these tools to an agent, users can invoke ``DiffPy``
88
functionalities and automate PDF refinements through conversation.
99

10-
After you have installed ``diffpy.apps``, the next step is to connect it to
11-
your local agent. ``diffpy.apps`` server should be able to connect to any
12-
Desktop agent that supports the MCP (Model Context Protocol), and we have provided
13-
instructions for :ref:`connect_claude_desktop` and :ref:`connect_chatgpt_desktop` below.
14-
1510
.. _mcp_setup:
1611

1712
Setup
1813
-----
1914

20-
.. _connect_claude_desktop:
15+
After you have installed ``diffpy.apps``, the next step is to connect it to
16+
your local agent. The configurations are required for the first time only.
2117

22-
Connect to Claude Desktop
23-
~~~~~~~~~~~~~~~~~~~~~~~~~
24-
1. Copy the path to the conda executable. There are many commands available,
25-
here are two examples
18+
``diffpy.apps`` communicates with the agent through the
19+
MCP (Model Context Protocol), and thus can be configured for any agents
20+
that support the MCP. Here we provide the setup instructions for ``Claude``
21+
agent and ``ChatGPT`` agent.
22+
23+
.. _connect_claude:
24+
25+
For Claude User
26+
~~~~~~~~~~~~~~~~
27+
28+
How to connect to Claude Code Terminal
29+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
1. Install ``Claude Code`` terminal.
31+
32+
2. Copy the path to the ``conda`` executable. There are many commands available,
33+
and here are two examples:
2634

2735
.. code-block:: bash
2836
2937
whereis conda # linux or macOS terminal
3038
where.exe conda # windows powershell
3139
32-
2. Install ``Claude Desktop`` (hereafter referred to as ``Claude``).
33-
3. Open ``Claude`` and open "Settings".
34-
4. Navigate to the "Developer" section.
35-
5. In the "Local MCP servers" region, click "Edit Config" and Open the configuration file. It's name should be ``claude_desktop_config.json``.
40+
3. Replace ``<path/to/conda>`` with the path to your ``conda`` executable and ``<conda_env_name>`` with the name of your conda environment, then run the following command:
41+
42+
.. code-block:: bash
43+
44+
claude mcp add --scope local diffpy-apps -- \
45+
<path/to/conda> run --no-capture-output -n <conda_env_name> \
46+
python -m diffpy.apps.parametric_refinement.refinement_server \
47+
48+
.. note::
49+
50+
The ``claude mcp add`` command saves the server configuration according to the
51+
scope you specify:
52+
53+
``--scope local`` adds it to the project-specific section of
54+
``~/.claude.json``.
55+
56+
``--scope project`` adds it to the project's ``.mcp.json``.
57+
58+
``--scope user`` adds it to the top-level configuration in
59+
``~/.claude.json``.
60+
61+
The default scope is ``local``.
62+
63+
64+
.. note::
65+
66+
``diffpy.apps`` MCP server is launched by ``conda`` instead of the commonly
67+
used ``uv`` because one of ``diffpy.apps`` core dependencies, ``diffpy.srreal`` is
68+
better managed via ``conda``
69+
70+
71+
4. Restart the ``Claude CLI``
72+
5. Run the following command in the conversation with ``Claude CLI`` to verify the connection:
73+
74+
.. code-block:: bash
75+
76+
/mcp
77+
78+
6. Check :ref:`agent_example` to see how to use it to perform PDF refinement.
79+
80+
7. To remove the configuration, run the following command in the the terminal:
81+
82+
.. code-block:: bash
83+
84+
claude mcp remove "diffpy-apps" -s local
85+
86+
replace ``local`` with the actual scope you used when adding the configuration.
87+
88+
89+
How to connect to Claude Desktop
90+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
1. Install ``Claude Code`` Desktop.
92+
2. Open ``Claude Desktop`` and open "Settings".
93+
3. Navigate to the "Developer" section.
94+
4. In the "Local MCP servers" region, click "Edit Config" and Open the configuration file. Its name should be ``claude_desktop_config.json``.
3695

3796
.. Figure:: img/claude_edit_config.png
3897
:align: center
3998

40-
Figure 1: Screenshot of "Edit Config" in ``Claude``.
99+
Figure 1: Screenshot of "Edit Config" in ``Claude Desktop``.
100+
101+
5. Copy the path to the conda executable. There are many commands available,
102+
here are two examples
103+
104+
.. code-block:: bash
105+
106+
whereis conda # linux or macOS terminal
107+
where.exe conda # windows powershell
41108
42-
6. Add the following configuration, and replace ``</path/to/conda>`` with the path to your conda executable and ``<conda_env_name>`` with the name of your conda environment.
109+
110+
3. Replace ``<path/to/conda>`` with the path to your ``conda`` executable and ``<conda_env_name>`` with the name of your conda environment, then add the configuration as shown below.
43111

44112
.. code-block:: json
45113
@@ -67,12 +135,12 @@ would look like this:
67135
{
68136
"mcpServers": {
69137
"diffpy.apps": {
70-
"command": "/path/to/bin/conda",
138+
"command": "/Users/mr_neutron/miniconda3/bin/conda",
71139
"args": [
72140
"run",
73141
"--no-capture-output",
74142
"-n",
75-
"diffpy_apps",
143+
"diffpy.apps_env",
76144
"python",
77145
"-m",
78146
"diffpy.apps.parametric_refinement.refinement_server"
@@ -89,12 +157,12 @@ would look like this:
89157
{
90158
"mcpServers": {
91159
"diffpy.apps": {
92-
"command": "C:\\path\\to\\bin\\conda.bat",
160+
"command": "C:\\Users\\mr_neutron\\miniconda3\\condabin\\conda.bat",
93161
"args": [
94162
"run",
95163
"--no-capture-output",
96164
"-n",
97-
"diffpy_apps",
165+
"diffpy.apps_env",
98166
"python",
99167
"-m",
100168
"diffpy.apps.parametric_refinement.refinement_server"
@@ -105,7 +173,6 @@ would look like this:
105173
}
106174
107175
108-
109176
7. Restart the ``Claude``.
110177

111178
8. Go to the same "Local MCP servers" section and verify that the
@@ -116,22 +183,29 @@ would look like this:
116183

117184
Figure 2: Screenshot of active ``diffpy.apps`` server in ``Claude``.
118185

186+
9. Check :ref:`agent_example` to see how to use it to perform PDF refinement.
119187

120-
.. _connect_chatgpt_desktop:
188+
10. To remove the configuration, remove the added block from the configuration file.
121189

122-
Connect to ChatGPT Desktop
123-
~~~~~~~~~~~~~~~~~~~~~~~~~~
124-
1. Copy the path to the conda executable. There are many commands available,
190+
.. _connect_chatgpt:
191+
192+
For ChatGPT users
193+
~~~~~~~~~~~~~~~~~
194+
195+
1. Install the Desktop version or Terminal version of ``ChatGPT``.
196+
197+
2. Open the configuration file ``~/.codex/config.toml``.
198+
199+
3. Copy the path to the conda executable. There are many commands available,
125200
here are two examples
126201

127202
.. code-block:: bash
128203
129204
whereis conda # linux or macOS terminal
130205
where.exe conda # windows powershell
131206
132-
1. Install ``ChatGPT Desktop`` (hereafter referred to as ``ChatGPT``).
133-
2. Open ``~/.codex/config.toml``.
134-
3. Add the following configuration, and replace ``<path/to/python>`` with the path to the Python executable in your conda environment.
207+
208+
4. Replace ``<path/to/conda>`` with the path to your ``conda`` executable and ``<conda_env_name>`` with the name of your conda environment, then add the configuration as shown below.
135209

136210
.. code-block:: toml
137211
@@ -153,9 +227,11 @@ here are two examples
153227
double backslashes (e.g., ``C:\\path\\to\\bin\\conda.bat``).
154228

155229

156-
4. Restart the ``ChatGPT``.
230+
4. Restart the ``ChatGPT Desktop`` or ``Codex``.
157231

158-
5. Open "Settings", and navigate to the "Integration" section. Open
232+
5. Verify the connection of the ``diffpy.apps`` server.
233+
234+
For ``ChatGPT`` Desktop, open "Settings", and navigate to the "Integration" section. Open
159235
"Plugins" tab, and verify that the ``diffpy.apps`` server is listed in the
160236
"MCPs" field and active.
161237

@@ -164,38 +240,99 @@ here are two examples
164240

165241
Figure 2: Screenshot of active ``diffpy.apps`` server in ``ChatGPT``.
166242

243+
For ``ChatGPT`` Terminal (``Codex``), enter the following command in the conversation with the agent:
244+
245+
.. code-block:: bash
246+
247+
/mcp
248+
249+
6. Check :ref:`agent_example` to see how to use it to perform PDF refinement.
250+
251+
7. To remove the configuration, delete the added block from the configuration file.
252+
253+
.. _agent_example:
167254

168255
Example Usage
169256
-------------
170-
Once you ``diffpy.apps`` MCP server is running, you can interact with it
171-
through the agent.
172257

173-
Here is a simple example of conducting Ni structure refinement.
258+
After successfully connecting the ``diffpy.apps`` server to your agent,
259+
you can interact with it to perform PDF refinement tasks.
260+
Please see :ref:`mcp_setup` for instructions.
261+
262+
Here we assume that you are using ``Claude Code`` Desktop as your agent. If you are
263+
using a different agent, please replace ``Claude`` in the following steps.
174264

175265
1. Download the :download:`Ni.gr<data/Ni.gr>` and :download:`Ni.cif<data/Ni.cif>`
176266
files to your working directory.
177267

178-
2. Open ``Claude``, launch the "Code" tab or select "Cowork" in "Chat or Cowork"
268+
2. Open ``Claude Code`` Desktop, launch the "Code" tab or select "Cowork" in "Chat or Cowork"
179269
tab.
180270

181-
3. Add the working directory folder to the ``Claude``.
271+
.. note::
272+
273+
In some Desktop distributions, the developers provide separate
274+
channels for agent interactions, and the
275+
Chat-only window may not have access to the MCP servers. When
276+
this happens, make sure to switch to the Agent interaction channel.
182277

183-
4. Start your conversation! For example, try to ask
184-
*Tell me what can diffpy.apps do and how it can help me refine the
185-
Ni.cif against the Ni.gr.*
278+
Terminal distributions can usually discover the MCP servers automatically.
186279

187280

281+
3. Add the working directory folder to the ``Claude Code`` Desktop.
282+
283+
4. Start your conversation! Explore your preferred way to communicate with the agent.
284+
285+
For example, Mr Neutron follows the steps and started a conversation with the agent:
286+
287+
.. code-block:: text
288+
289+
> (Mr Neutron) Make sure you can find `diffpy.apps` MCP server, `Ni.cif` and `Ni.gr`
290+
> (Agent) Yes, I found both files in your ...
291+
> (Mr Neutron) Use diffpy.apps MCP server
292+
1. Add `Ni.gr` as Profile
293+
2. Add `Ni.cif` as PDF model
294+
3. Plot them together
295+
> (Agent) I added both files with the diffpy server and ...
296+
297+
and the following image shows the result:
298+
299+
.. figure:: img/example_bad_ni.png
300+
:align: center
301+
302+
Ni PDF plot(before refinement). Generated by Claude Code
303+
304+
Mr Neutron knows that the initial plot is not ideal because the structure has not been refined yet. So he continues:
305+
306+
.. code-block:: text
307+
308+
> (Mr Neutron) The plot looks incorrect. Now refine the Ni structure:
309+
1. constrain Ni structure according to it's spacegroup symmetry
310+
2. refine ni.scale and other space group symmetry parameters
311+
3. fit it over the range from 1-20 angstrum for simplicity
312+
> (Agent) I refined the Ni model under Fm-3m symmetry over 1-20 Å.
313+
Rw (the fit's weighted residual) went from 0.59
314+
with only scale refined to 0.161 with all three parameters.
315+
The plot is saved as ...
316+
317+
and the following image shows the refined result:
318+
319+
.. figure:: img/example_good_ni.png
320+
:align: center
321+
322+
Ni PDF plot(after refinement). Generated by Claude Code
323+
324+
Mr Neutron is satisfied with the refined result.
325+
326+
.. _diffpy-agent-skills:
327+
188328
How to add Diffpy agent skills
189329
------------------------------
190330

191-
Another advantage of using the Diffpy agent is that its behavior can be
192-
tuned to suit specific tasks and workflows by adding custom skills and
193-
context.
194-
195-
We have prepared a basic skill that you can readily deploy and use with the
196-
Diffpy agent.
331+
In previous example, Mr Neutron still needs to write down the sequence of
332+
actions for the simple PDF refinement task. The effort can be further reduced
333+
by adding our prepared agent skills into the context.
197334

198-
To use it, run
335+
To use it, run the following command in the terminal after installing ``diffpy.apps``.
199336

200337
.. code-block:: bash
201338
@@ -259,10 +396,13 @@ Skills are simply markdown files providing context for the agents.
259396
They help to enable the agent to follow the best practices, and to
260397
efficiently perform workflows sharing similar patterns.
261398
Please refer to the documentation from your favorite agent platform, such as
262-
`Claude Documentation <https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview>`_
399+
`Claude Documentation <https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview>`_,
263400
for more details.
264401

265402
``diffpy-app agentify`` fetches our prepared agent skills from
266403
`cmi-agent-skills <https://github.com/diffpy/cmi-agent-skills>`_ GitHub repository.
267404
If you are willing to contribute your skills, you can submit Pull Requests in
268-
the same repository. Thanks for sharing your work with the community!
405+
the same repository.
406+
We expect the description of the workflows to follow the consistent format and wording
407+
conventions, i.e. the diffpy macro language. Please see :doc:`diffpy-macro` for more
408+
details. Thanks for sharing your work with the community!

‎docs/source/img/example_bad_ni.png‎

473 KB
Loading
467 KB
Loading

‎docs/source/index.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ We recommend installing ``diffpy.apps`` using `conda <https://docs.conda.io/en/l
3737

3838
.. code-block:: bash
3939
40-
conda create -n diffpy_mcp
41-
conda activate diffpy_mcp
40+
conda create -n diffpy.apps_env python=3.13
41+
conda activate diffpy.apps_env
4242
conda install -c conda-forge diffpy.apps
4343
4444

‎news/update-doc.rst‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Update the documentation.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

0 commit comments

Comments
 (0)