deepmodeling / deepmodeling/dftio
[Code scan] Convert atom-type arrays to scalars in feature_to_block
- 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
`feature_to_block()` indexes `ase.data.chemical_symbols` with the ndarray returned by `idp.untransform(...)`:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/interfaces/ham_to_feature.py#L199
The same pattern appears for edge atoms:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/interfaces/ham_to_feature.py#L226-L227
When atom types are shaped like `(N, 1)`, `idp.untransform(data[_keys.ATOM_TYPE_KEY][atom].reshape(-1))` returns an array such as `array([14])`, and list indexing with that ndarray raises `TypeError`.
## Suggested fix
Convert the untransformed result to a scalar before indexing:
```python
atomic_number = int(np.asarray(idp.untransform(...)).reshape(-1)[0])
symbol = ase.data.chemical_symbols[atomic_number]
```
Contributor guide
Assessment
This issue has not been assessed yet.