-
Notifications
You must be signed in to change notification settings - Fork 200
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
fix: allow StructureData without specified cell #5341
fix: allow StructureData without specified cell #5341
Conversation
Since StructureData is supposed to support storing non-periodic structures, it should also support not specifying a cell. The default [1,1,1] was both not distinguishable from an actual cell [1,1,1], and dangerous because it could give the impression that a structure was ready for a periodic calculation when in fact no cell had been specified. The new default `None` clearly signals that no cell was specified. A check is added that will raise when specifying periodicity without specifying a cell.
This PR includes some optional changes that could be undone while still fixing #5248
Once could use |
See also my comment in the issue. |
I forgot that if we want to forbid In the interest of backwards compatibility I will remove this check, i.e. inconsistent structures with |
Thanks a lot for your comments, Gio!
Note that When using
Yes, let's not change the return value of When calling
I believe this function already exists, it's called |
d9bf9ec
to
b190ecc
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5341 +/- ##
===========================================
+ Coverage 79.63% 82.13% +2.51%
===========================================
Files 517 533 +16
Lines 37040 38499 +1459
===========================================
+ Hits 29492 31619 +2127
+ Misses 7548 6880 -668
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Thanks Leo for the work on this.
I'm not sure I understand. What can be now done that would be a problem if we raise when
My suggestion is to have a
Agreed.
I'm not sure - I think we would end up in the same situation we want to go away for KpointsData, for instance: if you call get_kpoints_mesh and the data was set as a list (or viceversa) you get an exception. But in practice it's not so nice to have to catch exceptions that depend on how the class has been setup. Better to return zero (generalised) volume for
See my suggested behaviour above.
Yes, this would be used internally by the function so we don't duplicate code. But I feel that |
User code will fail, for example if someone does s=StructureData()
s.set_cell(...)
s.set_pbc(...) which was legal before. This happened already in our own test base, so I do not think it is safe to assume this won't happen elsewhere. If you prefer, and if others agree, I'd still be ok with making this breaking change here.
I cannot easily estimate unintended consequences of this change.
Let's discuss this when we've decided the question above since it is linked.
On reflection, I agree not to raise, and
Did you check the implementation of |
@giovannipizzi please let me know whether you'll have the time to review/respond to the comments or whether I should look for another reviewer (which is not a problem, just let me know) |
Hi @ltalirz sorry, admittedly I'm a bit swamped at the moment... If you find another reviewer that'd be great! Otherwise let me know an I'll try to prioritize checking this carefully |
@sphuber Since @giovannipizzi is busy, would you perhaps be able to give this a look? |
I would gladly take a look but It seems like @giovannipizzi had very specific comments about the changes and it doesn't seem like a PR that I can easily take over. I am not so familiar with the |
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 added some little comments. The main logical change I suggest is the following: we now make it legal to set the cell to None, BUT this is only valid for pbc = (False, False, False)
. Note that this is NOT enforced at every function call, but ONLY in the _validate
(i.e. before storing), and some methods will check and raise if this is not the case (e.g. get_dimensionality).
This still breaks backward incompatibility because now cell is not set anymore to diag([1, 1, 1])
.
I hope nobody was relying on it for actual simulations; on the other hand people might have relied on it e.g. for testing... Probably this is OK to change in 2.0 (@ltalirz however mention this in the wiki page with the list of changes of 2.0).
I still have a conceptual issue that I mentioned in my original comment to the issue: this kind of improves the situation for 0D systems, but still leaves the issue for the non-PBC directions of 1D and 2D systems... Probably it's OK as fixing it properly would require more massive changes, but I would still like to point out this problem.
If we want to solve it as ASE does, one should also allow for zero size of the cell:
ase.build.surface('Al', (1, 0, 0), layers=3)
that returns Atoms(symbols='Al12', pbc=[True, True, False], cell=[4.05, 4.05, 0.0])
Anyway, I'm quite sure that this is "recent" behaviour of ASE ("recent" = after I wrote the initial class, i.e. < 7 years ;-) ).
for more information, see https://pre-commit.ci
Ah, then I remembered correctly! ASE used to have the AiiDA choice |
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 a lot @ltalirz, this seems good to me! :-)
Is there any documentation we need to update? (Could you please check?)
Also, can you please add a note here, for users? https://github.com/aiidateam/aiida-core/wiki/AiiDA-2.0-plugin-migration-guide
@ltalirz will you take are of fixing the failing tests? |
Checked aiida-core docs and didn't find anything that needed updating;
Done! |
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 a lot @ltalirz !
`_validate_and_fix_ase_cell` function is not needed anymore, since it add a dummy cell to gas phase molecule. In the old AiiDA, there needed to be default cell, otherwise StructureData would not work. But that has been fixed so we should get rid of this login in AWB. The fix in aiida-core was done here aiidateam/aiida-core#5341 and released in version 2.0 https://github.com/aiidateam/aiida-core/blob/main/CHANGELOG.md#v200---2022-04-27
fix #5248
Prior to this change, when a user would create a
StructureData
without specifying a cell,AiiDA would set a default cell
That is problematic, since this cell is not distinguishable from a valid cell.
We therefore change the default cell to
[[0,0,0],[0,0,0],[0,0,0]]
, mirroringe.g. how things work in ASE.
Furthermore, we remove the requirement that a cell set by the user must have
a finite 3d volume, since a cell with zero volume is an appropriate choice when storing non-periodic
structures (molecules, ...).
The only requirement we retain is that structures that are indicated as nd-periodic
must have a finite nd volume. This requirement is validated upon calling
.store()
.Note: Since we are not changing the default value of
pbc
, this means that the following will now raise:When trying to store "dummy" instances of
StructureData
, users can use the following instead: