# How to calculation voltage and Capacity , daw plot of Voltage & Capacity

Hello ,

I have a question about calculation Voltage of material ZnCr2O4 by Pymatgen. After VASP calculation, I used the code as bellow:

``````from pymatgen.core import Composition, Element
from pymatgen.entries.compatibility import MaterialsProjectCompatibility
from pymatgen.entries.computed_entries import ComputedEntry
from mp_api.client import MPRester
from pymatgen.io.vasp import Vasprun
from pymatgen.util.plotting import pretty_plot
%matplotlib inline
import re
import matplotlib as mpl
import palettable
from pymatgen.analysis.phase_diagram import (CompoundPhaseDiagram,PDPlotter,PhaseDiagram,)
from pymatgen.analysis.interface_reactions import GrandPotentialInterfacialReactivity, InterfacialReactivity
from pymatgen.core import Composition, Element

API=‘API KEy'
rester = MPRester(API)
vasprun = Vasprun("vasprun.xml")
entry = vasprun.get_computed_entry(inc_structure=True)
rester = MPRester(API)
mp_entries = rester.get_entries_in_chemsys(["Zn", "Cr", "O"])
compatibility = MaterialsProjectCompatibility()
entry = compatibility.process_entry(entry)
entries = compatibility.process_entries([entry] + mp_entries)
pd = PhaseDiagram(entries)
comp = Composition("ZnCr2O4")
#now we can call the get_element_profile method
el_profile = pd.get_element_profile(element=Element("Zn"), comp=comp)

uZn0 = -1.259
for i, d in enumerate(el_profile):
voltage = -(d["chempot"] - uZn0)
print("Voltage: %s V" % voltage)
print(d["reaction"])
print("")

``````

After run this code, I have reaction:

Voltage: 0.0007436100000000057 V
ZnCr2O4 → ZnCr2O4

Voltage: 3.6552094650000035 V
ZnCr2O4 → 2 CrO2 + Zn

I draw the plot of ‘‘voltage& Zn uptake per f.u’’ by the code:

``````
mpl.rcParams['axes.linewidth']=3
mpl.rcParams['lines.markeredgewidth']=4
mpl.rcParams['lines.linewidth']=3
mpl.rcParams['lines.markersize']=15
mpl.rcParams['xtick.major.width']=3
mpl.rcParams['xtick.major.size']=8
mpl.rcParams['xtick.minor.width']=3
mpl.rcParams['xtick.minor.size']=4
mpl.rcParams['ytick.major.width']=3
mpl.rcParams['ytick.major.size']=8
mpl.rcParams['ytick.minor.width']=3
mpl.rcParams['ytick.minor.size']=4
# Plot of Li uptake per formula unit (f.u.) of Li6PS5Cl against voltage vs Li/Li+.
colors = palettable.colorbrewer.qualitative.Set1_9.mpl_colors
plt = pretty_plot(50, 40)
for i, d in enumerate(el_profile):
v = - (d["chempot"] - uZn0)
if i != 0:
plt.plot([x2, x2], [y1, 100*d["evolution"]/32 ], 'k', linewidth=3)
x1 = v
y1 =100* d["evolution"] /32
if i != len(el_profile) - 1:
x2 = - (el_profile[i + 1]["chempot"] - uZn0)
else:
x2 = 5.0
if i in [0, 4, 5, 7]:
products = [re.sub(r"(\d+)", r"\$_{\1}\$", p.reduced_formula)
for p in d["reaction"].products if p.reduced_formula != "Zn"]

plt.annotate(
", ".join(products), xy=(v + 0.05, y1 + 0.3), fontsize=90, color=colors[0]
)
plt.plot([x1, x2], [y1, y1], color=colors[0], linewidth=5)
else:
plt.plot([x1, x2], [y1, y1], "k", linewidth=3)

plt.xlim((0, 5.0))
plt.ylim((-5, 5.0))
plt.xlabel("Voltage vs Zn/Zn\$^2+\$ (V)")
plt.ylabel("Zn uptake per f.u.")
plt.tight_layout()
``````

So how can I draw the plot of Voltage & Capacity of this material?
I find information about ZnCr2O4 (mp-19410) in Material Project as bellow:

Affter VASP calcualtion, how can I calculation exactly Voltage and Capacity of this material ( as show in table) by pymatgen code?