Skip to content

Commit

Permalink
Merge pull request #17 from QuantumChemist/main
Browse files Browse the repository at this point in the history
[WIP] not so small bug fix
  • Loading branch information
JaGeo authored Jan 25, 2024
2 parents 9041316 + 323a202 commit 7cea18a
Show file tree
Hide file tree
Showing 11 changed files with 4,859 additions and 4,316 deletions.
120 changes: 69 additions & 51 deletions autoplex/auto/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
update_user_incar_settings,
)
from jobflow import Flow, Maker
from pymatgen.io.phonopy import get_ph_bs_symm_line

from autoplex.auto.jobs import (
dft_phonopy_gen_data,
Expand Down Expand Up @@ -45,6 +44,8 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
"""
Maker to calculate harmonic phonons with DFT, fit GAP and benchmark the results.
User has no data.
Parameters
----------
name : str
Expand All @@ -69,16 +70,16 @@ class CompleteDFTvsMLBenchmarkWorkflow(Maker):
displacements: list[float] = field(default_factory=lambda: [0.01])
min_length: int = 20
symprec: float = 1e-4
uc: bool = False
uc: bool = False # to get rattled unit cells
supercell_matrix: Matrix3D | None = None

def make(
self,
structure_list: list[Structure],
mp_ids,
phonon_displacement_maker,
benchmark_structure: Structure,
mp_id,
benchmark_structure: Structure, # structures
mp_id, # benchmark_mp_ids
**fit_kwargs,
):
"""
Expand All @@ -104,7 +105,6 @@ def make(
flows.append(isoatoms)

for struc_i, structure in enumerate(structure_list):
mp_id = mp_ids[struc_i]
autoplex_datagen = DFTDataGenerationFlow(
name="datagen",
phonon_displacement_maker=phonon_displacement_maker,
Expand All @@ -114,9 +114,9 @@ def make(
symprec=self.symprec,
uc=self.uc,
supercell_matrix=self.supercell_matrix,
).make(structure=structure, mp_id=mp_id)
).make(structure=structure, mp_id=mp_ids[struc_i])
flows.append(autoplex_datagen)
datagen.update({mp_id: autoplex_datagen.output})
datagen.update({mp_ids[struc_i]: autoplex_datagen.output})

autoplex_fit = PhononDFTMLFitFlow().make(
species=isoatoms.output["species"],
Expand All @@ -139,12 +139,17 @@ def make(
born_maker=None,
min_length=self.min_length,
).make(structure=benchmark_structure)
dft_phonons = update_user_incar_settings(dft_phonons, {"NPAR": 4})
dft_phonons = update_user_incar_settings(
dft_phonons, {"NPAR": 4, "ISPIN": 1, "LAECHG": False, "ISMEAR": 0}
)
flows.append(dft_phonons)

dft_reference = dft_phonons.output
else:
dft_reference = datagen[mp_id]["phonon_data"]["001"]
dft_reference = datagen[mp_id]["phonon_data"][
"001"
] # flag take all phonon runs
# explanation for 001 = 0.01

autoplex_bm = PhononDFTMLBenchmarkFlow(name="testBM").make(
structure=benchmark_structure,
Expand All @@ -167,9 +172,11 @@ def make(


@dataclass
class AddDataToDataset(Maker):
class AddDataToDataset(
Maker
): # merge with complete wf and set another flag for adding data
"""
Maker to add more data to existing daaset (.xyz file).
Maker to add more data to existing dataset (.xyz file).
Parameters
----------
Expand Down Expand Up @@ -204,7 +211,7 @@ def make(
structure_list: list[Structure],
mp_ids,
xyz_file,
dft_reference_bs_file,
dft_reference: PhononBSDOSDoc | None,
benchmark_structure: Structure,
mp_id,
**fit_kwargs,
Expand All @@ -220,8 +227,8 @@ def make(
materials project id.
xyz_file:
the already existing training data xyz file.
dft_reference_bs_file:
path to the DFT phonon bandstructure file.
dft_reference:
DFT reference file containing the PhononBSDOCDoc object.
benchmark_structure: Structure
pymatgen structure for benchmarking.
mp_id:
Expand All @@ -232,13 +239,10 @@ def make(
fit_input = {}
collect = []

dft_reference = get_ph_bs_symm_line(dft_reference_bs_file)

if xyz_file is None:
raise Exception("Error. Please provide an existing xyz file.")

for i, structure in enumerate(structure_list):
mp_id = mp_ids[i]
if self.add_dft_random_struct:
addDFTrand = self.add_dft_random(
structure,
Expand All @@ -249,7 +253,7 @@ def make(
self.supercell_matrix,
)
flows.append(addDFTrand)
fit_input.update({mp_id: addDFTrand.output})
fit_input.update({mp_ids[i]: addDFTrand.output})
if self.add_dft_phonon_struct:
addDFTphon = self.add_dft_phonons(
structure,
Expand All @@ -259,9 +263,11 @@ def make(
self.min_length,
)
flows.append(addDFTphon)
fit_input.update({mp_id: addDFTphon.output})
fit_input.update({mp_ids[i]: 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_ids[i]: {**addDFTrand.output, **addDFTphon.output}}
)
if self.add_rss_struct:
raise NotImplementedError

Expand All @@ -284,25 +290,24 @@ def make(
ml_dir=add_data_fit.output,
)
flows.append(add_data_ml_phonon)
if (
mp_id not in mp_ids
or dft_reference is None
or self.add_dft_phonon_struct is False
):
dft_phonons = DFTPhononMaker(
symprec=self.symprec,
phonon_displacement_maker=self.phonon_displacement_maker,
born_maker=None,
min_length=self.min_length,
).make(structure=benchmark_structure)
dft_phonons = update_user_incar_settings(
dft_phonons, {"NPAR": 4, "ISPIN": 1, "LAECHG": False, "ISMEAR": 0}
)
flows.append(dft_phonons)

dft_reference = dft_phonons.output
else:
dft_reference = fit_input[mp_id]["phonon_data"]["001"]
if dft_reference is None:
if (mp_id in mp_ids) and self.add_dft_phonon_struct:
dft_reference = fit_input[mp_id]["phonon_data"]["001"]
elif (mp_id not in mp_ids) or ( # else?
self.add_dft_phonon_struct is False
):
dft_phonons = DFTPhononMaker(
symprec=self.symprec,
phonon_displacement_maker=self.phonon_displacement_maker,
born_maker=None,
min_length=self.min_length,
).make(structure=benchmark_structure)
dft_phonons = update_user_incar_settings(
dft_phonons, {"NPAR": 4, "ISPIN": 1, "LAECHG": False, "ISMEAR": 0}
)
flows.append(dft_phonons)
dft_reference = dft_phonons.output

add_data_bm = PhononDFTMLBenchmarkFlow(name="addDataBM").make(
structure=benchmark_structure,
Expand Down Expand Up @@ -415,29 +420,42 @@ def make(self, structure: Structure, mp_id):
materials project id
"""
# TODO later adding: for i no. of potentials

dft_phonon = dft_phonopy_gen_data(
structure,
self.displacements,
self.symprec,
self.phonon_displacement_maker,
self.min_length,
)
dft_random = dft_random_gen_data(
structure,
mp_id,
self.phonon_displacement_maker,
self.n_struct,
self.uc,
self.supercell_matrix,
)

return Flow(
[dft_phonon, dft_random], # flows
output={
if self.n_struct != 0:
dft_random = dft_random_gen_data(
structure,
mp_id,
self.phonon_displacement_maker,
self.n_struct,
self.uc,
self.supercell_matrix,
)

flows = [dft_phonon, dft_random]
output = {
"rand_struc_dir": dft_random.output,
"phonon_dir": dft_phonon.output["dirs"],
"phonon_data": dft_phonon.output["data"],
},
}

else:
flows = [dft_phonon]
output = {
"phonon_dir": dft_phonon.output["dirs"],
"phonon_data": dft_phonon.output["data"],
}

return Flow(
flows, # flows
output=output,
)


Expand Down Expand Up @@ -532,7 +550,7 @@ def make(
benchmark = PhononBenchmarkMaker(name="Benchmark").make(
structure=structure,
mp_id=mp_id,
ml_phonon_bs=ml_phonon_task_doc.phonon_bandstructure, # TODO take BS at top lvl
ml_phonon_bs=ml_phonon_task_doc.phonon_bandstructure, # TODO take BS at top lvl?
dft_phonon_bs=dft_phonon_task_doc.phonon_bandstructure,
)
flows.append(benchmark)
Expand Down
8 changes: 8 additions & 0 deletions autoplex/data/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def make(
supercell_matrix=None,
phonon_maker=self.phonon_displacement_maker,
)
vasp_random_displacement_calcs = update_user_incar_settings(
vasp_random_displacement_calcs,
{"NPAR": 4, "ISPIN": 1, "LAECHG": False, "ISMEAR": 0},
)
jobs.append(vasp_random_displacement_calcs)
outputs.append(vasp_random_displacement_calcs.output["dirs"])

Expand Down Expand Up @@ -159,6 +163,10 @@ def make(self, all_species: list[Species]):
user_kpoints_settings={"grid_density": 1},
),
).make(iso_atom)
isoatom_calcs = update_user_incar_settings(
isoatom_calcs,
{"NPAR": 4, "ISPIN": 1, "LAECHG": False, "ISMEAR": 0},
)
jobs.append(isoatom_calcs)
isoatoms.append(isoatom_calcs.output.output.energy_per_atom)
# create a flow including all jobs
Expand Down
Loading

0 comments on commit 7cea18a

Please sign in to comment.