Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codespell/ignore_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ mater

;; Frobenius norm used in np.linalg.norm
fro

;; "number of input arguments" used in diffpy.srfit.equation.literals.Operator
nin
23 changes: 23 additions & 0 deletions news/refinement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Add more flexible interface to utilize ``diffpy.srfit``.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
1 change: 1 addition & 0 deletions requirements/conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pyyaml
diffpy.srfit
diffpy.srreal
diffpy.structure
networkx
3 changes: 3 additions & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
numpy
inline-snapshot
mcp[cli]
textx
14 changes: 0 additions & 14 deletions src/diffpy/__init__.py

This file was deleted.

37 changes: 18 additions & 19 deletions src/diffpy/apps/pdfadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from pathlib import Path

import numpy
from scipy.optimize import least_squares

from diffpy.srfit.fitbase import (
FitContribution,
FitRecipe,
Expand All @@ -14,6 +12,7 @@
from diffpy.srfit.pdf import PDFGenerator, PDFParser
from diffpy.srfit.structure import constrainAsSpaceGroup
from diffpy.structure.parsers import getParser
from scipy.optimize import least_squares


class PDFAdapter:
Expand Down Expand Up @@ -65,8 +64,8 @@ def initialize_profile(
"""
profile = Profile()
parser = PDFParser()
parser.parseString(Path(profile_path).read_text())
profile.loadParsedData(parser)
parser.parse_file(profile_path)
profile.load_parsed_data(parser)
if q_range is not None:
profile.meta["qmin"] = q_range[0]
profile.meta["qmax"] = q_range[1]
Expand All @@ -77,7 +76,7 @@ def initialize_profile(
"xmax": calculation_range[1],
"dx": calculation_range[2],
}
profile.setCalculationRange(**calculation_range)
profile.set_calculation_range(**calculation_range)
self.profile = profile

def initialize_structures(
Expand Down Expand Up @@ -185,10 +184,10 @@ def initialize_contribution(self, equation=None):
"""
equation = equation[0] if equation is not None else None
contribution = FitContribution("pdfcontribution")
contribution.setProfile(self.profile)
contribution.set_profile(self.profile)
for pdfgenerator in self.pdfgenerators:
contribution.addProfileGenerator(pdfgenerator)
contribution.setEquation(equation)
contribution.add_profile_generator(pdfgenerator)
contribution.set_equation(equation)
self.contribution = contribution
return self.contribution

Expand All @@ -204,9 +203,9 @@ def initialize_recipe(
"""

recipe = FitRecipe()
recipe.addContribution(self.contribution)
qdamp = recipe.newVar("qdamp", fixed=False, value=0.04)
qbroad = recipe.newVar("qbroad", fixed=False, value=0.02)
recipe.add_contribution(self.contribution)
qdamp = recipe.create_new_variable("qdamp", fixed=False, value=0.04)
qbroad = recipe.create_new_variable("qbroad", fixed=False, value=0.02)
for i, (pdfgenerator, spacegroup) in enumerate(
zip(self.pdfgenerators, self.spacegroups)
):
Expand All @@ -215,23 +214,23 @@ def initialize_recipe(
"delta2",
]:
par = getattr(pdfgenerator, pname)
recipe.addVar(
recipe.add_variable(
par, name=f"{pdfgenerator.name}_{pname}", fixed=False
)
recipe.constrain(pdfgenerator.qdamp, qdamp)
recipe.constrain(pdfgenerator.qbroad, qbroad)
recipe.add_constraint(pdfgenerator.qdamp, qdamp)
recipe.add_constraint(pdfgenerator.qbroad, qbroad)
stru_parset = pdfgenerator.phase
spacegroupparams = constrainAsSpaceGroup(stru_parset, spacegroup)
for par in spacegroupparams.xyzpars:
recipe.addVar(
recipe.add_variable(
par, name=f"{pdfgenerator.name}_{par.name}", fixed=False
)
for par in spacegroupparams.latpars:
recipe.addVar(
recipe.add_variable(
par, name=f"{pdfgenerator.name}_{par.name}", fixed=False
)
for par in spacegroupparams.adppars:
recipe.addVar(
recipe.add_variable(
par, name=f"{pdfgenerator.name}_{par.name}", fixed=False
)
recipe.fithooks[0].verbose = 0
Expand All @@ -247,7 +246,7 @@ def add_contribution_variables(self, variable_names):
e.g. 's0' for scale factor.
"""
for var_name in variable_names:
self.recipe.addVar(
self.recipe.add_variable(
getattr(self.contribution, var_name),
name=var_name,
fixed=False,
Expand Down Expand Up @@ -275,7 +274,7 @@ def set_initial_variable_values(self, variable_name_to_value: dict):
Mapping from recipe variable names to new values.
"""
for vname, vvalue in variable_name_to_value.items():
self.recipe._parameters[vname].setValue(vvalue)
self.recipe._parameters[vname].set_value(vvalue)

def get_results(self):
"""Return the current fit results as a JSON-compatible
Expand Down
Empty file.
Loading
Loading