# Adding Energy Corrections to Custom Entries

To use the outputs of custom DFT calculations in conjunction with the entries from the Materials Project ([provided the custom calculations are run with the same settings](/methodology/materials-methodology/calculation-details.md)) , a [series of corrections ](/methodology/materials-methodology/thermodynamic-stability/thermodynamic-stability/gga-gga+u-r2scan-mixing.md)have to applied to the outputs of the calculation:

```python
from pymatgen.io.vasp import Vasprun
from pymatgen.entries.computed_entries import ComputedStructureEntry
from pymatgen.entries.compatibility import MaterialsProject2020Compatibility

vasprun = Vasprun("vasprun.xml")
processed_entry = ComputedStructureEntry(
    structure = vasprun.structures[-1],
    energy = vasprun.final_energy,
    parameters = {'run_type': 'GGA', 'potcar_symbols': vasprun.potcar_symbols}
)
processed_entry.energy_adjustments = MaterialsProject2020Compatibility().get_adjustments(cse)
```

For structures containing anions, [another correction](/methodology/materials-methodology/thermodynamic-stability/thermodynamic-stability/anion-and-gga-gga+u-mixing.md) has to be applied by supplying oxidation states:

```python
from pymatgen.entries.compatibility import MaterialsProject2020Compatibility
from pymatgen.analysis.bond_valence import BVAnalyzer

#if oxidation states are not known a-priori, use Bond Valences to assign them
try:
    bva = BVAnalyzer()
    entry.data["oxidation_states"] = {
        site.species.elements[0].name : bva.get_valences(entry.structure)[i]
        for i, site in enumerate(entry.structure)
    }
except Exception as exc:
    oxi_states = entry.composition.oxi_state_guesses()
    if len(oxi_states) > 0:
        entry.data["oxidation_states"] = oxi_states[0]

processed_entry = MaterialsProject2020Compatibility()
processed_entry.process_entry(entry)
```

Then the computed structure entry will contain an individual list of energy corrections, accessible through `processed_entry.energy_adjustments`, an overall correction value in `processed_entry.corrections`, and a final corrected energy in `processed_entry.energy` or `processed_entry.energy_per_atom` .


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.materialsproject.org/methodology/materials-methodology/thermodynamic-stability/thermodynamic-stability/adding-energy-corrections-to-custom-entries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
