Skip to content

Commit

Permalink
Merge pull request #50 from nfragapane/main
Browse files Browse the repository at this point in the history
[WIP] New data generation jobs
  • Loading branch information
JaGeo authored May 15, 2024
2 parents 22da7af + 2ea7506 commit 2d59ae1
Show file tree
Hide file tree
Showing 17 changed files with 935 additions and 232 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip cache purge
python -m pip install --upgrade pip
python -m pip install flake8 pytest pytest-mock pytest-split pytest-cov
python -m pip install types-setuptools
Expand Down
56 changes: 32 additions & 24 deletions autoplex/auto/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
If True, will add randomly distorted structures for DFT calculation.
add_rss_struct: bool.
If True, will add RSS generated structures for DFT calculation.
n_struct: int.
n_structures: int.
The total number of randomly displaced structures to be generated.
phonon_displacement_maker: BaseVaspMaker
Maker used to compute the forces for a supercell.
n_struct: int.
n_structures: int.
The total number of randomly displaced structures to be generated.
displacements: list[float]
displacement distance for phonons
Expand All @@ -71,13 +71,15 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
uc: bool.
If True, will generate randomly distorted structures (unitcells)
and add static computation jobs to the flow.
cell_factor_sequence: list[float]
volume_scale_factors: list[float]
list of factors to resize cell parameters. Default is [0.975, 1.0, 1.025, 1.05].
std_dev: float
Standard deviation std_dev for normal distribution to draw numbers from
rattle_std: float
Standard deviation for normal distribution to draw numbers from
to generate the rattled structures.
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.
ml_models: list[str]
list of the ML models to be used. Default is GAP.
"""
Expand All @@ -90,14 +92,15 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
phonon_displacement_maker: BaseVaspMaker = field(
default_factory=TightDFTStaticMaker
)
n_struct: int = 1
n_structures: int = 1
displacements: list[float] = field(default_factory=lambda: [0.01])
min_length: int = 20
symprec: float = 1e-4
uc: bool = False
cell_factor_sequence: list[float] | None = None
std_dev: float = 0.01
volume_scale_factors: list[float] | None = None
rattle_std: float = 0.01
supercell_matrix: Matrix3D | None = None
distort_type: int = 0
ml_models: list[str] = field(default_factory=lambda: ["GAP"])

def make(
Expand All @@ -108,7 +111,7 @@ def make(
f_max: float = 40.0,
pre_xyz_files: list[str] | None = None,
pre_database_dir: str | None = None,
regularization: float = 0.1,
atom_wise_regularization_parameter: float = 0.1,
f_min: float = 0.01, # unit: eV Å-1
atom_wise_regularization: bool = True,
auto_delta: bool = True,
Expand All @@ -135,7 +138,7 @@ def make(
names of the pre-database train xyz file and test xyz file.
pre_database_dir:
the pre-database directory.
regularization: float
atom_wise_regularization_parameter: float
regularization value for the atom-wise force components.
f_min: float
minimal force cutoff value for atom-wise regularization.
Expand All @@ -161,11 +164,12 @@ def make(
structure,
mp_id,
self.phonon_displacement_maker,
self.n_struct,
self.n_structures,
self.uc,
self.cell_factor_sequence,
self.std_dev,
self.volume_scale_factors,
self.rattle_std,
self.supercell_matrix,
self.distort_type,
)
flows.append(addDFTrand)
fit_input.update({mp_id: addDFTrand.output})
Expand Down Expand Up @@ -201,7 +205,7 @@ def make(
f_max=f_max,
pre_xyz_files=pre_xyz_files,
pre_database_dir=pre_database_dir,
regularization=regularization,
atomwise_regularization_param=atom_wise_regularization_parameter,
f_min=f_min,
atom_wise_regularization=atom_wise_regularization,
auto_delta=auto_delta,
Expand Down Expand Up @@ -313,11 +317,12 @@ def add_dft_random(
structure: Structure,
mp_id: str,
phonon_displacement_maker: BaseVaspMaker,
n_struct: int = 1,
n_structures: int = 1,
uc: bool = False,
cell_factor_sequence: list[float] | None = None,
std_dev: float = 0.01,
volume_custom_scale_factors: list[float] | None = None,
rattle_std: float = 0.01,
supercell_matrix: Matrix3D | None = None,
distort_type: int = 0,
):
"""Add DFT phonon runs for randomly displaced structures.
Expand All @@ -329,28 +334,31 @@ def add_dft_random(
materials project id
phonon_displacement_maker: BaseVaspMaker
Maker used to compute the forces for a supercell.
n_struct: int.
n_structures: int.
The total number of randomly displaced structures to be generated.
uc: bool.
If True, will generate randomly distorted structures (unitcells)
and add static computation jobs to the flow.
cell_factor_sequence: list[float]
volume_custom_scale_factors: list[float]
list of factors to resize cell parameters.
std_dev: float
Standard deviation std_dev for normal distribution to draw numbers from
rattle_std: float
Standard deviation for normal distribution to draw numbers from
to generate the rattled structures.
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.
"""
additonal_dft_random = dft_random_gen_data(
structure,
mp_id,
phonon_displacement_maker,
n_struct,
n_structures,
uc,
cell_factor_sequence,
std_dev,
volume_custom_scale_factors,
rattle_std,
supercell_matrix,
distort_type,
)
return Flow(
additonal_dft_random,
Expand Down
25 changes: 15 additions & 10 deletions autoplex/auto/phonons/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ def dft_random_gen_data(
structure: Structure,
mp_id,
phonon_displacement_maker,
n_struct: int = 1,
n_structures: int = 1,
uc: bool = False,
cell_factor_sequence: list[float] | None = None,
std_dev: float = 0.01,
volume_custom_scale_factors: list[float] | None = None,
rattle_std: float = 0.01,
supercell_matrix: Matrix3D | None = None,
distort_type: int = 0,
):
"""
Job to generate random structured DFT reference database to be used for fitting ML potentials.
Expand All @@ -254,31 +255,35 @@ def dft_random_gen_data(
Maker used to compute the forces for a supercell.
mp_id:
materials project id
n_struct: int.
n_structures: int.
The total number of randomly displaced structures to be generated.
uc: bool.
If True, will generate randomly distorted structures (unitcells)
and add static computation jobs to the flow.
cell_factor_sequence: list[float]
volume_custom_scale_factors: list[float]
list of factors to resize cell parameters.
std_dev: float
Standard deviation std_dev for normal distribution to draw numbers from to generate the rattled structures.
rattle_std: float.
Rattle amplitude (standard deviation in normal distribution).
Default=0.01.
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.
"""
jobs = []

random_datagen = RandomStructuresDataGenerator(
name="RandomDataGen",
phonon_displacement_maker=phonon_displacement_maker,
n_struct=n_struct,
n_structures=n_structures,
uc=uc,
std_dev=std_dev,
rattle_std=rattle_std,
distort_type=distort_type,
).make(
structure=structure,
mp_id=mp_id,
supercell_matrix=supercell_matrix,
cell_factor_sequence=cell_factor_sequence,
volume_custom_scale_factors=volume_custom_scale_factors,
)
jobs.append(random_datagen)

Expand Down
21 changes: 11 additions & 10 deletions autoplex/data/common/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

from autoplex.data.common.jobs import (
convert_to_extxyz,
generate_randomized_structures,
get_supercell_job,
plot_force_distribution,
)
from autoplex.data.phonons.jobs import generate_randomized_structures

__all__ = ["GenerateTrainingDataForTesting"]

Expand Down Expand Up @@ -56,8 +56,8 @@ def make(
train_structure_list: list[Structure],
cell_factor_sequence: list[float] | None = None,
potential_filename: str = "gap.xml",
n_struct: int = 50,
std_dev: float = 0.01,
n_structures: int = 50,
rattle_std: float = 0.01,
relax_cell: bool = True,
steps: int = 1000,
supercell_matrix: Matrix3D | None = None,
Expand All @@ -78,10 +78,11 @@ def make(
list of factor to resize cell parameters.
potential_filename: str
param_file_name for :obj:`quippy.potential.Potential()'`.
n_struct : int.
n_structures : int.
Total number of randomly displaced structures to be generated.
std_dev: float
Standard deviation std_dev for normal distribution to draw numbers from to generate the rattled structures.
rattle_std: float.
Rattle amplitude (standard deviation in normal distribution).
Default=0.01.
relax_cell : bool
Whether to allow the cell shape/volume to change during relaxation.
steps : int
Expand Down Expand Up @@ -126,10 +127,10 @@ def make(

for cell_factor in cell_factor_sequence:
rand_struc_job = generate_randomized_structures(
supercell.output,
n_struct=n_struct,
cell_factor_sequence=[cell_factor],
std_dev=std_dev,
structure=supercell.output,
n_structures=n_structures,
volume_custom_scale_factors=[cell_factor],
rattle_std=rattle_std,
)
jobs.append(rand_struc_job)
static_conv_jobs = self.static_run_and_convert(
Expand Down
Loading

0 comments on commit 2d59ae1

Please sign in to comment.