Skip to content

Conversation

@mbercx
Copy link
Member

@mbercx mbercx commented Nov 4, 2025

Note

There is a lot of code debt in the TrajectoryData, and the API is quite old and not optimal. Fixing all of that is beyond the scope of this PR, and probably we should redesign it in aiida-atomistic.

Fixes #6376
Fixes #7037

Pinging @danielhollas, @rikigigi and @dbidoggia for review, since they raised the original issues.

The current changes try to remain backwards-compatible for get_step_data, i.e. it now keeps on returning the same tuple of length 5. However, this does mean that the method does not return the pbc. For the get_step_structure method, I directly set the pbc from the property obtained from the attributes.

@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.63%. Comparing base (9b69202) to head (cdd3e3d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7079      +/-   ##
==========================================
+ Coverage   79.61%   79.63%   +0.03%     
==========================================
  Files         566      566              
  Lines       43546    43566      +20     
==========================================
+ Hits        34663    34690      +27     
+ Misses       8883     8876       -7     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbercx mbercx force-pushed the fix/trajectory-pbc branch from c263b2b to ac70fb7 Compare November 4, 2025 01:29
@mbercx mbercx closed this Nov 4, 2025
@mbercx mbercx force-pushed the fix/trajectory-pbc branch from ac70fb7 to d50cf17 Compare November 4, 2025 01:44
@mbercx mbercx reopened this Nov 4, 2025
@mbercx mbercx marked this pull request as ready for review November 4, 2025 01:51
@mbercx mbercx force-pushed the fix/trajectory-pbc branch 2 times, most recently from 16f0cc0 to 1af1745 Compare November 4, 2025 02:09
@mbercx mbercx changed the title [WIP] 🐛 TrajectoryData: Add pbc 🐛 TrajectoryData: Add pbc Nov 4, 2025

self._internal_validate(stepids, cells, symbols, positions, times, velocities)
# set symbols as attribute for easier querying
pbc = pbc or [True, True, True]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pbc = pbc or [True, True, True]
pbc = pbc or [True, True, True]

This default makes me uneasy. Should we instead look at the cells and see if it is defined and non-zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sensible check! My MC3D bias is showing again ^^

Copy link
Member Author

Choose a reason for hiding this comment

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

if it is defined and non-zero?

Can the cells be defined as zero? 🤔

Choose a reason for hiding this comment

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

Do not know when I would use a structure without specifying cells, but agree to consider them False if not specified

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently you can set e.g. cell = [[0, 0, 0], [0, 1, 0], [0, 0, 1]], but I'm not sure that's sensible? @danielhollas right now I've adapted the default to be [False, False, False] in case cells=None. Is that sufficient? Or what did you have in mind?

@dbidoggia
Copy link

Thanks @mbercx seems to be fine!

@mbercx mbercx requested a review from danielhollas November 5, 2025 23:29
Copy link
Collaborator

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

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

@mbercx thank you very much for working on this. I'd like to also try this out in my app to verify.

Also, can you please add test cases for the default PBC behaviour?

@mbercx mbercx force-pushed the fix/trajectory-pbc branch from 3b71180 to 4144eb6 Compare November 6, 2025 09:39
@mbercx
Copy link
Member Author

mbercx commented Nov 6, 2025

Done! Check if you agree with the logic:

  • If cells is None and
    • pbc is not specified (None) -> In this case we set pbc to [False, False, False]
    • pbc is equal to [False, False, False] -> All good
    • pbc is set to anything else -> raise. Can't have periodic boundary conditions without a cell, I suppose.
  • If cells is not None and
    • pbc is not specified (None) -> In this case raise a deprecation warning that it should be specified and will be set to [True, True, True]
    • pbc is specified -> All good

I've also added tests for all cases. Not sure if a deprecation makes too much sense long term, as I noted above we will replace the TrajectoryData with a new version in aiida-atomistic.

@mbercx mbercx requested a review from danielhollas November 6, 2025 09:45
Currently, the `TrajectoryData` is not functional for structures that are not periodic,
since their `pbc` property is not considered when using the `set_structurelist` method,
which is also used in the constructor.

Here we adapt the class to also accept the `pbc` input in the `set_trajectory` method.
The input should be a list/tuple of length 3 with boolean values, which is validated in
the `_internal_validate` method. It is also optional; in case it is not provided the
current default behavior is maintained, i.e. the structure is assumed to be periodic.
The `pbc` should also be the same for all structures in the trajectory, which is
validated in the `set_structurelist` method. In line with the current approach for
`symbols`, the `pbc` are stored in the attributes and a property is added.

The current changes try to remain backwards-compatible for `get_step_data`, i.e. it now
keeps on returning the same tuple of length 5. However, this does mean that the method
does not return the `pbc`. For the `get_step_structure` method, we intead directly set
the `pbc` from fhe property obtained from the attributes.
@mbercx mbercx force-pushed the fix/trajectory-pbc branch from 4144eb6 to cdd3e3d Compare November 18, 2025 05:45
@mbercx
Copy link
Member Author

mbercx commented Nov 18, 2025

@danielhollas if you have a moment, could you have another look? We could still squeeze this into 2.7.2, since it's fixing a bug in my view. I want to avoid having this open too long and it falling through the cracks. 🙏

@danielhollas
Copy link
Collaborator

Yep, it's in my todo list for this week, thanks for the ping!

FWIW: I am not sure this should go to the patch release: it's a non-trivial change that fixes a bug that's been there forever so I think it's okay for it to be released in minor version, as it is basically adding new capability (and changes the API).

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.

pbc in TrajectoryData TrajectoryData does not preserve periodicity information

3 participants