Skip to content

Commit 28131c8

Browse files
authored
Merge pull request #31 from ycexiao/refinement
refactor: use a more flexible interface to utilize `diffpy.srfit`
2 parents 08b858d + ae57d1b commit 28131c8

15 files changed

Lines changed: 1837 additions & 51 deletions

.codespell/ignore_words.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ mater
66

77
;; Frobenius norm used in np.linalg.norm
88
fro
9+
10+
;; "number of input arguments" used in diffpy.srfit.equation.literals.Operator
11+
nin

news/refinement.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Add more flexible interface to utilize ``diffpy.srfit``.
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>

requirements/conda.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ pyyaml
66
diffpy.srfit
77
diffpy.srreal
88
diffpy.structure
9+
networkx
10+
mcp[cli]

src/diffpy/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +0,0 @@
1-
#!/usr/bin/env python
2-
##############################################################################
3-
#
4-
# (c) 2026 The Trustees of Columbia University in the City of New York.
5-
# All rights reserved.
6-
#
7-
# File coded by: Billinge Group members and community contributors.
8-
#
9-
# See GitHub contributions for a more detailed list of contributors.
10-
# https://github.com/diffpy/diffpy.apps/graphs/contributors
11-
#
12-
# See LICENSE.rst for license information.
13-
#
14-
##############################################################################

src/diffpy/apps/pdfadapter.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def initialize_profile(
6565
"""
6666
profile = Profile()
6767
parser = PDFParser()
68-
parser.parseString(Path(profile_path).read_text())
69-
profile.loadParsedData(parser)
68+
parser.parse_file(profile_path)
69+
profile.load_parsed_data(parser)
7070
if q_range is not None:
7171
profile.meta["qmin"] = q_range[0]
7272
profile.meta["qmax"] = q_range[1]
@@ -77,7 +77,7 @@ def initialize_profile(
7777
"xmax": calculation_range[1],
7878
"dx": calculation_range[2],
7979
}
80-
profile.setCalculationRange(**calculation_range)
80+
profile.set_calculation_range(**calculation_range)
8181
self.profile = profile
8282

8383
def initialize_structures(
@@ -185,10 +185,10 @@ def initialize_contribution(self, equation=None):
185185
"""
186186
equation = equation[0] if equation is not None else None
187187
contribution = FitContribution("pdfcontribution")
188-
contribution.setProfile(self.profile)
188+
contribution.set_profile(self.profile)
189189
for pdfgenerator in self.pdfgenerators:
190-
contribution.addProfileGenerator(pdfgenerator)
191-
contribution.setEquation(equation)
190+
contribution.add_profile_generator(pdfgenerator)
191+
contribution.set_equation(equation)
192192
self.contribution = contribution
193193
return self.contribution
194194

@@ -204,9 +204,9 @@ def initialize_recipe(
204204
"""
205205

206206
recipe = FitRecipe()
207-
recipe.addContribution(self.contribution)
208-
qdamp = recipe.newVar("qdamp", fixed=False, value=0.04)
209-
qbroad = recipe.newVar("qbroad", fixed=False, value=0.02)
207+
recipe.add_contribution(self.contribution)
208+
qdamp = recipe.create_new_variable("qdamp", fixed=False, value=0.04)
209+
qbroad = recipe.create_new_variable("qbroad", fixed=False, value=0.02)
210210
for i, (pdfgenerator, spacegroup) in enumerate(
211211
zip(self.pdfgenerators, self.spacegroups)
212212
):
@@ -215,23 +215,23 @@ def initialize_recipe(
215215
"delta2",
216216
]:
217217
par = getattr(pdfgenerator, pname)
218-
recipe.addVar(
218+
recipe.add_variable(
219219
par, name=f"{pdfgenerator.name}_{pname}", fixed=False
220220
)
221-
recipe.constrain(pdfgenerator.qdamp, qdamp)
222-
recipe.constrain(pdfgenerator.qbroad, qbroad)
221+
recipe.add_constraint(pdfgenerator.qdamp, qdamp)
222+
recipe.add_constraint(pdfgenerator.qbroad, qbroad)
223223
stru_parset = pdfgenerator.phase
224224
spacegroupparams = constrainAsSpaceGroup(stru_parset, spacegroup)
225225
for par in spacegroupparams.xyzpars:
226-
recipe.addVar(
226+
recipe.add_variable(
227227
par, name=f"{pdfgenerator.name}_{par.name}", fixed=False
228228
)
229229
for par in spacegroupparams.latpars:
230-
recipe.addVar(
230+
recipe.add_variable(
231231
par, name=f"{pdfgenerator.name}_{par.name}", fixed=False
232232
)
233233
for par in spacegroupparams.adppars:
234-
recipe.addVar(
234+
recipe.add_variable(
235235
par, name=f"{pdfgenerator.name}_{par.name}", fixed=False
236236
)
237237
recipe.fithooks[0].verbose = 0
@@ -247,7 +247,7 @@ def add_contribution_variables(self, variable_names):
247247
e.g. 's0' for scale factor.
248248
"""
249249
for var_name in variable_names:
250-
self.recipe.addVar(
250+
self.recipe.add_variable(
251251
getattr(self.contribution, var_name),
252252
name=var_name,
253253
fixed=False,
@@ -275,7 +275,7 @@ def set_initial_variable_values(self, variable_name_to_value: dict):
275275
Mapping from recipe variable names to new values.
276276
"""
277277
for vname, vvalue in variable_name_to_value.items():
278-
self.recipe._parameters[vname].setValue(vvalue)
278+
self.recipe._parameters[vname].set_value(vvalue)
279279

280280
def get_results(self):
281281
"""Return the current fit results as a JSON-compatible

src/diffpy/apps/refinebase/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)