Skip to content

Commit

Permalink
Make error check slightly safer for old Castep format
Browse files Browse the repository at this point in the history
"except ValueError" is a bit broad and could catch unrelated
problems. Checking that _read_entry returned an int is still not 100%
specific to the problem but seems safer.
  • Loading branch information
ajjackson committed Apr 18, 2024
1 parent 0d3f089 commit cddba3c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions euphonic/readers/castep.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,19 @@ def read_interpolation_data(
np.reshape(_read_entry(f, float_type),
(n_cells_in_sc, 3*n_atoms, 3*n_atoms)),
axes=[0, 2, 1]))
try:
cell_origins = np.reshape(
_read_entry(f, int_type), (n_cells_in_sc, 3))
except ValueError:

cell_origins = _read_entry(f, int_type)
if isinstance(cell_origins, int):
raise ValueError('Old castep file detected: '
'Euphonic only supports post-Castep 17.1 files. '
'Please rerun the calculation with a newer version '
'of Castep with the original .cell file and a '
'.castep file with a single line with the '
'"continuation: <old.castep_bin>" keyword and '
'use the new output .castep_bin file in Euphonic.')

cell_origins = np.reshape(cell_origins, (n_cells_in_sc, 3))

_ = _read_entry(f, int_type) # FC row not used
elif header == b'BORN_CHGS':
born = np.reshape(
Expand Down

0 comments on commit cddba3c

Please sign in to comment.