Skip to content
Merged
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
12 changes: 6 additions & 6 deletions docs/examples/sequential_fit_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ def main():
output_result_dir=str(output_folder),
filename_order_pattern=r"(\d+)K\.gr",
refinable_variable_names=[
"a_1",
"a_phase_1",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit variable name.

"s0",
"Uiso_0_1",
"delta2_1",
"Uiso_phase_1_atom_1",
"delta2_phase_1",
"qdamp",
"qbroad",
],
initial_variable_values={
"s0": 0.4,
"qdamp": 0.04,
"qbroad": 0.02,
"a_1": 3.52,
"Uiso_0_1": 0.005,
"delta2_1": 2,
"a_phase_1": 3.52,
"Uiso_phase_1_atom_1": 0.005,
"delta2_phase_1": 2,
},
xmin=1.5,
xmax=25.0,
Expand Down
23 changes: 23 additions & 0 deletions news/fix-miscellaneous.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news added: fix miscellaneous errors.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
42 changes: 32 additions & 10 deletions src/pdfbl/sequential/pdfadapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ def initialize_recipe(
- constrain variables of the scatters
- change symmetry constraints
"""

def modify_xyz_adp_name(parname, nth_phase):
parname, nth_atom = parname.split("_")
return f"{parname}_phase_{nth_phase+1}_atom_{int(nth_atom)+1}"

def modify_lat_delta_name(parname, nth_phase):
return f"{parname}_phase_{nth_phase+1}"

recipe = FitRecipe()
recipe.addContribution(self.contribution)
qdamp = recipe.newVar("qdamp", fixed=False, value=0.04)
Expand All @@ -264,7 +272,9 @@ def initialize_recipe(
"delta2",
]:
par = getattr(pdfgenerator, pname)
recipe.addVar(par, name=pname + f"_{i+1}", fixed=False)
recipe.addVar(
par, name=modify_lat_delta_name(pname, i), fixed=False
)
if len(self.pdfgenerators) > 1:
recipe.addVar(
getattr(self.contribution, f"s{i+1}"),
Expand All @@ -277,11 +287,17 @@ def initialize_recipe(
stru_parset = pdfgenerator.phase
spacegroupparams = constrainAsSpaceGroup(stru_parset, spacegroup)
for par in spacegroupparams.xyzpars:
recipe.addVar(par, name=par.name + f"_{i+1}", fixed=False)
recipe.addVar(
par, name=modify_xyz_adp_name(par.name, i), fixed=False
)
for par in spacegroupparams.latpars:
recipe.addVar(par, name=par.name + f"_{i+1}", fixed=False)
recipe.addVar(
par, name=modify_lat_delta_name(par.name, i), fixed=False
)
for par in spacegroupparams.adppars:
recipe.addVar(par, name=par.name + f"_{i+1}", fixed=False)
recipe.addVar(
par, name=modify_xyz_adp_name(par.name, i), fixed=False
)
recipe.addVar(self.contribution.s0, name="s0", fixed=False)
recipe.fix("all")
recipe.fithooks[0].verbose = 0
Expand Down Expand Up @@ -313,12 +329,18 @@ def residual(self, p=[]):
The residual array.
"""
residual = self.recipe.residual(p)
if self.intermediate_results is not None:
fitresults = FitResults(self.recipe)
for (key, step), values in self.intermediate_results.items():
if (self.iter_count % step) == 0:
value = getattr(fitresults, key)
values.put(value)
fitresults_dict = None
for (key, step), values in self.intermediate_results.items():
if (self.iter_count % step) == 0:
if fitresults_dict is None:
fitresults_dict = self.save_results(mode="dict")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time-consuming step. Recompute only when fitresults_dict is None.

value = fitresults_dict.get(key, None)
if value is None:
raise KeyError(
f"{key} is not found in the fit results. "
f"Available keys are: {list(fitresults_dict.keys())}"
)
values.put(value)
self.iter_count += 1
return residual

Expand Down
5 changes: 2 additions & 3 deletions src/pdfbl/sequential/sequential_cmi_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import Literal

from bg_mpl_stylesheets.styles import all_styles
from diffpy.srfit.fitbase import FitResults
from matplotlib import pyplot as plt
from prompt_toolkit import PromptSession
from prompt_toolkit.patch_stdout import patch_stdout
Expand Down Expand Up @@ -476,8 +475,8 @@ def _run_one_cycle(self, stop_event=SimpleNamespace(is_set=lambda: False)):
new_value
)
for entry_name in self.visualization_data.get("results", {}):
fit_results = FitResults(self.adapter.recipe)
entry_value = getattr(fit_results, entry_name)
fitresults_dict = self.adapter.save_results(mode="dict")
entry_value = fitresults_dict.get(entry_name, None)
self.visualization_data["results"][entry_name]["ydata"].put(
entry_value
)
Expand Down
Loading
Loading