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

Fix use of PatchedPhaseDiagram in ThermoBuilder #566

Merged
merged 6 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions emmet-api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
setup(
name="emmet-api",
use_scm_version={
"root": ".",
"root": "..",
Copy link
Contributor

Choose a reason for hiding this comment

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

This basically reverts #565

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I had to revert as the git information wasn't properly being accessed by setuptools when root is set to .

I will try and find another solution, but in the mean time this change needed to happen so our deployment pipelines don't break.

"relative_to": __file__,
"write_to": "emmet/api/_version.py",
"write_to": "emmet-api/emmet/api/_version.py",
"write_to_template": '__version__ = "{version}"',
"fallback_version": fallback_version,
},
Expand All @@ -20,14 +20,7 @@
author_email="feedback@materialsproject.org",
url="https://github.com/materialsproject/emmet",
packages=find_namespace_packages(include=["emmet.*"]),
install_requires=[
"emmet-core[all]",
"fastapi",
"uvicorn",
"gunicorn",
"boto3",
"maggma",
],
install_requires=["emmet-core[all]", "fastapi", "uvicorn", "gunicorn", "boto3", "maggma"],
python_requires=">=3.8",
license="modified BSD",
zip_safe=False,
Expand Down
24 changes: 6 additions & 18 deletions emmet-builders/emmet/builders/vasp/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ def get_items(self) -> Iterator[List[Dict]]:
# Remove overlapping chemical systems
processed = set()
to_process_chemsys = []
for chemsys in sorted(
updated_chemsys | new_chemsys | affected_chemsys,
key=lambda x: len(x),
reverse=True,
):
for chemsys in sorted(updated_chemsys | new_chemsys | affected_chemsys, key=lambda x: len(x), reverse=True,):
if chemsys not in processed:
processed |= chemsys_permutations(chemsys)
to_process_chemsys.append(chemsys)
Expand Down Expand Up @@ -236,20 +232,17 @@ def _produce_pair(self, pd_entries, thermo_type, elements):
try:
docs, pds = ThermoDoc.from_entries(pd_entries, thermo_type, deprecated=False)

pd_data = None
pd_docs = [None]

if self.phase_diagram:
if self.num_phase_diagram_eles is None or len(elements) <= self.num_phase_diagram_eles:
pd_docs = []

for pd in pds:
chemsys = '-'.join(sorted(set([e.symbol for e in pd.elements])))
chemsys = "-".join(sorted(set([e.symbol for e in pd.elements])))
pd_id = "{}_{}".format(chemsys, str(thermo_type))
pd_doc = PhaseDiagramDoc(
phase_diagram_id=pd_id,
chemsys=chemsys,
phase_diagram=pd,
thermo_type=thermo_type,
phase_diagram_id=pd_id, chemsys=chemsys, phase_diagram=pd, thermo_type=thermo_type,
)

pd_data = jsanitize(pd_doc.dict(), allow_bson=True)
Expand Down Expand Up @@ -337,10 +330,7 @@ def get_entries(self, chemsys: str) -> List[Dict]:
d["material_id"]: d.get("average_oxidation_states", {})
for d in self.oxidation_states.query(
properties=["material_id", "average_oxidation_states"],
criteria={
"material_id": {"$in": material_ids},
"state": "successful",
},
criteria={"material_id": {"$in": material_ids}, "state": "successful"},
)
}

Expand All @@ -361,9 +351,7 @@ def get_entries(self, chemsys: str) -> List[Dict]:

return all_entries

def get_updated_chemsys(
self,
) -> Set:
def get_updated_chemsys(self,) -> Set:
"""Gets updated chemical system as defined by the updating of an existing material"""

updated_mats = self.thermo.newer_in(self.materials, criteria=self.query)
Expand Down
4 changes: 2 additions & 2 deletions emmet-builders/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
setup(
name="emmet-builders",
use_scm_version={
"root": ".",
"root": "..",
"relative_to": __file__,
"write_to": "emmet/builders/_version.py",
"write_to": "emmet-builders/emmet/builders/_version.py",
"write_to_template": '__version__ = "{version}"',
"fallback_version": fallback_version,
},
Expand Down
69 changes: 30 additions & 39 deletions emmet-core/emmet/core/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ class DecompositionProduct(BaseModel):
"""

material_id: MPID = Field(
None,
description="The Materials Project ID for the material this decomposition points to.",
None, description="The Materials Project ID for the material this decomposition points to.",
)
formula: str = Field(
None,
description="The formula of the decomposed material this material decomposes to.",
None, description="The formula of the decomposed material this material decomposes to.",
)
amount: float = Field(
None,
description="The amount of the decomposed material by formula units this this material decomposes to.",
None, description="The amount of the decomposed material by formula units this this material decomposes to.",
)


Expand All @@ -48,22 +45,19 @@ class ThermoDoc(PropertyDoc):
property_name = "thermo"

thermo_type: Union[ThermoType, RunType] = Field(
...,
description="Functional types of calculations involved in the energy mixing scheme.",
..., description="Functional types of calculations involved in the energy mixing scheme.",
)

thermo_id: str = Field(
...,
description="Unique document ID which is composed of the Material ID and thermo data type.",
..., description="Unique document ID which is composed of the Material ID and thermo data type.",
)

uncorrected_energy_per_atom: float = Field(
..., description="The total DFT energy of this material per atom in eV/atom."
)

energy_per_atom: float = Field(
...,
description="The total corrected DFT energy of this material per atom in eV/atom.",
..., description="The total corrected DFT energy of this material per atom in eV/atom.",
)

energy_uncertainy_per_atom: float = Field(None, description="")
Expand All @@ -73,8 +67,7 @@ class ThermoDoc(PropertyDoc):
energy_above_hull: float = Field(..., description="The energy above the hull in eV/Atom.")

is_stable: bool = Field(
False,
description="Flag for whether this material is on the hull and therefore stable.",
False, description="Flag for whether this material is on the hull and therefore stable.",
)

equilibrium_reaction_energy_per_atom: float = Field(
Expand All @@ -89,18 +82,15 @@ class ThermoDoc(PropertyDoc):
)

decomposition_enthalpy: float = Field(
None,
description="Decomposition enthalpy as defined by `get_decomp_and_phase_separation_energy` in pymatgen.",
None, description="Decomposition enthalpy as defined by `get_decomp_and_phase_separation_energy` in pymatgen.",
)

decomposition_enthalpy_decomposes_to: List[DecompositionProduct] = Field(
None,
description="List of decomposition data associated with the decomposition_enthalpy quantity.",
None, description="List of decomposition data associated with the decomposition_enthalpy quantity.",
)

energy_type: str = Field(
...,
description="The type of calculation this energy evaluation comes from.",
..., description="The type of calculation this energy evaluation comes from.",
)

entry_types: List[str] = Field(description="List of available energy types computed for this material.")
Expand All @@ -122,7 +112,20 @@ def from_entries(
# lowest energy entries.
patched_pd = PatchedPhaseDiagram(entries, keep_all_spaces=True)

pd = patched_pd.pds[frozenset(patched_pd.elements)] # Main PD of parent chemsys
# Main PD of parent chemsys
try:
pd = patched_pd.pds[frozenset(patched_pd.elements)]
except KeyError:
entries_by_comp = defaultdict(list)
for e in entries:
entries_by_comp[e.composition.reduced_formula].append(e)

# Only use lowest entry per composition to speed up QHull in Phase Diagram
reduced_entries = [
sorted(comp_entries, key=lambda e: e.energy_per_atom)[0] for comp_entries in entries_by_comp.values()
]
pd = PhaseDiagram(reduced_entries)
patched_pd.pds = {frozenset(patched_pd.elements): pd}

docs = []

Expand Down Expand Up @@ -173,23 +176,15 @@ def _energy_eval(entry: ComputedStructureEntry):
d["equilibrium_reaction_energy_per_atom"] = pd.get_equilibrium_reaction_energy(blessed_entry)
else:
d["decomposes_to"] = [
{
"material_id": de.data["material_id"],
"formula": de.composition.formula,
"amount": amt,
}
{"material_id": de.data["material_id"], "formula": de.composition.formula, "amount": amt}
for de, amt in decomp.items()
]

try:
decomp, energy = pd.get_decomp_and_phase_separation_energy(blessed_entry)
d["decomposition_enthalpy"] = energy
d["decomposition_enthalpy_decomposes_to"] = [
{
"material_id": de.data["material_id"],
"formula": de.composition.formula,
"amount": amt,
}
{"material_id": de.data["material_id"], "formula": de.composition.formula, "amount": amt}
for de, amt in decomp.items()
]
except ValueError:
Expand Down Expand Up @@ -242,23 +237,19 @@ class PhaseDiagramDoc(BaseModel):
property_name = "phase_diagram"

phase_diagram_id: str = Field(
...,
description="Phase diagram ID consisting of the chemical system and thermo type",
..., description="Phase diagram ID consisting of the chemical system and thermo type",
)

chemsys: str = Field(
...,
description="Dash-delimited string of elements in the material",
..., description="Dash-delimited string of elements in the material",
)

thermo_type: Union[ThermoType, RunType] = Field(
...,
description="Functional types of calculations involved in the energy mixing scheme.",
..., description="Functional types of calculations involved in the energy mixing scheme.",
)

phase_diagram: PhaseDiagram = Field(
...,
description="Phase diagram for the chemical system.",
..., description="Phase diagram for the chemical system.",
)

last_updated: datetime = Field(
Expand Down
15 changes: 4 additions & 11 deletions emmet-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
setup(
name="emmet-core",
use_scm_version={
"root": ".",
"root": "..",
"relative_to": __file__,
"write_to": "emmet/core/_version.py",
"write_to": "emmet-core/emmet/core/_version.py",
"write_to_template": '__version__ = "{version}"',
"fallback_version": fallback_version,
},
Expand All @@ -21,10 +21,7 @@
author_email="feedback@materialsproject.org",
url="https://github.com/materialsproject/emmet",
packages=find_namespace_packages(include=["emmet.*"]),
package_data={
"emmet.core.vasp.calc_types": ["*.yaml"],
"emmet.core.subtrates": ["*.json"],
},
package_data={"emmet.core.vasp.calc_types": ["*.yaml"], "emmet.core.subtrates": ["*.json"]},
include_package_data=True,
install_requires=[
"pymatgen>=2021.3,<2023.0",
Expand All @@ -35,11 +32,7 @@
"spglib<2.0.0",
],
extras_require={
"all": [
"robocrys>=0.2.7",
"pymatgen-analysis-diffusion>=2022.1.15",
"pymatgen-analysis-alloys>=0.0.3",
],
"all": ["robocrys>=0.2.7", "pymatgen-analysis-diffusion>=2022.1.15", "pymatgen-analysis-alloys>=0.0.3"],
},
python_requires=">=3.8",
license="modified BSD",
Expand Down