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

Open
wants to merge 13 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 60.52632% with 15 lines in your changes missing coverage. Please review.

Project coverage is 77.90%. Comparing base (c532b34) to head (758e7a3).

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 ⚠️
src/aiida/tools/data/structure.py 83.34% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6632      +/-   ##
==========================================
- Coverage   77.92%   77.90%   -0.01%     
==========================================
  Files         563      563              
  Lines       41671    41702      +31     
==========================================
+ Hits        32467    32483      +16     
- Misses       9204     9219      +15     

☔ 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.

src/aiida/orm/nodes/data/array/kpoints.py Outdated Show resolved Hide resolved
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
tests/orm/nodes/data/test_kpoints.py Outdated Show resolved Hide resolved
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!

@mikibonacci mikibonacci marked this pull request as ready for review December 13, 2024 16:36
@mikibonacci
Copy link
Contributor Author

Hi @unkcpz , I think the PR is ready, I should have added all you requested changes. But let me know if I forgot something, thanks!

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, all good! can you fix the docstring and then we can get it merged.

The doc build failed because of:

�[2Kreading sources... [100%] tutorials/index

/home/docs/checkouts/readthedocs.org/user_builds/aiida-core/envs/6632/lib/python3.11/site-packages/aiida/orm/nodes/data/structure.py:docstring of aiida.orm.nodes.data.structure.has_atomistic:2: WARNING: Field list ends without a blank line; unexpected unindent.
looking for now-outdated files... none found

@@ -223,16 +223,24 @@ def set_cell_from_structure(self, structuredata):

:param structuredata: an instance of StructureData
"""
from aiida.orm import StructureData
from aiida.orm.nodes.data.structure import StructureData as LegacyStructureData
Copy link
Member

Choose a reason for hiding this comment

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

LegacyStructureData, I like the name 👍

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