# Path: pyqha/constants.py
# RY_KBAR          = 10.0 * AU_GPA / 2.0


from .constants import RY_KBAR
from math import pow
from scipy.optimize import curve_fit
from scipy import interpolate
import numpy as np

################################################################################

def print_eos_data(x,y,a,chi,ylabel="Etot"):   
    """
    Print the data and the fitted results using the Murnaghan EOS. It can be used for
    different fitted quantities using the proper ylabel. ylabel can be "Etot", 
    "Fvib", etc.
    """
    print ("# Murnaghan EOS \t\t chi squared= {:.10e}".format(chi))
    print ("# "+ylabel+"min= {:.10e} Ry".format(a[0])+"\t Vmin= {:.10e} a.u.^3".format(a[1])+"\t B0= {:.10e} kbar".format(a[2]*RY_KBAR)
    +"\t dB0/dV= {:.10e}".format(a[3]))
    print (80*"#")
    print ("# V *a.u.^3)","\t\t",ylabel," (Ry)\t\t",ylabel+"fit"," (Ry)\t\t",ylabel+"-"+ylabel+"fit (Ry)\tP (kbar)")
    for i in range(0,len(y)):
        print ("{:.10e}".format(x[i]),"\t", "{:.10e}".format(y[i])+
        "\t {:.10e}".format(E_Murn(x[i],a))+
        "\t {:.10e}".format(y[i]-E_Murn(x[i],a))+
        "\t {:.10e}".format(P_Murn(x[i],a)*RY_KBAR))

################################################################################

def write_Etotfitted(filename,x,y,a,chi,ylabel="E"): 
    """
    Write in filename the data and the fitted results using the Murnaghan EOS. It can be used for
    different fitted quantities using the proper ylabel. ylabel can be "Etot", 
    "Fvib", etc.
    """
    fout=open(filename, "w")
    fout.write("# Murnaghan EOS \t\t chi squared= {:.10e}".format(chi))

# Path: pyqha/constants.py
# RY_KBAR          = 10.0 * AU_GPA / 2.0


# Path: pyqha/eos.py
from .constants import RY_KBAR
from math import pow
from scipy.optimize import curve_fit
from scipy import interpolate
import numpy as np


################################################################################

def print_eos_data(x,y,a,chi,ylabel="Etot"):   
    """
    Print the data and the fitted results using the Murnaghan EOS. It can be used for
    different fitted quantities using the proper ylabel. ylabel can be "Etot", 
    "Fvib", etc.
    """
    print ("# Murnaghan EOS \t\t chi squared= {:.10e}".format(chi))
    print ("# "+ylabel+"min= {:.10e} Ry".format(a[0])+"\t Vmin= {:.10e} a.u.^3".format(a[1])+"\t B0= {:.10e} kbar".format(a[2]*RY_KBAR)
    +"\t dB0/dV= {:.10e}".format(a[3]))
    print (80*"#")
    print ("# V *a.u.^3)","\t\t",ylabel," (Ry)\t\t",ylabel+"fit"," (Ry)\t\t",ylabel+"-"+ylabel+"fit (Ry)\tP (kbar)")
    for i in range(0,len(y)):
        print ("{:.10e}".format(x[i]),"\t", "{:.10e}".format(y[i])+
        "\t {:.10e}".format(E_Murn(x[i],a))+
        "\t {:.10e}".format(y[i]-E_Murn(x[i],a))+
        "\t {:.10e}".format(P_Murn(x[i],a)*RY_KBAR))

################################################################################

def write_Etotfitted(filename,x,y,a,chi,ylabel="E"): 
    """
    Write in filename the data and the fitted results using the Murnaghan EOS. It can be used for
    different fitted quantities using the proper ylabel. ylabel can be "Etot", 
    "Fvib", etc.
    """
    fout=open(filename, "w")
    fout.write("# Murnaghan EOS \t\t chi squared= {:.10e}".format(chi))

    fout.write("# E0= {:.10e} Ry".format(a[1])+"\t V0= {:.10e} a.u.^3".format(a[1])+"\t B0= {:.10e} kbar".format(a[2]*RY_KBAR)