pace-neutrons / Euphonic

Euphonic is a Python package for efficient simulation of phonon bandstructures, density of states and inelastic neutron scattering intensities from force constants.
GNU General Public License v3.0
28 stars 11 forks source link

Cannot read Castep 16.11 bin file #295

Closed mducle closed 6 months ago

mducle commented 6 months ago

The following is a valid .castep_bin file as far as I can tell, and has the required FORCE_CON field but euphonic gives the following error when trying to read it:

cp-out.castep_bin.zip

>>> fc = ForceConstants.from_castep("cp-out.castep_bin")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\\mambaforge\envs\eu39\lib\site-packages\euphonic\force_constants.py", line 1833, in from_castep
    data = castep.read_interpolation_data(filename)
  File "C:\mambaforge\envs\eu39\lib\site-packages\euphonic\readers\castep.py", line 472, in read_interpolation_data
    cell_origins = np.reshape(
  File "C:\mambaforge\envs\eu39\lib\site-packages\numpy\core\fromnumeric.py", line 285, in reshape
    return _wrapfunc(a, 'reshape', newshape, order=order)
  File "C:\mambaforge\envs\eu39\lib\site-packages\numpy\core\fromnumeric.py", line 56, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)
  File "C:\mambaforge\envs\eu39\lib\site-packages\numpy\core\fromnumeric.py", line 45, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)
ValueError: cannot reshape array of size 1 into shape (1,3)

The file was generated by Castep 16.11 - possibly there was some change of format of the bin-files between Castep-16 and Castep-19 which was what euphonic was written against.

krefson commented 6 months ago

There was a change in the format of the checkpoint file in 17.1, which would affect the reading by Euphonic. (The field phonon_supercell_origins was added).

There's code in CASTEP to read older versions of the checkpoint file, so the easiest thing to do may be to perform a minimal "continuation" run (Literally just have one line in the param reading "continuation : "; you will need the original .cell file too). Run with the current version and this ought to regenate a checkpoint which Euphonic can read.

mducle commented 6 months ago

If there is demand for this, we could compute the phonon_supercell_origins field in Euphonic. There is already some code in the phonopy reader which could be repurposed for this.