Skip to content

change: let the set_structure method take a path, parameter set, or structure object - #20

Merged
sbillinge merged 6 commits into
diffpy:mainfrom
cadenmyers13:set-structure-inputs
Nov 3, 2026
Merged

sbillinge merged 6 commits into
diffpy:mainfrom
cadenmyers13:set-structure-inputs

Conversation

@cadenmyers13

Copy link
Copy Markdown
Contributor

What problem does this PR address?

set_structure now takes whichever form of structure the user has, either a Path, ParameterSet, or structure object. This essentially merges set_structure_from_parset into set_structure which simplifies the code a bit. I found this slightly confusing when i first started writing cmi code.

A structure object (unchanged):

generator.set_structure(structure)          # parameters under generator.phase

A ParameterSet, used as it is, with its own name. Giving one ParameterSet to several generators shares the structure:

phase = structure_to_parameter_set("ni", structure)
xray_generator.set_structure(phase)
neutron_generator.set_structure(phase)      # both under .ni, shared

The path to a structure file, as a Path or str, read with diffpy.structure.load_structure:

generator.set_structure(Path("ni.cif"))     # parameters under generator.phase

name with a ParameterSet raises an error. A ParameterSet keeps its own name. Renaming it would rename it in every generator that shares it, so name can only be used with a structure or a path:

phase = structure_to_parameter_set("phase", structure)
generator.set_structure(phase, name="ni")
# ValueError: set_structure was given the name 'ni' with a ParameterSet, which
# keeps its own name, 'phase'. Please leave out the name, or give it when you
# create the ParameterSet.

name now defaults to None, so set_structure can tell whether one was given. For a structure or a path, it still means "phase". set_structure_from_parset is unchanged, so existing scripts keep working.

cadenmyers13 and others added 2 commits November 2, 2026 12:23
…e file path

Tests in tests/test_generators.py for BasePDFGenerator and
DebyePDFGenerator.set_structure accepting a diffpy.cmistructure
ParameterSet (kept under its own name; a name given with it raises a
ValueError) or a pathlib.Path/str path read with load_structure.
Signatures (name now defaults to None) and docstrings are updated; the
bodies are not implemented yet, so these tests and the existing ones
relying on the default name fail until they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge ready for review

cadenmyers13 and others added 2 commits November 2, 2026 13:09
docformatter v1.7.7 depends on untokenize 0.1.1, which fails to build
on Python 3.14 (now used by pre-commit.ci). v1.7.8 drops untokenize.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cadenmyers13
cadenmyers13 marked this pull request as draft November 2, 2026 18:52
cadenmyers13 and others added 2 commits November 2, 2026 16:04
BasePDFGenerator.set_structure (and so DebyePDFGenerator's) now uses a
diffpy.cmistructure ParameterSet as it is, raising a ValueError if a
name is also given, and reads a pathlib.Path or str with
diffpy.structure.load_structure. The default name "phase" now applies
only to structure objects and paths.

test_set_structure_with_parameter_set no longer reads generator.phase,
which only exists when the ParameterSet is named "phase"; it checks the
ParameterSet managed under its own name instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….cmipdf into set-structure-inputs

# Conflicts:
#	src/diffpy/cmipdf/basepdfgenerator.py
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.31%. Comparing base (fe9d2c7) to head (f6387a9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
+ Coverage   97.05%   97.31%   +0.26%     
==========================================
  Files           6        6              
  Lines         340      373      +33     
==========================================
+ Hits          330      363      +33     
  Misses         10       10              
Files with missing lines Coverage Δ
tests/test_generators.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cadenmyers13
cadenmyers13 marked this pull request as ready for review November 2, 2026 21:13
@cadenmyers13

Copy link
Copy Markdown
Contributor Author

@sbillinge ready for review now

@sbillinge
sbillinge merged commit 64ab38d into diffpy:main Nov 3, 2026
7 checks passed
@cadenmyers13
cadenmyers13 deleted the set-structure-inputs branch November 3, 2026 15:15
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