Exemple #1
0
def test_potential_increasing_right_of_R0():
    """potential increases to the right of R0, and remains negative."""
    ri = rprev = R0
    vprev = lj.potential(ri**2)
    for i in range(10):
        ri = 2*ri
        vi = lj.potential(ri**2)
        print(f'{i} {ri}: {vi}')
        assert vprev < vi
        assert vi < 0.0
        vprev = vi
        rprev = ri
Exemple #2
0
def test_potential_minimum():
    """potential has a minimum at r = R0"""
    r0 = R0
    vr0 = lj.potential(r0**2)
    d = 0.1
    for i in range(5):
        rLeft  = r0 - d
        rRight = r0 + d
        vLeft  = lj.potential(rLeft**2)
        vRight = lj.potential(rRight**2)
        print(f'{d}: {vLeft} < {vr0} < {vRight}')
        assert vLeft  > vr0
        assert vRight > vr0
        d *= 0.1
Exemple #3
0
def test_force_is_derivative_of_potential():
    n = 1000
    # Generate n random numbers in ]0,5*R0]
    # np.random.random generate numbers in [
    rij = (5*R0)*(1.0 - np.random.random(n))
    fij = lj.force_factor(rij**2)*rij
    d = 1e-10
    rij0 = rij - d
    vij0 = lj.potential(rij0**2)
    rij1 = rij + d
    vij1 = lj.potential(rij1**2)
    dvij = (vij1 - vij0)/(2*d)
    for i in range(n):
        print(f'{i} {fij[i]} == {dvij[i]} {np.abs(fij[i]-dvij[i])}')
        assert fij[i] == pytest.approx(dvij[i],1e-4)
Exemple #4
0
def test_potential_decreasing_left_of_R0():
    """potential increases to the right of R0, and remains negative."""
    ri = rprev = R0
    vprev = lj.potential(ri**2)
    for i in range(10):
        ri = 0.9*ri
        vi = lj.potential(ri**2)
        print(f'{i} {ri}: {vi}')
        assert vi > vprev
        if ri > 1:
            assert vi < 0.0
        else:
            assert vi > 0.0
        vprev = vi
        rprev = ri
Exemple #5
0
def test_computeEnergy():
    """"""
    box = md.Box(0., 0., 5. * md.hcp.uc_centered_a, 0.5 * md.hcp.uc_centered_b)
    atoms = md.MD(box, cutoff=2.5)
    if __plot:
        cmn.figure()
        cmn.plotBox(box)
        cmn.plotAtoms(atoms.x, atoms.y, radius=atoms.radius)
        cmn.plt.show()
    atoms.buildVerletLists()
    print(atoms.vl)
    energy = atoms.computeEnergy()
    r01sq = md.hcp.uc_centered_a**2
    r02sq = (2 * md.hcp.uc_centered_a)**2
    expected = 4 * lj.potential(r01sq) + 3 * lj.potential(r02sq)
    print(energy)
    print(expected)
    assert energy == expected
Exemple #6
0
def test_potential_cutoff():
    """not actually a test, just to show the magnitude of the interaction at cut-off."""
    for i in range(1,11):
        rc = i*R0
        vrc = lj.potential(rc**2)
        print(f'{i} {rc}: `{vrc} {"cut-off" if i==3 else ""}')
Exemple #7
0
def test_potential_zero():
    """potential has a zero at r = 1.0"""
    r =  1.0
    vr = lj.potential(r**2)
    assert vr == 0.0