def fit(self):
# Quadratic fit to get an initial guess for the parameters.
# Thanks: https://github.com/materialsproject/pymatgen
# -> pymatgen/io/abinitio/eos.py
a, b, c = np.polyfit(self.volume, self.energy, 2)
v0 = -b/(2*a)
e0 = a*v0**2 + b*v0 + c
b0 = 2*a*v0
b1 = 4 # b1 is usually a small number like 4
if not self.volume.min() < v0 and v0 < self.volume.max():
raise StandardError('The minimum volume of a fitted parabola is not in the input volumes')
# need to use lst2dct and dct2lst here to keep the order of parameters
pp0_dct = dict(e0=e0, b0=b0, b1=b1, v0=v0)
target = lambda pp, v: self.energy - self.func(v, self.func.lst2dct(pp))
pp_opt, ierr = leastsq(target,
self.func.dct2lst(pp0_dct),
args=(self.volume,))
self.params = self.func.lst2dct(pp_opt)
评论列表
文章目录