Ligands.FitCharges - asche1/PyCrystalField GitHub Wiki
Ligands.FitCharges
Ligands.FitCharges(self, chisqfunc, fitargs, method='Powell', **kwargs):
Fit the effective charges of a point charge model by minimizing a user-provided chi squared function chisqfunc.
Parameters
chisqfunc: function, defining the chi^2 to be minimized. The first input argument must be a Ligands object, the rest are inputs that may or may not be minimized. Example:
def GlobalError(LigandsObject, LigandCharge, EnergyOffset):
# Build Hamiltonian
newH = LigandsObject.PointChargeModel(symequiv, LigandCharge=LigandCharge, printB=False)
newH.diagonalize()
# Compute error in eigenvalues
return sum((newH.eigenvalues.real + EnergyOffset - ObservedEigenvals)**2)
fitargs: list of strings, giving the names of the variables to be fitted. For example, ifchisqfunc = GlobalErrorabove, one could setfitargs = ['LigandCharge','EnergyOffset']orfitargs = ['LigandCharge'], orfitargs = ['EnergyOffset'].method: string, minimization method from the scipy library. Default: 'Powell'kwargs: dictionary, other arguments to be passed to the scipy.optimize.minimize function.
Returns
newH: aCFLevelsobject giving the CEF Hamiltonian from the final fitted point charge model.finalvals: a dictionary with the fitted values of thefitargs.