-
Notifications
You must be signed in to change notification settings - Fork 96
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
Electrode Workflow #655
Merged
Merged
Electrode Workflow #655
Changes from 37 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
70b29b1
start electrodes
jmmshn 25cfc9a
start electrode
jmmshn 6cec20e
start electrode
jmmshn 9b66d67
start electrode
jmmshn 68aab1a
start electrode
jmmshn 3a30efa
start electrode
jmmshn 5921016
VASP electrode job
jmmshn 5495c87
VASP electrode job
jmmshn 98b9b29
lint
jmmshn df07747
n steps
jmmshn 638d784
n steps
jmmshn 5320449
n steps
jmmshn 1862501
n steps
jmmshn b9825f3
rm defect changes
jmmshn 982463d
rm defect changes
jmmshn 8f7c7bf
update
jmmshn 5f1316e
update
jmmshn f60c5ad
update
jmmshn db76d90
update structure matcher
jmmshn f084145
debugging
jmmshn 8b44900
debugging
jmmshn 27d6944
debugging
jmmshn aca956c
debugging
jmmshn c098638
debugging
jmmshn 76afa32
append names
jmmshn 5b65a4a
append names
jmmshn 2ac0fb2
append names
jmmshn d2f1643
append names
jmmshn 0e1a069
append names
jmmshn e96652f
dev script change
jmmshn 9cc4705
working test
jmmshn 0551925
Merge remote-tracking branch 'mp/main' into js_runs
jmmshn 2a7b36d
typo
jmmshn 217b7a1
lint
jmmshn 25cc070
lint
jmmshn 140b973
lint
jmmshn d9b73f2
lint
jmmshn 098722f
allow different bulk relax
jmmshn de48025
update
jmmshn f31781c
update
jmmshn 0b53ecb
update
jmmshn 5bd1726
update
jmmshn 793fdf1
hydrogen
jmmshn f366294
Merge remote-tracking branch 'mp/main' into js_runs
jmmshn 7e38d37
update emmet
jmmshn 50e6b97
Merge branch 'main' into electrode
jmmshn 934b04d
ulid tests
jmmshn 515091b
lint
jmmshn c7fbc94
emmet
jmmshn c6300b5
Merge branch 'main' into electrode
utf 80ae1fb
Merge remote-tracking branch 'mp/main' into electrode
jmmshn 823c92d
update ulid
jmmshn bdcc97d
update ulid
jmmshn 1b0e5db
update ulid
jmmshn 842070d
Merge remote-tracking branch 'mp/main' into electrode
jmmshn 1d9e1bd
Merge branch 'main' into electrode
utf f16c016
Update pyproject.toml
utf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
"""Flow for electrode analysis.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass, field | ||
from typing import TYPE_CHECKING | ||
|
||
from jobflow import Flow, Maker | ||
from pymatgen.analysis.structure_matcher import ElementComparator, StructureMatcher | ||
|
||
from atomate2.common.jobs.electrode import get_stable_inserted_structure | ||
|
||
if TYPE_CHECKING: | ||
from pymatgen.alchemy import ElementLike | ||
from pymatgen.core.structure import Structure | ||
from pymatgen.io.vasp.outputs import VolumetricData | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
__author__ = "Jimmy Shen" | ||
__email__ = "[email protected]" | ||
|
||
|
||
@dataclass | ||
class ElectrodeInsertionMaker(Maker, ABC): | ||
"""Attempt ion insertion into a structure. | ||
|
||
The basic unit for cation insertion is: | ||
[get_stable_inserted_structure]: | ||
(static) -> (chgcar analysis) -> | ||
N x (relax) -> (return best structure) | ||
|
||
The workflow is: | ||
[relax structure] | ||
[get_stable_inserted_structure] | ||
[get_stable_inserted_structure] | ||
[get_stable_inserted_structure] | ||
... until the insertion is no longer topotactic. | ||
|
||
This workflow requires the users to provide the following functions: | ||
self.get_charge_density(task_doc: TaskDoc): | ||
Get the charge density of a TaskDoc output from a calculation. | ||
self.update_static_maker(): | ||
Ensure that the static maker will store the desired data. | ||
|
||
Attributes | ||
---------- | ||
name: str | ||
The name of the flow created by this maker. | ||
relax_maker: RelaxMaker | ||
A maker to perform relaxation calculations. | ||
static_maker: Maker | ||
A maker to perform static calculations. | ||
structure_matcher: StructureMatcher | ||
The structure matcher to use to determine if additional insertion is needed. | ||
""" | ||
|
||
relax_maker: Maker | ||
static_maker: Maker | ||
name: str = "ion insertion" | ||
structure_matcher: StructureMatcher = field( | ||
default_factory=lambda: StructureMatcher( | ||
comparator=ElementComparator(), | ||
) | ||
) | ||
|
||
def __post_init__(self) -> None: | ||
"""Ensure that the static maker will store the desired data.""" | ||
self.update_static_maker() | ||
|
||
def make( | ||
self, | ||
structure: Structure, | ||
inserted_element: ElementLike, | ||
n_steps: int | None, | ||
insertions_per_step: int = 4, | ||
) -> Flow: | ||
"""Make the flow. | ||
|
||
Parameters | ||
---------- | ||
structure: | ||
Structure to insert ion into. | ||
inserted_species: | ||
Species to insert. | ||
n_steps: int | ||
The maximum number of sequential insertion steps to attempt. | ||
insertions_per_step: int | ||
The maximum number of ion insertion sites to attempt. | ||
|
||
Returns | ||
------- | ||
Flow for ion insertion. | ||
""" | ||
# First relax the structure | ||
relax = self.relax_maker.make(structure) | ||
# add ignored_species to the structure matcher | ||
sm = _add_ignored_species(self.structure_matcher, inserted_element) | ||
# Get the inserted structure | ||
inserted_structure = get_stable_inserted_structure( | ||
structure=relax.output.structure, | ||
inserted_element=inserted_element, | ||
structure_matcher=sm, | ||
static_maker=self.static_maker, | ||
relax_maker=self.relax_maker, | ||
get_charge_density=self.get_charge_density, | ||
n_steps=n_steps, | ||
insertions_per_step=insertions_per_step, | ||
) | ||
return Flow([relax, inserted_structure]) | ||
|
||
@abstractmethod | ||
def get_charge_density(self, prev_dir) -> VolumetricData: | ||
"""Get the charge density of a structure. | ||
|
||
Parameters | ||
---------- | ||
prev_dir: | ||
The previous directory where the static calculation was performed. | ||
|
||
Returns | ||
------- | ||
The charge density. | ||
""" | ||
|
||
@abstractmethod | ||
def update_static_maker(self) -> None: | ||
"""Ensure that the static maker will store the desired data.""" | ||
|
||
|
||
def _add_ignored_species( | ||
structure_matcher: StructureMatcher, species: ElementLike | ||
) -> StructureMatcher: | ||
"""Add an ignored species to a structure matcher.""" | ||
sm_dict = structure_matcher.as_dict() | ||
ignored_species = set(sm_dict.get("ignored_species", set())) | ||
ignored_species.add(str(species)) | ||
sm_dict["ignored_species"] = list(ignored_species) | ||
return StructureMatcher.from_dict(sm_dict) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a paper or anything that documents this further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah link is here, I'll add it to the PR.
https://www.nature.com/articles/s41524-020-00422-3