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

Enable more refined supercell settings and adapt DFT settings in phonon workflow #100

Merged
merged 121 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
44a916c
adapt_supercell_algo
JaGeo Sep 4, 2024
3102b60
uncomment special treatment of large supercells for now
JaGeo Sep 4, 2024
0d4516c
generalize sueprcell settings
JaGeo Sep 4, 2024
bcb348f
fix supercells ml
JaGeo Sep 4, 2024
bcbac92
fix tests
JaGeo Sep 5, 2024
2035fb2
remove some custodian handlers
JaGeo Sep 5, 2024
b41fe72
fix typo
JaGeo Sep 5, 2024
af4bf58
remove layers of complexity in workflow construction
JaGeo Sep 6, 2024
15878a3
remove more layers
JaGeo Sep 6, 2024
b3545d9
remove layered flows in tutorial
JaGeo Sep 6, 2024
ed4ee96
Set default NPAR
JaGeo Sep 6, 2024
a5d8ac7
add a draft for a settings test workflow
JaGeo Sep 8, 2024
7467350
extend draft supercell job
JaGeo Sep 8, 2024
85d1eb3
replace displacement maker
JaGeo Sep 8, 2024
7bc7563
Fix supercell flow
JaGeo Sep 10, 2024
e7e50f1
fix supercell generation
JaGeo Sep 10, 2024
aff71cb
fix enumeration bug
JaGeo Sep 10, 2024
b5fdaaf
add some draft text for doc
JaGeo Sep 10, 2024
a02b850
fix second enumerate problem
JaGeo Sep 10, 2024
c6d5258
debug test worfklow propertly
JaGeo Sep 10, 2024
63bdaae
fix settings
JaGeo Sep 11, 2024
ab3fad5
fix supercell code
JaGeo Sep 12, 2024
20178c6
add mpid
JaGeo Sep 12, 2024
4e20836
fix workflow
JaGeo Sep 13, 2024
339d4d7
Merge pull request #103 from JaGeo/main
QuantumChemist Sep 17, 2024
600253f
ignore test submission file
QuantumChemist Sep 17, 2024
e4ac467
adjusting the docs
QuantumChemist Sep 17, 2024
36162da
renamed adaptive supercell settings to supercell settings and removed…
QuantumChemist Sep 17, 2024
a1f9de4
changed type hint
QuantumChemist Sep 17, 2024
8e49142
remove all TightDFTStaticMakerBigSupercells references and instances
QuantumChemist Sep 17, 2024
b2040c7
adding preprocessing_data=True to the documentation to make sure user…
QuantumChemist Sep 18, 2024
de093c0
Added hint adapted from libatoms GAP tutorial (https://libatoms.githu…
QuantumChemist Sep 18, 2024
3c6d38c
add mp-id key to outputs
QuantumChemist Sep 24, 2024
8bb62b2
adapt chanes
JaGeo Sep 25, 2024
3ad9698
combine
JaGeo Sep 25, 2024
5ada9e1
add info to fitting
JaGeo Sep 25, 2024
6fffa2f
enforcing n_structres = 10 as min, and fixing variable names and dosc…
QuantumChemist Sep 26, 2024
ab985da
fix linting
QuantumChemist Sep 26, 2024
09caa3f
Merge branch 'main' into adapt_supercell_algo
JaGeo Oct 1, 2024
52257e1
add comment
JaGeo Oct 1, 2024
67ea22c
Update autoplex/fitting/common/utils.py
JaGeo Oct 1, 2024
77cd627
update atomate2 requirement
JaGeo Oct 3, 2024
fb24c14
remove setting environment variable
JaGeo Oct 4, 2024
5f00830
test openblas
JaGeo Oct 5, 2024
979f09c
tryingto set all openblas libraries to unparallel use
JaGeo Oct 5, 2024
59c2db3
test switching this to a flow
JaGeo Oct 7, 2024
4a8895a
right pin on atomate2
JaGeo Oct 7, 2024
58e6ead
remove another layer of job flow
JaGeo Oct 7, 2024
e44cffb
uncommnt loop
JaGeo Oct 7, 2024
f8739bd
remove if clause causing flows to fail
JaGeo Oct 8, 2024
647126a
simplify code
JaGeo Oct 8, 2024
dc40838
remove todos
JaGeo Oct 8, 2024
657eb3c
this is just to check if pushing works
QuantumChemist Oct 9, 2024
e192807
Update pyproject.toml
QuantumChemist Oct 9, 2024
99fa3e4
Merge pull request #138 from autoatml/main
QuantumChemist Oct 9, 2024
aecd3d1
pre-commit fixes
QuantumChemist Oct 9, 2024
54785e3
pre-commit autoupdate
QuantumChemist Oct 9, 2024
286e56e
pre-commit fixes
QuantumChemist Oct 9, 2024
050c777
fix unit tests
QuantumChemist Oct 9, 2024
7d35d80
remove debug prints
QuantumChemist Oct 9, 2024
ff3101e
adjust unit test to new minimum required numbers of rattled structure…
QuantumChemist Oct 9, 2024
34a83bc
Merge pull request #139 from autoatml/main
QuantumChemist Oct 9, 2024
49c73e4
precommit autoupdate
QuantumChemist Oct 9, 2024
e380d40
added some type hints
QuantumChemist Oct 10, 2024
af2c766
change num_processes_fit example to 48
QuantumChemist Oct 10, 2024
d557323
remove test files
JaGeo Oct 10, 2024
a54996f
add mpids to names
JaGeo Oct 10, 2024
5480997
switch off custodian
JaGeo Oct 10, 2024
70e90f8
fix auto flow tests, fix write_benchmark, break lots of doc strings
JaGeo Oct 14, 2024
42e5bdf
fixing docstrings
QuantumChemist Oct 15, 2024
54d3f5d
displacement is now passed to MLPhononMaker and it's ensured that DFT…
QuantumChemist Oct 15, 2024
6cb8159
fixing small typo
QuantumChemist Oct 16, 2024
2cfae3c
fixing hyper_parameter_loop
QuantumChemist Oct 16, 2024
7b6398d
fixing unit test
QuantumChemist Oct 16, 2024
3f1a9d6
cleaned up the code
QuantumChemist Oct 16, 2024
0389f47
fixed unit test
QuantumChemist Oct 16, 2024
189f7d1
adjusted mlip default json file names
QuantumChemist Oct 17, 2024
28e901a
default soap_dict not automatically determined from default json file…
QuantumChemist Oct 17, 2024
e618f60
pre-commit migrate-config to fix codespell deprecated stage names
QuantumChemist Oct 17, 2024
f1d87f9
added unit test to check correct soap_dict
QuantumChemist Oct 17, 2024
cdcf103
added unit test to check correct soap_dict
QuantumChemist Oct 17, 2024
79d36b5
allow more error tolreance for gap fit because the value tends to flu…
QuantumChemist Oct 17, 2024
b42eab5
sort frequencies in total RMSE
QuantumChemist Oct 17, 2024
d24baed
remove parameter hyper_list as it is not used anymore
QuantumChemist Oct 17, 2024
27c02dd
solve merge conflicts
JaGeo Oct 17, 2024
fde1ee0
remove comment
JaGeo Oct 17, 2024
134cfe7
make sure no unnessesary VASP files are written
QuantumChemist Oct 18, 2024
2d24953
rearrange fucntions in file
QuantumChemist Oct 18, 2024
0357ef0
rearrange fucntions in file
QuantumChemist Oct 18, 2024
b570a5d
fix rmse sorting
QuantumChemist Oct 18, 2024
b2ea3f8
make VASP settings more user accessible
QuantumChemist Oct 18, 2024
5653658
added unit test for RMSE
QuantumChemist Oct 18, 2024
805b8de
small fix for passing inputgen to isoatommaker
QuantumChemist Oct 18, 2024
63139bf
expose IsoAtomStaticMaker
QuantumChemist Oct 21, 2024
ef49ed9
expose IsoAtomStaticMaker
QuantumChemist Oct 21, 2024
ed2dc76
adjust unit tests to reameing iso_atom job name
QuantumChemist Oct 21, 2024
8fdc395
added a unit test to check changing makers
QuantumChemist Oct 21, 2024
881b5ef
added a unit test to check changing makers
QuantumChemist Oct 21, 2024
3ad35c6
improved naming og the displcaement maker for rattled supercells
QuantumChemist Oct 21, 2024
d019a0f
improved naming of the displcaement maker for rattled supercells
QuantumChemist Oct 21, 2024
4d4dc7c
displacement maker adjustment in docs
QuantumChemist Oct 21, 2024
dea4676
added tst data and a proper unit test for checking different makers
QuantumChemist Oct 21, 2024
8dd8006
make sure unscaled rattled supercell is not added when int 1 and floa…
QuantumChemist Oct 21, 2024
c338de3
added scale_cell unit test
QuantumChemist Oct 21, 2024
d2a4dba
added test for reduce supercell size
QuantumChemist Oct 21, 2024
65a469c
fixing tests in test_auto_jobs
QuantumChemist Oct 21, 2024
ee93420
Merge pull request #154 from autoatml/main
QuantumChemist Oct 21, 2024
2de7edf
fixing tests in test_auto_flows
QuantumChemist Oct 21, 2024
fe7d798
fixing tests in test_fitting_utils
QuantumChemist Oct 21, 2024
5db58bb
Merge branch 'adapt_supercell_algo' of github.com:autoatml/autoplex i…
QuantumChemist Oct 21, 2024
80cf076
minor change
QuantumChemist Oct 21, 2024
9e23c51
trying without GAP in dict
QuantumChemist Oct 21, 2024
284d00d
fix dict test
JaGeo Oct 21, 2024
ca2faa4
try to fix dict
JaGeo Oct 22, 2024
752b4d3
remove line
JaGeo Oct 22, 2024
1303a0a
Merge branch 'main' of github.com:autoatml/autoplex into adapt_superc…
JaGeo Oct 22, 2024
1410dcb
empty line
JaGeo Oct 22, 2024
908fee0
Merge branch 'main' of github.com:autoatml/autoplex into adapt_superc…
JaGeo Oct 22, 2024
a8ebdd2
fix docs, fix pyproject
JaGeo Oct 22, 2024
18eba44
trying to print the metrics for testing
QuantumChemist Oct 22, 2024
6fa6ef5
fixing the unit test
QuantumChemist Oct 22, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ coverage.xml
.pytest_cache/
cover/
job*/
submit*

# Translations
*.mo
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.1
rev: v0.6.9
hooks:
- id: ruff
args: [--fix]
Expand All @@ -22,11 +22,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.10.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
rev: 1.19.0
hooks:
- id: blacken-docs
additional_dependencies: [black]
Expand All @@ -39,7 +39,7 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.11.2
hooks:
- id: mypy
files: ^autoplex/.*\.py$
Expand All @@ -48,7 +48,7 @@ repos:
- types-pkg_resources==0.1.2
- types-paramiko
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
stages: [commit, commit-msg]
Expand Down
154 changes: 94 additions & 60 deletions autoplex/auto/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any

from autoplex.data.phonons.flows import TightDFTStaticMaker

if TYPE_CHECKING:
from atomate2.common.schemas.phonons import PhononBSDOSDoc
from atomate2.vasp.jobs.base import BaseVaspMaker
from emmet.core.math import Matrix3D
from pymatgen.core.structure import Structure

from jobflow import Flow, Maker
Expand All @@ -17,12 +18,14 @@
complete_benchmark,
dft_phonopy_gen_data,
dft_random_gen_data,
generate_supercells,
get_iso_atom,
run_supercells,
)
from autoplex.benchmark.phonons.jobs import write_benchmark_metrics
from autoplex.fitting.common.flows import MLIPFitMaker

__all__ = ["CompleteDFTvsMLBenchmarkWorkflow"]
__all__ = ["CompleteDFTvsMLBenchmarkWorkflow", "DFTSupercellSettingsMaker"]


# Volker's idea: provide several default flows with different setting/setups
Expand Down Expand Up @@ -61,8 +64,6 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
Default=10.
displacements: list[float]
displacement distance for phonons
min_length: float
min length of the supercell that will be built
symprec: float
Symmetry precision to use in the
reduction of symmetry to find the primitive/conventional cell
Expand All @@ -71,8 +72,6 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
uc: bool.
If True, will generate randomly distorted structures (unitcells)
and add static computation jobs to the flow.
supercell_matrix: Matrix3D or None
The matrix to construct the supercell.
distort_type : int.
0- volume distortion, 1- angle distortion, 2- volume and angle distortion. Default=0.
volume_scale_factor_range : list[float]
Expand Down Expand Up @@ -117,8 +116,8 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
List of SOAP delta values that are checked.
n_sparse_list: list
List of GAP n_sparse values that are checked.
adaptive_supercell_settings: bool
prevent too big rattled supercells or too tight phonopy supercell settings.
supercell_settings: dict
settings for supercell generation
benchmark_kwargs: dict
kwargs for the benchmark flows
"""
Expand All @@ -130,13 +129,11 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
phonon_displacement_maker: BaseVaspMaker = None
n_structures: int = 10
displacements: list[float] = field(default_factory=lambda: [0.01])
min_length: int = 20
symprec: float = 1e-4
uc: bool = False
volume_custom_scale_factors: list[float] | None = None
volume_scale_factor_range: list[float] | None = None
rattle_std: float = 0.01
supercell_matrix: Matrix3D | None = None
distort_type: int = 0
min_distance: float = 1.5
angle_percentage_scale: float = 10
Expand All @@ -150,7 +147,7 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
atomwise_regularization_list: list | None = None
soap_delta_list: list | None = None
n_sparse_list: list | None = None
adaptive_supercell_settings: bool = True
supercell_settings: dict = field(default_factory=lambda: {"min_length": 15})
benchmark_kwargs: dict = field(default_factory=dict)

def make(
Expand Down Expand Up @@ -225,7 +222,6 @@ def make(
volume_custom_scale_factors=self.volume_custom_scale_factors,
volume_scale_factor_range=self.volume_scale_factor_range,
rattle_std=self.rattle_std,
supercell_matrix=self.supercell_matrix,
distort_type=self.distort_type,
min_distance=self.min_distance,
rattle_type=self.rattle_type,
Expand All @@ -234,23 +230,30 @@ def make(
angle_max_attempts=self.angle_max_attempts,
angle_percentage_scale=self.angle_percentage_scale,
w_angle=self.w_angle,
adaptive_rattled_supercell_settings=self.adaptive_supercell_settings,
supercell_settings=self.supercell_settings,
)
flows.append(addDFTrand)
fit_input.update({mp_id: addDFTrand.output})
if self.add_dft_phonon_struct:
addDFTphon = self.add_dft_phonons(
structure,
self.displacements,
self.symprec,
self.phonon_displacement_maker,
self.min_length,
self.adaptive_supercell_settings,
structure=structure,
displacements=self.displacements,
symprec=self.symprec,
phonon_displacement_maker=self.phonon_displacement_maker,
supercell_settings=self.supercell_settings,
)
flows.append(addDFTphon)
fit_input.update({mp_id: addDFTphon.output})
if self.add_dft_random_struct and self.add_dft_phonon_struct:
fit_input.update({mp_id: {**addDFTrand.output, **addDFTphon.output}})
fit_input.update(
{
mp_id: {
"rand_struc_dir": addDFTrand.output["rand_struc_dir"],
"phonon_dir": addDFTphon.output["phonon_dir"],
"phonon_data": addDFTphon.output["phonon_data"],
}
}
)
if self.add_rss_struct:
raise NotImplementedError

Expand Down Expand Up @@ -281,7 +284,7 @@ def make(
**fit_kwargs,
)
flows.append(add_data_fit)
if "regularization" in fit_kwargs and fit_kwargs["regularization"]:
if fit_kwargs.get("regularization"):
hyper_list.append(
{
"f="
Expand All @@ -291,7 +294,7 @@ def make(
hyper_list.append(
{"f=" + str(atomwise_regularization_parameter): "default"}
)
if "separated" in fit_kwargs and fit_kwargs["separated"]:
if fit_kwargs.get("separated"):
hyper_list.append(
{"f=" + str(atomwise_regularization_parameter): "default phonon"}
)
Expand All @@ -306,7 +309,6 @@ def make(
complete_bm = complete_benchmark(
ibenchmark_structure=ibenchmark_structure,
benchmark_structure=benchmark_structure,
min_length=self.min_length,
ml_model=ml_model,
ml_path=add_data_fit.output["mlip_path"],
mp_ids=mp_ids,
Expand All @@ -316,6 +318,7 @@ def make(
symprec=self.symprec,
phonon_displacement_maker=self.phonon_displacement_maker,
dft_references=dft_references,
supercell_settings=self.supercell_settings,
**self.benchmark_kwargs,
)
flows.append(complete_bm)
Expand Down Expand Up @@ -373,7 +376,6 @@ def make(
complete_bm = complete_benchmark(
ibenchmark_structure=ibenchmark_structure,
benchmark_structure=benchmark_structure,
min_length=self.min_length,
ml_model=ml_model,
ml_path=loop_data_fit.output["mlip_path"],
mp_ids=mp_ids,
Expand All @@ -383,6 +385,7 @@ def make(
symprec=self.symprec,
phonon_displacement_maker=self.phonon_displacement_maker,
dft_references=dft_references,
supercell_settings=self.supercell_settings,
**self.benchmark_kwargs,
)
flows.append(complete_bm)
Expand All @@ -399,14 +402,13 @@ def make(

return Flow(jobs=flows, output=collect_bm, name=self.name)

@staticmethod
def add_dft_phonons(
self,
structure: Structure,
displacements: list[float],
symprec: float,
phonon_displacement_maker: BaseVaspMaker,
min_length: float,
adaptive_phonopy_supercell_settings: bool = True,
supercell_settings: dict,
):
"""Add DFT phonon runs for reference structures.

Expand All @@ -423,39 +425,30 @@ def add_dft_phonons(
and to handle all symmetry-related tasks in phonopy
phonon_displacement_maker: BaseVaspMaker
Maker used to compute the forces for a supercell.
min_length: float
min length of the supercell that will be built
adaptive_phonopy_supercell_settings: bool
prevent too tight phonopy supercell settings
"""
additonal_dft_phonon = dft_phonopy_gen_data(
structure,
displacements,
symprec,
phonon_displacement_maker,
min_length,
adaptive_phonopy_supercell_settings,
)
supercell_settings: dict
supercell settings

return Flow(
jobs=additonal_dft_phonon, # flows
output={
"phonon_dir": additonal_dft_phonon.output["dirs"],
"phonon_data": additonal_dft_phonon.output["data"],
},
name=self.name,
"""
dft_phonons = dft_phonopy_gen_data(
structure=structure,
displacements=displacements,
symprec=symprec,
phonon_displacement_maker=phonon_displacement_maker,
supercell_settings=supercell_settings,
)
# let's append a name
dft_phonons.name = "single-atom displaced supercells"
return dft_phonons

@staticmethod
def add_dft_random(
self,
structure: Structure,
mp_id: str,
phonon_displacement_maker: BaseVaspMaker,
uc: bool = False,
volume_custom_scale_factors: list[float] | None = None,
volume_scale_factor_range: list[float] | None = None,
rattle_std: float = 0.01,
supercell_matrix: Matrix3D | None = None,
distort_type: int = 0,
n_structures: int = 10,
min_distance: float = 1.5,
Expand All @@ -465,7 +458,7 @@ def add_dft_random(
rattle_seed: int = 42,
rattle_mc_n_iter: int = 10,
w_angle: list[float] | None = None,
adaptive_rattled_supercell_settings: bool = True,
supercell_settings: dict | None = None,
):
"""Add DFT phonon runs for randomly displaced structures.

Expand All @@ -480,8 +473,6 @@ def add_dft_random(
uc: bool.
If True, will generate randomly distorted structures (unitcells)
and add static computation jobs to the flow.
supercell_matrix: Matrix3D or None
The matrix to construct the supercell.
distort_type : int.
0- volume distortion, 1- angle distortion, 2- volume and angle distortion. Default=0.
n_structures : int.
Expand Down Expand Up @@ -520,8 +511,8 @@ def add_dft_random(
Number of Monte Carlo iterations.
Larger number of iterations will generate larger displacements.
Default=10.
adaptive_rattled_supercell_settings: bool
prevent too big rattled supercells
supercell_settings: dict
settings for supercells
"""
additonal_dft_random = dft_random_gen_data(
structure=structure,
Expand All @@ -532,7 +523,6 @@ def add_dft_random(
volume_custom_scale_factors=volume_custom_scale_factors,
volume_scale_factor_range=volume_scale_factor_range,
rattle_std=rattle_std,
supercell_matrix=supercell_matrix,
distort_type=distort_type,
rattle_seed=rattle_seed,
rattle_mc_n_iter=rattle_mc_n_iter,
Expand All @@ -541,10 +531,54 @@ def add_dft_random(
angle_percentage_scale=angle_percentage_scale,
w_angle=w_angle,
min_distance=min_distance,
adaptive_rattled_supercell_settings=adaptive_rattled_supercell_settings,
supercell_settings=supercell_settings,
)
return Flow(
jobs=additonal_dft_random,
output={"rand_struc_dir": additonal_dft_random.output},
name=self.name,
additonal_dft_random.name = "rattled supercells"
return additonal_dft_random


@dataclass
class DFTSupercellSettingsMaker(Maker):
"""
Maker to test the DFT and supercell settings.

This maker is used to test your queue settings for the rattled and phonon supercells.
Although the cells are not displaced, it provides an impression of the required memory
and other resources as the process runs without symmetry considerations.

Parameters
----------
name (str): The name of the maker. Default is "test dft and supercell settings".
supercell_settings (dict): Settings for the supercells. Default is {"min_length": 15}.
DFT_Maker (BaseVaspMaker): The DFT maker to be used. Default is TightDFTStaticMaker.

"""

name: str = "test dft and supercell settings"
supercell_settings: dict = field(default_factory=lambda: {"min_length": 15})
DFT_Maker: BaseVaspMaker = field(default_factory=TightDFTStaticMaker)

def make(self, structure_list: list[Structure], mp_ids: list[str]):
"""
Generate and runs supercell jobs for the given list of structures.

Args:
structure_list (list[Structure]): List of structures to process.
mp_ids (list[str]): List of MP IDs.

Returns
-------
Flow: A Flow object containing the jobs and their output.
"""
job_list = []

# Modify to run for more than one cell
supercell_job = generate_supercells(structure_list, self.supercell_settings)
job_list.append(supercell_job)

supercell_job = run_supercells(
structure_list, supercell_job.output, mp_ids, self.DFT_Maker
)
job_list.append(supercell_job)

return Flow(jobs=job_list, output=supercell_job.output, name=self.name)
Loading
Loading