Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed May 27, 2021
1 parent e74f55f commit aad5eeb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 38 deletions.
20 changes: 5 additions & 15 deletions emmet-builders/emmet/builders/vasp/materials.py
@@ -1,21 +1,13 @@
from datetime import datetime
from itertools import chain
from operator import itemgetter
from typing import Dict, Iterator, List, Optional
from typing import Dict, Iterable, Iterator, List, Optional

from maggma.builders import Builder
from maggma.stores import Store
from pymatgen.core import Structure
from pymatgen.analysis.structure_analyzer import oxide_type
from pymatgen.analysis.structure_matcher import ElementComparator, StructureMatcher
from maggma.utils import grouper

from emmet.builders.utils import maximal_spanning_non_intersecting_subsets

# from emmet.core import SETTINGS
from emmet.builders import SETTINGS
from emmet.builders.settings import EmmetBuildSettings
from emmet.core.utils import group_structures, jsanitize
from emmet.core.vasp.calc_types import TaskType
from emmet.core.vasp.material import MaterialsDoc
from emmet.core.vasp.task import TaskDocument

Expand All @@ -33,11 +25,8 @@ class MaterialsBuilder(Builder):
1.) Find all documents with the same formula
2.) Select only task documents for the task_types we can select properties from
3.) Aggregate task documents based on strucutre similarity
4.) Convert task docs to property docs with metadata for selection and aggregation
5.) Select the best property doc for each property
6.) Build material document from best property docs
7.) Post-process material document
8.) Validate material document
4.) Create a MaterialDoc from the group of task documents
5.) Validate material document
"""

Expand All @@ -56,6 +45,7 @@ def __init__(
materials: Store of materials documents to generate
task_validation: Store for storing task validation results
query: dictionary to limit tasks to be analyzed
settings: EmmetSettings to use in the build process
"""

self.tasks = tasks
Expand Down
4 changes: 2 additions & 2 deletions emmet-builders/emmet/builders/vasp/task_validator.py
@@ -1,15 +1,15 @@
from typing import Dict, List, Union, Optional
from typing import Dict, List, Optional, Union

import numpy as np
from maggma.builders import MapBuilder
from maggma.core import Store
from pymatgen.core import Structure

from emmet.builders import SETTINGS
from emmet.builders.settings import EmmetBuildSettings
from emmet.core.vasp.calc_types import run_type, task_type
from emmet.core.vasp.task import TaskDocument
from emmet.core.vasp.validation import DeprecationMessage, ValidationDoc
from emmet.builders.settings import EmmetBuildSettings


class TaskValidator(MapBuilder):
Expand Down
33 changes: 12 additions & 21 deletions emmet-builders/emmet/builders/vasp/thermo.py
@@ -1,23 +1,17 @@
from collections import defaultdict
from datetime import datetime
from itertools import chain
from typing import Dict, Iterator, List, Optional, Set, Tuple
from typing import Dict, Iterable, Iterator, List, Optional, Set, Tuple

from maggma.core import Builder, Store
from maggma.utils import grouper
from monty.json import MontyDecoder
from pymatgen.core import Structure
from pymatgen.analysis.phase_diagram import PhaseDiagramError
from pymatgen.analysis.structure_analyzer import oxide_type
from pymatgen.entries.compatibility import MaterialsProjectCompatibility
from pymatgen.entries.compatibility import MaterialsProject2020Compatibility
from pymatgen.entries.computed_entries import ComputedEntry, ComputedStructureEntry

from emmet.core.utils import jsanitize
from emmet.builders.utils import (
chemsys_permutations,
maximal_spanning_non_intersecting_subsets,
)
from emmet.builders.utils import chemsys_permutations
from emmet.core.thermo import ThermoDoc
from emmet.core.vasp.calc_types import run_type
from emmet.core.utils import jsanitize


class Thermo(Builder):
Expand Down Expand Up @@ -121,13 +115,12 @@ def get_items(self) -> Iterator[List[Dict]]:
entries = self.get_entries(chemsys)
yield entries

def process_item(self, item: Tuple[List[str], List[ComputedEntry]]):
def process_item(self, item: List[Dict]):

entries = item
if len(entries) == 0:
if len(item) == 0:
return []

entries = [ComputedStructureEntry.from_dict(entry) for entry in entries]
entries = [ComputedStructureEntry.from_dict(entry) for entry in item]
# determine chemsys
elements = sorted(
set([el.symbol for e in entries for el in e.composition.elements])
Expand Down Expand Up @@ -229,9 +222,7 @@ def get_entries(self, chemsys: str) -> List[Dict]:
new_q["chemsys"] = {"$in": list(query_chemsys)}
new_q["deprecated"] = False
materials_docs = list(
self.materials.query(
criteria=new_q, properties=[self.materials.key, "entries"]
)
self.materials.query(criteria=new_q, properties=["material_id", "entries"])
)

# Get Oxidation state data for each material
Expand Down Expand Up @@ -268,7 +259,7 @@ def get_entries(self, chemsys: str) -> List[Dict]:
def get_updated_chemsys(
self,
) -> Set:
""" Gets updated chemical system as defined by the updating of an existing material """
"""Gets updated chemical system as defined by the updating of an existing material"""

updated_mats = self.thermo.newer_in(self.materials, criteria=self.query)
updated_chemsys = set(
Expand All @@ -281,7 +272,7 @@ def get_updated_chemsys(
return updated_chemsys

def get_new_chemsys(self) -> Set:
""" Gets newer chemical system as defined by introduction of a new material """
"""Gets newer chemical system as defined by introduction of a new material"""

# All materials that are not present in the thermo collection
thermo_mat_ids = self.thermo.distinct(self.thermo.key)
Expand All @@ -294,7 +285,7 @@ def get_new_chemsys(self) -> Set:
return new_mat_chemsys

def get_affected_chemsys(self, chemical_systems: Set) -> Set:
""" Gets chemical systems affected by changes in the supplied chemical systems """
"""Gets chemical systems affected by changes in the supplied chemical systems"""
# First get all chemsys with any of the elements we've marked
affected_chemsys = set()
affected_els = list({el for c in chemical_systems for el in c.split("-")})
Expand Down

0 comments on commit aad5eeb

Please sign in to comment.