Skip to content

Commit

Permalink
Merge remote-tracking branch 'materialsproject/master' into s_group
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn committed Jan 13, 2021
2 parents e04688a + 987507f commit d9141f2
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v2.3.4

- uses: actions/setup-python@v2.1.4
- uses: actions/setup-python@v2.2.1
with:
python-version: 3.7

Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/checkout@v2.3.4

- uses: actions/setup-python@v2.1.4
- uses: actions/setup-python@v2.2.1
with:
python-version: 3.7

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/testing.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v2.3.4

- name: Set up Python 3.7
uses: actions/setup-python@v2.1.4
uses: actions/setup-python@v2.2.1
with:
python-version: 3.7

Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v2.3.4

- name: Set up Python 3.7
uses: actions/setup-python@v2.1.4
uses: actions/setup-python@v2.2.1
with:
python-version: 3.7

Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
steps:
- uses: actions/checkout@v2.3.4

- uses: actions/setup-python@v2.1.4
- uses: actions/setup-python@v2.2.1
with:
python-version: 3.8

Expand Down
2 changes: 1 addition & 1 deletion emmet-builders/setup.py
Expand Up @@ -7,7 +7,7 @@

setup(
name="emmet-builders",
use_scm_version={"relative_to": Path(__file__).parent},
use_scm_version={"root": "..", "relative_to": __file__},
setup_requires=["setuptools_scm"],
description="Builders for the Emmet Library",
author="The Materials Project",
Expand Down
10 changes: 5 additions & 5 deletions emmet-core/emmet/core/thermo.py
@@ -1,15 +1,15 @@
""" Core definition of a Thermo Document """
from datetime import datetime
from enum import Enum
from typing import ClassVar, Dict, List
from typing import ClassVar, Dict, List, Union

from pydantic import BaseModel, Field
from pymatgen.analysis.phase_diagram import PhaseDiagram, PhaseDiagramError
from pymatgen.core.periodic_table import Element

from emmet.core.material_property import PropertyDoc
from emmet.core.structure import StructureMetadata
from emmet.stubs import Composition, ComputedEntry
from emmet.stubs import Composition, ComputedEntry, ComputedStructureEntry


class DecompositionProduct(BaseModel):
Expand Down Expand Up @@ -83,14 +83,14 @@ class ThermoDoc(PropertyDoc):
description="List of available energy types computed for this material"
)

entries: Dict[str, ComputedEntry] = Field(
None,
entries: Dict[str, Union[ComputedEntry, ComputedStructureEntry]] = Field(
...,
description="List of all entries that are valid for this material."
" The keys for this dictionary are names of various calculation types",
)

@classmethod
def from_entries(cls, entries: List[ComputedEntry]):
def from_entries(cls, entries: List[Union[ComputedEntry, ComputedStructureEntry]]):

pd = PhaseDiagram(entries)

Expand Down
6 changes: 3 additions & 3 deletions emmet-core/emmet/core/vasp/material.py
Expand Up @@ -12,7 +12,7 @@
from emmet.core.structure import StructureMetadata
from emmet.core.vasp.calc_types import CalcType, RunType, TaskType
from emmet.core.vasp.task import TaskDocument
from emmet.stubs import ComputedEntry, Structure
from emmet.stubs import ComputedStructureEntry, Structure


class MaterialsDoc(CoreMaterialsDoc, StructureMetadata):
Expand All @@ -34,7 +34,7 @@ class MaterialsDoc(CoreMaterialsDoc, StructureMetadata):
None, description="Mappingionary for tracking the provenance of properties"
)

entries: Mapping[RunType, ComputedEntry] = Field(
entries: Mapping[RunType, ComputedStructureEntry] = Field(
None, description="Dictionary for tracking entries for VASP calculations"
)

Expand Down Expand Up @@ -136,7 +136,7 @@ def _structure_eval(task: TaskDocument):

if len(relevant_calcs) > 0:
best_task_doc = relevant_calcs[0]
entry = best_task_doc.entry
entry = best_task_doc.structure_entry
entry.data["task_id"] = entry.entry_id
entry.entry_id = material_id
entries[rt] = entry
Expand Down
16 changes: 15 additions & 1 deletion emmet-core/emmet/core/vasp/task.py
Expand Up @@ -18,7 +18,13 @@
run_type,
task_type,
)
from emmet.stubs import ComputedEntry, Matrix3D, Structure, Vector3D
from emmet.stubs import (
ComputedEntry,
ComputedStructureEntry,
Matrix3D,
Structure,
Vector3D,
)


class Status(ValueEnum):
Expand Down Expand Up @@ -153,3 +159,11 @@ def entry(self):
}

return ComputedEntry.from_dict(entry_dict)

@property
def structure_entry(self):
""" Turns a Task Doc into a ComputedStructureEntry"""
entry_dict = self.entry.as_dict()
entry_dict["structure"] = self.output.structure

return ComputedStructureEntry.from_dict(entry_dict)
32 changes: 16 additions & 16 deletions emmet-core/emmet/core/vasp/validation.py
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, List, Union

import numpy as np
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, PyObject

from emmet.core import SETTINGS
from emmet.core.utils import DocEnum
Expand All @@ -11,11 +11,12 @@


class DeprecationMessage(DocEnum):

kpoints = "kpoints", "Too few Kpoints"
encut = "encut", "ENCUT too low"
ldau = "ldau", "LDAU parameters don't match"
manual = "manual", "Manually deprecated"
MANUAL = "M", "manual deprecation"
KPTS = "C001", "Too few KPoints"
ENCUT = "C002", "ENCUT too low"
FORCES = "C003", "Forces too large"
CONVERGENCE = "E001", "Calculation did not converge"
LDAU = "I001", "LDAU Parameters don't match the inputset"


class ValidationDoc(BaseModel):
Expand All @@ -30,7 +31,10 @@ class ValidationDoc(BaseModel):
default_factory=datetime.utcnow,
)
reasons: List[Union[DeprecationMessage, str]] = Field(
[], description="List of deprecation tags detailing why this task isn't valid"
None, description="List of deprecation tags detailing why this task isn't valid"
)
warnings: List[str] = Field(
[], description="List of potential warnings about this calculation"
)

class Config:
Expand All @@ -41,7 +45,7 @@ def from_task_doc(
cls,
task_doc: TaskDocument,
kpts_tolerance: float = SETTINGS.VASP_KPTS_TOLERANCE,
input_sets: Dict[str, type] = SETTINGS.VASP_DEFAULT_INPUT_SETS,
input_sets: Dict[str, PyObject] = SETTINGS.VASP_DEFAULT_INPUT_SETS,
LDAU_fields: List[str] = SETTINGS.VASP_CHECKED_LDAU_FIELDS,
) -> "ValidationDoc":
"""
Expand All @@ -58,7 +62,6 @@ def from_task_doc(
task_type = task_doc.task_type
inputs = task_doc.orig_inputs

is_valid = True
reasons = []
data = {}

Expand All @@ -74,16 +77,14 @@ def from_task_doc(
)
data["kpts_ratio"] = num_kpts / valid_num_kpts
if data["kpts_ratio"] < kpts_tolerance:
is_valid = False
reasons.append(DeprecationMessage.kpoints)
reasons.append(DeprecationMessage.KPTS)

# Checking ENCUT
encut = inputs.get("incar", {}).get("ENCUT")
valid_encut = valid_input_set.incar["ENCUT"]
data["encut_ratio"] = float(encut) / valid_encut # type: ignore
if data["encut_ratio"] < 1:
is_valid = False
reasons.append(DeprecationMessage.encut)
reasons.append(DeprecationMessage.ENCUT)

# Checking U-values
if valid_input_set.incar.get("LDAU"):
Expand All @@ -108,14 +109,13 @@ def from_task_doc(
input_set_ldau_params[el] != input_params
for el, input_params in input_ldau_params.items()
):
is_valid = False
reasons.append(DeprecationMessage.ldau)
reasons.append(DeprecationMessage.LDAU)

doc = ValidationDoc(
task_id=task_doc.task_id,
task_type=task_doc.task_type,
run_type=task_doc.run_type,
valid=is_valid,
valid=len(reasons) == 0,
reasons=reasons,
**data
)
Expand Down
2 changes: 1 addition & 1 deletion emmet-core/emmet/core/xrd.py
Expand Up @@ -54,7 +54,7 @@ def get_target_and_edge(cls, values: Dict):
return values

@classmethod
def from_structure(
def from_structure( # type: ignore[override]
cls,
material_id: str,
spectrum_id: str,
Expand Down
11 changes: 7 additions & 4 deletions emmet-core/emmet/stubs/__init__.py
@@ -1,3 +1,4 @@
# isort: off
"""
This module stubs in pydantic models for common MSONable classes, particularly those in Pymatgen
Use pymatgen classes in pydantic models by importing them from there when you need schema
Expand All @@ -7,14 +8,15 @@
from pymatgen.analysis.diffraction.xrd import DiffractionPattern
from pymatgen.analysis.xas.spectrum import XAS
from pymatgen.core.structure import Composition, Lattice, Structure
from pymatgen.entries.computed_entries import ComputedEntry
from pymatgen.entries.computed_entries import ComputedEntry, ComputedStructureEntry

from emmet.stubs.utils import patch_msonable, use_model
from emmet.stubs.math import Matrix3D, Vector3D
from emmet.stubs.misc import Composition as StubComposition
from emmet.stubs.misc import ComputedEntry as StubComputedEntry
from emmet.stubs.structure import Lattice as StubLattice
from emmet.stubs.structure import Structure as StubStructure
from emmet.stubs.utils import patch_msonable, use_model
from emmet.stubs.entries import Composition as StubComposition
from emmet.stubs.entries import ComputedEntry as StubComputedEntry
from emmet.stubs.entries import ComputedStructureEntry as StubComputedStructureEntry
from emmet.stubs.xrd import XRDPattern as StubXRDPattern

"""
Expand All @@ -27,6 +29,7 @@
use_model(Composition, StubComposition, add_monty=False)
use_model(ComputedEntry, StubComputedEntry)
use_model(DiffractionPattern, StubXRDPattern)
use_model(ComputedStructureEntry, StubComputedStructureEntry)

# This is after the main block since it depends on that
from emmet.stubs.xas import XASSpectrum # noqa
Expand Down
Expand Up @@ -3,6 +3,8 @@
from pydantic import BaseModel, Field
from pymatgen.core.periodic_table import Element

from emmet.stubs.structure import Structure


class Composition(BaseModel):
"""A dictionary mapping element to total quantity"""
Expand Down Expand Up @@ -32,3 +34,11 @@ class ComputedEntry(BaseModel):
)
data: Dict = Field(None, description="Dictionary of extra data")
entry_id: str = Field(None, description="Entry ID")


class ComputedStructureEntry(ComputedEntry):
"""
A entry of thermodynamic information for a particular structure
"""

structure: Structure
2 changes: 1 addition & 1 deletion emmet-core/requirements.txt
@@ -1,4 +1,4 @@
pymatgen==2020.4.29
pymatgen==2020.12.31
monty==4.0.2
pydantic==1.7.3
pybtex==0.23.0
Expand Down
1 change: 1 addition & 0 deletions tests/emmet-core/test_thermo.py
Expand Up @@ -68,6 +68,7 @@ def entries():
)


@pytest.mark.xfail
def test_from_entries(entries):
docs = ThermoDoc.from_entries(entries)

Expand Down

0 comments on commit d9141f2

Please sign in to comment.