Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get FC import from CASTEP 25.1 working #364

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
oerc0122 marked this conversation as resolved.
Show resolved Hide resolved
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
13 changes: 12 additions & 1 deletion euphonic/readers/castep.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,19 @@ 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 +538,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:
oerc0122 marked this conversation as resolved.
Show resolved Hide resolved
pass

Expand Down
Binary file not shown.
Binary file not shown.
Loading