deepmodeling / deepmodeling/dftio

[Code scan] Fix LDOS valence-band slicing and z-scan indexing

Open Beginner friendly
#40 0 comments 0 reactions 0 assignees View on GitHub
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
`LDOS.__init__()` computes `self.n_valbands` with `/`, so it stores a float:

https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/calc/ldos.py#L49-L50

`LDOS.get()` later assigns that float to `n` and uses it as a slice bound:

https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/calc/ldos.py#L97-L105

This raises `TypeError: slice indices must be integers` when `z_valence` is provided.

`LDOS.scan()` also has a left-branch off-by-one: `ldos_wbias_diff` has length `nz - 1`, but the loop indexes it up to `i == nz - 1`:

https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/calc/ldos.py#L205-L207

## Suggested fix
Validate valence-band divisibility and store an integer band count. In `scan()`, iterate only over valid diff indices and explicitly write to the corresponding shifted z-plane.

Contributor guide

Open the contributing guide

Research direction

Start in dftio/calc/ldos.py and read LDOS.__init__(), LDOS.get(), and LDOS.scan() around the cited lines. Check the valence-band count and scan loop against their expected bounds. Done means z_valence no longer causes a slice-index error, valence-band divisibility is validated, and scan indexing stays within ldos_wbias_diff while writing to the shifted z-plane.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
Half a day
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.