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

Implementation of adaptive supercell settings and improvement of the documentation #80

Merged
merged 59 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ed4f05e
improved jobflow-remote setup tutorial
QuantumChemist Jul 6, 2024
cff92f0
improved jobflow-remote setup tutorial
QuantumChemist Jul 6, 2024
e62eeef
fix minor typo
naik-aakash Jul 8, 2024
f988064
minor changes
QuantumChemist Jul 8, 2024
1eec958
improving jobflow-remote setup text
QuantumChemist Jul 8, 2024
16f1456
improving the jfr tutorial
QuantumChemist Jul 11, 2024
e4e8c24
prevent too big ratlled supercells
QuantumChemist Jul 11, 2024
ca798b9
prevent too tight phonopy supercell settings
QuantumChemist Jul 11, 2024
a50b3b3
improved unit test
QuantumChemist Jul 11, 2024
8c5380e
Merge branch 'JaGeo:main' into main
QuantumChemist Jul 18, 2024
431bd49
minor changes
QuantumChemist Jul 18, 2024
f2019c2
Merge branch 'main' of https://github.com/QuantumChemist/autoplex
QuantumChemist Jul 18, 2024
41e3224
adjusted adaptive supercell settings
QuantumChemist Jul 18, 2024
a7a2472
making data_preprocessing continue even if not all data calculations …
QuantumChemist Jul 25, 2024
21e4c61
change adaptive supercell routine
QuantumChemist Jul 26, 2024
b0477d1
update jfremote installation instruction
QuantumChemist Jul 31, 2024
87a5685
add warning
QuantumChemist Jul 31, 2024
343b197
add warning
QuantumChemist Jul 31, 2024
fa00767
unit test to check get_supercell_size
QuantumChemist Jul 31, 2024
c381339
adjust unit tests
QuantumChemist Jul 31, 2024
2808165
change benchmark DFT calcs to be also ffected by adaptive supercell s…
QuantumChemist Jul 31, 2024
f511621
started adding a reduce_phonopy_supercell_settings function
QuantumChemist Jul 31, 2024
6203ec5
adaptive supercell settings improvement
QuantumChemist Jul 31, 2024
7232e25
changes in reduce_supercell_size
QuantumChemist Aug 1, 2024
13c9eaf
setting supercell_matrix for phonopy supercells
QuantumChemist Aug 1, 2024
1d8b602
adjusting unit test
QuantumChemist Aug 1, 2024
f5579fe
adjust adaptive phonopy supercells
QuantumChemist Aug 5, 2024
1e3b7cd
adjusted adaptive supercell search
QuantumChemist Aug 6, 2024
3e3673b
adjusted adaptive supercell search
QuantumChemist Aug 6, 2024
61bed6f
adjusted adaptive supercell search
QuantumChemist Aug 6, 2024
87b12e7
adjusted adaptive supercell search
QuantumChemist Aug 7, 2024
799e988
adjusting unit test
QuantumChemist Aug 8, 2024
af7ceec
lets try this adaptive supercell settings
QuantumChemist Aug 9, 2024
2e56706
Merge branch 'main' into main
QuantumChemist Aug 9, 2024
3ebfb81
added a coarse step_size
QuantumChemist Aug 13, 2024
26241c5
added step_size
QuantumChemist Aug 13, 2024
ee3ae24
adjust atomate2 and pymatgen
QuantumChemist Aug 13, 2024
e395cb3
change matgl version because of dependencies conflicts caused by atom…
QuantumChemist Aug 13, 2024
4aed55e
changed one value
QuantumChemist Aug 23, 2024
d59d968
add a draft implementation
JaGeo Aug 24, 2024
698f2d8
add one fall back
JaGeo Aug 24, 2024
22703b5
change documentation
JaGeo Aug 24, 2024
e5072c8
Apply suggestions from code review
JaGeo Aug 24, 2024
e8a8f9f
cleanup
QuantumChemist Aug 26, 2024
9debe3b
replacing print with logging
QuantumChemist Aug 26, 2024
3071c15
minor changes
QuantumChemist Aug 26, 2024
e90111d
Merge pull request #5 from QuantumChemist/supercell_options_jg
QuantumChemist Aug 26, 2024
c7887bc
small change in dosctring
QuantumChemist Aug 26, 2024
9ef0b18
fixed several issues with the unit tests. Made reduce_supercell_size …
QuantumChemist Aug 26, 2024
2083467
fixed wrong logic
QuantumChemist Aug 26, 2024
de9b72b
more fixes
QuantumChemist Aug 26, 2024
d590116
fixed unit test with new atomate2 vasp input format
QuantumChemist Aug 27, 2024
bec0bfe
add missing dosctring
QuantumChemist Aug 27, 2024
e4f516c
remove mlip_haper and adjust documentation
QuantumChemist Aug 27, 2024
28b504f
fix mock vasp
QuantumChemist Aug 27, 2024
9d5bd25
add device=cpu for MACE test
QuantumChemist Aug 27, 2024
2ce7f14
add device=cuda for MACE documentation
QuantumChemist Aug 27, 2024
8db454f
fixing docstrings, variable names and types in the fit part
QuantumChemist Aug 27, 2024
a85dfad
fixing a few things regarding database_dir
QuantumChemist Aug 27, 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ After setting up `atomate2`, make sure to add `VASP_INCAR_UPDATES: {"NPAR": numb
Set a number that is a divisor of the number of tasks you use for the VASP calculations.

# Installation
autoplex relies on the atomate2 and ase frameworks.
`autoplex` relies on the `atomate2` and `ase` frameworks.

Developers installation: Navigate to autoplex and install it by `pip install -e .[docs,strict,dev]`.
Developers installation: Navigate to `autoplex` and install it by `pip install -e .[docs,strict,dev]`.

Alternatively, the dependencies atomate2 and ase can be installed individually via
Alternatively, the dependencies `atomate2` and `ase` can be installed individually via
```bash
pip install atomate2[strict]

pip install ase@git+https://gitlab.com/ase/ase.git@aae51d57721847624cea569f3a2d4bb6aa5032b4
```

Additionally, to be able to fit and validate `ACEpotentials`, one also needs to install julia as autoplex relies on [ACEpotentials](https://acesuit.github.io/ACEpotentials.jl/dev/gettingstarted/installation/) which support fitting of linear ACE and currently no python package exists for the same.
Please run following commands to enable ACEpotentials fitting and functionality.
Please run following commands to enable `ACEpotentials` fitting and functionality.

Install julia
`curl -fsSL https://install.julialang.org | sh`
Expand Down
21 changes: 20 additions & 1 deletion autoplex/auto/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ 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.
benchmark_kwargs: dict
kwargs for the benchmark flows
"""

name: str = "add_data"
Expand Down Expand Up @@ -146,6 +150,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
benchmark_kwargs: dict = field(default_factory=dict)

def make(
Expand Down Expand Up @@ -227,6 +232,7 @@ 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,
)
flows.append(addDFTrand)
fit_input.update({mp_id: addDFTrand.output})
Expand All @@ -237,6 +243,7 @@ def make(
self.symprec,
self.phonon_displacement_maker,
self.min_length,
self.adaptive_supercell_settings,
)
flows.append(addDFTphon)
fit_input.update({mp_id: addDFTphon.output})
Expand Down Expand Up @@ -398,6 +405,7 @@ def add_dft_phonons(
symprec: float,
phonon_displacement_maker: BaseVaspMaker,
min_length: float,
adaptive_phonopy_supercell_settings: bool = True,
):
"""Add DFT phonon runs for reference structures.

Expand All @@ -416,9 +424,16 @@ def add_dft_phonons(
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
structure,
displacements,
symprec,
phonon_displacement_maker,
min_length,
adaptive_phonopy_supercell_settings,
)

return Flow(
Expand Down Expand Up @@ -449,6 +464,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,
):
"""Add DFT phonon runs for randomly displaced structures.

Expand Down Expand Up @@ -503,6 +519,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
"""
additonal_dft_random = dft_random_gen_data(
structure=structure,
Expand All @@ -522,6 +540,7 @@ 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,
)
return Flow(
jobs=additonal_dft_random,
Expand Down
77 changes: 66 additions & 11 deletions autoplex/auto/phonons/jobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""General AutoPLEX automation jobs."""
from __future__ import annotations

import warnings
from pathlib import Path
from typing import TYPE_CHECKING

Expand All @@ -12,6 +13,7 @@
from pymatgen.core.structure import Structure

from autoplex.benchmark.phonons.flows import PhononBenchmarkMaker
from autoplex.data.common.utils import generate_supercell_matrix
from autoplex.data.phonons.flows import (
DFTPhononMaker,
IsoAtomMaker,
Expand All @@ -20,6 +22,10 @@
TightDFTStaticMaker,
TightDFTStaticMakerBigSupercells,
)
from autoplex.data.phonons.utils import (
reduce_supercell_size,
update_phonon_displacement_maker,
)


@job
Expand All @@ -38,6 +44,7 @@ def complete_benchmark( # this function was put here to prevent circular import
dft_references=None,
relax_maker_kwargs: dict | None = None,
static_maker_kwargs: dict | None = None,
benchmark_kwargs: dict | None = None,
**ml_phonon_maker_kwargs,
):
"""
Expand Down Expand Up @@ -134,14 +141,16 @@ def complete_benchmark( # this function was put here to prevent circular import
) or ( # else?
add_dft_phonon_struct is False
):
dft_phonons = DFTPhononMaker(
dft_phonons = dft_phonopy_gen_data(
structure=benchmark_structure,
displacements=[0.01],
symprec=symprec,
phonon_displacement_maker=phonon_displacement_maker,
born_maker=None,
min_length=min_length,
).make(structure=benchmark_structure)
**benchmark_kwargs,
)
jobs.append(dft_phonons)
dft_references = dft_phonons.output
dft_references = dft_phonons["data"]["001"].output

add_data_bm = PhononBenchmarkMaker(name="Benchmark").make(
ml_model=ml_model,
Expand Down Expand Up @@ -182,35 +191,76 @@ def complete_benchmark( # this function was put here to prevent circular import

@job(data=["data"])
def dft_phonopy_gen_data(
structure: Structure, displacements, symprec, phonon_displacement_maker, min_length
structure: Structure,
displacements,
symprec,
phonon_displacement_maker,
min_length,
adaptive_phonopy_supercell_settings: bool = True,
):
"""
Job to generate DFT reference database using phonopy to be used for fitting ML potentials.

Parameters
----------
structure: Structure
pymatgen Structure object
pymatgen Structure object.
phonon_displacement_maker : .BaseVaspMaker or None
Maker used to compute the forces for a supercell.
displacements: list[float]
list of phonon displacement
list of phonon displacement.
min_length: float
min length of the supercell that will be built
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
(use_primitive_standard_structure, use_conventional_standard_structure)
and to handle all symmetry-related tasks in phonopy
and to handle all symmetry-related tasks in phonopy.
adaptive_phonopy_supercell_settings: bool
prevent too tight phonopy supercell settings.
"""
jobs = []
dft_phonons_output = {}
dft_phonons_dir_output = []
supercell_matrix = None

if phonon_displacement_maker is None:
phonon_displacement_maker = TightDFTStaticMaker(name="dft phonon static")
if min_length >= 18:
if min_length >= 15:
phonon_displacement_maker = TightDFTStaticMakerBigSupercells()
if adaptive_phonopy_supercell_settings:
lattice_avg = sum(structure.lattice.abc) / 3
if lattice_avg > 10.5:
try:
supercell_matrix = reduce_supercell_size(
structure=structure,
min_length=min_length,
max_length=25,
min_limit=15,
max_atoms=500,
min_atoms=300,
step_size=1.0,
)
except ValueError:
warnings.warn(
message="Falling back to a reduced reciprocal k-point density "
"depending on the average lattice parameter length. "
"Check if this is ok for your use case.",
stacklevel=2,
)
supercell_matrix = generate_supercell_matrix(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe instead of reducing the reciprocal k-points density, we could also as a "last resort" fall-back solution, pass a supercell_matrix like that, with the risk that the supercell might not be cubic or have 90 degrees angles at all.

structure=structure,
supercell_matrix=supercell_matrix,
max_sites=500,
)

# in case everything fails and a fitting supercell matrix cannot be found,
# reduce the reciprocal k-point density:
if supercell_matrix == [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
supercell_matrix = None
phonon_displacement_maker = update_phonon_displacement_maker(
lattice_avg, TightDFTStaticMakerBigSupercells()
)

for displacement in displacements:
dft_phonons = DFTPhononMaker(
Expand All @@ -219,7 +269,8 @@ def dft_phonopy_gen_data(
born_maker=None,
displacement=displacement,
min_length=min_length,
).make(structure=structure)
max_length=35,
).make(structure=structure, supercell_matrix=supercell_matrix)
jobs.append(dft_phonons)
dft_phonons_output[
f"{displacement}".replace(".", "") # key must not contain '.'
Expand Down Expand Up @@ -249,6 +300,7 @@ def dft_random_gen_data(
rattle_seed: int = 42,
rattle_mc_n_iter: int = 10,
w_angle: list[float] | None = None,
adaptive_rattled_supercell_settings: bool = True,
):
"""
Job to generate random structured DFT reference database to be used for fitting ML potentials.
Expand Down Expand Up @@ -306,6 +358,8 @@ def dft_random_gen_data(
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
"""
jobs = []

Expand All @@ -326,6 +380,7 @@ def dft_random_gen_data(
angle_percentage_scale=angle_percentage_scale,
rattle_mc_n_iter=rattle_mc_n_iter,
w_angle=w_angle,
adaptive_rattled_supercell_settings=adaptive_rattled_supercell_settings,
).make(
structure=structure,
mp_id=mp_id,
Expand Down
15 changes: 10 additions & 5 deletions autoplex/data/common/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,27 @@ def generate_randomized_structures(
rattle_seed: int = 42,
rattle_mc_n_iter: int = 10,
w_angle: list[float] | None = None,
adaptive_rattled_supercell_settings: bool = True,
):
"""
Take in a pymatgen Structure object and generates angle/volume distorted + rattled structures.

Parameters
----------
structure : Structure.
structure: Structure.
Pymatgen structures object.
supercell_matrix: Matrix3D.
Matrix for obtaining the supercell.
distort_type : int.
distort_type: int.
0- volume distortion, 1- angle distortion, 2- volume and angle distortion. Default=0.
n_structures : int.
n_structures: int.
Total number of distorted structures to be generated.
Must be provided if distorting volume without specifying a range, or if distorting angles.
Default=10.
volume_scale_factor_range : list[float]
volume_scale_factor_range: list[float]
[min, max] of volume scale factors.
e.g. [0.90, 1.10] will distort volume +-10%.
volume_custom_scale_factors : list[float]
volume_custom_scale_factors: list[float]
Specify explicit scale factors (if range is not specified).
If None, will default to [0.90, 0.95, 0.98, 0.99, 1.01, 1.02, 1.05, 1.10].
min_distance: float
Expand Down Expand Up @@ -227,6 +228,8 @@ def generate_randomized_structures(
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

Returns
-------
Expand All @@ -235,11 +238,13 @@ def generate_randomized_structures(
"""
if supercell_matrix is None:
supercell_matrix = [[2, 0, 0], [0, 2, 0], [0, 0, 2]]

supercell = get_supercell(
unitcell=get_phonopy_structure(structure),
supercell_matrix=supercell_matrix,
)
structure = get_pmg_structure(supercell)

# distort cells by volume or angle
if distort_type == 0:
distorted_cells = scale_cell(
Expand Down
Loading