Skip to content

Crystal lattice and co. - #36

Merged
damskii9992 merged 46 commits into
developfrom
MWP_sample_model_2
Oct 20, 2026
Merged

damskii9992 merged 46 commits into
developfrom
MWP_sample_model_2

Conversation

@damskii9992

Copy link
Copy Markdown
Collaborator

This PR adds the crystal Lattice class and related classes to my sample_model module.

@damskii9992 damskii9992 added the [scope] enhancement Adds/improves features (major.MINOR.patch) label Sep 30, 2026
@damskii9992 damskii9992 added [priority] medium Normal/default priority [area] Structure Model Regarding the model description labels Sep 30, 2026
@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.62533% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.40%. Comparing base (bff2252) to head (ccfd5c4).

Files with missing lines Patch % Lines
src/easyimaging/sample_model/lattice.py 95.70% 6 Missing and 1 partial ⚠️
src/easyimaging/measurement/measurement.py 85.71% 5 Missing ⚠️
src/easyimaging/sample_model/atom_site.py 96.66% 3 Missing and 1 partial ⚠️
...c/easyimaging/regions_of_interest/rectangle_roi.py 89.47% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #36      +/-   ##
===========================================
+ Coverage    92.65%   95.40%   +2.75%     
===========================================
  Files            9       14       +5     
  Lines          572     1307     +735     
  Branches        92      129      +37     
===========================================
+ Hits           530     1247     +717     
- Misses          36       52      +16     
- Partials         6        8       +2     
Flag Coverage Δ
unittests 95.40% <97.62%> (+2.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/easyimaging/sample_model/__init__.py 100.00% <100.00%> (ø)
src/easyimaging/sample_model/atoms.py 100.00% <100.00%> (ø)
src/easyimaging/sample_model/crystals.py 100.00% <100.00%> (ø)
src/easyimaging/utils/__init__.py 100.00% <ø> (ø)
...c/easyimaging/regions_of_interest/rectangle_roi.py 96.04% <89.47%> (-0.95%) ⬇️
src/easyimaging/sample_model/atom_site.py 96.66% <96.66%> (ø)
src/easyimaging/measurement/measurement.py 91.56% <85.71%> (-0.88%) ⬇️
src/easyimaging/sample_model/lattice.py 95.70% <95.70%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rozyczko

rozyczko commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

I looked a bit at the new code and found three functionality issues:

  1. saving and reloading a Lattice does not work. to_dict writes the list of atom sites without any of the sites.
from easyimaging.sample_model import AtomSite, Atoms, Lattice

L = Lattice.cubic(3.0, atom_sites=[AtomSite(Atoms.Fe, 0, 0, 0, 300)])
d = L.to_dict()

print(d['atom_sites'])
# shows {'@module': 'easyscience.base_classes.easy_list', '@class': 'EasyList', '@version': '2.5.1'}   <- no sites

print(d['length_b']['fixed'])
# shows False   <- the link to length_a is gone (should be True for cubic!)

Lattice.from_dict(d)
# TypeError: atom_sites must be a list of AtomSite objects.
  1. User-supplied unique_names are dropped. Lattice.cubic and .hexagonal always mark unique_name as auto-generated, even when the caller set it.
from easyimaging.sample_model import Lattice, Atoms
from easyimaging.sample_model.crystals import body_centered_cubic

print('unique_name' in Lattice(3, 4, 5, unique_name='Mine').to_dict())       # True
print('unique_name' in Lattice.cubic(3.0, unique_name='Mine2').to_dict())    # False
print('unique_name' in Lattice.hexagonal(3.0, 5.0, unique_name='Mine3').to_dict())  # False
print('unique_name' in body_centered_cubic(2.87, Atoms.Fe, 300, unique_name='my_bcc').to_dict())  # False
  1. String atoms give a wrong name. The crystals functions accept 'Fe' as documented, but the lattice comes out named 'Unknown BCC Lattice_0'
from easyimaging.sample_model import Atoms
from easyimaging.sample_model.crystals import body_centered_cubic

print(body_centered_cubic(2.87, Atoms.Fe, 300).unique_name)  # 'Fe BCC Lattice_0'
print(body_centered_cubic(2.87, 'Fe', 300).unique_name)      # 'Unknown BCC Lattice_0'

Comment on lines +10 to +16
- [Lattice](sample_model/lattice.md) - The crystallographic unit cell of
the sample model.
- [AtomSite](sample_model/atom_site.md) - The atomic sites of a
crystallographic lattice.
- [Atoms](sample_model/atoms.md) - The atomic species occupying an atomic
site.
- [crystals](sample_model/crystals) - A module containing convenience

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't the links have sample_model prefix removed? We're already in sample_models...

Comment thread src/easyimaging/sample_model/lattice.py
Comment on lines +201 to +202
lattice.length_c.make_dependent_on('length_a', {'length_a': lattice.length_a})
return lattice

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should probably also set alpha=90.0 etc.
Also, tie all the angles to alpha

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, that would still allow alpha to be fitted, which is weird. I think it's better to create an internal Parameter and tie all the angles to that Parameter, thereby "locking" them.

Comment on lines +382 to +383
Create a hexagonal close-packed (HCP) lattice with four atom sites.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You create a lattice with two atoms only...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Haha, I haven't gone through these docstrings yet. These are still just Claudes auto-generated docstrings 🙃

@damskii9992
damskii9992 requested a review from rozyczko October 16, 2026 12:04
@damskii9992

Copy link
Copy Markdown
Collaborator Author

Ready for a re-review. Addressed all comments except for the creation of weird lattices, which will be handled by a validator which will be implemented when I actually have a calculator . . .

@rozyczko

Copy link
Copy Markdown
Member

I looked a bit at the new code and found three functionality issues:

  1. saving and reloading a Lattice does not work. to_dict writes the list of atom sites without any of the sites.

This still holds.
After Lattice.cubic(3.0).to_dict() then from_dict, setting length_a to 4.0 leaves length_b and length_c at 3.0, and all three lengths plus all three angles show up as fittable.

I guess you're just waiting for 3.0 to be merged? This of course is a non-issue there.

@damskii9992
damskii9992 merged commit 3eb9095 into develop Oct 20, 2026
33 checks passed
@damskii9992
damskii9992 deleted the MWP_sample_model_2 branch October 20, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[area] Structure Model Regarding the model description [priority] medium Normal/default priority [scope] enhancement Adds/improves features (major.MINOR.patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants