Skip to content

Commit

Permalink
Update pypolymlp feature
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Jun 28, 2024
1 parent 20a4021 commit 3d49320
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -2176,6 +2176,8 @@ def develop_mlp(self, params: Optional[Union[PypolymlpParams, dict, str]] = None

if params is not None:
_params = parse_mlp_params(params)
else:
_params = params

disps = self._mlp_dataset["displacements"]
forces = self._mlp_dataset["forces"]
Expand Down
36 changes: 24 additions & 12 deletions phono3py/cui/create_force_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def _create_phono3py_fc3(
cutoff_pair_distance: Optional[float],
fc_calculator: Optional[str],
fc_calculator_options: Optional[str],
use_pypoymplp: bool,
use_pypolymlp: bool,
mlp_params: Union[str, dict, PypolymlpParams],
displacement_distance: Optional[float],
number_of_snapshots: Optional[int],
Expand Down Expand Up @@ -495,7 +495,7 @@ def _create_phono3py_fc3(
# from _get_type2_dataset
file_exists(e.filename, log_level)

if use_pypoymplp:
if use_pypolymlp:
phono3py.mlp_dataset = dataset
run_pypolymlp_to_compute_forces(
phono3py,
Expand Down Expand Up @@ -524,19 +524,31 @@ def run_pypolymlp_to_compute_forces(
log_level: int,
):
"""Run pypolymlp to compute forces."""
if displacement_distance is None:
_displacement_distance = 0.001
else:
_displacement_distance = displacement_distance

if log_level:
print("-" * 29 + " pypolymlp start " + "-" * 30)
print("MLP parameters:")
print("Pypolymlp is a generator of polynomial machine learning potentials.")
print("Please cite the paper:")
print("A. Seko, J. Appl. Phys. 133, 011101 (2023).")
print("Pypolymlp is developed at https://github.com/sekocha/pypolymlp.")
if mlp_params:
print("Parameters:")
for k, v in asdict(parse_mlp_params(mlp_params)).items():
if v is not None:
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 displacement_distance is None:
_displacement_distance = 0.001
else:
_displacement_distance = displacement_distance

if log_level > 1:
print("")
if log_level:
if number_of_snapshots:
print("Generate random displacements")
Expand All @@ -547,7 +559,7 @@ def run_pypolymlp_to_compute_forces(
else:
print("Generate displacements")
print(
f" displacement distance: {_displacement_distance:.5f}".rstrip("0").rstrip(
f" Displacement distance: {_displacement_distance:.5f}".rstrip("0").rstrip(
"."
)
)
Expand All @@ -561,16 +573,16 @@ def run_pypolymlp_to_compute_forces(
if log_level:
print(
" Number of supercells for computing forces: "
f"{ph3py.displacements.shape[0]}",
flush=True,
f"{ph3py.displacements.shape[0]}"
)
print("Evaluate forces by pypolymlp", 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.")
ph3py.develop_mlp(params=mlp_params)

ph3py.evaluate_mlp()

if log_level:
Expand Down

0 comments on commit 3d49320

Please sign in to comment.