Skip to content

Commit d214efa

Browse files
authored
Merge pull request #31 from ycexiao/add-readme-example
docs: add function docstring and readme example
2 parents 2eec85b + a34509d commit d214efa

File tree

6 files changed

+200
-49
lines changed

6 files changed

+200
-49
lines changed

README.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ To view the basic usage and available commands, type ::
9393

9494
pdfbl.sequential -h
9595

96+
Examples
97+
--------
98+
99+
To run a temperature sequential refinement, ::
100+
101+
from pdfbl.sequential.sequential_cmi_runner import SequentialCMIRunner
102+
runner = SequentialCMIRunner()
103+
runner.load_inputs(
104+
input_data_dir="path/to/inputs",
105+
output_result_dir="path/to/outputs",
106+
structure_path="path/to/structure.cif",
107+
filename_order_pattern=r"(\d+)K\.gr", # regex pattern to extract the temperature from the filename
108+
)
109+
runner.run(mode="batch") # or mode="stream" for running sequentially as data becomes available
110+
96111
Getting Started
97112
---------------
98113

docs/source/api/pdfbl.sequential.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
:show-inheritance:
1212

1313

14-
Submodules
15-
----------
16-
1714
pdfbl.sequential.pdfadapter module
1815
----------------------------------
1916

news/add-readme-example.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 example in the ``README.rst``.
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>

src/pdfbl/sequential/pdfadapter.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ class PDFAdapter:
2929
3030
Methods
3131
-------
32-
init_profile(profile_path, qmin=None, qmax=None, xmin=None, xmax=None, dx=None)
32+
initialize_profile(profile_path, qmin=None, qmax=None, xmin=None, xmax=None, dx=None)
3333
Load and initialize the PDF profile from the given file path with
3434
some optional parameters.
35-
init_structures(structure_paths : list[str], run_parallel=True)
35+
initialize_structures(structure_paths : list[str], run_parallel=True)
3636
Load and initialize the structures from the given file paths, and
3737
generate corresponding PDFGenerator objects.
38-
init_contribution(equation_string=None)
38+
initialize_contribution(equation_string=None)
3939
Initialize the FitContribution object combining the PDF generators and
4040
the profile.
41-
init_recipe()
41+
initialize_recipe()
4242
Initialize the FitRecipe object for the fitting process.
4343
set_initial_variable_values(variable_name_to_value : dict)
4444
Update parameter values from the provided dictionary.
@@ -54,7 +54,7 @@ def __init__(self):
5454
self.intermediate_results = {}
5555
self.iter_count = 0
5656

57-
def moniter_intermediate_results(
57+
def monitor_intermediate_results(
5858
self, key: str, step: int = 10, queue: Queue = None
5959
):
6060
"""Store an intermediate result during the fitting process.
@@ -72,7 +72,7 @@ def moniter_intermediate_results(
7272
queue = Queue()
7373
self.intermediate_results[(key, step)] = queue
7474

75-
def init_profile(
75+
def initialize_profile(
7676
self,
7777
profile_path: str,
7878
qmin=None,
@@ -119,15 +119,17 @@ def init_profile(
119119
profile.setCalculationRange(xmin=xmin, xmax=xmax, dx=dx)
120120
self.profile = profile
121121

122-
def init_structures(self, structure_paths: list[str], run_parallel=True):
122+
def initialize_structures(
123+
self, structure_paths: list[str], run_parallel=True
124+
):
123125
"""Load and initialize the structures from the given file paths,
124126
and generate corresponding PDFGenerator objects.
125127
126128
The target output, FitRecipe, requires a profile object, multiple
127129
PDFGenerator objects, and a FitContribution object combining them. This
128130
method creates the PDFGenerator objects from the structure files.
129131
130-
Must be called after init_profile.
132+
Must be called after initialize_profile.
131133
132134
Parameters
133135
----------
@@ -182,7 +184,7 @@ def init_structures(self, structure_paths: list[str], run_parallel=True):
182184
self.spacegroups = spacegroups
183185
self.pdfgenerators = pdfgenerators
184186

185-
def init_contribution(self, equation_string=None):
187+
def initialize_contribution(self, equation_string=None):
186188
"""Initialize the FitContribution object combining the PDF
187189
generators and the profile.
188190
@@ -191,7 +193,7 @@ def init_contribution(self, equation_string=None):
191193
method creates the FitContribution object combining the profile and PDF
192194
generators.
193195
194-
Must be called after init_profile and init_structures.
196+
Must be called after initialize_profile and initialize_structures.
195197
196198
Parameters
197199
----------
@@ -230,7 +232,7 @@ def init_contribution(self, equation_string=None):
230232
self.contribution = contribution
231233
return self.contribution
232234

233-
def init_recipe(
235+
def initialize_recipe(
234236
self,
235237
):
236238
"""Initialize the FitRecipe object for the fitting process.
@@ -240,7 +242,7 @@ def init_recipe(
240242
method creates the FitRecipe object combining the profile, PDF
241243
generators, and contribution.
242244
243-
Must be called after init_contribution.
245+
Must be called after initialize_contribution.
244246
245247
Notes
246248
-----
@@ -311,17 +313,18 @@ def residual(self, p=[]):
311313
The residual array.
312314
"""
313315
residual = self.recipe.residual(p)
314-
fitresults = FitResults(self.recipe)
315-
for (key, step), values in self.intermediate_results.items():
316-
if (self.iter_count % step) == 0:
317-
value = getattr(fitresults, key)
318-
values.put(value)
316+
if self.intermediate_results is not None:
317+
fitresults = FitResults(self.recipe)
318+
for (key, step), values in self.intermediate_results.items():
319+
if (self.iter_count % step) == 0:
320+
value = getattr(fitresults, key)
321+
values.put(value)
319322
self.iter_count += 1
320323
return residual
321324

322325
def refine_variables(self, variable_names: list[str]):
323326
"""Refine the parameters specified in the list and in that
324-
order. Must be called after init_recipe.
327+
order. Must be called after initialize_recipe.
325328
326329
Parameters
327330
----------
@@ -357,7 +360,7 @@ def save_results(
357360
self, mode: Literal["str", "dict"] = "str", filename=None
358361
):
359362
"""Save the fitting results. Must be called after
360-
refine_parameters.
363+
refine_variables.
361364
362365
Parameters
363366
----------

0 commit comments

Comments
 (0)