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

VASP Defect Code #215

Merged
merged 61 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c29a6b7
form_en jobs
jmmshn Dec 2, 2022
bea5d6e
form_en jobs
jmmshn Dec 2, 2022
b1921a5
form_en jobs
jmmshn Dec 2, 2022
883a7ab
sets
jmmshn Dec 2, 2022
d4881de
sets
jmmshn Dec 2, 2022
5a9ef4e
schema
jmmshn Dec 2, 2022
af9ec70
vasp test in vasp dir
jmmshn Dec 2, 2022
4d4c6ce
vasp test in vasp dir
jmmshn Dec 2, 2022
4aa9a92
vasp test in vasp dir
jmmshn Dec 2, 2022
1e08269
Merge branch 'patch_storage' into defect2
jmmshn Dec 2, 2022
6a9b34b
formation energy test
jmmshn Dec 2, 2022
feae60b
more checks
jmmshn Dec 2, 2022
05637fb
default defect sets
jmmshn Dec 7, 2022
6ef60fa
Merge branch 'patch_storage' into defect2
jmmshn Dec 7, 2022
1db44ac
Merge remote-tracking branch 'mp/main' into defect2
jmmshn Jan 30, 2023
73b317c
update isort
jmmshn Jan 30, 2023
d67f0b4
Merge branch 'isort_patch' into defect2
jmmshn Jan 30, 2023
c84e913
moved formation energy schema over
jmmshn Jan 30, 2023
2fa05bb
typehint for 3.8
jmmshn Jan 31, 2023
70f86c9
lint
jmmshn Jan 31, 2023
bfb6ce3
Merge remote-tracking branch 'mp/main' into defect2
jmmshn Jan 31, 2023
28b707c
lint
jmmshn Jan 31, 2023
aa4d484
removed Formation Energy Document
jmmshn Jan 31, 2023
cba7b39
addtional info for builders
jmmshn Feb 4, 2023
f72cf4f
addtional info for builders
jmmshn Feb 4, 2023
cde513d
update
jmmshn Feb 5, 2023
600ec5f
updated info
jmmshn Feb 6, 2023
0d887fc
generalized maker
jmmshn Feb 10, 2023
afb8027
need to update maker
jmmshn Feb 10, 2023
3c12af7
need to update maker
jmmshn Feb 10, 2023
66bc16e
ISIF=3 in test
jmmshn Feb 10, 2023
8fd537d
update lattice
jmmshn Feb 10, 2023
975e5f5
update lattice
jmmshn Feb 10, 2023
f39417f
update lattice
jmmshn Feb 10, 2023
55ad3a0
updated naming
jmmshn Feb 10, 2023
f63bfa5
Merge branch 'auto_lreal' into defect2
jmmshn Feb 21, 2023
f887f23
Merge branch 'auto_lreal' into defect2
jmmshn Feb 21, 2023
2416ce5
pass grid
jmmshn Feb 28, 2023
2f2c790
pass grid
jmmshn Feb 28, 2023
80d8fe0
don't pass grid
jmmshn Feb 28, 2023
c1e23d8
check isif 2
jmmshn Feb 28, 2023
233a00c
check isif 2
jmmshn Feb 28, 2023
628b6f3
correct recursive
jmmshn Feb 28, 2023
7e0d38b
correct recursive
jmmshn Feb 28, 2023
554a495
merge
jmmshn Mar 1, 2023
bbd5383
merge
jmmshn Mar 1, 2023
335bfe7
lint
jmmshn Mar 1, 2023
c24f669
found the chg bug
jmmshn Mar 1, 2023
5e44d35
Merge remote-tracking branch 'mp/main' into defect2
jmmshn Mar 2, 2023
47d30ed
response to comments
jmmshn Mar 2, 2023
cdf2c71
response to comments
jmmshn Mar 2, 2023
30eeebe
response to comments
jmmshn Mar 3, 2023
6c9d2a9
response to comments
jmmshn Mar 3, 2023
4715fb6
response to comments
jmmshn Mar 3, 2023
58ac5c4
docs
jmmshn Mar 3, 2023
f8eb43d
docs
jmmshn Mar 3, 2023
11c7c08
Update src/atomate2/common/analysis/defects/jobs.py
jmmshn Mar 3, 2023
5cb534c
lint
jmmshn Mar 3, 2023
b3f6f3e
replace correctly
jmmshn Mar 3, 2023
0d36f00
Update src/atomate2/common/schemas/defects.py
jmmshn Mar 6, 2023
b90d99f
Update src/atomate2/common/schemas/defects.py
jmmshn Mar 6, 2023
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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ amset = ["amset>=0.4.15", "pydash"]
cclib = ["cclib"]
mp = ["mp-api>=0.27.5"]
phonons = ["phonopy>=1.10.8", "seekpath"]
defects = ["pymatgen-analysis-defects>=2022.11.21", "dscribe>=1.2.0"]
defects = ["pymatgen-analysis-defects>=2022.11.30", "dscribe>=1.2.0"]
docs = [
"numpydoc==1.5.0",
"ipython==8.8.0",
Expand All @@ -53,7 +53,7 @@ dev = ["pre-commit>=2.12.1"]
tests = ["pytest==7.2.1", "pytest-cov==4.0.0", "FireWorks==2.0.3"]
strict = [
"pydantic==1.10.4",
"pymatgen==2023.1.20",
"pymatgen==2023.1.30",
"custodian==2022.5.26",
"monty==2022.9.9",
"jobflow==0.1.9",
Expand All @@ -65,7 +65,7 @@ strict = [
"numpy",
"mp-api==0.30.8",
"dscribe==1.2.1",
"pymatgen-analysis-defects==2022.11.21",
"pymatgen-analysis-defects==2023.1.30",
]

[project.scripts]
Expand Down
171 changes: 169 additions & 2 deletions src/atomate2/common/analysis/defects/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
from __future__ import annotations

import logging
from abc import ABC, abstractmethod
from dataclasses import dataclass
from pathlib import Path

import numpy.typing as npt
from jobflow import Flow, Job, Maker, OutputReference
from pymatgen.analysis.defects.core import Defect
from pymatgen.core.structure import Structure

from atomate2.common.analysis.defects.jobs import (
bulk_supercell_calculation,
get_ccd_documents,
get_charged_structures,
get_supercell_from_prv_calc,
spawn_defect_calcs,
spawn_energy_curve_calcs,
)

Expand All @@ -27,10 +34,10 @@ class ConfigurationCoordinateMaker(Maker):
----------
name: str
The name of the flow created by this maker.
relax_maker: .BaseVaspMaker or None
relax_maker: Maker
A maker to perform a atomic-position-only relaxation on the defect charge
states.
static_maker: .BaseVaspMaker or None
static_maker: Maker
A maker to perform the single-shot static calculation of the distorted
structures.
distortions: tuple[float, ...]
Expand Down Expand Up @@ -138,3 +145,163 @@ def make(
output=ccd_job.output,
name=name,
)


@dataclass
class FormationEnergyMaker(Maker, ABC):
"""Maker class to help calculate of the formation energy diagram.

Maker class to calculate formation energy diagrams. The main settings for
this maker is the `relax_maker` which contains the settings for the atomic
relaxations that each defect supercell will undergo. The `relax_maker`
uses a `ChargeStateRelaxSetGenerator` by default but more complex makers
like the `HSEDoubleRelaxMaker` can be used for more accurate (but expensive)
calculations.
If the `validate_maker` is set to True, the maker will check for some basic
settings in the `relax_maker` to make sure the calculations are done correctly.

Attributes
----------
relax_maker: Maker
A maker to perform a atomic-position-only relaxation on the defect charge
states. Since these calculations are expensive and the settings might get
messy, it is recommended for each implementation of this maker to check
some of the most important settings in the `relax_maker`. Please see
`FormationEnergyMaker.validate_maker` for more details.
name: str
The name of the flow created by this maker.
"""

relax_maker: Maker
name: str = "formation energy"

def __post_init__(self):
self.validate_maker()

def make(
self,
defect: Defect,
bulk_supercell_dir: str | Path | None = None,
supercell_matrix: npt.NDArray | None = None,
defect_index: int | str = "",
):
"""Make a flow to calculate the formation energy diagram.

Start a series of charged supercell relaxations from a single defect
structure. Since the standard finite size correction (Freysoldt) requires
a bulk supercell calculation (to obtain the pristine electrostatic potentia),
this maker will either perform a bulk supercell calculation or use a existing
one if provided.
If a value for the dielectric constant is provided, the Freysoldt correction
will be applied to the formation energy.

Parameters
----------
defects: Defect
List of defects objects to calculate the formation energy diagram for.
utf marked this conversation as resolved.
Show resolved Hide resolved
bulk_supercell_dir: str | Path | None
If provided, the bulk supercell calculation will be skipped.
supercell_matrix: NDArray | None
The supercell transformation matrix. If None, the supercell matrix
will be computed automatically. If `bulk_supercell_dir` is provided,
this parameter will be ignored.
defect_index : int | str
Additional index to give unique names to the defect calculations.
Useful for external bookkeeping of symmetry distinct defects.

Returns
-------
flow: Flow
The workflow to calculate the formation energy diagram.
"""
jobs = []
if bulk_supercell_dir is None:
get_sc_job = bulk_supercell_calculation(
uc_structure=defect.structure,
relax_maker=self.relax_maker,
sc_mat=supercell_matrix,
update_bulk_maker=self.update_bulk_maker,
)
sc_mat = get_sc_job.output["sc_mat"]
lattice = get_sc_job.output["sc_struct"].lattice
bulk_supercell_dir = get_sc_job.output["dir_name"]
else:
# all additional reader functions need to be in this job
# b/c they might receive Response objects instead of data.
get_sc_job = get_supercell_from_prv_calc(
uc_structure=defect.structure,
prv_calc_dir=bulk_supercell_dir,
sc_mat_ref=supercell_matrix,
structure_from_prv=self.structure_from_prv,
)
sc_mat = get_sc_job.output["sc_mat"]
lattice = get_sc_job.output["lattice"]

spawn_output = spawn_defect_calcs(
defect=defect,
sc_mat=sc_mat,
relax_maker=self.relax_maker,
relaxed_sc_lattice=lattice,
defect_index=defect_index,
add_info={
"bulk_supercell_dir": bulk_supercell_dir,
"bulk_supercell_matrix": sc_mat,
"bulk_supercell_uuid": get_sc_job.uuid,
},
)
jobs.extend([get_sc_job, spawn_output])

return Flow(
jobs=jobs,
name=self.name,
)

@abstractmethod
def update_bulk_maker(self, relax_maker: Maker):
utf marked this conversation as resolved.
Show resolved Hide resolved
"""Update the maker for the bulk job.

Common usage case:
While almost all of the settings for the bulk relaxation and defect
relaxation should be the same, it is usually desirable to allow lattice
relaxation for the bulk job only.
Assuming the `relax_maker` is only allows atomic relaxations, this method
will update the bulk job to allow lattice relaxations.

Parameters
----------
relax_maker: Maker
The maker used to create the defect job.

Returns:
--------
Maker:
The updated maker.
"""
raise NotImplementedError("This method is not implemented yet.")

@abstractmethod
def structure_from_prv(self, previous_dir: str) -> Structure:
"""Copy the output structure from previous directory.

Parameters
----------
previous_dir: str
The directory to copy from.

Returns
-------
structure: Structure
"""

@abstractmethod
def validate_maker(self):
"""Check some key settings in the relax maker.

Since this workflow is pretty complex but allows you to use any
relax maker, it can be easy to make mistakes in the settings.
This method should check the most important settings and raise
an error if something is wrong.

Example: For VASP, the relax maker should have:
`ISIF = 2` and `use_structure_charge = True`
"""
Loading