Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure that supercell_matrices of single-atom-displaced and rattled supercells are the same per default #258

Merged
merged 33 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3022c3b
increase M3GNET RMSE tolereance because of fluctuations
QuantumChemist Nov 14, 2024
a01c5a6
prettify GAP parameters representation and remove GAP related things …
QuantumChemist Nov 14, 2024
f3d35a0
rearrange file entires to make it look better, added user-defined for…
QuantumChemist Nov 15, 2024
1b7e6c0
fix unit test
QuantumChemist Nov 15, 2024
3754c8c
fix unit test
QuantumChemist Nov 15, 2024
d76dc84
small format fix
QuantumChemist Nov 15, 2024
4dc423e
fix unit test
QuantumChemist Nov 15, 2024
c02bfc3
removed a comment
QuantumChemist Nov 15, 2024
1b95862
decrease default max_length for rattled supercells
QuantumChemist Nov 15, 2024
8d0c3a8
Merge branch 'autoatml:main' into main
QuantumChemist Nov 18, 2024
0337f46
reducing max_length default a bit
QuantumChemist Nov 18, 2024
e51db69
Merge branch 'main' of github.com:QuantumChemist/autoplex
QuantumChemist Nov 18, 2024
eacd697
added missing doctsring
QuantumChemist Nov 19, 2024
c89312c
set max_length to 20
QuantumChemist Nov 19, 2024
a508a53
set max_length to 20
QuantumChemist Nov 19, 2024
b8ae70c
add fallback to single-atom-dsipl- supercells
QuantumChemist Nov 19, 2024
10ac1e5
minor changes in file format
QuantumChemist Nov 19, 2024
bc5ca78
supercell_matrix is only determined once by reduce_supercell_size_job
QuantumChemist Nov 19, 2024
cb4c995
filter out supercell_matrix key to prevent problems with mismacthing …
QuantumChemist Nov 19, 2024
9f02c13
filter out supercell_matrix mpid key as mpids are not used here
QuantumChemist Nov 19, 2024
d60d9fc
adjust job number and remove print
QuantumChemist Nov 19, 2024
75f2668
adjust defaults
QuantumChemist Nov 19, 2024
6da2b0f
fix unit tests
QuantumChemist Nov 20, 2024
14a9eb5
fix unit tests
QuantumChemist Nov 20, 2024
776384d
putting the phonon GAP defaults to SI settings
QuantumChemist Nov 20, 2024
6b3ceb2
fix unit test
QuantumChemist Nov 20, 2024
125eec1
fix unit test
QuantumChemist Nov 20, 2024
a0f3d83
fix unit test
QuantumChemist Nov 20, 2024
f35ef28
added user info about supercell settings
QuantumChemist Nov 20, 2024
bbae8f5
Merge branch 'autoatml:main' into main
QuantumChemist Nov 20, 2024
bc7dec9
addressing Yb's comments
QuantumChemist Nov 20, 2024
5b35adf
adjust unit test
QuantumChemist Nov 20, 2024
a84458d
fix unit test
QuantumChemist Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +292 to +294
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaGeo , I restructured the code in a way that the reduce_supercell_size_job is only called once and the matrix is passed like that. But I have left the reduce_supercell_size_job (which only will be triggered if no matrix is gieven) in the other functions as it was before, too, in case a user wants to use the single-atom displ. and rattled supercell constructors separately.
I have thought a lot about it and I don't see a reason why single-atom displ. and rattled supercells of the same wf should have different settings. Do you think I shall still add the possibility?

Copy link
Collaborator

@JaGeo JaGeo Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be that someone wants it. At the moment, I also do not see a clear use case. Let's, for now, keep it with this single job. Just make sure everything works with this functionality for now and we just keep in mind that we don't have it implemented yet :).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see if I can maybe put some "NotImplemented" warning. In principle the user can still at the moment pass different settings if they call the supercell constructors separately.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a simple user info instead


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
Loading