mirror of https://github.com/phonopy/phono3py.git
Merge pull request #390 from phonopy/fc3-cutoff-in-fdf5
Add fc3_cutoff entry in fc3.hdf5
This commit is contained in:
commit
8bf63c030c
|
@ -301,6 +301,7 @@ class Phono3py:
|
|||
self._fc2 = None
|
||||
self._fc3 = None
|
||||
self._fc3_nonzero_indices = None # available only symfc
|
||||
self._fc3_cutoff = None # available only symfc
|
||||
|
||||
# MLP
|
||||
self._mlp = None
|
||||
|
@ -365,6 +366,11 @@ class Phono3py:
|
|||
def fc3_nonzero_indices(self, fc3_nonzero_indices):
|
||||
self._fc3_nonzero_indices = fc3_nonzero_indices
|
||||
|
||||
@property
|
||||
def fc3_cutoff(self) -> float | None:
|
||||
"""Return cutoff value of fc3."""
|
||||
return self._fc3_cutoff
|
||||
|
||||
@property
|
||||
def fc2(self) -> NDArray | None:
|
||||
"""Setter and getter of second order force constants (fc2).
|
||||
|
@ -1537,6 +1543,9 @@ class Phono3py:
|
|||
if fc_calculator == "symfc":
|
||||
symfc_solver = cast(SymfcFCSolver, fc_solver.fc_solver)
|
||||
fc3_nonzero_elems = symfc_solver.get_nonzero_atomic_indices_fc3()
|
||||
options = symfc_solver.options
|
||||
if options is not None and "cutoff" in options:
|
||||
self._fc3_cutoff = options["cutoff"].get(3, None)
|
||||
if fc3_nonzero_elems is not None:
|
||||
if is_compact_fc:
|
||||
self._fc3_nonzero_indices = np.array(
|
||||
|
|
|
@ -164,6 +164,7 @@ def create_phono3py_force_constants(
|
|||
fc3_nonzero_indices=phono3py.fc3_nonzero_indices,
|
||||
filename=filename,
|
||||
p2s_map=phono3py.primitive.p2s_map,
|
||||
fc3_cutoff=phono3py.fc3_cutoff,
|
||||
compression=settings.hdf5_compression,
|
||||
)
|
||||
|
||||
|
|
|
@ -681,6 +681,7 @@ def _store_force_constants(ph3py: Phono3py, settings: Phono3pySettings, log_leve
|
|||
ph3py.fc3,
|
||||
fc3_nonzero_indices=ph3py.fc3_nonzero_indices,
|
||||
p2s_map=ph3py.primitive.p2s_map,
|
||||
fc3_cutoff=ph3py.fc3_cutoff,
|
||||
compression=settings.hdf5_compression,
|
||||
)
|
||||
if log_level:
|
||||
|
|
|
@ -307,6 +307,7 @@ def write_fc3_to_hdf5(
|
|||
fc3_nonzero_indices: NDArray | None = None,
|
||||
filename: str = "fc3.hdf5",
|
||||
p2s_map: NDArray | None = None,
|
||||
fc3_cutoff: float | None = None,
|
||||
compression: str = "gzip",
|
||||
):
|
||||
"""Write fc3 in fc3.hdf5.
|
||||
|
@ -325,6 +326,8 @@ def write_fc3_to_hdf5(
|
|||
p2s_map : ndarray, optional
|
||||
Primitive atom indices in supercell index system shape=(n_patom,),
|
||||
dtype=intc
|
||||
fc3_cutoff : float, optional
|
||||
Cutoff distance for fc3.
|
||||
compression : str or int, optional
|
||||
h5py's lossless compression filters (e.g., "gzip", "lzf"). None gives no
|
||||
compression. See the detail at docstring of h5py.Group.create_dataset.
|
||||
|
@ -338,6 +341,8 @@ def write_fc3_to_hdf5(
|
|||
w.create_dataset(
|
||||
"fc3_nonzero_indices", data=fc3_nonzero_indices, compression=compression
|
||||
)
|
||||
if fc3_cutoff is not None:
|
||||
w.create_dataset("fc3_cutoff", data=fc3_cutoff)
|
||||
if p2s_map is not None:
|
||||
w.create_dataset("p2s_map", data=p2s_map)
|
||||
|
||||
|
|
|
@ -128,6 +128,8 @@ def test_phono3py_load_with_typeII_dataset(
|
|||
assert "fc3_nonzero_indices" not in f
|
||||
else:
|
||||
assert "fc3_nonzero_indices" in f
|
||||
assert "fc3_cutoff" in f
|
||||
assert f["fc3_cutoff"][()] == pytest.approx(4.0)
|
||||
file_path.unlink()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue