Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing support for atomistic StructureData #6632

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mikibonacci
Copy link
Contributor

@mikibonacci mikibonacci commented Nov 22, 2024

  • orm.StructureData has a to_atomistic method, and an has_atomistic function is implemented
  • adapted the set_cell_from_structure method for KpointsData
  • added tests for both structure and kpoints. Test are skipped if aiida-atomistic is not installed (skip_atomistic fixture)

mikibonacci and others added 2 commits November 22, 2024 11:39
- orm.StructureData `to_atomistic` method and `has_atomistic` function
- adapted `set_cell_from_structure` method for KpointsData
- added tests for both structure and kpoints.
Copy link

codecov bot commented Nov 22, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 77.89%. Comparing base (ef60b66) to head (fe6cbcc).
Report is 146 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/orm/nodes/data/structure.py 37.50% 10 Missing ⚠️
src/aiida/orm/nodes/data/array/kpoints.py 70.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6632      +/-   ##
==========================================
+ Coverage   77.51%   77.89%   +0.38%     
==========================================
  Files         560      567       +7     
  Lines       41444    42199     +755     
==========================================
+ Hits        32120    32865     +745     
- Misses       9324     9334      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

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

Thanks @mikibonacci!
The goal of the PR is quite clear.

I have some requests on the verbose if..else conditions of array/kpoints.py which a bit unreadable. I'd suggest if the operation of different conditions are the same, it might be clear to combine conditions using or?
The tests seems can be improved by creating an atomic lib structure fixture to be used for multiple tests.

'An instance of StructureData should be passed to ' 'the KpointsData, found instead {}'.format(
structuredata.__class__
)
error_message = (
Copy link
Member

Choose a reason for hiding this comment

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

I think this can directly move to raise exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/aiida/orm/nodes/data/array/kpoints.py Outdated Show resolved Hide resolved
src/aiida/orm/nodes/data/structure.py Outdated Show resolved Hide resolved
src/aiida/orm/nodes/data/structure.py Show resolved Hide resolved
src/aiida/orm/nodes/data/structure.py Show resolved Hide resolved
src/aiida/orm/nodes/data/structure.py Outdated Show resolved Hide resolved
src/aiida/orm/nodes/data/structure.py Outdated Show resolved Hide resolved
tests/orm/nodes/data/test_kpoints.py Outdated Show resolved Hide resolved
Comment on lines 93 to 94
@pytest.fixture(autouse=True)
def init_profile(self):
Copy link
Member

Choose a reason for hiding this comment

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

I think here you want to create a structure to be shared for many sub-tests. It would be better to use fixture.
The profile is more suitable for if you need to test the store and read data nodes from DB. If you need profile, there is aiida_profile fixture to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @unkcpz, would it be better to put also the last two tests in the above TestKpoints class but marked with the skip_atomistic fixture, and then in the init profile add a self.atomistic = self.structure.to_atomistic which run only if has_atomistic?

Copy link
Member

Choose a reason for hiding this comment

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

would it be better to put also the last two tests in the above TestKpoints class but marked with the skip_atomistic fixture

Yes, I think that'll be better!

tests/test_dataclasses.py Outdated Show resolved Hide resolved
Comment on lines 97 to 118
from aiida_atomistic import StructureData, StructureDataMutable

alat = 5.430 # angstrom
cell = [
[
0.5 * alat,
0.5 * alat,
0.0,
],
[
0.0,
0.5 * alat,
0.5 * alat,
],
[0.5 * alat, 0.0, 0.5 * alat],
]
self.alat = alat
mutable = StructureDataMutable()
mutable.set_cell(cell)
mutable.add_atom(positions=(0.000 * alat, 0.000 * alat, 0.000 * alat), symbols='Si')
mutable.add_atom(positions=(0.250 * alat, 0.250 * alat, 0.250 * alat), symbols='Si')
self.structure = StructureData.from_mutable(mutable)
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved as a generate_atomistic_structure_data() when called it return this example structure.
I think there is also quite a bit duplicated code between TestKpoints and TestKpointsAtomisticStructureData. My suggestion is to combine these to above and use https://docs.pytest.org/en/stable/how-to/parametrize.html that same test logic works for both of them.

@mikibonacci
Copy link
Contributor Author

Hi @unkcpz , I pushed some fix following your suggestion, thanks! To give a comment, I used the pytest parameterization in the test_kpoints.py, so we don't have code duplication. I am not sure it is really a 100% parametrization, in the sense that in the new generate_structure (the old init_profile), I put a check for the structure data type, but in this way we don't need to implement a new method to generate the atomistic version. For sure this will change when the orm.StructureData will be removed.

If anything else, please let me know :) Thanks!

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