msmjax.bspline.coefficients

Code for coefficients of B-spline (quasi-)interpolation.

References

[1] Hardy, D. J.; Wolff, M. A.; Xia, J.; Schulten, K.; Skeel, R. D. Multilevel Summation with B-Spline Interpolation for Pairwise Interactions in Molecular Dynamics Simulations. J. Chem. Phys. 2016, 144 (11), 114112. https://doi.org/10.1063/1.4943868.

msmjax.bspline.coefficients.calc_Phi(p, u)[source]

Evaluate the B-spline denoted by Phi in the article.

Parameters:
  • p (int) – The degree of the spline in the convention of the article.

  • u (numpy.typing.ArrayLike) – The value or array or values where the function should be evaluated.

Return type:

ndarray

Returns:

The values(s) of Phi(u) at u.

Raises:

ValueError – If p is not a positive, even integer.

msmjax.bspline.coefficients.build_col_of_B(p)[source]

Create a column of B according to the equation before (10).

This function creates a vector with Phi(u) evaluated at all the integers inside its domain. Only the part of the column starting at and including the main diagonal is returned.

Parameters:

p (int) – The degree of the spline in the convention of the article.

Return type:

ndarray

Returns:

A vector of p/2 elements with all the non-zero entries in any column of the banded matrix B, starting at and including the main diagonal.

msmjax.bspline.coefficients.build_col_of_B2(p)[source]

Create a column of B**2 based on the column of B.

Parameters:

p (int) – The degree of the spline in the convention of the article.

Return type:

ndarray

Returns:

A vector with all the non-zero entries in any column of the banded matrix B**2, starting at and including the main diagonal.

msmjax.bspline.coefficients.build_Toeplitz_matrix(p, n_rows)[source]

Build an approximation to B**2 as a Toeplitz matrix.

Parameters:
  • p (int) – The degree of the spline in the convention of the article.

  • n_rows (int) – The number of rows of the matrix.

Return type:

ndarray

Returns:

The matrix as a vector in a format that scipy.linalg.toeplitz can understand.

Raises:

ValueError – If n_rows is too small for this matrix.

msmjax.bspline.coefficients.build_Toeplitz_system(p, rhs, padding)[source]

Build a finite approximation to the linear system defining the cm.

Parameters:
  • p (int) – The degree of the spline in the convention of the article.

  • rhs (ndarray) – The non-zero part of the right hand side, which must have an odd length.

  • padding (int) – The amount of padding around the minimal Toeplitz approximation, as a positive integer.

Return type:

tuple[ndarray, ndarray]

Returns:

A tuple with two vectors. The first one represents the Toeplitz coefficient matrix, and the second one is the symmetric Kronecker delta independent right-hand side.

Raises:

ValueError – If “padding” is negative or zero, or if rhs has an even length.

msmjax.bspline.coefficients.compute_c_m(p, C_coeffs, mu, rtol=1e-05, atol=1e-08)[source]

Compute c_m the coefficients of the approximation to B^(-2).

The solution is based on the construction of progressively larger approximations to an infinite Toeplitz matrix, until the solution converges.

Parameters:
  • p (int) – The degree of the spline in the convention of the article.

  • mu (int) – A non-negative integer determining how many terms are calculated. The output will contain (2 * mu + 1) coefficients.

  • C_coeffs (ndarray) – The right-hand side of the unnumbered equation in appendix C that defined the c_m, in the basis of powers of E (not delta**2!), as a NumPy array.

  • rtol (float) – The relative tolerance to be passes to np.allclose() when checking for convergence.

  • atol (float) – The absolute tolerance to be passes to np.allclose() when checking for convergence.

Return type:

ndarray

Returns:

The coefficients c_m in a Numpy Array.

Raises:

ValueError – If mu is negative.

msmjax.bspline.coefficients.generating_function(z, s)[source]

Compute the function defined in equation (B1) of the paper.

Parameters:
  • z (Expr) – The argument on which the function will be Mclaurin-expanded.

  • s (Expr) – The parameter that determines the Mclaurin coefficients.

Return type:

Mul

Returns:

The value of the function.

msmjax.bspline.coefficients.calc_Mclaurin_coefficient(function, variable, order)[source]

Calculate a coefficient in truncated McLaurin series of a function.

Parameters:
  • function (Function) – A SymPy function.

  • variable (Symbol) – The SymPy variable of the power series.

  • order (int) – The order of the coefficient.

Return type:

Expr

Returns:

The coefficient as a SymPy expression.

msmjax.bspline.coefficients.calc_B_p_over_2(p)[source]

Build the polynomial B_(p/2) defined in equation B1.

Parameters:

p (int) – The index of the polynomial. It must be a positive even integer.

Return type:

Poly

Returns:

The polynomial as a SymPy object. The variable is s=delta**2.

Raises:

ValueError – If p does not make sense.

msmjax.bspline.coefficients.calc_polynomials(p)[source]

Obtain the polynomials b and C defined by equation (C1).

Parameters:

p (int) – The index of the polynomial. It must be an even integer greater than 2.

Return type:

tuple[Poly, Poly]

Returns:

A tuple with the polynomials (b, C) as SymPy objects.

Raises:

ValueError – If p violates the constraints.

msmjax.bspline.coefficients.explode_Add(add_object)[source]

Extract all the coefficients from a sum of powers of a single variable.

This function is intended for a narrow class of sympy.Add objects containing only positive and negative values of a single variable, and its behavior for any other inputs is undefined.

Parameters:

add_object (Add) – The sympy.Add object to be analyzed.

Return type:

dict

Returns:

A dictionary of coefficients of the powers contained in add_object. The keys are the exponents.

Raises:

ValueError – If the argument is not a sympy.Add object.

msmjax.bspline.coefficients.coeff_dict_to_array(coefficients)[source]

Translate the output of explode_Add() into a numerical array.

Parameters:

coefficients (dict) – The return code of explode_Add(), a dictionary of SymPy objects indexed by their exponent.

Return type:

ndarray

Returns:

A NumPy array of floating point numbers with the coefficients, that can be passed to an equation solver.

Raises:

ValueError – If the list of coefficients does not correspond to an even function.

msmjax.bspline.coefficients.compute_quasi_omega_prime(p, mu)[source]

Compute the coefficients \(\omega_{\mu,m}'\) from the article.

They are introduced in the inline equations in the text after Eq. (13).

Parameters:
  • p (int) – The degree of the spline in the convention of the article.

  • mu (int) – Adjustable parameter in the quasi-interpolation scheme that controls its accuracy at grid points.

Returns:

  • The coefficients denoted $omega_{mu,m}’$ in the article.

  • The coefficients denoted $c_m$ in the article, in the unnumbered equation after Eq. 12 that defines the expansion of the operator A.

Return type:

Tuple containing

msmjax.bspline.coefficients.compute_j_zeroplus(p)[source]

Compute the sequence J of spline-nesting coefficients given by eq. (22).

Parameters:

p (int) – The degree of the spline in the convention of the article.

Return type:

ndarray

Returns:

Array of coefficients for expressing B-splines at one grid level in terms of the B-splines at the next finer level. The result contains only the elements with non-negative index, those with negative index follow by symmetry.