Skip to content

Commit

Permalink
Merge pull request #258 from QuantumChemist/main
Browse files Browse the repository at this point in the history
Make sure that supercell_matrices of single-atom-displaced and rattled supercells are the same per default
  • Loading branch information
QuantumChemist authored Nov 20, 2024
2 parents f339119 + a84458d commit cb1393f
Show file tree
Hide file tree
Showing 8 changed files with 452 additions and 392 deletions.
29 changes: 28 additions & 1 deletion src/autoplex/auto/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
from dataclasses import dataclass, field
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -41,6 +42,7 @@
run_supercells,
)
from autoplex.benchmark.phonons.jobs import write_benchmark_metrics
from autoplex.data.phonons.jobs import reduce_supercell_size_job
from autoplex.fitting.common.flows import MLIPFitMaker

__all__ = [
Expand Down Expand Up @@ -186,7 +188,9 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
atomwise_regularization_list: list | None = None
soap_delta_list: list | None = None
n_sparse_list: list | None = None
supercell_settings: dict = field(default_factory=lambda: {"min_length": 15})
supercell_settings: dict = field(
default_factory=lambda: {"min_length": 15, "max_length": 20}
)
benchmark_kwargs: dict = field(default_factory=dict)
path_to_default_hyperparameters: Path | str = MLIP_PHONON_DEFAULTS_FILE_PATH
summary_filename_prefix: str = "results_"
Expand Down Expand Up @@ -245,6 +249,8 @@ def make(
pymatgen structure for benchmarking.
benchmark_mp_ids: list[str] | None
Materials Project ID of the benchmarking structure.
use_defaults_fitting: bool
Use the fit defaults.
fit_kwargs : dict.
dict including MLIP fit keyword args.
Expand All @@ -266,6 +272,27 @@ def make(
}

for structure, mp_id in zip(structure_list, mp_ids):
self.supercell_settings.setdefault(mp_id, {})
logging.info(
"Currently, "
"the same supercell settings for single-atom displaced and rattled supercells are used."
)
supercell_matrix_job = reduce_supercell_size_job(
structure=structure,
min_length=self.supercell_settings.get("min_length", 15),
max_length=self.supercell_settings.get("max_length", 20),
fallback_min_length=self.supercell_settings.get(
"fallback_min_length", 12
),
max_atoms=self.supercell_settings.get("max_atoms", 500),
min_atoms=self.supercell_settings.get("min_atoms", 50),
step_size=self.supercell_settings.get("step_size", 1.0),
)
flows.append(supercell_matrix_job)
self.supercell_settings[mp_id][
"supercell_matrix"
] = supercell_matrix_job.output

if self.add_dft_random_struct:
add_dft_rand = self.add_dft_random(
structure=structure,
Expand Down
19 changes: 18 additions & 1 deletion src/autoplex/auto/phonons/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,26 @@ def dft_phonopy_gen_data(
jobs = []
dft_phonons_output = {}
dft_phonons_dir_output = []
if supercell_settings is None:
supercell_settings = field(
default_factory=lambda: {"min_length": 15, "max_length": 20}
)
supercell_matrix = supercell_settings.get(mp_id, {}).get("supercell_matrix")
if not supercell_matrix:
supercell_matrix = reduce_supercell_size(structure, **supercell_settings)
filtered_settings = { # mismatching mp_ids would lead to a key error
key: value
for key, value in supercell_settings.items()
if key
in [
"min_length",
"max_length",
"fallback_min_length",
"max_atoms",
"min_atoms",
"step_size",
]
}
supercell_matrix = reduce_supercell_size(structure, **filtered_settings)

if phonon_displacement_maker is None:
phonon_displacement_maker = TightDFTStaticMaker(name="dft phonon static")
Expand Down
24 changes: 21 additions & 3 deletions src/autoplex/data/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ class RandomStructuresDataGenerator(Maker):
rattle_seed: int = 42
rattle_mc_n_iter: int = 10
w_angle: list[float] | None = None
supercell_settings: dict | None = field(default_factory=lambda: {"min_length": 15})
supercell_settings: dict | None = field(
default_factory=lambda: {"min_length": 15, "max_length": 20}
)

def make(
self,
Expand All @@ -378,7 +380,9 @@ def make(
If None, will default to [0.90, 0.95, 0.98, 0.99, 1.01, 1.02, 1.05, 1.10].
"""
if self.supercell_settings is None:
self.supercell_settings = field(default_factory=lambda: {"min_length": 15})
self.supercell_settings = field(
default_factory=lambda: {"min_length": 15, "max_length": 20}
)
jobs = [] # initializing empty job list
outputs = []

Expand Down Expand Up @@ -733,9 +737,23 @@ def make_from_ml_model(
self.phonon_displacement_maker,
self.static_energy_maker,
) = ml_prep
filtered_settings = {
key: value
for key, value in supercell_settings.items()
if key
in [
"min_length",
"max_length",
"fallback_min_length",
"max_atoms",
"min_atoms",
"step_size",
]
}
supercell_matrix = reduce_supercell_size(
structure=structure, **supercell_settings
structure=structure, **filtered_settings
)

flow = self.make(
structure=structure, supercell_matrix=supercell_matrix, **make_kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion src/autoplex/data/phonons/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def reduce_supercell_size_job(
structure: Structure,
min_length: float = 18,
max_length: float = 22,
max_length: float = 20,
fallback_min_length: float = 12,
min_atoms: int = 100,
max_atoms: int = 500,
Expand Down
7 changes: 4 additions & 3 deletions src/autoplex/fitting/common/mlip-phonon-defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"do_copy_at_file": "F",
"openmp_chunk_size": 10000,
"gp_file": "gap_file.xml",
"two_body": true,
"e0_offset": 0.0,
"two_body": false,
"three_body": false,
"soap": true
},
Expand Down Expand Up @@ -45,10 +46,10 @@
"atom_sigma": 0.5,
"zeta": 4,
"cutoff": 5.0,
"cutoff_transition_width": 0.5,
"cutoff_transition_width": 1.0,
"central_weight": 1.0,
"n_sparse": 6000,
"delta": 0.50,
"delta": 1.00,
"f0": 0.0,
"covariance_type": "dot_product",
"sparse_method": "cur_points"
Expand Down
Loading

0 comments on commit cb1393f

Please sign in to comment.