Skip to content

[Code scan] Fix VASP tutorial commands and parsed output paths #44

Description

@njzjz

This issue comes from a Codex global repository scan.

Problem

The VASP quickstart points --root at a single calculation directory and uses an empty prefix:

```bash
dftio parse \
--mode vasp \
--root example/vasp/GaAs \
--prefix "" \
--outroot ./parsed_data \
--eigenvalue
```

The parser discovers calculations with glob(os.path.join(root, '*' + prefix + '*')):

dftio/dftio/io/parse.py

Lines 64 to 67 in c9d128f

if isinstance(root, list) and all(isinstance(item, str) for item in root):
self.raw_datas = root
else:
self.raw_datas = glob.glob(os.path.join(root, '*' + prefix + '*'))

With --root example/vasp/GaAs --prefix "", discovery returns files like EIGENVAL and POSCAR, then the VASP parser tries to read EIGENVAL/POSCAR:

super(VASPParser, self).__init__(root, prefix)
self.raw_sys = [read(self.raw_datas[idx]+'/POSCAR') for idx in range(len(self.raw_datas))]
log.warning("VASP parser only supports the static (SCF or NSCF) calculations. MD and RELAX is not supported yet.")

The band tutorial has the same root issue and also omits --eigenvalue:

```bash
dftio parse \
--mode vasp \
--root example/vasp/GaAs \
--outroot ./parsed_bands
```

The docs also describe a top-level 0.dat, but write_dat() creates <formula>.<idx>/cell.dat, kpoints.npy, and eigenvalues.npy:

dftio/dftio/io/parse.py

Lines 251 to 267 in c9d128f

out_dir = os.path.join(outroot, self.formula(idx=idx)+".{}".format(idx))
os.makedirs(out_dir, exist_ok=True)
# The abacus must have PBC, so here we save cell by default
# np.savetxt(os.path.join(out_dir, "cell.dat"), structure[_keys.CELL_KEY].reshape(-1, 3))
# np.savetxt(os.path.join(out_dir, "positions.dat"), structure[_keys.POSITIONS_KEY].reshape(-1, 3))
# np.savetxt(os.path.join(out_dir, "atomic_numbers.dat"), structure[_keys.ATOMIC_NUMBERS_KEY], fmt='%d')
# np.savetxt(os.path.join(out_dir, "pbc.dat"), structure[_keys.PBC_KEY])
# write structure
self.write_struct(structure, out_dir, fmt=fmt)
# write eigenvalue
if eigenvalue:
eigstatus = self.get_eigenvalue(idx=idx, band_index_min=band_index_min)
self.check_eigenvalue(idx=idx, eigstatus=eigstatus)
np.save(os.path.join(out_dir, "kpoints.npy"), eigstatus[_keys.KPOINT_KEY])
np.save(os.path.join(out_dir, "eigenvalues.npy"), eigstatus[_keys.ENERGY_EIGENVALUE_KEY])

dftio band -r ./parsed_data points one directory too high, and the plot file is band_structure.png:

self.kpoints = np.load(os.path.join(self.path, "kpoints.npy"))
self.eigs = np.load(os.path.join(self.path, "eigenvalues.npy"))
if len(self.eigs.shape)==3 :
assert self.eigs.shape[0]== 1, "only 1 band structure is supported!"
self.eigs = self.eigs[0]
assert self.eigs.shape[0] == self.kpoints.shape[0], "eigenvalues and kpoints shape mismatch!"
def plot(self, bmin:int=0, bmax:int=None):
# plot band structure
fig, ax = plt.subplots()
nbands = self.eigs.shape[1]
if bmax is None:
bmax = nbands
else:
bmax = min(bmax, nbands)
assert bmax>bmin, "max should be larger than min!"
if self.kpoints.shape[0] > 1:
ax.plot(self.eigs[:,bmin:bmax], 'b-', lw=1)
ax.set_xlabel("k-point")
ax.set_title("Band Structure")
else:
for e in self.eigs[0, bmin:bmax]:
ax.hlines(e, xmin=-0.5, xmax=0.5, color='b', linewidth=1)
ax.set_xticks([])
ax.set_title("Energy levels")
ax.text(0.5, 0.5, f"band windown: {bmin} - {bmax}", ha='center', va='center', transform=ax.transAxes)
ax.set_ylabel("Energy (eV)")
plt.savefig(os.path.join(self.path, "band_structure.png"), dpi=300)

Suggested fix

Use a command like --root example/vasp --prefix GaAs --eigenvalue, document the generated <formula>.0 subdirectory, and point dftio band -r at that subdirectory. Update the expected plot filename to band_structure.png.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions