#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Objectif : modéliser le pouvoir tampon d'une tampon de première espèce'
"""
#Importation des librairies
import numpy as np
# from scipy.optimize import curve_fit
import matplotlib.pyplot as plt

#Définition des fonctions

def beta(pH, Ke, Ka, c, c0):
    return np.log(10)*c0*(10**(-pH)+Ke/10**(-pH)+(Ka*c/c0)*(10**(-pH)/(Ka+10**(-pH))**2))

#Liste de données:

pH_exp = np.array([3.69, 4.11, 4.59, 4.59, 5.07, 5.57])
a = np.array([-0.623, -0.320, -0.213, 0.213, 0.262, 0.400])



#Run 

Ke = 10**(-14)
Ka = 10**(-4.75)
c = 0.1
c0 = 1
c_aj = 0.1
V_tot = 27


pH_theo = np.linspace(3,7)
B_theo = beta(pH_theo, Ke,Ka, c , c0)
B_exp = c_aj/(V_tot*abs(a))*(1/0.45)
plt.plot(pH_theo, B_theo,'r', label='courbe théorique')
plt.plot(pH_exp, B_exp, 'g', label = 'courbe expérimentale')
plt.axvline(x=4.75, label ='pH=pKa')
plt.title(label= 'Courbe B = f(pH)')
plt.xlabel('pH' )
plt.ylabel('B')
plt.legend()
plt.show()