Skip to content

feat: add component.py - #5

Merged
sbillinge merged 4 commits into
diffpy:mainfrom
cadenmyers13:component-parameters
Oct 28, 2026
Merged

sbillinge merged 4 commits into
diffpy:mainfrom
cadenmyers13:component-parameters

Conversation

@cadenmyers13

@cadenmyers13 cadenmyers13 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Implements the two helpers on Component that every component (peak profile, instrument, texture) uses for its refinable values:

  • create_parameters_from(refinable_obj, names) creates the component's srfit Parameters from a pyobjcryst model. Each Parameter starts at ObjCryst's default value, with ObjCryst's limits as its bounds. names maps our Parameter names to ObjCryst's ({"eta0": "Eta0"}), so the names users see don't depend on ObjCryst's. Some of those can't be Python names (2ThetaDispl), and some will change when workarounds are replaced.
  • push_parameters(refinable_obj) writes the Parameter values into a pyobjcryst model before each calculation.

Why the limits matter: ObjCryst silently clamps a value set outside its limits. If a fit steps to W = 2 while the limit is 1, srfit reports W = 2 but the pattern is calculated with W = 1, and the fit stops responding to W. To prevent this:

  • The limits become the Parameters' bounds, so least_squares(..., bounds=recipe.get_bounds_array()) stays inside them.
  • push_parameters raises a ValueError if a value gets past a limit anyway, naming the limit and the value ObjCryst would have used. All values are checked before any is written, so an error leaves the model unchanged.
    tests/test_component.py ..............                       [100%]
    14 passed

@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge ready for merge. I closed the other PR because it was stalling #4

@sbillinge
sbillinge merged commit e69395e into diffpy:main Oct 28, 2026
3 of 4 checks passed
@cadenmyers13
cadenmyers13 deleted the component-parameters branch October 28, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants