Skip to content

Commit

Permalink
Merge branch 'develop' into publish-gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Sep 3, 2024
2 parents 3123d3d + b7fea1a commit 7087bb8
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
exclude: ^example/AlN-LDA/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.6.3
hooks:
- id: ruff
args: [ "--fix", "--show-fixes" ]
Expand Down
76 changes: 47 additions & 29 deletions doc/command-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ These options have no respective configuration file tags.

This is used to create `FORCES_FC3` from `phono3py_disp.yaml` and force
calculator outputs containing forces in supercells. `phono3py_disp.yaml` has to
be located at the current directory. Calculator interface has to be specified
except for VASP (default) case.
be located at the current directory.

```bash
% phono3py --cf3 disp-{00001..00755}/vasprun.xml
Expand All @@ -97,14 +96,26 @@ except for VASP (default) case.
% phono3py --cf3 supercell_out/disp-{00001..00111}/Si.out
```

````{note}
The calculator interface should be stored in `phono3py_disp.yaml`, so it is not
needed to set it manually. Command-line-options like `--qe` will be ignored. If
the calculator interface is missing from `phono3py_disp.yaml` but needed, please
update the `phono3py` section in the file as follows:
```yaml
phono3py:
calculator: qe
```
````

(cf3_file_option)=

### `--cf3-file` (command option only)

This is used to create `FORCES_FC3` from a text file containing a list of
calculator output file names. `phono3py_disp.yaml` has to be located at the
current directory. Calculator interface has to be specified except for VASP
(default) case.
current directory. The calculator interface is unnecessary to specify, see the
note at {ref}`--cf3 <cf3_option>`.

```bash
% phono3py --cf3-file file_list.dat
Expand All @@ -130,8 +141,9 @@ together with `--cutoff-pair` option.

This is used to create `FORCES_FC2` similarly to `--cf3` option.
`phono3py_disp.yaml` has to be located at the current directory. This is
optional. Calculator interface has to be specified except for VASP (default)
case. `FORCES_FC2` is necessary to run with `--dim-fc2` option.
optional. `FORCES_FC2` is necessary to run with `--dim-fc2` option. The
calculator interface is unnecessary to specify, see the note at {ref}`--cf3
<cf3_option>`.

```bash
% phono3py --cf2 disp_fc2-{00001..00002}/vasprun.xml
Expand All @@ -142,8 +154,8 @@ case. `FORCES_FC2` is necessary to run with `--dim-fc2` option.
### `--cfz` (command option only)

This is used to create `FORCES_FC3` and `FORCES_FC2` subtracting residual forces
combined with `--cf3` and `--cf2`, respectively. Calculator interface has to be
specified except for VASP (default) case.
combined with `--cf3` and `--cf2`, respectively. The calculator interface is
unnecessary to specify, see the note at {ref}`--cf3 <cf3_option>`.

In the following example, it is supposed that `disp3-00000/vasprun.xml` and
`disp2-00000/vasprun.xml` contain the forces of the perfect supercells. In ideal
Expand Down Expand Up @@ -204,7 +216,6 @@ When using with `--cf2`, `--cf3` has to be specified simultaneously as below,
% phono3py --cf3 disp-{00001..00755}/vasprun.xml --cf2 disp_fc2-{00001..00002}/vasprun.xml --sp
```


## Supercell, primitive cell, masses, magnetic moments

(dim_option)=
Expand Down Expand Up @@ -299,6 +310,7 @@ web page](https://phonopy.github.io/phonopy/setting-tags.html#magmom).
## Displacement creation

(create_displacements_option)=

### `-d` (`CREATE_DISPLACEMENTS = .TRUE.`)

**`phono3py-load` doesn't have this option.**
Expand All @@ -317,6 +329,7 @@ information about primitive cell (`primitive_matrix` key) in
```

(random_displacements_option)=

### `--rd` (`RANDOM_DISPLACEMENTS`), `--rd-fc2` (`RANDOM_DISPLACEMENTS_FC2`) and `--random-seed` (`RANDOM_SEED`)

**`phono3py-load` doesn't have this option.**
Expand All @@ -336,6 +349,7 @@ and/or `--rd-fc2`,
```

(amplitude_option)=

### `--amplitude` (`DISPLACEMENT_DISTANCE`)

**`phono3py-load` doesn't have this option.**
Expand All @@ -348,6 +362,7 @@ The default value depends on calculator. See
{ref}`default_displacement_distance_for_calculator`.

(fc_calculator_option)=

### `--fc-calc`, `--fc-calculator` (`FC_CALCULATOR`)

Choice of force constants calculator.
Expand All @@ -357,14 +372,17 @@ Choice of force constants calculator.
```

To use different force constants calculators for fc2 and fc3

```bash
% phono3py-load --fc-calc "symfc|" ...
```

Those for fc2 and fc3 are seprated by `|` such as `symfc|` . Blank means to
employ the finite difference method for systematic displacements generated by
the option `-d`.

(fc_calculator_options_option)=

### `--fc-calc-opt`, `--fc-calculator-options` (`FC_CALCULATOR_OPTIONS`)

Special options for force constants calculators.
Expand Down Expand Up @@ -608,9 +626,9 @@ $$
\bigl|\Phi_{-\lambda\lambda'\lambda''}\bigl|^2
\left\{(n_{\lambda'}+ n_{\lambda''}+1)
\delta(\omega-\omega_{\lambda'}-\omega_{\lambda''}) \right.
+ (n_{\lambda'}-n_{\lambda''})
* (n_{\lambda'}-n_{\lambda''})
\left[\delta(\omega+\omega_{\lambda'}-\omega_{\lambda''})
+ \left. \delta(\omega-\omega_{\lambda'}+\omega_{\lambda''})
* \left. \delta(\omega-\omega_{\lambda'}+\omega_{\lambda''})
\right]\right\}.
$$

Expand Down Expand Up @@ -840,7 +858,7 @@ $$
\bigl|\Phi_{-\lambda\lambda_1\lambda_2}\bigl|^2
(n_{\lambda_1}-n_{\lambda_2})
\left[\delta(\omega+\omega_{\lambda_1}-\omega_{\lambda_2})
+ \delta(\omega-\omega_{\lambda_1}+\omega_{\lambda_2})
* \delta(\omega-\omega_{\lambda_1}+\omega_{\lambda_2})
\right]
\end{align*}
$$
Expand All @@ -854,7 +872,7 @@ $$
\bigl|\Phi_{-\lambda\lambda_1\lambda_2}\bigl|^2
(n_{\lambda_1}+ n_{\lambda_2}+1)
\left[ \delta(\omega-\omega_{\lambda_1}-\omega_{\lambda_2})
+ \delta(\omega + \omega_{\lambda_1} + \omega_{\lambda_2}) \right]
* \delta(\omega + \omega_{\lambda_1} + \omega_{\lambda_2}) \right]
\end{align*},
$$

Expand Down Expand Up @@ -922,11 +940,11 @@ $$
\bigl|\Phi_{-\lambda\lambda_1\lambda_2}\bigl|^2 &
\left\{(n_{\lambda_1}+ n_{\lambda_2}+1)
\left[ \delta(\omega-\omega_{\lambda_1}-\omega_{\lambda_2})
+ \delta(\omega+\omega_{\lambda_1}+\omega_{\lambda_2}) \right] \right.
* \delta(\omega+\omega_{\lambda_1}+\omega_{\lambda_2}) \right] \right.
\\
& + (n_{\lambda_1}-n_{\lambda_2})
\left[\delta(\omega+\omega_{\lambda_1}-\omega_{\lambda_2})
+ \left. \delta(\omega-\omega_{\lambda_1}+\omega_{\lambda_2})
* \left. \delta(\omega-\omega_{\lambda_1}+\omega_{\lambda_2})
\right]\right\},
\end{align*}
$$
Expand All @@ -941,14 +959,14 @@ $$
\left\{
\left[ \frac{(n_{\lambda_1}+ n_{\lambda_2}+1)}{
(\omega-\omega_{\lambda_1}-\omega_{\lambda_2})_\mathrm{p}}
+ \frac{(n_{\lambda_1}+ n_{\lambda_2}+1)}{
* \frac{(n_{\lambda_1}+ n_{\lambda_2}+1)}{
(\omega+\omega_{\lambda_1}+\omega_{\lambda_2})_\mathrm{p}}
\right]
\right. \\
& + \left[
\frac{(n_{\lambda_1}-n_{\lambda_2})}{(\omega +
\omega_{\lambda_1} - \omega_{\lambda_2})_\mathrm{p}}
+ \left. \frac{(n_{\lambda_1}-n_{\lambda_2})}{(\omega -
* \left. \frac{(n_{\lambda_1}-n_{\lambda_2})}{(\omega -
\omega_{\lambda_1} + \omega_{\lambda_2})_\mathrm{p}}
\right]\right\},
\end{align*}
Expand Down Expand Up @@ -1012,7 +1030,7 @@ A_\lambda(\omega) = \frac{1}{\pi} \frac{4\Omega^2_\lambda
\Gamma_\lambda(\omega)}
{\left[\omega^2 - \Omega^2_\lambda -
2\Omega_\lambda \Delta_\lambda(\omega) \right]^2
+ \left[ 2\Omega_\lambda
* \left[ 2\Omega_\lambda
\Gamma_\lambda(\omega) \right]^2},
$$

Expand Down Expand Up @@ -1348,12 +1366,12 @@ Using this option, output file names are slightly modified. For example, with

This rule is applied to

+ `fc3.hdf5`
+ `fc2.hdf5`
+ `kappa-xxx.hdf5`
+ `phonon-xxx.hdf5`
+ `pp-xxx.hdf5`
+ `gamma_detail-xxx.hdf5` (write only)
* `fc3.hdf5`
* `fc2.hdf5`
* `kappa-xxx.hdf5`
* `phonon-xxx.hdf5`
* `pp-xxx.hdf5`
* `gamma_detail-xxx.hdf5` (write only)

(input_filename_option)=

Expand All @@ -1367,11 +1385,11 @@ specifying `-i iso --fc3`, a file name `fc3.iso.hdf5` is read instead of

This rule is applied to

+ `fc3.hdf5`
+ `fc2.hdf5`
+ `kappa-xxx.hdf5`
+ `phonon-xxx.hdf5`
+ `pp-xxx.hdf5`
* `fc3.hdf5`
* `fc2.hdf5`
* `kappa-xxx.hdf5`
* `phonon-xxx.hdf5`
* `pp-xxx.hdf5`

### `--io` (command option only)

Expand Down
7 changes: 6 additions & 1 deletion phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
PypolymlpParams,
develop_polymlp,
evalulate_polymlp,
load_polymlp,
parse_mlp_params,
)
from phonopy.structure.atoms import PhonopyAtoms
Expand Down Expand Up @@ -2226,8 +2227,12 @@ def develop_mlp(
verbose=self._log_level - 1 > 0,
)

def load_mlp(self, filename: str = "pypolymlp.mlp"):
"""Load machine learning potential of pypolymlp."""
self._mlp = load_polymlp(filename=filename)

def evaluate_mlp(self):
"""Evaluate the machine learning potential of pypolymlp.
"""Evaluate machine learning potential of pypolymlp.
This method calculates the supercell energies and forces from the MLP
for the displacements in self._dataset of type 2. The results are stored
Expand Down
28 changes: 20 additions & 8 deletions phono3py/cui/create_force_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ def parse_forces(
distance_to_A=physical_units["distance_to_A"],
force_to_eVperA=physical_units["force_to_eVperA"],
)

assert dataset is not None

if "natom" in dataset and dataset["natom"] != natom:
Expand All @@ -273,6 +272,12 @@ def parse_forces(
f'Displacement dataset for {fc_type} was read from "{filename_read_from}".'
)

if calculator is not None and log_level:
print(
f"Displacements and forces were converted from {calculator} "
"unit to A and eV/A."
)

# Overwrite dataset['cutoff_distance'] when necessary.
if fc_type == "fc3" and cutoff_pair_distance:
if "cutoff_distance" not in dataset or (
Expand Down Expand Up @@ -497,7 +502,8 @@ def _read_dataset_fc3(
file_exists(e.filename, log_level=log_level)

if use_pypolymlp:
phono3py.mlp_dataset = dataset
if forces_in_dataset(dataset):
phono3py.mlp_dataset = dataset
run_pypolymlp_to_compute_forces(
phono3py,
mlp_params,
Expand All @@ -516,6 +522,7 @@ def run_pypolymlp_to_compute_forces(
displacement_distance: Optional[float] = None,
number_of_snapshots: Optional[int] = None,
random_seed: Optional[int] = None,
mlp_filename: str = "pypolymlp.mlp",
log_level: int = 0,
):
"""Run pypolymlp to compute forces."""
Expand All @@ -531,10 +538,18 @@ def run_pypolymlp_to_compute_forces(
print(f" {k}: {v}")
if log_level > 1:
print("")
if log_level:
print("Developing MLPs by pypolymlp...", flush=True)

ph3py.develop_mlp(params=mlp_params)
if forces_in_dataset(ph3py.mlp_dataset):
if log_level:
print("Developing MLPs by pypolymlp...", flush=True)
ph3py.develop_mlp(params=mlp_params)
else:
if pathlib.Path(mlp_filename).exists():
if log_level:
print(f'Load MLPs from "{mlp_filename}".')
ph3py.load_mlp(mlp_filename)
else:
raise RuntimeError(f'"{mlp_filename}" is not found.')

if log_level:
print("-" * 30 + " pypolymlp end " + "-" * 31, flush=True)
Expand Down Expand Up @@ -572,9 +587,6 @@ def run_pypolymlp_to_compute_forces(
flush=True,
)

if ph3py.mlp_dataset is None:
msg = "mlp_dataset has to be set before calling this method."
raise RuntimeError(msg)
if ph3py.supercells_with_displacements is None:
raise RuntimeError("Displacements are not set. Run generate_displacements.")

Expand Down
27 changes: 23 additions & 4 deletions phono3py/cui/create_force_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from phonopy.cui.create_force_sets import check_number_of_force_files
from phonopy.cui.load_helper import get_nac_params
from phonopy.cui.phonopy_script import file_exists, files_exist, print_error
from phonopy.file_IO import parse_FORCE_SETS, write_FORCE_SETS
from phonopy.file_IO import is_file_phonopy_yaml, parse_FORCE_SETS, write_FORCE_SETS
from phonopy.interface.calculator import get_calc_dataset

from phono3py.file_IO import (
Expand Down Expand Up @@ -72,10 +72,24 @@ def create_FORCES_FC3_and_FORCES_FC2(
"""
interface_mode = settings.calculator

disp_filename_candidates = [
"phono3py_disp.yaml",
]
if cell_filename is not None:

if log_level:
print("")

if (
log_level
and cell_filename is not None
and not is_file_phonopy_yaml(cell_filename, keyword="phono3py")
):
print(f'*Unnecessary to specify "{cell_filename}".')

if cell_filename is not None and is_file_phonopy_yaml(
cell_filename, keyword="phono3py"
):
disp_filename_candidates.insert(0, cell_filename)
disp_filenames = files_exist(
disp_filename_candidates, log_level=log_level, is_any=True
Expand All @@ -86,6 +100,10 @@ def create_FORCES_FC3_and_FORCES_FC2(
if ph3py_yaml.calculator is not None:
interface_mode = ph3py_yaml.calculator # overwrite

if interface_mode is not None:
if log_level:
print(f"Calculator interface: {interface_mode}")

if settings.create_forces_fc3 or settings.create_forces_fc3_file:
calc_dataset_fc3 = _get_force_sets_fc3(
settings, ph3py_yaml.dataset, disp_filename, interface_mode, log_level
Expand Down Expand Up @@ -172,7 +190,9 @@ def create_FORCE_SETS_from_FORCES_FCx(
phonon_smat, input_filename: Optional[str], cell_filename: Optional[str], log_level
):
"""Convert FORCES_FC3 or FORCES_FC2 to FORCE_SETS."""
if cell_filename is not None:
if cell_filename is not None and is_file_phonopy_yaml(
cell_filename, keyword="phono3py"
):
disp_filename = cell_filename
elif input_filename is None:
disp_filename = "phono3py_disp.yaml"
Expand Down Expand Up @@ -286,7 +306,6 @@ def _get_force_sets_fc3(
settings, disp_dataset, disp_filename, interface_mode, log_level
) -> dict:
if log_level:
print("")
print(f'FC3 Displacement dataset was read from "{disp_filename}".')

if "first_atoms" in disp_dataset: # type-1
Expand Down
Loading

0 comments on commit 7087bb8

Please sign in to comment.