def setUp(self):
        d = [
            {"correction": 0.0, "data": {}, "energy": -108.56492362, "parameters": {}, "composition": {"Li": 54}},
            {
                "correction": 0.0,
                "data": {},
                "energy": -577.94689128,
                "parameters": {},
                "composition": {"O": 32, "Li": 64},
            },
            {"correction": 0.0, "data": {}, "energy": -17.02844794, "parameters": {}, "composition": {"O": 2}},
            {
                "correction": 0.0,
                "data": {},
                "energy": -959.64693323,
                "parameters": {},
                "composition": {"O": 72, "Li": 72},
            },
        ]
        entries = []
        for e in d:
            entries.append(ComputedEntry.from_dict(e))
        rcts = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
        prods = list(filter(lambda e: e.composition.reduced_formula == "Li2O2", entries))

        self.rxn = ComputedReaction(rcts, prods)
Example #2
0
    def test_get_entry_by_material_id(self, mongo_mprester):
        reference_file = Path(
            __file__).absolute().parent / "mp-9029_entry_by_material_id.json"

        e = mongo_mprester.get_entry_by_material_id('mp-9029')

        assert e == ComputedEntry.from_dict(json.load(open(reference_file)))
 def test_to_from_dict_with_adjustment_2(self):
     """
     Modern case where correction was provided manually
     """
     d = self.entry7.as_dict()
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.uncorrected_energy, 6.9)
     self.assertEqual(e.energy_adjustments[0].value, self.entry7.energy_adjustments[0].value)
Example #4
0
 def remove_structure(entries):
     ents = []
     for ient in entries:
         dd = ient.as_dict()
         ent = ComputedEntry.from_dict(dd)
         ent.data["volume"] = ient.structure.volume
         ents.append(ent)
     return ents
    def setUp(self):
        d = [
            {
                "correction": 0.0,
                "data": {},
                "energy": -108.56492362,
                "parameters": {},
                "composition": {
                    "Li": 54
                },
            },
            {
                "correction": 0.0,
                "data": {},
                "energy": -577.94689128,
                "parameters": {},
                "composition": {
                    "O": 32,
                    "Li": 64
                },
            },
            {
                "correction": 0.0,
                "data": {},
                "energy": -17.02844794,
                "parameters": {},
                "composition": {
                    "O": 2
                },
            },
            {
                "correction": 0.0,
                "data": {},
                "energy": -959.64693323,
                "parameters": {},
                "composition": {
                    "O": 72,
                    "Li": 72
                },
            },
        ]
        entries = []
        for e in d:
            entries.append(ComputedEntry.from_dict(e))
        rcts = list(
            filter(lambda e: e.composition.reduced_formula in ["Li", "O2"],
                   entries))
        prods = list(
            filter(lambda e: e.composition.reduced_formula == "Li2O2",
                   entries))

        self.rxn = ComputedReaction(rcts, prods)
Example #6
0
File: thermo.py Project: utf/emmet
    def process_item(self, item: Tuple[List[str], List[ComputedEntry]]):

        sandboxes, entries = item

        entries = [ComputedEntry.from_dict(entry) for entry in entries]
        # determine chemsys
        elements = sorted(
            set([el.symbol for e in entries for el in e.composition.elements]))
        chemsys = "-".join(elements)

        self.logger.debug(
            f"Procesing {len(entries)} entries for {chemsys} - {sandboxes}")

        material_entries = defaultdict(defaultdict(list))
        pd_entries = []
        for entry in entries:
            material_entries[entry.entry_id][entry.data["run_type"]].append(
                entry)

        # TODO: How to make this general and controllable via SETTINGS?
        for material_id in material_entries:
            if "GGA+U" in material_entries[material_id]:
                pd_entries.append(material_entries[material_id]["GGA+U"])
            elif "GGA" in material_entries[material_id]:
                pd_entries.append(material_entries[material_id]["GGA"])

        pd_entries = self.compatibility.process_entries(pd_entries)

        try:
            docs = ThermoDoc.from_entries(pd_entries, sandboxes=sandboxes)
            for doc in docs:
                doc.entries = material_entries[doc.material_id]
                doc.entry_types = list(
                    material_entries[doc.material_id].keys())

        except PhaseDiagramError as p:
            elsyms = []
            for e in entries:
                elsyms.extend([el.symbol for el in e.composition.elements])

            self.logger.warning(
                f"Phase diagram errorin chemsys {'-'.join(sorted(set(elsyms)))}: {p}"
            )
            return []
        except Exception as e:
            self.logger.error(f"Got unexpected error: {e}")
            return []

        return [d.dict() for d in docs]
Example #7
0
    def process_item(self, item) -> Dict:
        """
        - Add volume information to each entry to create the insertion electrode document
        - Add the host structure
        """
        if item is None:
            return None
        self.logger.debug(
            f"Working on {item['group_id']} with {len(item['thermo_docs'])}")

        entries = [
            tdoc_["entries"][tdoc_["energy_type"]]
            for tdoc_ in item["thermo_docs"]
        ]
        entries = list(map(ComputedStructureEntry.from_dict, entries))

        working_ion_entry = ComputedEntry.from_dict(
            item["working_ion_doc"]["entries"][item["working_ion_doc"]
                                               ["energy_type"]])
        working_ion = working_ion_entry.composition.reduced_formula

        decomp_energies = {
            d_["material_id"]: d_["energy_above_hull"]
            for d_ in item["thermo_docs"]
        }

        least_wion_ent = min(
            entries,
            key=lambda x: x.composition.get_atomic_fraction(working_ion))
        host_structure = least_wion_ent.structure.copy()
        host_structure.remove_species([item["working_ion"]])

        for ient in entries:
            ient.data["volume"] = ient.structure.volume
            ient.data["decomposition_energy"] = decomp_energies[ient.entry_id]

        ie = InsertionElectrodeDoc.from_entries(
            grouped_entries=entries,
            working_ion_entry=working_ion_entry,
            battery_id=item["group_id"],
            host_structure=host_structure,
        )
        if ie is None:
            return None  # {"failed_reason": "unable to create InsertionElectrode document"}
        return jsanitize(ie.dict())
Example #8
0
 def test_to_from_dict_with_adjustment_3(self):
     """
     Legacy case where the entry was serialized before the energy_adjustment
     attribute was part of ComputedEntry
     """
     # same as entry6
     d = {'@module': 'pymatgen.entries.computed_entries',
          '@class': 'ComputedEntry',
          'energy': 6.9,
          'composition': defaultdict(float, {'Fe': 6.0, 'O': 9.0}),
          'parameters': {},
          'data': {},
          'entry_id': None,
          'correction': -10}
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.uncorrected_energy, 6.9)
     self.assertAlmostEqual(e.correction, -10)
     assert len(e.energy_adjustments) == 1
 def test_to_from_dict_with_adjustment_3(self):
     """
     Legacy case where the entry was serialized before the energy_adjustment
     attribute was part of ComputedEntry
     """
     # same as entry6
     d = {
         "@module": "pymatgen.entries.computed_entries",
         "@class": "ComputedEntry",
         "energy": 6.9,
         "composition": defaultdict(float, {"Fe": 6.0, "O": 9.0}),
         "parameters": {},
         "data": {},
         "entry_id": None,
         "correction": -10,
     }
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.uncorrected_energy, 6.9)
     self.assertAlmostEqual(e.correction, -10)
     assert len(e.energy_adjustments) == 1
Example #10
0
    def entry(self) -> ComputedEntry:
        """ Turns a Task Doc into a ComputedEntry"""
        entry_dict = {
            "correction": 0.0,
            "entry_id": self.task_id,
            "composition": self.output.structure.composition,
            "energy": self.output.energy,
            "parameters": {
                "potcar_spec": self.input.potcar_spec,
                "is_hubbard": self.input.is_hubbard,
                "hubbards": self.input.hubbards,
                # This is done to be compatible with MontyEncoder for the ComputedEntry
                "run_type": str(self.run_type),
            },
            "data": {
                "oxide_type": oxide_type(self.output.structure),
                "aspherical": self.input.parameters.get("LASPH", True),
                "last_updated": self.last_updated,
            },
        }

        return ComputedEntry.from_dict(entry_dict)
Example #11
0
 def test_to_from_dict(self):
     d = self.entry.as_dict()
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.energy, -269.38319884)
Example #12
0
 def from_dict(cls, d):
     entries = [ComputedEntry.from_dict(dd) for dd in d["all_entries"]]
     elements = [Element.from_dict(dd) for dd in d["elements"]]
     return cls(entries, elements)
Example #13
0
 def convert(self, d):
     if 'structure' in d:
         return ComputedStructureEntry.from_dict(d)
     else:
         return ComputedEntry.from_dict(d)
Example #14
0
    def from_entries(
        cls,
        entries: Iterable[Union[ComputedEntry, ComputedStructureEntry]],
        working_ion_entry: Union[ComputedEntry, ComputedStructureEntry,
                                 PDEntry],
        strip_structures: bool = False,
    ):
        """
        Create a new InsertionElectrode.

        Args:
            entries: A list of ComputedEntries, ComputedStructureEntries, or
                subclasses representing the different topotactic states
                of the battery, e.g. TiO2 and LiTiO2.
            working_ion_entry: A single ComputedEntry or PDEntry
                representing the element that carries charge across the
                battery, e.g. Li.
            strip_structures: Since the electrode document only uses volume we can make the
                electrode object significantly leaner by dropping the structure data.
                If this parameter is set to True, the ComputedStructureEntry will be
                replaced with a ComputedEntry and the volume will be stored in
                ComputedEntry.data['volume']. If entries provided are ComputedEntries,
                must set strip_structures=False.
        """

        if strip_structures:
            ents = []
            for ient in entries:
                dd = ient.as_dict()
                ent = ComputedEntry.from_dict(dd)
                ent.data["volume"] = ient.structure.volume
                ents.append(ent)
            entries = ents

        _working_ion = working_ion_entry.composition.elements[0]
        _working_ion_entry = working_ion_entry

        # Prepare to make phase diagram: determine elements and set their energy
        # to be very high
        elements = set()
        for entry in entries:
            elements.update(entry.composition.elements)

        # Set an artificial high energy for each element for convex hull generation
        element_energy = max(entry.energy_per_atom for entry in entries) + 10

        pdentries: List[Union[ComputedEntry, ComputedStructureEntry,
                              PDEntry]] = []
        pdentries.extend(entries)
        pdentries.extend(
            [PDEntry(Composition({el: 1}), element_energy) for el in elements])

        # Make phase diagram to determine which entries are stable vs. unstable.
        # For each working ion concentration, we want one stable entry
        # to use in forming voltage pairs. PhaseDiagram allows for easy comparison
        # of entry energies.
        pd = PhaseDiagram(pdentries)

        def lifrac(e):
            return e.composition.get_atomic_fraction(_working_ion)

        # stable entries ordered by amount of Li asc
        _stable_entries = tuple(
            sorted((e for e in pd.stable_entries if e in entries), key=lifrac))

        # unstable entries ordered by amount of Li asc
        _unstable_entries = tuple(
            sorted((e for e in pd.unstable_entries if e in entries),
                   key=lifrac))

        # create voltage pairs
        _vpairs: Tuple[AbstractVoltagePair] = tuple(  # type: ignore
            InsertionVoltagePair.from_entries(
                _stable_entries[i],
                _stable_entries[i + 1],
                working_ion_entry,
            ) for i in range(len(_stable_entries) - 1))
        framework = _vpairs[0].framework
        return cls(  # pylint: disable=E1123
            voltage_pairs=_vpairs,
            working_ion_entry=_working_ion_entry,
            stable_entries=_stable_entries,
            unstable_entries=_unstable_entries,
            framework_formula=framework.reduced_formula,
        )
Example #15
0
    def from_entries(cls, entries, working_ion_entry, strip_structures=False):
        """
        Create a new InsertionElectrode.

        Args:
            entries: A list of ComputedStructureEntries (or subclasses)
                representing the different topotactic states of the battery,
                e.g. TiO2 and LiTiO2.
            working_ion_entry: A single ComputedEntry or PDEntry
                representing the element that carries charge across the
                battery, e.g. Li.
            strip_structures: Since the electrode document only uses volume we can make the
                electrode object significantly leaner by dropping the structure data.
                If this parameter is set to True, the ComputedStructureEntry will be replaced
                with ComputedEntry and the volume will be stored in ComputedEntry.data['volume']
        """

        if strip_structures:
            ents = []
            for ient in entries:
                dd = ient.as_dict()
                ent = ComputedEntry.from_dict(dd)
                ent.data["volume"] = ient.structure.volume
                ents.append(ent)
            entries = ents

        _working_ion = working_ion_entry.composition.elements[0]
        _working_ion_entry = working_ion_entry

        # Prepare to make phase diagram: determine elements and set their energy
        # to be very high
        elements = set()
        for entry in entries:
            elements.update(entry.composition.elements)

        # Set an artificial energy for each element for convex hull generation
        element_energy = max([entry.energy_per_atom for entry in entries]) + 10

        pdentries = []
        pdentries.extend(entries)
        pdentries.extend(
            [PDEntry(Composition({el: 1}), element_energy) for el in elements])

        # Make phase diagram to determine which entries are stable vs. unstable
        pd = PhaseDiagram(pdentries)

        def lifrac(e):
            return e.composition.get_atomic_fraction(_working_ion)

        # stable entries ordered by amount of Li asc
        _stable_entries = tuple(
            sorted([e for e in pd.stable_entries if e in entries], key=lifrac))

        # unstable entries ordered by amount of Li asc
        _unstable_entries = tuple(
            sorted([e for e in pd.unstable_entries if e in entries],
                   key=lifrac))

        # create voltage pairs
        _vpairs = tuple([
            InsertionVoltagePair.from_entries(
                _stable_entries[i],
                _stable_entries[i + 1],
                working_ion_entry,
            ) for i in range(len(_stable_entries) - 1)
        ])
        framework = _vpairs[0].framework
        return cls(
            voltage_pairs=_vpairs,
            working_ion_entry=_working_ion_entry,
            _stable_entries=_stable_entries,
            _unstable_entries=_unstable_entries,
            _framework_formula=framework.reduced_formula,
        )
Example #16
0
 def test_to_from_dict_structure_with_adjustment_3(self):
     """
     Legacy case where the structure entry was serialized before the energy_adjustment
     attribute was part of ComputedEntry
     """
     # ComputedStructureEntry for Oxygen, mp-12957, as of April 2020
     # with an arbitrary 1 eV correction added
     d = {
         "@module": "pymatgen.entries.computed_entries",
         "@class": "ComputedStructureEntry",
         "energy": -39.42116819,
         "composition": defaultdict(float, {"O": 8.0}),
         "parameters": {
             "run_type": "GGA",
             "is_hubbard": False,
             "pseudo_potential": {
                 "functional": "PBE",
                 "labels": ["O"],
                 "pot_type": "paw",
             },
             "hubbards": {},
             "potcar_symbols": ["PBE O"],
             "oxide_type": "None",
         },
         "data": {
             "oxide_type": "None"
         },
         "entry_id": "mp-12957",
         "correction": 1,
         "structure": {
             "@module":
             "pymatgen.core.structure",
             "@class":
             "Structure",
             "charge":
             None,
             "lattice": {
                 "matrix": [
                     [-1.7795583, 0.0, 3.86158265],
                     [4.17564656, -3.03266995, -0.01184798],
                     [4.17564656, 3.03266995, -0.01184798],
                 ],
                 "a":
                 4.251899376264673,
                 "b":
                 5.160741380296335,
                 "c":
                 5.160741380296335,
                 "alpha":
                 71.97975354157973,
                 "beta":
                 109.9211782454931,
                 "gamma":
                 109.9211782454931,
                 "volume":
                 97.67332322031668,
             },
             "sites": [
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.8531272, 0.15466029, 0.15466029],
                     "xyz": [
                         -0.22657617390155504,
                         -1.750215367360042e-17,
                         3.2907563697176516,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": 0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.84038763, 0.71790132, 0.21754949],
                     "xyz": [
                         2.410593174641884,
                         -1.5174019592685084,
                         3.234143088794756,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": -0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.17255465, 0.21942628, 0.21942628],
                     "xyz": [
                         1.5254221229000986,
                         -2.121360826524921e-18,
                         0.6611345262629937,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": 0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.15961237, 0.78245051, 0.28209968],
                     "xyz": [
                         4.161145821004675,
                         -1.5173989265985586,
                         0.6037435893572642,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": -0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.84038763, 0.21754949, 0.71790132],
                     "xyz": [
                         2.410593174641884,
                         1.5174019592685082,
                         3.234143088794756,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": -0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.82744535, 0.78057372, 0.78057372],
                     "xyz": [
                         5.046312697099901,
                         -1.3574974398403584e-16,
                         3.176752163737006,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": 0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.15961237, 0.28209968, 0.78245051],
                     "xyz": [
                         4.161145821004675,
                         1.5173989265985584,
                         0.6037435893572642,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": -0.002
                     },
                 },
                 {
                     "species": [{
                         "element": "O",
                         "occu": 1
                     }],
                     "abc": [0.1468728, 0.84533971, 0.84533971],
                     "xyz": [
                         6.798310993901555,
                         -1.7769364890338579e-16,
                         0.5471303202823484,
                     ],
                     "label":
                     "O",
                     "properties": {
                         "magmom": 0.002
                     },
                 },
             ],
         },
     }
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.uncorrected_energy, -39.42116819)
     self.assertAlmostEqual(e.energy, -38.42116819)
     self.assertAlmostEqual(e.correction, 1)
     assert len(e.energy_adjustments) == 1
Example #17
0
 def test_to_from_dict_structure_with_adjustment_3(self):
     """
     Legacy case where the structure entry was serialized before the energy_adjustment
     attribute was part of ComputedEntry
     """
     # ComputedStructureEntry for Oxygen, mp-12957, as of April 2020
     # with an arbitrary 1 eV correction added
     d = {'@module': 'pymatgen.entries.computed_entries',
          '@class': 'ComputedStructureEntry',
          'energy': -39.42116819,
          'composition': defaultdict(float, {'O': 8.0}),
          'parameters': {'run_type': 'GGA',
                         'is_hubbard': False,
                         'pseudo_potential': {'functional': 'PBE',
                                              'labels': ['O'],
                                              'pot_type': 'paw'},
                         'hubbards': {},
                         'potcar_symbols': ['PBE O'],
                         'oxide_type': 'None'},
          'data': {'oxide_type': 'None'},
          'entry_id': 'mp-12957',
          'correction': 1,
          'structure': {'@module': 'pymatgen.core.structure',
                        '@class': 'Structure',
                        'charge': None,
                        'lattice': {'matrix': [[-1.7795583, 0.0, 3.86158265],
                                               [4.17564656, -3.03266995, -0.01184798],
                                               [4.17564656, 3.03266995, -0.01184798]],
                                    'a': 4.251899376264673,
                                    'b': 5.160741380296335,
                                    'c': 5.160741380296335,
                                    'alpha': 71.97975354157973,
                                    'beta': 109.9211782454931,
                                    'gamma': 109.9211782454931,
                                    'volume': 97.67332322031668},
                        'sites': [{'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.8531272, 0.15466029, 0.15466029],
                                   'xyz': [-0.22657617390155504, -1.750215367360042e-17, 3.2907563697176516],
                                   'label': 'O',
                                   'properties': {'magmom': 0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.84038763, 0.71790132, 0.21754949],
                                   'xyz': [2.410593174641884, -1.5174019592685084, 3.234143088794756],
                                   'label': 'O',
                                   'properties': {'magmom': -0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.17255465, 0.21942628, 0.21942628],
                                   'xyz': [1.5254221229000986, -2.121360826524921e-18, 0.6611345262629937],
                                   'label': 'O',
                                   'properties': {'magmom': 0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.15961237, 0.78245051, 0.28209968],
                                   'xyz': [4.161145821004675, -1.5173989265985586, 0.6037435893572642],
                                   'label': 'O',
                                   'properties': {'magmom': -0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.84038763, 0.21754949, 0.71790132],
                                   'xyz': [2.410593174641884, 1.5174019592685082, 3.234143088794756],
                                   'label': 'O',
                                   'properties': {'magmom': -0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.82744535, 0.78057372, 0.78057372],
                                   'xyz': [5.046312697099901, -1.3574974398403584e-16, 3.176752163737006],
                                   'label': 'O',
                                   'properties': {'magmom': 0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.15961237, 0.28209968, 0.78245051],
                                   'xyz': [4.161145821004675, 1.5173989265985584, 0.6037435893572642],
                                   'label': 'O',
                                   'properties': {'magmom': -0.002}},
                                  {'species': [{'element': 'O', 'occu': 1}],
                                   'abc': [0.1468728, 0.84533971, 0.84533971],
                                   'xyz': [6.798310993901555, -1.7769364890338579e-16, 0.5471303202823484],
                                   'label': 'O',
                                   'properties': {'magmom': 0.002}}]}}
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.uncorrected_energy, -39.42116819)
     self.assertAlmostEqual(e.energy, -38.42116819)
     self.assertAlmostEqual(e.correction, 1)
     assert len(e.energy_adjustments) == 1
Example #18
0
    def test_calculated_reaction_energy_uncertainty_for_nan(self):
        # test that reaction_energy_uncertainty property is nan when the uncertainty
        # for any product/reactant is nan
        d = [
            {
                "correction": 0.0,
                "data": {},
                "energy": -108.56492362,
                "parameters": {},
                "composition": {"Li": 54},
            },
            {
                "correction": 0.0,
                "data": {},
                "energy": -17.02844794,
                "parameters": {},
                "composition": {"O": 2},
            },
            {
                "@module": "pymatgen.entries.computed_entries",
                "@class": "ComputedEntry",
                "energy": -38.76889738,
                "composition": defaultdict(float, {"Li": 4.0, "O": 4.0}),
                "energy_adjustments": [
                    {
                        "@module": "pymatgen.entries.computed_entries",
                        "@class": "ConstantEnergyAdjustment",
                        "@version": "2020.6.8",
                        "value": -1.864,
                        "uncertainty": np.nan,
                        "name": "MP2020 Composition Correction",
                        "cls": {
                            "@module": "pymatgen.entries.compatibility",
                            "@class": "MaterialsProject2020Compatibility",
                            "@version": "2020.6.8",
                            "compat_type": "Advanced",
                            "correct_peroxide": True,
                            "check_potcar_hash": False,
                        },
                        "description": "Constant energy adjustment (-1.864 eV)",
                    }
                ],
                "parameters": {
                    "run_type": "GGA",
                    "is_hubbard": False,
                    "pseudo_potential": {
                        "functional": "PBE",
                        "labels": ["Li_sv", "O"],
                        "pot_type": "paw",
                    },
                    "hubbards": {},
                    "potcar_symbols": ["PBE Li_sv", "PBE O"],
                    "oxide_type": "peroxide",
                },
                "data": {"oxide_type": "peroxide"},
                "entry_id": "mp-841",
                "correction": -1.864,
            },
        ]
        entries = []
        for e in d:
            entries.append(ComputedEntry.from_dict(e))
        rcts = list(
            filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries)
        )
        prods = list(
            filter(lambda e: e.composition.reduced_formula == "Li2O2", entries)
        )

        rxn_with_uncertainty = ComputedReaction(rcts, prods)
        self.assertTrue(
            isnan(rxn_with_uncertainty.calculated_reaction_energy_uncertainty)
        )
Example #19
0
 def from_dict(cls, d):
     entries = [ComputedEntry.from_dict(dd) for dd in d["all_entries"]]
     elements = [Element.from_dict(dd) for dd in d["elements"]]
     return cls(entries, elements)
Example #20
0
 def test_to_from_dict(self):
     d = self.entry.to_dict
     e = ComputedEntry.from_dict(d)
     self.assertAlmostEqual(e.energy, -269.38319884)
    def test_calculated_reaction_energy_uncertainty_for_nan(self):
        # test that reaction_energy_uncertainty property is nan when the uncertainty
        # for any product/reactant is nan
        d = [
            {
                "correction": 0.0,
                "data": {},
                "energy": -108.56492362,
                "parameters": {},
                "composition": {
                    "Li": 54
                },
            },
            {
                "correction": 0.0,
                "data": {},
                "energy": -17.02844794,
                "parameters": {},
                "composition": {
                    "O": 2
                },
            },
            {
                '@module':
                'pymatgen.entries.computed_entries',
                '@class':
                'ComputedEntry',
                'energy':
                -38.76889738,
                'composition':
                defaultdict(float, {
                    'Li': 4.0,
                    'O': 4.0
                }),
                'energy_adjustments': [{
                    '@module':
                    'pymatgen.entries.computed_entries',
                    '@class':
                    'ConstantEnergyAdjustment',
                    '@version':
                    '2020.6.8',
                    'value':
                    -1.864,
                    'uncertainty':
                    np.nan,
                    'name':
                    'MP2020 Composition Correction',
                    'cls': {
                        '@module': 'pymatgen.entries.compatibility',
                        '@class': 'MaterialsProject2020Compatibility',
                        '@version': '2020.6.8',
                        'compat_type': 'Advanced',
                        'correct_peroxide': True,
                        'check_potcar_hash': False
                    },
                    'description':
                    'Constant energy adjustment (-1.864 eV)'
                }],
                'parameters': {
                    'run_type': 'GGA',
                    'is_hubbard': False,
                    'pseudo_potential': {
                        'functional': 'PBE',
                        'labels': ['Li_sv', 'O'],
                        'pot_type': 'paw'
                    },
                    'hubbards': {},
                    'potcar_symbols': ['PBE Li_sv', 'PBE O'],
                    'oxide_type': 'peroxide'
                },
                'data': {
                    'oxide_type': 'peroxide'
                },
                'entry_id':
                'mp-841',
                'correction':
                -1.864
            },
        ]
        entries = []
        for e in d:
            entries.append(ComputedEntry.from_dict(e))
        rcts = list(
            filter(lambda e: e.composition.reduced_formula in ["Li", "O2"],
                   entries))
        prods = list(
            filter(lambda e: e.composition.reduced_formula == "Li2O2",
                   entries))

        rxn_with_uncertainty = ComputedReaction(rcts, prods)
        self.assertTrue(
            isnan(rxn_with_uncertainty.calculated_reaction_energy_uncertainty))