Skip to content

Commit a06f7f0

Browse files
committed
docs: add instructions to use diffpy.apps runmacro <macro-file>
1 parent feb7259 commit a06f7f0

7 files changed

Lines changed: 138 additions & 133 deletions

File tree

docs/example/runmacro_example.zip

38.2 KB
Binary file not shown.

docs/source/api/diffpy.apps.example_package.rst

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/source/api/diffpy.apps.rst

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/source/getting-started.rst

Lines changed: 115 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,72 +8,144 @@
88
Getting started
99
================
1010

11-
Here are some example templates provided to help you get started with writing your documentation. You can use these templates to create your own documentation.
11+
``diffpy.apps`` provides user applications to help with tasks using
12+
diffpy packages. This page contains the instructions for all applications
13+
available, including:
1214

13-
Reuse ``.rst`` files across multiple pages
14-
------------------------------------------
15+
- :ref:`runmacro`
1516

16-
Here is how you can reuse a reusable block of ``.rst`` files across multiple pages:
17+
.. _runmacro:
1718

18-
.. include:: snippets/example-table.rst
19+
Use ``runmacro`` to start refinement with a macro file
20+
------------------------------------------------------
1921

20-
.. warning::
22+
The ``runmacro`` application allows users to execute macros written in the
23+
diffpy macro language.
2124

22-
Ensure that the ``.rst`` file you are including is not too long. If it is too long, it may be better to split it into multiple files and include them separately.
25+
.. code-block:: bash
2326
24-
Refer to a specific section in the documentation
25-
------------------------------------------------
27+
diffpy.app runmacro <macro_file.dp-in>
2628
27-
You can use the ``ref`` tag to refer to a specific section in the documentation. For example, you can refer to the section below using the ``:ref:`` tag as shown :ref:`here <attach-image>`.
29+
To follow the example,
2830

29-
.. note::
31+
1. download the example files from :download:`here <../example/runmacro_example.zip>`
3032

31-
Please check the raw ``.rst`` file of this page to see the exact use of the ``:ref:`` tag.
33+
2. extract the downloaded files and navigate to the extracted directory
34+
35+
.. code-block:: bash
3236
33-
Embed your code snippets in the documentation
34-
---------------------------------------------
37+
mv /path/to/runmacro runmacro_example.zip working_directory
38+
cd working_directory
39+
unzip runmacro_example.zip
3540
36-
Here is how you can write a block of code in the documentation. You can use the ``code-block`` directive to write a block of code in the documentation. For example, you can write a block of code as shown below:
41+
3. run the macro using the ``runmacro`` application
3742

3843
.. code-block:: bash
3944
40-
# Create a new environment, without build dependencies (pure Python package)
41-
conda create -n <package_name>-env python=3.14 \
42-
--file requirements/tests.txt \
43-
--file requirements/conda.txt
45+
diffpy.app runmacro example_macro.dp-in
46+
47+
How to write macro
48+
~~~~~~~~~~~~~~~~~~
49+
50+
Let's still use the Ni example created earlier, but this time we will
51+
write the macro file from scratch.
52+
53+
1. Prepare the structure and profile file you want to work with.
54+
55+
.. note::
56+
57+
The structure file is a ``.cif`` file representing the atomic arrangement in
58+
your sample, and the profile file is a ``.gr`` file containing the
59+
experimental data.
60+
61+
Start the macro file with the following two lines:
62+
63+
.. code-block:: text
64+
65+
load structure G1 from "path/to/structure.cif"
66+
load profile exp_ni from "path/to/profile.gr"
4467
45-
# Create a new environment, with build dependencies (non-pure Python package)
46-
conda create -n <package_name>-env python=3.14 \
47-
--file requirements/tests.txt \
48-
--file requirements/conda.txt \
49-
--file requirements/build.txt
68+
``G1`` and ``exp_ni`` are the identifiers used in the macro to refer to the
69+
structure and profile files, respectively. Quotes ``""`` are must to specify
70+
the file paths.
5071

51-
# Activate the environment
52-
conda activate <package_name>_env
72+
2. (Optional) Declare the space group of the structure.
5373

54-
# Install your package locally
55-
# `--no-deps` to NOT install packages again from `requirements.pip.txt`
56-
pip install -e . --no-deps
74+
.. code-block:: text
5775
58-
# Run pytest locally
59-
pytest
76+
set G1 spacegroup as Fm-3m
6077
61-
# ... run example tutorials
78+
``G1`` is the identifier for the structure file loaded earlier. Space group
79+
symmetry ``Fm-3m`` is preserved during the refinement. You can also set
80+
it to be ``auto`` to use the one automatically parsed from the structure file.
81+
But if space group is not provided, nor can it be determined from the structure
82+
file, it will be considered as ``P1`` space group.
6283

63-
.. _attach-image:
84+
3. (Optional) Set the calculation parameters for the refinement.
6485

65-
Attach an image to the documentation
66-
------------------------------------
86+
.. code-block:: text
6787
68-
Here is how you attach an image to the documentation. The ``/docs/source/img/scikit-package-logo-text.png`` example image is provided in the template.
88+
set exp_ni calculation_range as 0.5 20.0 0.01 # r_min, r_max, r_step
89+
set exp_ni q_range as 0.5 20.0 # q_min, q_max
6990
70-
.. image:: ./img/scikit-package-logo-text.png
71-
:alt: codecov-in-pr-comment
72-
:width: 400px
73-
:align: center
91+
``exp_ni`` is the identifier for the profile file loaded earlier.
92+
``calculation_range`` specifies the range and step size for the calculation,
93+
while ``q_range`` specifies the range of Q values to be used in the refinement.
94+
If calculation parameters are not set, it will use the ones
95+
that are defined in the profile file.
7496

7597

76-
Other useful directives
77-
-----------------------
98+
4. Create the refinement equation.
7899

79-
Here is how you can do menu selection :menuselection:`Admin --> Settings` and display labels for buttons like :guilabel:`Privacy level`.
100+
.. code-block:: text
101+
102+
create equation variables s0
103+
set equation as "G1*s0"
104+
105+
``G1`` is the identifier for the structure file loaded earlier. In the
106+
equation, it represents the PDF data generated from the structure `G1`.
107+
``s0`` is created to count for the scaling factor.
108+
109+
5. Store the results.
110+
111+
.. code-block:: text
112+
113+
save to "output_results.json"
114+
115+
The results of the refinement will be saved to a file
116+
named ``output_results.json``.
117+
118+
6. List variables to be refined.
119+
120+
.. code-block:: text
121+
122+
variables:
123+
---
124+
- G1.a: 3.52
125+
- s0: 0.4
126+
- G1.Uiso_0: 0.005
127+
- G1.delta2: 2
128+
- qdamp: 0.04
129+
- qbroad: 0.02
130+
---
131+
132+
Only variables listed in this section will be refined during the
133+
execution of the macro, and the variables will also be refined in that order.
134+
Variables with initial values specified here will be used as the
135+
starting point for the refinement.
136+
137+
.. note::
138+
The naming of variables follows the format
139+
``structure_identifier.parameter``,
140+
``profile_parameter``, or
141+
``equation_parameter``.
142+
143+
For parameters belonging to a specific atom in the parameter,
144+
the naming follows the format ``structure_identifier.parameter_atomindex``.
145+
e.g. ``G1.Uiso_0`` here refers to the Uiso parameter of the first atom in
146+
the structure ``G1``.
147+
148+
For constrained parameters, it will use the first parameter in the
149+
constraint. e.g. Here, lattice parameter ``a=b=c``,
150+
and ``Usio_0=Uiso_i, i=1,2,3``, ``a`` and ``Uiso_0`` are used as the
151+
reference variables.

docs/source/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Table of contents
4444
:maxdepth: 2
4545

4646
getting-started
47-
Package API <api/diffpy.apps>
4847
release
4948
license
5049

docs/source/snippets/example-table.rst

Lines changed: 0 additions & 28 deletions
This file was deleted.

news/dsl-instruction.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: Add instructions to use diffpy.apps runmacro <macro-file>.
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)