# Path: msibi/potentials.py
# def tail_correction(r, V, r_switch):
#     """Apply a tail correction to a potential making it go to zero smoothly.
# 
#     Parameters
#     ----------
#     r : np.ndarray, shape=(n_points,), dtype=float
#         The radius values at which the potential is given.
#     V : np.ndarray, shape=r.shape, dtype=float
#         The potential values at each radius value.
#     r_switch : float, optional, default=pot_r[-1] - 5 * dr
#         The radius after which a tail correction is applied.
# 
#     References
#     ----------
#     .. [1] https://codeblue.umich.edu/hoomd-blue/doc/classhoomd__script_1_1pair_1_1pair.html
# 
#     """
#     r_cut = r[-1]
#     idx_r_switch, r_switch = find_nearest(r, r_switch)
# 
#     S_r = np.ones_like(r)
#     r = r[idx_r_switch:]
#     S_r[idx_r_switch:] = ((r_cut ** 2 - r ** 2) ** 2 *
#                           (r_cut ** 2 + 2 * r ** 2 - 3 * r_switch ** 2) /
#                           (r_cut ** 2 - r_switch ** 2) ** 3)
#     return V * S_r
# 
# def mie(r, eps, sig, m=12, n=6):
#     """Mie pair potential.  """
#     prefactor = (m  / (m - n)) * (m / n)**(n / (m - n))
#     return prefactor * eps * ((sig / r) ** m - (sig / r) ** n)
# 
# def alpha_array(alpha0, pot_r, form='linear'):
#     """Generate an array of alpha values used for scaling in the IBI step. """
#     if form == 'linear':
#         return alpha0 * (1.0 - pot_r / pot_r[-1])
#     else:
#         raise ValueError('Unsupported alpha form')


import pytest
import numpy as np
from msibi.potentials import tail_correction, mie, alpha_array



def test_tail_correction():
    dr = 0.05
    r = np.arange(0, 2.5, dr)
    V = mie(r, 1, 1)
    smooth_V = tail_correction(r, V, r_switch=2.25)
    assert smooth_V[-1] == 0.0


def test_calc_alpha_array():
    alpha0 = 1.0
    dr = 0.1
    r = np.arange(0, 2.5, dr)
    form = 'linear'
    alpha = alpha_array(alpha0, r, form)
    assert alpha[0] == alpha0
    assert alpha[-1] == 0.0

    form = 'margaret-thatcher'
    with pytest.raises(ValueError):

# Path: msibi/potentials.py
# def tail_correction(r, V, r_switch):
#     """Apply a tail correction to a potential making it go to zero smoothly.
# 
#     Parameters
#     ----------
#     r : np.ndarray, shape=(n_points,), dtype=float
#         The radius values at which the potential is given.
#     V : np.ndarray, shape=r.shape, dtype=float
#         The potential values at each radius value.
#     r_switch : float, optional, default=pot_r[-1] - 5 * dr
#         The radius after which a tail correction is applied.
# 
#     References
#     ----------
#     .. [1] https://codeblue.umich.edu/hoomd-blue/doc/classhoomd__script_1_1pair_1_1pair.html
# 
#     """
#     r_cut = r[-1]
#     idx_r_switch, r_switch = find_nearest(r, r_switch)
# 
#     S_r = np.ones_like(r)
#     r = r[idx_r_switch:]
#     S_r[idx_r_switch:] = ((r_cut ** 2 - r ** 2) ** 2 *
#                           (r_cut ** 2 + 2 * r ** 2 - 3 * r_switch ** 2) /
#                           (r_cut ** 2 - r_switch ** 2) ** 3)
#     return V * S_r
# 
# def mie(r, eps, sig, m=12, n=6):
#     """Mie pair potential.  """
#     prefactor = (m  / (m - n)) * (m / n)**(n / (m - n))
#     return prefactor * eps * ((sig / r) ** m - (sig / r) ** n)
# 
# def alpha_array(alpha0, pot_r, form='linear'):
#     """Generate an array of alpha values used for scaling in the IBI step. """
#     if form == 'linear':
#         return alpha0 * (1.0 - pot_r / pot_r[-1])
#     else:
#         raise ValueError('Unsupported alpha form')


# Path: msibi/tests/test_potentials.py
import pytest
import numpy as np
from msibi.potentials import tail_correction, mie, alpha_array




def test_tail_correction():
    dr = 0.05
    r = np.arange(0, 2.5, dr)
    V = mie(r, 1, 1)
    smooth_V = tail_correction(r, V, r_switch=2.25)
    assert smooth_V[-1] == 0.0


def test_calc_alpha_array():
    alpha0 = 1.0
    dr = 0.1
    r = np.arange(0, 2.5, dr)
    form = 'linear'
    alpha = alpha_array(alpha0, r, form)
    assert alpha[0] == alpha0
    assert alpha[-1] == 0.0

    form = 'margaret-thatcher'
    with pytest.raises(ValueError):

        alpha = alpha_array(alpha0, r, form)