deepmodeling / deepmodeling/dftio
[Code scan] Fix AtomicData registration and batched conversion crashes
- Dominant language
- Jupyter Notebook
- Stars
- 16
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
This issue comes from a Codex global repository scan.
## Problem
Several `AtomicData` code paths mix PyTorch assumptions into NumPy objects or mishandle optional batched data:
`register_fields(env_fields=...)` and `register_fields(onsitenv_fields=...)` always fail because `allfields` includes those fields but the RHS uniqueness count omits them:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/AtomicData.py#L141-L142
Batched validation uses `ndarray.view(-1, 3, 3)`, which is not reshape for NumPy arrays:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/AtomicData.py#L377
`to_ase()` enters the `cell is None` branch and then dereferences `cell.shape`:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/AtomicData.py#L680-L684
Unbatched `to_ase(extra_fields=...)` sets masks to `slice(None)` and later calls `.sum()` on those slices:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/AtomicData.py#L729-L733
## Suggested fix
Include env/onsitenv fields in the uniqueness count and duplicate checks, replace NumPy `view(-1, 3, 3)` with `reshape(-1, 3, 3)`, handle `cell is None` without dereferencing it, and branch unbatched extra-field masking away from `.sum()` on `slice` objects.
Contributor guide
Research direction
Start in dftio/data/AtomicData.py at the referenced register_fields, batched validation, and to_ase sections. Reproduce the four reported paths, then verify registration, batched validation, cell-less conversion, and unbatched extra-field conversion complete without crashes and preserve their expected data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100