ITADN

[BUG] Converting from Quantum Espresso cp.x traj gives error when there is only one line in the energy output file

#899OpenConstant206462 创建于 2025-09-20
bug
C
Constant206462commented
### Bug summary In dpdata/qe/traj.py in `load_energy` function `data = np.loadtxt(fname)` is expected to be 2D array, but in the case when the .evp file contains a single line, it becomes a 1D array, which raises error afterwards. Solution: add the following after loading the data `if data.ndim == 1: data = data[np.newaxis, :]` ### dpdata Version dpdata v0.2.25 ### Input Files, Running Commands, Error Log, etc. Input files: [qe-cpx.zip](https://github.com/user-attachments/files/22440887/qe-cpx.zip) Error log: dpdata --from_format qe/cp/traj P Traceback (most recent call last): File "/home/constant/miniconda3/envs/deepmd310/bin/dpdata", line 8, in <module> sys.exit(dpdata_cli()) ^^^^^^^^^^^^ File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/cli.py", line 56, in dpdata_cli convert(**vars(parsed_args)) File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/cli.py", line 96, in convert s = LabeledSystem(from_file, fmt=from_format, type_map=type_map) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/system.py", line 197, in __init__ self.from_fmt( File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/system.py", line 234, in from_fmt return self.from_fmt_obj(load_format(fmt), file_name, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/system.py", line 1224, in from_fmt_obj data = fmtobj.from_labeled_system(file_name, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/plugins/qe.py", line 31, in from_labeled_system data["energies"], data["forces"], es = dpdata.qe.traj.to_system_label( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/qe/traj.py", line 262, in to_system_label energy, esteps = load_energy(prefix + ".evp", begin=begin, step=step) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/constant/miniconda3/envs/deepmd310/lib/python3.12/site-packages/dpdata/qe/traj.py", line 174, in load_energy for ii in data[begin::step, 0]: ~~~~^^^^^^^^^^^^^^^^ IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed ### Steps to Reproduce Unpack zip and run `dpdata --from_format qe/cp/traj P` ### Further Information, Files, and Links _No response_
3 条评论