-
Notifications
You must be signed in to change notification settings - Fork 192
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
base: main
Are you sure you want to change the base?
Conversation
- orm.StructureData `to_atomistic` method and `has_atomistic` function - adapted `set_cell_from_structure` method for KpointsData - added tests for both structure and kpoints.
for more information, see https://pre-commit.ci
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this 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 = ( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #6632 (comment)
tests/orm/nodes/data/test_kpoints.py
Outdated
@pytest.fixture(autouse=True) | ||
def init_profile(self): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
for more information, see https://pre-commit.ci
tests/orm/nodes/data/test_kpoints.py
Outdated
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) |
There was a problem hiding this comment.
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.
both in kpoints.py and test_kpoints.py
for more information, see https://pre-commit.ci
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! |
orm.StructureData
has ato_atomistic
method, and anhas_atomistic
function is implementedset_cell_from_structure
method forKpointsData
aiida-atomistic
is not installed (skip_atomistic
fixture)