# Source code for pymatgen.entries

# coding: utf-8
# Copyright (c) Pymatgen Development Team.

"""
Entries are containers for calculated information, which is used in
many analyses. This module contains entry related tools and implements
the base Entry class, which is the basic entity that can be used to
store calculated information. Other Entry classes such as ComputedEntry
and PDEntry inherit from this class.
"""

from pymatgen.core.composition import Composition
from monty.json import MSONable
from abc import ABCMeta, abstractmethod

__author__ = "Shyue Ping Ong, Anubhav Jain, Ayush Gupta"
__version__ = "1.1"
__maintainer__ = "Shyue Ping Ong"
__email__ = "shyuep@gmail.com"
__status__ = "Production"
__date__ = "Mar 03, 2020"

[docs]class Entry(MSONable, metaclass=ABCMeta):
"""
A lightweight object containing the energy associated with
a specific chemical composition. This base class is not
intended to be instantiated directly. Note that classes
which inherit from Entry must define a .energy property.

"""

def __init__(self,
composition: Composition,
energy: float):
"""
Initializes an Entry.

Args:
composition (Composition): Composition of the entry. For
flexibility, this can take the form of all the typical input
taken by a Composition, including a {symbol: amt} dict,
a string formula, and others.
energy (float): Energy of the entry.
"""
self._energy = energy
self.composition = Composition(composition)

@property
def is_element(self) -> bool:
"""
:return: Whether composition of entry is an element.
"""
return self.composition.is_element

@property
@abstractmethod
def energy(self) -> float:
"""
:return: the energy of the entry.
"""

@property
def energy_per_atom(self) -> float:
"""
:return: the energy per atom of the entry.
"""
return self.energy / self.composition.num_atoms

def __str__(self):
return self.__repr__()

[docs]    def normalize(self, mode: str = "formula_unit") -> None:
"""
Normalize the entry's composition and energy.

Args:
mode: "formula_unit" is the default, which normalizes to
composition.reduced_formula. The other option is "atom", which
normalizes such that the composition amounts sum to 1.
"""
factor = self._normalization_factor(mode)
self.composition /= factor
self._energy /= factor

def _normalization_factor(self, mode: str = "formula_unit") -> float:
if mode == "atom":
factor = self.composition.num_atoms
else:
comp, factor = self.composition.get_reduced_composition_and_factor()
return factor

[docs]    def as_dict(self) -> dict:
"""
:return: MSONable dict.
"""
return {"@module": self.__class__.__module__,
"@class": self.__class__.__name__,
"energy": self._energy,
"composition": self.composition.as_dict()}
{"ft_lang_label":"__label__en","ft_lang_prob":0.6649413,"math_prob":0.7100563,"size":2762,"snap":"2023-14-2023-23","text_gpt3_token_len":667,"char_repetition_ratio":0.16823785,"word_repetition_ratio":0.016759777,"special_character_ratio":0.26393917,"punctuation_ratio":0.22435898,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.963303,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-24T18:23:17Z\",\"WARC-Record-ID\":\"<urn:uuid:485f179f-f109-49f9-a037-1ffc9272fe05>\",\"Content-Length\":\"15290\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f5e80747-0842-4746-801d-c845a647833b>\",\"WARC-Concurrent-To\":\"<urn:uuid:edbe7dfe-a063-4d6a-abf6-a4b2ce845b06>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://pymatgen.org/_modules/pymatgen/entries.html\",\"WARC-Payload-Digest\":\"sha1:KSZQQALMQ67UOCQT7NQXIWWINHMPFEPH\",\"WARC-Block-Digest\":\"sha1:SZWU2QYAGMILW3T5NWXWDRA2SAA2CANK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296945288.47_warc_CC-MAIN-20230324180032-20230324210032-00008.warc.gz\"}"}