Skip to content

Commit

Permalink
Merge pull request #32 from phonopy/phelel-script-read-nac
Browse files Browse the repository at this point in the history
Read NAC params in phelel command
  • Loading branch information
atztogo authored Oct 9, 2024
2 parents 57c63dc + 66349f0 commit e0ba360
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/phelel/api_phelel.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,5 +509,6 @@ def _get_phonopy(
symprec=self._symprec,
is_symmetry=self._is_symmetry,
store_dense_svecs=False,
calculator=self._calculator,
log_level=self._log_level,
)
17 changes: 16 additions & 1 deletion src/phelel/cui/create_supercells.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""Utilities of main CUI script."""

import pathlib
from typing import Optional, Union

from phono3py.interface.calculator import (
get_additional_info_to_write_fc2_supercells,
get_additional_info_to_write_supercells,
get_default_displacement_distance,
)
from phonopy.cui.phonopy_script import store_nac_params
from phonopy.interface.calculator import write_supercells_with_displacements

from phelel.api_phelel import Phelel
Expand All @@ -17,6 +19,7 @@ def create_phelel_supercells(
settings,
symprec,
interface_mode="vasp",
load_phelel_yaml=False,
log_level=1,
):
"""Create displacements and supercells.
Expand All @@ -26,6 +29,8 @@ def create_phelel_supercells(
"""
optional_structure_info = cell_info["optional_structure_info"]
unitcell_filename = cell_info["optional_structure_info"][0]
phe_yml = cell_info["phonopy_yaml"]

phelel = Phelel(
cell_info["unitcell"],
Expand All @@ -39,7 +44,7 @@ def create_phelel_supercells(

if log_level:
print("")
print('Unit cell was read from "%s".' % optional_structure_info[0])
print(f'Unit cell was read from "{unitcell_filename}".')

generate_phelel_supercells(
phelel,
Expand All @@ -50,6 +55,16 @@ def create_phelel_supercells(
log_level=log_level,
)

if pathlib.Path("BORN").exists() or (phe_yml and phe_yml.nac_params):
store_nac_params(
phelel.phonon,
settings,
phe_yml,
unitcell_filename,
log_level,
load_phonopy_yaml=load_phelel_yaml,
)

additional_info = get_additional_info_to_write_supercells(
interface_mode, phelel.supercell_matrix
)
Expand Down
25 changes: 19 additions & 6 deletions src/phelel/cui/phelel_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
print_error,
print_error_message,
print_version,
store_nac_params,
)
from phonopy.interface.calculator import get_default_physical_units
from phonopy.structure.cells import print_cell
Expand Down Expand Up @@ -47,22 +48,22 @@ def finalize_phelel(
filename: Union[str, pathlib.Path] = "phelel.yaml",
sys_exit_after_finalize: bool = True,
) -> None:
"""Write phono3py.yaml and then exit.
"""Write phelel.yaml and then exit.
Parameters
----------
phono3py : Phono3py
Phono3py instance.
phelel : Phelel
Phelel instance.
confs : dict
This contains the settings and command options that the user set.
log_level : int
Log level. 0 means quiet.
displacements_mode : Bool
When True, crystal structure is written in the length unit of
calculator interface in phono3py_disp.yaml. Otherwise, the
calculator interface in phelel_disp.yaml. Otherwise, the
default unit (angstrom) is used.
filename : str, optional
phono3py.yaml is written in this filename.
phelel.yaml is written in this filename.
"""
if displacements_mode:
Expand Down Expand Up @@ -165,6 +166,7 @@ def main(**argparse_control):
cell_info,
settings,
symprec,
load_phelel_yaml=load_phelel_yaml,
log_level=log_level,
)
finalize_phelel(
Expand All @@ -189,7 +191,7 @@ def main(**argparse_control):

if log_level > 0:
print("")
print('Crystal structure was read from "%s".' % unitcell_filename)
print(f'Crystal structure was read from "{unitcell_filename}".')
print("Settings:")
if (np.diag(np.diag(supercell_matrix)) - supercell_matrix).any():
print(" Supercell matrix:")
Expand Down Expand Up @@ -246,12 +248,23 @@ def main(**argparse_control):
print(f'Read displacement datasets from "{filename}".')
phe_yml = PhelelYaml()
phe_yml.read(filename)

phelel.dataset = phe_yml.dataset
if phe_yml.phonon_dataset is None:
phelel.phonon_dataset = phe_yml.dataset
else:
phelel.phonon_dataset = phe_yml.phonon_dataset

if pathlib.Path("BORN").exists() or phe_yml.nac_params:
store_nac_params(
phelel.phonon,
settings,
cell_info["phonopy_yaml"],
unitcell_filename,
log_level,
load_phonopy_yaml=load_phelel_yaml,
)

if settings.create_derivatives:
create_derivatives(
phelel,
Expand Down
2 changes: 1 addition & 1 deletion src/phelel/interface/vasp/derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,5 @@ def _read_PAW_strength_and_overlap(
Dijs.append(dij)
qijs.append(qij)
if log_level:
print('"{Dij_qij_path}" was read.')
print(f'"{Dij_qij_path}" was read.')
return Dijs, qijs
2 changes: 1 addition & 1 deletion test/cui/test_phelel_cui.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __contains__(self, item):


def test_phelel_script():
"""Test phonopy-load command."""
"""Test phelel command."""
# Check sys.exit(0)
cell_filename = str(cwd / ".." / "phelel_disp_C111.yaml")
argparse_control = _get_phelel_load_args(cell_filename=cell_filename)
Expand Down

0 comments on commit e0ba360

Please sign in to comment.