Skip to content

Commit

Permalink
Get FC import from CASTEP 25.1 working
Browse files Browse the repository at this point in the history
- CASTEP 25.1 adds extra fields to BORN and DIELECTRIC sections of
  castep_bin file; read (and discard) this information
- It also seems to _create_ a BORN section even if you didn't need
  one? That throws off some Euphonic logic which assumes you would
  only ever have BORN and DIELECTRIC data at the same time.
- As FC behaviour isn't really defined when you only have one, let's
  discard it in that case.

I need to test a wider range of import/present/not-present cases to be
sure this will always do the right thing.
  • Loading branch information
ajjackson committed Feb 6, 2025
1 parent d0b6851 commit 254b47c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 4 additions & 4 deletions euphonic/force_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ def __init__(self, crystal: Crystal, force_constants: Quantity,
self.cell_origins = cell_origins
self.n_cells_in_sc = n_sc

if born is not None:
if born is not None and dielectric is not None:
self._born = born.to(ureg.e).magnitude
self.born_unit = str(born.units)
self._dielectric = dielectric.to(ureg(
'e**2/(bohr*hartree)')).magnitude
self.dielectric_unit = str(dielectric.units)
else:
self._born = born
self._born = None
self.born_unit = str(ureg.e)
self._dielectric = dielectric
self._dielectric = None
self.dielectric_unit = str(ureg((
'e**2/(bohr*hartree)')))

Expand Down Expand Up @@ -473,7 +473,7 @@ def _calculate_phonons_at_qpts(
[weights], [[np.ndarray, type(None)]], [(len(qpts),)], ['weights'])

# Set default splitting params
if self.born is None:
if self.born is None or self.dielectric is None:
dipole = False
if not dipole:
splitting = False
Expand Down
14 changes: 13 additions & 1 deletion euphonic/readers/castep.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,20 @@ def read_interpolation_data(
elif header == b'BORN_CHGS':
born = np.reshape(
_read_entry(f, float_type), (n_atoms, 3, 3))

if castep_version > Version("25.1"):
# Extra field marks if born charges were read from BORN
_ = _read_entry(f)


elif header == b'DIELECTRIC':
entry = _read_entry(f, float_type)
dielectric = np.transpose(np.reshape(
_read_entry(f, float_type), (3, 3)))
entry, (3, 3)))

if castep_version > Version("25.1"):
# Extra field marks if dielectric tensor was read from BORN
_ = _read_entry(f)

data_dict: Dict[str, Any] = {}
cry_dict = data_dict['crystal'] = {}
Expand Down Expand Up @@ -528,6 +539,7 @@ def read_interpolation_data(
data_dict['dielectric'] = dielectric*ureg(
'e**2/(hartree*bohr)').to(dielectric_unit).magnitude
data_dict['dielectric_unit'] = dielectric_unit

except UnboundLocalError:
pass

Expand Down

0 comments on commit 254b47c

Please sign in to comment.