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 5 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 32.14286% with 19 lines in your changes missing coverage. Please review.

Project coverage is 77.87%. Comparing base (ef60b66) to head (b9d739c).
Report is 135 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/orm/nodes/data/structure.py 35.30% 11 Missing ⚠️
src/aiida/orm/nodes/data/array/kpoints.py 27.28% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6632      +/-   ##
==========================================
+ Coverage   77.51%   77.87%   +0.37%     
==========================================
  Files         560      567       +7     
  Lines       41444    42171     +727     
==========================================
+ Hits        32120    32837     +717     
- Misses       9324     9334      +10     

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


🚨 Try these New Features:

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.

Comment on lines +241 to +242
else:
raise ValueError(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.

Maybe it is possible to move the exception to same condition and move the set_cell to same condition.

Copy link
Contributor Author

@mikibonacci mikibonacci Nov 23, 2024

Choose a reason for hiding this comment

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

Hi @unkcpz, thank you for the comment. I have actually another idea, which is replacing the whole block from line 228 to 245 with:

if has_atomistic():
    from aiida_atomistic import StructureData as AtomisticStructureData

if not isinstance(structuredata, StructureData) and not isinstance(structuredata, AtomisticStructureData if has_atomistic() else StructureData):
    raise ValueError('An instance of StructureData or aiida-atomistic StructureData should be passed to '
                'the KpointsData, found instead {}'.format(structuredata.__class__))
else:
    cell = structuredata.cell
    self.set_cell(cell, structuredata.pbc)

This seems redundant, but actually makes more compact the check. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I guess if the structuredata is neither StructureData nor the AtomisticStructureData, the else block of calling structuredata.cell and self.set_cell with structuredata.pbc will fail?
If so, why not use try..except block and put the current else block in the try and the catch the exceptions for correspond operations? Let me know if I am missing something and we can try it together in person.

Copy link
Contributor Author

@mikibonacci mikibonacci Nov 23, 2024

Choose a reason for hiding this comment

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

In the way you suggest, if structuredata was an arbitrary object which defines cell and pbc as attributes, the exceptions will not be raised but it should. And the user will not see the error (i.e. not providing an orm or atomistic StructureData).

Anyway, let's discuss this in person on monday

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
tests/orm/nodes/data/test_kpoints.py Show resolved Hide resolved
tests/test_dataclasses.py Outdated Show resolved Hide resolved
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