Update phono3py-load options

This commit is contained in:
Atsushi Togo 2022-05-08 15:57:05 +09:00
parent 5e733eb629
commit b0a4064905
5 changed files with 102 additions and 16 deletions

View File

@ -53,6 +53,7 @@ workload-distribution
cutoff-pair
external-tools
phono3py-api
phono3py-load
tips
citation
changelog

39
phono3py-load.md Normal file
View File

@ -0,0 +1,39 @@
(phono3py_load_command)=
# phono3py-load command
After phono3py v2.3.2, `phono3py-load` command is installed. This behaves
similarly to `phono3py.load` ({ref}`api-phono3py-load`) in the phono3py python
module. The main aim of introducing this command is to provide uniform usage
over many different force calculators. Once `phono3py_disp.yaml` is created, the
following operations will be the same using this command.
The following default behaviours are different from that of those of `phono3py`
command:
1. `phono3py_xxx.yaml` type file is always necessary in either of two ways:
- `phono3py_xxx.yaml` type file is given as the first argument of the
command.
- `phono3py_xxx.yaml` type file is put in the current directory with one of
the default filenames of `phono3py_params.yaml`, `phono3py_disp.yaml`,
`phono3py.yaml`. The searching preference order is `phono3py_params.yaml` >
`phono3py_disp.yaml` > `phono3py.yaml`.
2. `-c` option (read crystal structure) does not exist.
3. `-d` option (create displacements) does not exist.
4. Use of command options is recommended, but phono3py configuration file can be
read through `--config` option.
5. If parameters for non-analytical term correction (NAC) are found, NAC is
automatically enabled. This can be disabled by `--nonac` option.
6. When force constants are calculated from displacements and forces dataset,
force constants are automatically symmetrized. To disable this, `--no-sym-fc`
option is used.
7. `-o` option works differently from `phono3py` command. This option requires
one argument of string. The string is used as the output yaml filename that
replaces the default output yaml filename of `phono3py.yaml`.

View File

@ -181,6 +181,14 @@ def get_parser(fc_symmetry=False, is_nac=False, load_phono3py_yaml=False):
default=False,
help="Solve collective phonons",
)
if load_phono3py_yaml:
parser.add_argument(
"--config",
dest="conf_filename",
metavar="FILE",
default=None,
help="Phono3py configuration file",
)
parser.add_argument(
"--const-ave-pp",
dest="const_ave_pp",
@ -540,7 +548,14 @@ def get_parser(fc_symmetry=False, is_nac=False, load_phono3py_yaml=False):
"sampling modes of imag-self-energy calculation"
),
)
if not load_phono3py_yaml:
if load_phono3py_yaml:
parser.add_argument(
"-o",
dest="output_yaml_filename",
default=None,
help="Output yaml filename instead of default filename of phono3py.yaml",
)
else:
parser.add_argument(
"-o", dest="output_filename", default=None, help="Output filename extension"
)

View File

@ -112,10 +112,10 @@ def print_phono3py():
def finalize_phono3py(
phono3py: Phono3py,
confs,
confs_dict,
log_level,
displacements_mode=False,
filename="phono3py.yaml",
filename=None,
):
"""Write phono3py.yaml and then exit.
@ -123,7 +123,7 @@ def finalize_phono3py(
----------
phono3py : Phono3py
Phono3py instance.
confs : dict
confs_dict : dict
This contains the settings and command options that the user set.
log_level : int
Log level. 0 means quiet.
@ -135,6 +135,11 @@ def finalize_phono3py(
phono3py.yaml is written in this filename.
"""
if filename is None:
yaml_filename = "phono3py.yaml"
else:
yaml_filename = filename
if displacements_mode:
_calculator = phono3py.calculator
else:
@ -144,19 +149,19 @@ def finalize_phono3py(
yaml_settings = {"force_sets": False, "displacements": displacements_mode}
ph3py_yaml = Phono3pyYaml(
configuration=confs, physical_units=_physical_units, settings=yaml_settings
configuration=confs_dict, physical_units=_physical_units, settings=yaml_settings
)
ph3py_yaml.set_phonon_info(phono3py)
ph3py_yaml.calculator = _calculator
with open(filename, "w") as w:
with open(yaml_filename, "w") as w:
w.write(str(ph3py_yaml))
if log_level > 0:
print("")
if displacements_mode:
print('Displacement dataset was written in "%s".' % filename)
print(f'Displacement dataset was written in "{yaml_filename}".')
else:
print('Summary of calculation was written in "%s".' % filename)
print(f'Summary of calculation was written in "{yaml_filename}".')
print_end()
sys.exit(0)
@ -233,7 +238,9 @@ def read_phono3py_settings(args, argparse_control, log_level):
file_exists(args.filename[0], log_level)
if load_phono3py_yaml:
phono3py_conf_parser = Phono3pyConfParser(
args=args, default_settings=argparse_control
filename=args.conf_filename,
args=args,
default_settings=argparse_control,
)
cell_filename = args.filename[0]
else:
@ -246,13 +253,18 @@ def read_phono3py_settings(args, argparse_control, log_level):
)
cell_filename = phono3py_conf_parser.settings.cell_filename
else:
phono3py_conf_parser = Phono3pyConfParser(args=args)
if load_phono3py_yaml:
phono3py_conf_parser = Phono3pyConfParser(
args=args, filename=args.conf_filename
)
else:
phono3py_conf_parser = Phono3pyConfParser(args=args)
cell_filename = phono3py_conf_parser.settings.cell_filename
confs = phono3py_conf_parser.confs.copy()
confs_dict = phono3py_conf_parser.confs.copy()
settings = phono3py_conf_parser.settings
return settings, confs, cell_filename
return settings, confs_dict, cell_filename
def create_FORCES_FC2_from_FORCE_SETS_then_exit(log_level):
@ -997,10 +1009,12 @@ def main(**argparse_control):
if load_phono3py_yaml:
input_filename = None
output_filename = None
output_yaml_filename = args.output_yaml_filename
else:
(input_filename, output_filename) = get_input_output_filenames_from_args(args)
output_yaml_filename = None
settings, confs, cell_filename = read_phono3py_settings(
settings, confs_dict, cell_filename = read_phono3py_settings(
args, argparse_control, log_level
)
@ -1067,7 +1081,7 @@ def main(**argparse_control):
finalize_phono3py(
phono3py,
confs,
confs_dict,
log_level,
displacements_mode=True,
filename="phono3py_disp.yaml",
@ -1359,4 +1373,4 @@ def main(**argparse_control):
+ "-" * 11
)
finalize_phono3py(phono3py, confs, log_level)
finalize_phono3py(phono3py, confs_dict, log_level, filename=output_yaml_filename)

View File

@ -81,6 +81,7 @@ class Phono3pySettings(Settings):
"read_gamma": False,
"read_phonon": False,
"read_pp": False,
"output_yaml_filename": None,
"phonon_supercell_matrix": None,
"pinv_cutoff": 1.0e-8,
"pinv_solver": 0,
@ -243,6 +244,10 @@ class Phono3pySettings(Settings):
"""Set num_points_in_batch."""
self._v["num_points_in_batch"] = val
def set_output_yaml_filename(self, val):
"""Set output_yaml_filename."""
self._v["output_yaml_filename"] = val
def set_phonon_supercell_matrix(self, val):
"""Set phonon_supercell_matrix."""
self._v["phonon_supercell_matrix"] = val
@ -507,6 +512,10 @@ class Phono3pyConfParser(ConfParser):
if num_points_in_batch is not None:
self._confs["num_points_in_batch"] = num_points_in_batch
if "output_yaml_filename" in self._args:
if self._args.output_yaml_filename is not None:
self._confs["output_yaml_filename"] = self._args.output_yaml_filename
if "pinv_cutoff" in self._args:
if self._args.pinv_cutoff is not None:
self._confs["pinv_cutoff"] = self._args.pinv_cutoff
@ -661,7 +670,11 @@ class Phono3pyConfParser(ConfParser):
self.set_parameter(conf_key, int(confs[conf_key]))
# string
if conf_key in ("conductivity_type", "create_forces_fc3_file"):
if conf_key in (
"conductivity_type",
"create_forces_fc3_file",
"output_yaml_filename",
):
self.set_parameter(conf_key, confs[conf_key])
# specials
@ -868,6 +881,10 @@ class Phono3pyConfParser(ConfParser):
if "max_freepath" in params:
self._settings.set_max_freepath(params["max_freepath"])
# Output yaml filename instead of default filename of phono3py.yaml.
if "output_yaml_filename" in params:
self._settings.set_output_yaml_filename(params["output_yaml_filename"])
# Cutoff frequency for pseudo inversion of collision matrix
if "pinv_cutoff" in params:
self._settings.set_pinv_cutoff(params["pinv_cutoff"])