# pymatgen.util.convergence module

function for calculating the convergence of an x, y data set main api:

test_conv(xs, ys, name, tol)

tries to fit multiple functions to the x, y data

calculates which function fits best for tol < 0 returns the x value for which y is converged within tol of the assymtotic value for tol > 0 returns the x_value for which dy(x)/dx < tol for all x >= x_value, conv is true is such a x_value exists for the best fit a gnuplot line is printed plotting the data, the function and the assymthotic value

exception SplineInputError(msg)[source]

Bases: `Exception`

Error for Spline input

Parameters:

msg (str) – Message

determine_convergence(xs, ys, name, tol: float = 0.0001, extra='', verbose=False, mode='extra', plots=True)[source]

test it and at which x_value dy(x)/dx < tol for all x >= x_value, conv is true is such a x_value exists.

exponential(x, a, b, n)[source]

exponential function base n to fit convergence data

extrapolate_reciprocal(xs, ys, n, noise)[source]

return the parameters such that a + b / x^n hits the last two data points

extrapolate_simple_reciprocal(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

get_derivatives(xs, ys, fd=False)[source]

return the derivatives of y(x) at the points x if scipy is available a spline is generated to calculate the derivatives if scipy is not available the left and right slopes are calculated, if both exist the average is returned putting fd to zero always returns the finite difference slopes

get_weights(xs, ys, mode=2)[source]
Parameters:
• () (mode) –

• ()

• ()

Returns:

id_generator(size=8, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')[source]
Parameters:
• () (chars) –

• ()

Returns:

measure(function, xs, ys, popt, weights)[source]

measure the quality of a fit

multi_curve_fit(xs, ys, verbose)[source]

fit multiple functions to the x, y data, return the best fit

multi_reciprocal_extra(xs, ys, noise=False)[source]

Calculates for a series of powers ns the parameters for which the last two points are at the curve. With these parameters measure how well the other data points fit. return the best fit.

p0_exponential(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

p0_reciprocal(xs, ys)[source]

predictor for first guess for reciprocal

p0_simple_2reciprocal(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

p0_simple_4reciprocal(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

p0_simple_5reciprocal(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

p0_simple_reciprocal(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

p0_single_reciprocal(xs, ys)[source]
Parameters:
• () (ys) –

• ()

Returns:

print_and_raise_error(xs, ys, name)[source]
Parameters:
• () (name) –

• ()

• ()

Returns:

print_plot_line(function, popt, xs, ys, name, tol: float = 0.05, extra='')[source]

print the gnuplot command line to plot the x, y data with the fitted function using the popt parameters

reciprocal(x, a, b, n)[source]

reciprocal function to the power n to fit convergence data

simple_2reciprocal(x, a, b)[source]

reciprocal function to fit convergence data

simple_4reciprocal(x, a, b)[source]

reciprocal function to fit convergence data

simple_5reciprocal(x, a, b)[source]

reciprocal function to fit convergence data

simple_reciprocal(x, a, b)[source]

reciprocal function to fit convergence data

single_reciprocal(x, a, b, c)[source]

reciprocal function to fit convergence data