Ejemplo n.º 1
0
def test_compute_distances1_nimage_exclude():
    natom = 10
    nimage = 1
    cell = get_system_water32().cell
    pos = np.random.normal(0, 10, (natom, 3))
    exclude = np.array([[1, 0], [2, 1]])
    factor = (1+2*nimage)**3
    output = np.zeros(factor*(natom*(natom-1))//2 - 2, float)
    cell.compute_distances(output, pos, pairs=exclude, nimage=nimage)
    counter = 0
    ex_counter = 0
    for r0 in range(-1, 2):
        for r1 in range(-1, 2):
            for r2 in range(-1, 2):
                for i0 in range(natom):
                    for i1 in range(i0):
                        if (r0 == 0) and (r1 == 0) and (r2 == 0):
                            if ex_counter < len(exclude) and i0 == exclude[ex_counter,0] and i1 == exclude[ex_counter, 1]:
                                ex_counter += 1
                                continue
                        delta = pos[i0] - pos[i1]
                        cell.mic(delta)
                        cell.add_vec(delta, np.array([r0, r1, r2]))
                        assert abs(output[counter] - np.linalg.norm(delta)) < 1e-10
                        counter += 1
    assert ex_counter == 2
Ejemplo n.º 2
0
def test_generator_water32_cross():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_cross.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    assert isinstance(ff.parts[0], ForcePartValence)
    part_valence = ff.parts[0]
    assert part_valence.dlist.ndelta == 64
    for i, j in system.bonds:
        row0 = part_valence.dlist.lookup.get((i, j))
        row1 = part_valence.dlist.lookup.get((j, i))
        assert row0 is not None or row1 is not None
    assert part_valence.iclist.nic == 96
    iclist = part_valence.vlist.iclist
    for row in part_valence.vlist.vtab:
        assert row['kind'] == 3
        ic0 = iclist.ictab[row['ic0']]
        ic1 = iclist.ictab[row['ic1']]
        if ic0['kind'] == 0 and ic1['kind'] == 0:
            assert row['par0'] - 2.0000000000e+01*(kjmol/angstrom**2) < 1e-10
            assert row['par1'] - 0.9470000000e+00*angstrom < 1e-10
            assert row['par2'] - 0.9470000000e+00*angstrom < 1e-10
        elif ic0['kind'] == 0 and ic1['kind'] == 2:
            assert row['par0'] - 1.0000000000e+01*(kjmol/angstrom*rad) < 1e-10
            assert row['par1'] - 0.9470000000e+00*angstrom < 1e-10
            assert row['par2'] - 1.0500000000e+02*deg < 1e-10
        else:
            raise AssertionError('ICs in Cross term should be Bond-Bond or Bond-BendAngle')
    assert part_valence.vlist.nv == 96
Ejemplo n.º 3
0
def get_part_water32_14A_eidip():
    # Initialize system, nlist and scaling
    system = get_system_water32()
    #Reset charges
    system.charges *= 0.0
    #Set dipoles to random values
    dipoles = np.random.rand( system.natom, 3 )
    #Set polarizations to infinity (no energy to create dipoles)
    poltens_i = np.tile( np.diag([0.0,0.0,0.0]) , np.array([system.natom, 1]) )
    nlist = NeighborList(system)

    scalings = Scalings(system, 1.0, 1.0, 1.0)
    # Create the pair_pot and part_pair
    rcut = 14*angstrom
    alpha = 5.5/rcut
    pair_pot = PairPotEIDip(system.charges, dipoles, poltens_i, alpha, rcut)
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    part_pair.nlist.update()
    # The pair function
    def pair_fn(i, j, d, delta):
        energy = 0.0
        #Dipole-Dipole (only term for this test)
        fac1 = erfc(alpha*d) + 2.0*alpha*d/np.sqrt(np.pi)*np.exp(-alpha**2*d**2)
        fac2 = 3.0*erfc(alpha*d) + 4.0*alpha**3*d**3/np.sqrt(np.pi)*np.exp(-alpha**2*d**2) \
                + 6.0*alpha*d/np.sqrt(np.pi)*np.exp(-alpha**2*d**2)
        energy += np.dot( pair_pot.dipoles[i,:] , pair_pot.dipoles[j,:] )*fac1/d**3 - \
                         1.0*np.dot(pair_pot.dipoles[i,:],delta)*np.dot(delta,pair_pot.dipoles[j,:])*fac2/d**5
        return energy
    return system, nlist, scalings, part_pair, pair_fn
Ejemplo n.º 4
0
def test_gpos_vtens_morse_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i, j in system.bonds:
        part.add_term(Morse(0.3, 1.7, 2.0, Bond(i, j)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 5
0
def test_ewald_gpos_vtens_corr_water32():
    system = get_system_water32()
    scalings = Scalings(system, 0.0, 0.0, 0.5)
    for alpha in 0.05, 0.1, 0.2:
        part_ewald_corr = ForcePartEwaldCorrection(system, alpha, scalings, dielectric=0.8)
        check_gpos_part(system, part_ewald_corr)
        check_vtens_part(system, part_ewald_corr)
Ejemplo n.º 6
0
def test_pair_pot_ei_water32_dielectric():
    #Using a relative permittivity epsilon (!=1) should give the same results
    #as epsilon==1 with all charges scaled by 1.0/sqrt(epsilon)
    # Initialize system, nlist, scaling, ...
    system = get_system_water32()
    nlist = NeighborList(system)
    scalings = Scalings(system, 0.0, 0.5, 1.0)
    rcut = 14*angstrom
    alpha = 5.5/rcut
    dielectric = 1.44
    #Compute energy with epsilon 1 and scaled charges
    pair_pot = PairPotEI(system.charges/np.sqrt(dielectric), alpha, rcut)
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    ff = ForceField(system, [part_pair], nlist)
    ff.update_pos(system.pos)
    gpos0 = np.zeros(system.pos.shape, float)
    vtens0 = np.zeros((3, 3), float)
    energy0 = ff.compute(gpos0, vtens0)
    #Compute energy with epsilon=dielctric and original charges
    pair_pot = PairPotEI(system.charges, alpha, rcut, dielectric=dielectric)
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    ff = ForceField(system, [part_pair], nlist)
    ff.update_pos(system.pos)
    gpos1 = np.zeros(system.pos.shape, float)
    vtens1 = np.zeros((3, 3), float)
    energy1 = ff.compute(gpos1, vtens1)
    assert np.abs(energy0-energy1) < 1.0e-10
    assert np.all(np.abs(gpos0-gpos1)) < 1.0e-10
    assert np.all(np.abs(vtens0-vtens1) < 1.0e-10 )
Ejemplo n.º 7
0
def test_vlist_cross_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for j in range(system.natom):
        if len(system.neighs1[j])==2:
            i, k = system.neighs1[j]
            part.add_term(Cross(
                    1.2,
                    1.7 + 0.01*i,
                    1.9 + 0.01*k,
                    Bond(i, j),
                    Bond(j, k),
            ))
    energy = part.compute()
    check_energy = 0.0
    for j in range(system.natom):
        if len(system.neighs1[j])==2:
            i, k = system.neighs1[j]
            delta0 = system.pos[j] - system.pos[i]
            delta1 = system.pos[k] - system.pos[j]
            system.cell.mic(delta0)
            system.cell.mic(delta1)
            bond0 = np.linalg.norm(delta0)
            bond1 = np.linalg.norm(delta1)
            check_energy += 1.2*(bond0 - 1.7 - 0.01*i)*(bond1 - 1.9 - 0.01*k)
    assert abs(energy - check_energy) < 1e-8
Ejemplo n.º 8
0
def get_part_water32_9A_grimme():
    # Initialize system, nlist and scaling
    system = get_system_water32()
    nlist = NeighborList(system)
    scalings = Scalings(system)
    # Initialize parameters
    r0_table = {1: 1.001*angstrom, 8: 1.342*angstrom}
    c6_table = {1: 0.14*1e-3*kjmol*nanometer**6, 8: 0.70*1e-3*kjmol*nanometer**6}
    r0s = np.zeros(96, float)
    c6s = np.zeros(96, float)
    for i in xrange(system.natom):
        r0s[i] = r0_table[system.numbers[i]]
        c6s[i] = c6_table[system.numbers[i]]
    # Create the pair_pot and part_pair
    rcut = 9*angstrom
    pair_pot = PairPotGrimme(r0s, c6s, rcut, Hammer(1.0))
    assert abs(pair_pot.r0 - r0s).max() == 0.0
    assert abs(pair_pot.c6 - c6s).max() == 0.0
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    # Create a pair function:
    def pair_fn(i, j, d, delta):
        r0 = (r0s[i]+r0s[j])
        c6 = np.sqrt(c6s[i]*c6s[j])
        if d<rcut:
            return -1.1/(1.0 + np.exp(-20.0*(d/r0-1.0)))*c6/d**6*np.exp(1.0/(d-rcut))
        else:
            return 0.0
    return system, nlist, scalings, part_pair, pair_fn
Ejemplo n.º 9
0
def test_gpos_vtens_mm3quartic_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i, j in system.bonds:
        part.add_term(MM3Quartic(1.5, 2.0+0.01*i, Bond(i, j)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 10
0
def get_part_water32_9A_lj():
    # Initialize system, nlist and scaling
    system = get_system_water32()
    nlist = NeighborList(system)
    scalings = Scalings(system)
    # Initialize parameters
    rminhalf_table = {1: 0.2245*angstrom, 8: 1.7682*angstrom}
    epsilon_table = {1: -0.0460*kcalmol, 8: -0.1521*kcalmol}
    sigmas = np.zeros(96, float)
    epsilons = np.zeros(96, float)
    for i in xrange(system.natom):
        sigmas[i] = rminhalf_table[system.numbers[i]]*(2.0)**(5.0/6.0)
        epsilons[i] = epsilon_table[system.numbers[i]]
    # Create the pair_pot and part_pair
    rcut = 9*angstrom
    pair_pot = PairPotLJ(sigmas, epsilons, rcut, Hammer(1.0))
    assert abs(pair_pot.sigmas - sigmas).max() == 0.0
    assert abs(pair_pot.epsilons - epsilons).max() == 0.0
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    # Create a pair function:
    def pair_fn(i, j, d, delta):
        sigma = 0.5*(sigmas[i]+sigmas[j])
        epsilon = np.sqrt(epsilons[i]*epsilons[j])
        x = (sigma/d)**6
        return 4*epsilon*(x*(x-1))*np.exp(1.0/(d-rcut))
    return system, nlist, scalings, part_pair, pair_fn
Ejemplo n.º 11
0
def test_gpos_vtens_polyfour_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i, j in system.bonds:
        part.add_term(PolyFour([-0.5, 0.3, -0.16, 0.09], Bond(i, j)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 12
0
def test_generator_water32_cross():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water_cross.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    assert isinstance(ff.parts[0], ForcePartValence)
    part_valence = ff.parts[0]
    assert part_valence.dlist.ndelta == 64
    for i, j in system.bonds:
        row0 = part_valence.dlist.lookup.get((i, j))
        row1 = part_valence.dlist.lookup.get((j, i))
        assert row0 is not None or row1 is not None
    assert part_valence.iclist.nic == 96
    vlist = part_valence.vlist
    iclist = vlist.iclist
    assert vlist.nv == 96
    for irow in range(vlist.nv):
        row = vlist.vtab[irow]
        assert row['kind'] == 3
        ic0 = iclist.ictab[row['ic0']]
        ic1 = iclist.ictab[row['ic1']]
        if ic0['kind'] == 0 and ic1['kind'] == 0:
            np.testing.assert_allclose(row['par0'], 2.0000000000e+01*(kjmol/angstrom**2), rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par1'], 0.9470000000e+00*angstrom, rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par2'], 0.9470000000e+00*angstrom, rtol=0.0, atol=1e-10)
        elif ic0['kind'] == 0 and ic1['kind'] == 2:
            np.testing.assert_allclose(row['par0'], 1.0000000000e+01*(kjmol/angstrom*rad), rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par1'], 0.9470000000e+00*angstrom, rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par2'], 1.0500000000e+02*deg, rtol=0.0, atol=1e-10)
        else:
            raise AssertionError('ICs in Cross term should be Bond-Bond or Bond-BendAngle')
Ejemplo n.º 13
0
def test_atselect_water32():
    system = get_system_water32()
    o_indexes = (system.numbers == 8).nonzero()[0]
    for s in 'O', '8', '=2', '>1', '=2%H':
        fn = atsel_compile(s)
        assert fn(system, 0)
        assert not fn(system, 1)
        assert not fn(system, 2)
        assert fn(system, 3)
        assert not fn(system, 4)
        assert not fn(system, 5)
        assert fn(system, 6)
        assert not fn(system, 7)
        assert not fn(system, 8)
        assert (system.get_indexes(s)==o_indexes).all()
        assert (system.get_indexes(fn)==o_indexes).all()
    h_indexes = (system.numbers == 1).nonzero()[0]
    for s in 'H', '1', '=1', '<2', '=1%O':
        fn = atsel_compile(s)
        assert not fn(system, 0)
        assert fn(system, 1)
        assert fn(system, 2)
        assert not fn(system, 3)
        assert fn(system, 4)
        assert fn(system, 5)
        assert not fn(system, 6)
        assert fn(system, 7)
        assert fn(system, 8)
        assert (system.get_indexes(s)==h_indexes).all()
        assert (system.get_indexes(fn)==h_indexes).all()
Ejemplo n.º 14
0
def test_topology_water32():
    system = get_system_water32()
    assert system.bonds[0,0] == 0
    assert system.bonds[0,1] == 1
    assert system.bonds[1,0] == 0
    assert system.bonds[1,1] == 2
    assert system.bonds[2,0] == 3
    assert system.bonds[2,1] == 4
    assert system.bonds[3,0] == 3
    assert system.bonds[3,1] == 5
    for i in range(system.natom):
        if system.numbers[i] == 8:
            assert len(system.neighs1[i]) == 2
            n0, n1 = system.neighs1[i]
            assert system.numbers[n0] == 1
            assert system.numbers[n1] == 1
            assert len(system.neighs2[i]) == 0
            assert len(system.neighs3[i]) == 0
        elif system.numbers[i] == 1:
            assert len(system.neighs1[i]) == 1
            n, = system.neighs1[i]
            assert system.numbers[n] == 8
            assert len(system.neighs2[i]) == 1
            n, = system.neighs2[i]
            assert system.numbers[n] == 1
            assert len(system.neighs3[i]) == 0
Ejemplo n.º 15
0
def test_generator_water32_qmdffrep():
    system = get_system_water32()
    print(system.ffatypes)
    print(system.ffatype_ids)
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_fake_qmdffrep.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    qmdffrep = ff.part_pair_qmdffrep
    # check parameters
    A_cross = qmdffrep.pair_pot.amp_cross
    assert A_cross.shape == (2,2)
    print(A_cross)
    assert abs(A_cross[0,0] - 3.2490000000e+01) < 1e-10
    assert abs(A_cross[0,1] - 1.3395000000e+01) < 1e-10
    assert abs(A_cross[1,0] - 1.3395000000e+01) < 1e-10
    assert abs(A_cross[1,1] - 5.5225000000e+00) < 1e-10

    B_cross = qmdffrep.pair_pot.b_cross
    assert B_cross.shape == (2,2)
    assert abs(B_cross[0,0] - 4.08560961303e+00) < 1e-10
    assert abs(B_cross[0,1] - 5.00924416592e+00) < 1e-10
    assert abs(B_cross[1,0] - 5.00924416592e+00) < 1e-10
    assert abs(B_cross[1,1] - 6.34212100945e+00) < 1e-10

    # check scalings
    scalings = qmdffrep.scalings
    assert abs(scalings.scale1 - 0.0) < 1e-10
    assert abs(scalings.scale2 - 0.0) < 1e-10
    assert abs(scalings.scale3 - 0.5) < 1e-10
    assert abs(scalings.scale4 - 0.5) < 1e-10
Ejemplo n.º 16
0
def test_compute_distances2_nimage_exclude():
    n0 = 10
    n1 = 5
    nimage = 1
    cell = get_system_water32().cell
    pos0 = np.random.normal(0, 10, (n0, 3))
    pos1 = np.random.normal(0, 10, (n1, 3))
    factor = (1+2*nimage)**3
    exclude = np.array([[1, 0], [2, 1]])
    output = np.zeros(factor*n0*n1 - 2, float)
    cell.compute_distances(output, pos0, pos1, pairs=exclude, nimage=nimage)
    counter = 0
    ex_counter = 0
    for r0 in xrange(-1, 2):
        for r1 in xrange(-1, 2):
            for r2 in xrange(-1, 2):
                for i0 in xrange(n0):
                    for i1 in xrange(n1):
                        if (r0 == 0) and (r1 == 0) and (r2 == 0):
                            if ex_counter < len(exclude) and i0 == exclude[ex_counter,0] and i1 == exclude[ex_counter, 1]:
                                ex_counter += 1
                                continue
                        delta = pos0[i0] - pos1[i1]
                        cell.mic(delta)
                        cell.add_vec(delta, np.array([r0, r1, r2]))
                        assert abs(output[counter] - np.linalg.norm(delta)) < 1e-10
                        counter += 1
    assert ex_counter == 2
Ejemplo n.º 17
0
def test_ewald_vtens_neut_water32():
    # fake water model, negative oxygens and neutral hydrogens
    system = get_system_water32()
    system.charges -= 0.1
    for alpha in 0.05, 0.1, 0.2:
        part_ewald_neut = ForcePartEwaldNeutralizing(system, alpha)
        check_vtens_part(system, part_ewald_neut)
Ejemplo n.º 18
0
def get_part_water32_9A_mm3():
    # Initialize system, nlist and scaling
    system = get_system_water32()
    nlist = NeighborList(system)
    scalings = Scalings(system)
    # Initialize parameters
    sigma_table  = {1: 1.62*angstrom, 8: 1.82*angstrom}
    epsilon_table = {1: 0.020*kcalmol, 8: 0.059*kcalmol}
    sigmas = np.zeros(96, float)
    epsilons = np.zeros(96, float)
    onlypaulis = np.zeros(96, np.int32)
    for i in xrange(system.natom):
        sigmas[i] = sigma_table[system.numbers[i]]
        epsilons[i] = epsilon_table[system.numbers[i]]
    # Create the pair_pot and part_pair
    rcut = 9*angstrom
    pair_pot = PairPotMM3(sigmas, epsilons, onlypaulis, rcut, Hammer(1.0))
    assert abs(pair_pot.sigmas - sigmas).max() == 0.0
    assert abs(pair_pot.epsilons - epsilons).max() == 0.0
    part_pair = ForcePartPair(system, nlist, scalings, pair_pot)
    # Create a pair function:
    def pair_fn(i, j, d, delta):
        sigma = sigmas[i]+sigmas[j]
        epsilon = np.sqrt(epsilons[i]*epsilons[j])
        x = (sigma/d)
        if d<rcut:
            return epsilon*(1.84e5*np.exp(-12.0/x)-2.25*x**6)*np.exp(1.0/(d-rcut))
        else:
            return 0.0
    return system, nlist, scalings, part_pair, pair_fn
Ejemplo n.º 19
0
def test_gpos_vtens_bond_fues_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i, j in system.bonds:
        part.add_term(Fues(0.3, 1.7, Bond(i, j)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 20
0
def test_ewald_gpos_vtens_reci_water32():
    system = get_system_water32()
    dielectric = 1.4
    for alpha in 0.05, 0.1, 0.2:
        part_ewald_reci = ForcePartEwaldReciprocal(system, alpha, gcut=alpha / 0.75, dielectric=dielectric)
        check_gpos_part(system, part_ewald_reci)
        check_vtens_part(system, part_ewald_reci)
Ejemplo n.º 21
0
def test_add_part():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_bondharm.txt')
    ff = ForceField.generate(system, fn_pars)
    part_press = ForcePartPressure(system, 1e-3)
    ff.add_part(part_press)
    assert part_press in ff.parts
    assert ff.part_press is part_press
    assert ff.compute() == ff.part_valence.energy + ff.part_press.energy
Ejemplo n.º 22
0
def test_add_part():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water_bondharm.txt')
    ff = ForceField.generate(system, fn_pars)
    part_press = ForcePartPressure(system, 1e-3)
    ff.add_part(part_press)
    assert part_press in ff.parts
    assert ff.part_press is part_press
    assert ff.compute() == ff.part_valence.energy + ff.part_press.energy
Ejemplo n.º 23
0
def test_gpos_vtens_mm3benda_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i1 in range(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    part.add_term(MM3Bend(1.5, 2.0+0.01*i2, BendAngle(i0, i1, i2)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 24
0
def test_clean_momenta_3d():
    sys = get_system_water32()
    sys.set_standard_masses()
    masses = sys.masses
    vel = get_random_vel(300, False, masses)
    com_mom = np.dot(masses, vel)
    assert abs(com_mom).max() > 1e-10
    clean_momenta(sys.pos, vel, masses, sys.cell)
    com_mom = np.dot(masses, vel)
    assert abs(com_mom).max() < 1e-10
Ejemplo n.º 25
0
def test_remove_com_moment():
    sys = get_system_water32()
    sys.set_standard_masses()
    masses = sys.masses
    vel = get_random_vel(300, False, masses)
    com_mom = np.dot(masses, vel)
    assert abs(com_mom).max() > 1e-10
    remove_com_moment(vel, masses)
    com_mom = np.dot(masses, vel)
    assert abs(com_mom).max() < 1e-10
Ejemplo n.º 26
0
def test_gpos_vtens_ub_water():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i1 in range(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    part.add_term(Harmonic(2.1,2.0*angstrom,UreyBradley(i0, i1, i2)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 27
0
def test_gpos_vtens_bend_cos_water32():
    system = get_system_water32()
    part = ForcePartValence(system)
    for i1 in range(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    part.add_term(Harmonic(1.1+0.01*i0, -0.2, BendCos(i0, i1, i2)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Ejemplo n.º 28
0
def test_generator_water32():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water.txt')
    ff = ForceField.generate(system, fn_pars)
    # get all ff parts
    assert len(ff.parts) == 7
    part_valence = ff.part_valence
    part_pair_dampdisp = ff.part_pair_dampdisp
    part_pair_exprep = ff.part_pair_exprep
    part_pair_ei = ff.part_pair_ei
    part_ewald_reci = ff.part_ewald_reci
    part_ewald_cor = ff.part_ewald_cor
    part_ewald_neut = ff.part_ewald_neut
    # check dampdisp parameters
    c6_cross = part_pair_dampdisp.pair_pot.cn_cross
    assert abs(c6_cross[0,0] - 1.9550248340e+01) < 1e-10
    assert abs(c6_cross[1,1] - 2.7982205915e+00) < 1e-10
    assert (c6_cross == c6_cross.T).all()
    assert (c6_cross > 0).all()
    b_cross = part_pair_dampdisp.pair_pot.b_cross
    assert abs(b_cross[0,0] - 3.2421589363e+00/angstrom) < 1e-10
    assert abs(b_cross[0,1] - 3.3501628381e+00/angstrom) < 1e-10
    assert abs(b_cross[1,1] - 3.4581667399e+00/angstrom) < 1e-10
    assert (b_cross == b_cross.T).all()
    assert (b_cross > 0).all()
    # check exprep parameters
    amp_cross = part_pair_exprep.pair_pot.amp_cross
    assert (amp_cross > 0).all()
    assert (amp_cross == amp_cross.T).all()
    assert abs(amp_cross[0,0] - 4.2117588157e+02) < 1e-10
    assert abs(amp_cross[1,1] - 2.3514195495e+00) < 1e-10
    b_cross = part_pair_exprep.pair_pot.b_cross
    assert (b_cross > 0).all()
    assert (b_cross == b_cross.T).all()
    assert abs(b_cross[0,0] - 4.4661933834e+00/angstrom) < 1e-10
    assert abs(b_cross[1,1] - 4.4107388814e+00/angstrom) < 1e-10
    # check charges
    for i in range(system.natom):
        if system.numbers[i] == 1:
            assert abs(system.charges[i] - 3.6841957737e-01) < 1e-5
        else:
            assert abs(system.charges[i] + 2*3.6841957737e-01) < 1e-5
    # check valence
    assert part_valence.dlist.ndelta == 64
    assert part_valence.iclist.nic == 96
    assert (part_valence.iclist.ictab['kind'][:96] == 0).sum() == 64
    assert (part_valence.iclist.ictab['kind'][:96] == 1).sum() == 32
    assert part_valence.vlist.nv == 96
    mask_kind_0 = part_valence.iclist.ictab['kind'][:96] == 0
    assert abs(part_valence.vlist.vtab['par0'][:96][mask_kind_0] - 4.0088096730e+03*(kjmol/angstrom**2)).max() < 1e-10
    assert abs(part_valence.vlist.vtab['par1'][:96][mask_kind_0] - 1.0238240000e+00*angstrom).max() < 1e-10
    mask_kind_1 = part_valence.iclist.ictab['kind'][:96] == 1
    assert abs(part_valence.vlist.vtab['par0'][:96][mask_kind_1] - 3.0230353700e+02*kjmol).max() < 1e-10
    assert abs(part_valence.vlist.vtab['par1'][:96][mask_kind_1] - np.cos(8.8401698835e+01*deg)).max() < 1e-10
Ejemplo n.º 29
0
def test_generator_water32_lj():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water_lj.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_lj = ff.part_pair_lj
    # check parameters
    assert abs(part_pair_lj.pair_pot.sigmas[0] - 3.15*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.sigmas[1] - 0.4*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[0] - 0.1521*kcalmol) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[1] - 0.046*kcalmol) < 1e-10
Ejemplo n.º 30
0
def test_generator_water32_lj():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_lj.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_lj = ff.part_pair_lj
    # check parameters
    assert abs(part_pair_lj.pair_pot.sigmas[0] - 3.15*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.sigmas[1] - 0.4*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[0] - 0.1521*kcalmol) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[1] - 0.046*kcalmol) < 1e-10
Ejemplo n.º 31
0
def test_ewaldreciprocalinteraction_water32():
    alpha = 0.1
    dielectric = 1.3
    # original system
    system0 = get_system_water32()
    part0 = ForcePartEwaldReciprocal(system0,
                                     alpha,
                                     gcut=2.0 * alpha,
                                     dielectric=dielectric)
    nmol = int(system0.natom / 3)
    ndel = 2
    for ndel in range(4):
        # delete some molecules
        system1 = system0.subsystem(np.arange(3 * (nmol - ndel)))
        part1 = ForcePartEwaldReciprocal(system1,
                                         alpha,
                                         gcut=2.0 * alpha,
                                         dielectric=dielectric)
        # system containing only deleted molecules
        system2 = system0.subsystem(np.arange(3 * (nmol - ndel), 3 * nmol))
        part2 = ForcePartEwaldReciprocal(system2,
                                         alpha,
                                         gcut=2.0 * alpha,
                                         dielectric=dielectric)
        # energy difference between the different parts
        eref = part0.compute() - part1.compute() - part2.compute()
        # direct calculation of energy difference
        # setup class using the system with deleted molecules
        ewald_interaction = ForcePartEwaldReciprocalInteraction(
            system1.cell,
            alpha,
            2.0 * alpha,
            pos=system1.pos,
            charges=system1.charges,
            dielectric=dielectric)
        # compute the energy difference from inserting the molecules again
        shape = ewald_interaction.cosfacs.shape
        cosfacs, sinfacs = np.zeros(shape), np.zeros(shape)
        ewald_interaction.compute_structurefactors(system2.pos,
                                                   system2.charges, cosfacs,
                                                   sinfacs)
        e = ewald_interaction.compute_deltae(cosfacs, sinfacs)
        assert np.abs(e - eref) < 1e-12
Ejemplo n.º 32
0
def test_cell_water32():
    cell = get_system_water32().cell
    assert (cell.rspacings == 9.865*angstrom).all()
    assert (cell.gspacings == 1/(9.865*angstrom)).all()
    assert abs(cell.volume - abs(np.linalg.det(cell.rvecs))) < 1e-10

    assert abs(np.dot(cell.gvecs, cell.rvecs.transpose()) - np.identity(3)).max() < 1e-5
    assert abs(np.dot(cell.gvecs.transpose(), cell.rvecs) - np.identity(3)).max() < 1e-5
    vec1 = np.array([10.0, 0.0, 5.0])*angstrom
    cell.mic(vec1)
    assert abs(vec1 - np.array([0.135, 0.0, -4.865])*angstrom).max() < 1e-10
    vec2 = np.array([10.0, 0.0, 5.0])*angstrom
    cell.add_vec(vec2, cell.to_center(vec2))
    assert abs(vec1 - vec2).max() < 1e-10
    cell.add_vec(vec1, np.array([1,2,3]))
    assert abs(vec1 - np.array([10.0, 19.73, 24.73])*angstrom).max() < 1e-10

    cell2 = Cell(-cell.rvecs)
    assert abs(cell2.volume - abs(np.linalg.det(cell.rvecs))) < 1e-10
Ejemplo n.º 33
0
def test_compute_distances1_nimage():
    natom = 10
    nimage = 1
    cell = get_system_water32().cell
    pos = np.random.normal(0, 10, (natom, 3))
    factor = (1+2*nimage)**3
    output = np.zeros(factor*(natom*(natom-1))//2, float)
    cell.compute_distances(output, pos, nimage=nimage)
    counter = 0
    for r0 in range(-1, 2):
        for r1 in range(-1, 2):
            for r2 in range(-1, 2):
                for i0 in range(natom):
                    for i1 in range(i0):
                        delta = pos[i0] - pos[i1]
                        cell.mic(delta)
                        cell.add_vec(delta, np.array([r0, r1, r2]))
                        assert abs(output[counter] - np.linalg.norm(delta)) < 1e-10
                        counter += 1
Ejemplo n.º 34
0
def test_generator_water32_exprep3():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_exprep3.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_exprep = ff.part_pair_exprep
    # check parameters
    amp_cross = part_pair_exprep.pair_pot.amp_cross
    assert (amp_cross > 0).all()
    assert (amp_cross == amp_cross.T).all()
    assert abs(amp_cross[0, 0] - 4.2117588157e+02) < 1e-10
    assert abs(amp_cross[0, 1] - 1.4360351514e+01) < 1e-10
    assert abs(amp_cross[1, 1] - 2.3514195495e+00) < 1e-10
    b_cross = part_pair_exprep.pair_pot.b_cross
    assert (b_cross > 0).all()
    assert (b_cross == b_cross.T).all()
    assert abs(b_cross[0, 0] - 4.4661933834e+00 / angstrom) < 1e-10
    assert abs(b_cross[0, 1] - 4.0518324069e+00 / angstrom) < 1e-10
    assert abs(b_cross[1, 1] - 4.4107388814e+00 / angstrom) < 1e-10
Ejemplo n.º 35
0
def test_generator_water32_dampdisp2():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_dampdisp2.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_dampdisp = ff.part_pair_dampdisp
    # check parameters
    c6_cross = part_pair_dampdisp.pair_pot.c6_cross
    assert abs(c6_cross[0, 0] - 1.9550248340e+01) < 1e-10
    assert abs(c6_cross[0, 1] - 6.4847208208e+00) < 1e-10
    assert abs(c6_cross[1, 1] - 2.7982205915e+00) < 1e-10
    assert (c6_cross == c6_cross.T).all()
    assert (c6_cross > 0).all()
    b_cross = part_pair_dampdisp.pair_pot.b_cross
    assert abs(b_cross[0, 0] - 3.2421589363e+00 / angstrom) < 1e-10
    assert abs(b_cross[0, 1] - 3.3501628381e+00 / angstrom) < 1e-10
    assert abs(b_cross[1, 1] - 3.4581667399e+00 / angstrom) < 1e-10
    assert (b_cross == b_cross.T).all()
    assert (b_cross > 0).all()
Ejemplo n.º 36
0
def test_generator_water32_bondfues():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_bondfues.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    assert isinstance(ff.parts[0], ForcePartValence)
    part_valence = ff.parts[0]
    assert part_valence.dlist.ndelta == 64
    for i, j in system.bonds:
        row = part_valence.dlist.lookup.get((i, j))
        assert row is not None
    assert (part_valence.iclist.ictab['kind'] == 0).all()
    assert part_valence.iclist.nic == 64
    assert (part_valence.vlist.vtab['kind'] == 2).all()
    assert abs(part_valence.vlist.vtab['par0'] - 4.0088096730e+03 *
               (kjmol / angstrom**2)).max() < 1e-10
    assert abs(part_valence.vlist.vtab['par1'] -
               1.0238240000e+00 * angstrom).max() < 1e-10
    assert part_valence.vlist.nv == 64
Ejemplo n.º 37
0
def test_generator_water32_bendcharm():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water_bendcharm.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    assert isinstance(ff.parts[0], ForcePartValence)
    part_valence = ff.parts[0]
    assert part_valence.dlist.ndelta == 64
    for i, j in system.bonds:
        row = part_valence.dlist.lookup.get((i, j))
        assert row is not None
    assert (part_valence.iclist.ictab['kind'] == 1).all()
    assert part_valence.iclist.nic == 32
    assert (part_valence.vlist.vtab['kind'] == 0).all()
    assert abs(part_valence.vlist.vtab['par0'] -
               3.0230353700e+02 * kjmol).max() < 1e-10
    assert abs(part_valence.vlist.vtab['par1'] -
               np.cos(8.8401698835e+01 * deg)).max() < 1e-10
    assert part_valence.vlist.nv == 32
Ejemplo n.º 38
0
def test_generator_water32_fixq_dielectric():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_water_fixq_dielectric.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 4
    part_pair_ei = ff.part_pair_ei
    part_ewald_reci = ff.part_ewald_reci
    part_ewald_cor = ff.part_ewald_cor
    part_ewald_neut = ff.part_ewald_neut
    # check part settings
    print(part_pair_ei.pair_pot.dielectric)
    print(part_ewald_reci.dielectric)
    print(part_ewald_cor.dielectric)
    print(part_ewald_neut.dielectric)
    assert part_pair_ei.pair_pot.dielectric == 1.44
    assert part_pair_ei.pair_pot.dielectric == part_ewald_reci.dielectric
    assert part_pair_ei.pair_pot.dielectric == part_ewald_cor.dielectric
    assert part_pair_ei.pair_pot.dielectric == part_ewald_neut.dielectric
Ejemplo n.º 39
0
def test_generator_water32_d3bj():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_fake_d3bj.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    d3bj = ff.part_pair_disp68bjdamp
    gps = d3bj.pair_pot.global_pars
    # check parameters
    c6HH = 1.4633211522e+01
    c6HO = 2.5121581791e+01
    c6OO = 2.4261074778e+00
    c8HH = 5.74321564987e+00
    c8HO = 5.01673173654e+00
    c8OO = 3.13071058512e+00

    c6_cross = d3bj.pair_pot.c6_cross
    assert c6_cross.shape == (2, 2)
    assert abs(c6_cross[0, 0] - c6HH) < 1e-10
    assert abs(c6_cross[0, 1] - c6HO) < 1e-10
    assert abs(c6_cross[1, 0] - c6HO) < 1e-10
    assert abs(c6_cross[1, 1] - c6OO) < 1e-10

    c8_cross = d3bj.pair_pot.c8_cross
    assert c8_cross.shape == (2, 2)
    assert abs(c8_cross[0, 0] - c8HH) < 1e-10
    assert abs(c8_cross[0, 1] - c8HO) < 1e-10
    assert abs(c8_cross[1, 0] - c8HO) < 1e-10
    assert abs(c8_cross[1, 1] - c8OO) < 1e-10

    gps = d3bj.pair_pot.global_pars
    assert len(gps) == 4
    assert abs(gps[0] - 1.0) < 1e-10
    assert abs(gps[1] - 2.0) < 1e-10
    assert abs(gps[2] - 3.0) < 1e-10
    assert abs(gps[3] - 4.0) < 1e-10

    R_cross = d3bj.pair_pot.R_cross
    assert R_cross.shape == (2, 2)
    assert abs(R_cross[0, 0] - np.sqrt(c8HH / c6HH)) < 1e-10
    assert abs(R_cross[0, 1] - np.sqrt(c8HO / c6HO)) < 1e-10
    assert abs(R_cross[1, 0] - np.sqrt(c8HO / c6HO)) < 1e-10
    assert abs(R_cross[1, 1] - np.sqrt(c8OO / c6OO)) < 1e-10
Ejemplo n.º 40
0
def test_generator_water32_ljcross():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_water_ljcross.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_dampdisp = ff.part_pair_ljcross
    # check parameters
    eps_cross = part_pair_dampdisp.pair_pot.eps_cross
    assert abs(eps_cross[0, 0] - 0.25 * kcalmol) < 1e-10
    assert abs(eps_cross[0, 1] - 0.0707 * kcalmol) < 1e-10
    assert abs(eps_cross[1, 1] - 0.02 * kcalmol) < 1e-10
    assert (eps_cross == eps_cross.T).all()
    assert (eps_cross > 0).all()
    sig_cross = part_pair_dampdisp.pair_pot.sig_cross
    assert abs(sig_cross[0, 0] - 2.96 * angstrom) < 1e-10
    assert abs(sig_cross[0, 1] - 2.83746 * angstrom) < 1e-10
    assert abs(sig_cross[1, 1] - 2.72 * angstrom) < 1e-10
    assert (sig_cross == sig_cross.T).all()
    assert (sig_cross > 0).all()
Ejemplo n.º 41
0
def test_nlist_water32_9A():
    system = get_system_water32()
    nlist = NeighborList(system)
    rcut = 9 * angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    nneigh = nlist.nneigh
    assert ((nlist.neighs['a'][:nneigh] > nlist.neighs['b'][:nneigh]) |
            (nlist.neighs['r0'][:nneigh] != 0) |
            (nlist.neighs['r1'][:nneigh] != 0) |
            (nlist.neighs['r2'][:nneigh] != 0)).all()
    for a in random.sample(xrange(system.natom), 5):
        # compute the distances in the neighborlist manually and check.
        check = {}
        for b in xrange(system.natom):
            delta = system.pos[b] - system.pos[a]
            delta -= np.floor(delta /
                              (9.865 * angstrom) + 0.5) * (9.865 * angstrom)
            assert abs(delta).max() < 0.5 * 9.865 * angstrom
            for l2 in xrange(0, 2):
                for l1 in xrange((l2 != 0) * -1, 2):
                    for l0 in xrange((l2 != 0 or l1 != 0) * -1, 2):
                        my_delta = delta + np.array([l0, l1, l2
                                                     ]) * 9.865 * angstrom
                        d = np.linalg.norm(my_delta)
                        if d <= rcut:
                            if (l0 != 0) or (l1 != 0) or (l2 != 0) or (a > b):
                                check[(b, l0, l1, l2)] = (d, my_delta)
        # compare
        counter = 0
        for row in nlist.neighs[:nneigh]:
            if row['a'] == a:
                key = row['b'], row['r0'], row['r1'], row['r2']
                assert key in check
                assert abs(check[key][0]) <= rcut
                assert abs(check[key][0] - row['d']) < 1e-8
                assert abs(check[key][1][0] - row['dx']) < 1e-8
                assert abs(check[key][1][1] - row['dy']) < 1e-8
                assert abs(check[key][1][2] - row['dz']) < 1e-8
                counter += 1
        assert counter == len(check)
Ejemplo n.º 42
0
def test_compute_distances2_include():
    n0 = 10
    n1 = 5
    cell = get_system_water32().cell
    pos0 = np.random.normal(0, 10, (n0, 3))
    pos1 = np.random.normal(0, 10, (n1, 3))
    # all
    output_all = np.zeros(n0 * n1, float)
    cell.compute_distances(output_all, pos0, pos1)
    # exclude
    pairs = np.array([[1, 0], [3, 2], [5, 3]])
    output_ex = np.zeros(n0 * n1 - 3, float)
    cell.compute_distances(output_ex,
                           pos0,
                           pos1,
                           pairs=pairs,
                           do_include=False)
    # include
    output_in = np.zeros(3, float)
    cell.compute_distances(output_in, pos0, pos1, pairs=pairs, do_include=True)
    assert set(output_all) == set(output_ex) | set(output_in)
Ejemplo n.º 43
0
def test_compute_distances2_nimage():
    n0 = 10
    n1 = 5
    nimage = 1
    cell = get_system_water32().cell
    pos0 = np.random.normal(0, 10, (n0, 3))
    pos1 = np.random.normal(0, 10, (n1, 3))
    factor = (1+2*nimage)**3
    output = np.zeros(factor*n0*n1, float)
    cell.compute_distances(output, pos0, pos1, nimage=nimage)
    counter = 0
    for r0 in range(-1, 2):
        for r1 in range(-1, 2):
            for r2 in range(-1, 2):
                for i0 in range(n0):
                    for i1 in range(n1):
                        delta = pos0[i0] - pos1[i1]
                        cell.mic(delta)
                        cell.add_vec(delta, np.array([r0, r1, r2]))
                        assert abs(output[counter] - np.linalg.norm(delta)) < 1e-10
                        counter += 1
Ejemplo n.º 44
0
def test_generator_water32_ubharm():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water_ubharm.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    assert isinstance(ff.parts[0], ForcePartValence)
    part_valence = ff.parts[0]
    assert part_valence.dlist.ndelta == 32
    for i, j in system.bonds:
        row = part_valence.dlist.lookup.get((i, j))
        assert row is None
    for i, n2s in system.neighs2.items():
        for j in n2s:
            row0 = part_valence.dlist.lookup.get((i, j))
            row1 = part_valence.dlist.lookup.get((j, i))
            assert row0 is not None or row1 is not None
    assert (part_valence.iclist.ictab['kind'] == 5).all()
    assert part_valence.iclist.nic == 32
    assert (part_valence.vlist.vtab['kind'] == 0).all()
    assert abs(part_valence.vlist.vtab['par0'] - 2.5465456475e+02*(kjmol/angstrom**2)).max() < 1e-10
    assert abs(part_valence.vlist.vtab['par1'] - 2.6123213151e+00*angstrom).max() < 1e-10
    assert part_valence.vlist.nv == 32
Ejemplo n.º 45
0
def test_nlist_inc_r3():
    cell = get_system_water32().cell
    rmax = np.array([2, 2, 2])
    r = np.array([-2, 1, 1])
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([-1, 1, 1])).all()
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([0, 1, 1])).all()
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([1, 1, 1])).all()
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([2, 1, 1])).all()
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([-2, 2, 1])).all()
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([-1, 2, 1])).all()
    r = np.array([2, 2, 0])
    assert nlist_inc_r(cell, r, rmax)
    assert (r == np.array([-2, -2, 1])).all()
    r = np.array([2, 2, 2])
    assert not nlist_inc_r(cell, r, rmax)
    assert (r == np.array([0, 0, 0])).all()
Ejemplo n.º 46
0
def test_generator_water32_dampdisp1():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_water_dampdisp1.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_dampdisp = ff.part_pair_dampdisp
    # check parameters
    c6_cross = part_pair_dampdisp.pair_pot.cn_cross
    assert c6_cross.shape == (2,2)
    assert abs(c6_cross[0,0] - 1.9550248340e+01) < 1e-10
    assert abs(c6_cross[1,1] - 2.7982205915e+00) < 1e-10
    vratio = 3.13071058512e+00/5.13207980365e+00 # v[0]/v[1]
    tmp = 2*c6_cross[0,0]*c6_cross[1,1]/(c6_cross[0,0]/vratio + c6_cross[1,1]*vratio)
    assert abs(c6_cross[0,1] - tmp) < 1e-10
    assert (c6_cross == c6_cross.T).all()
    assert (c6_cross > 0).all()
    b_cross = part_pair_dampdisp.pair_pot.b_cross
    assert b_cross.shape == (2,2)
    assert abs(b_cross[0,0] - 3.2421589363e+00/angstrom) < 1e-10
    assert abs(b_cross[0,1] - 3.3501628381e+00/angstrom) < 1e-10
    assert abs(b_cross[1,1] - 3.4581667399e+00/angstrom) < 1e-10
    assert (b_cross == b_cross.T).all()
    assert (b_cross > 0).all()
Ejemplo n.º 47
0
def test_detect_bonds_water32():
    system = get_system_water32()
    assert system.nbond == 64
    check_detect_bonds(system)
Ejemplo n.º 48
0
def test_iter_matches_water4_nonoverlapping():
    system = get_system_water32().subsystem(range(12))
    water = system.subsystem([0, 1, 2])
    assert len(list(system.iter_matches(water))) == 8
    assert len(list(system.iter_matches(water, overlapping=False))) == 4
Ejemplo n.º 49
0
def test_generator_formaldehyde_wrong_cross():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_formaldehyde_wrong_cross.txt')
    with assert_raises(IOError):
        ff = ForceField.generate(system, fn_pars)
Ejemplo n.º 50
0
def test_chk():
    system0 = get_system_water32()
    with tmpdir(__name__, 'test_chk') as dirname:
        system0.to_file('%s/tmp.chk' % dirname)
        system1 = System.from_file('%s/tmp.chk' % dirname)
        compare_water32(system0, system1, 1e-10)
Ejemplo n.º 51
0
def get_ff_water32():
    system = get_system_water32()
    fn_pars = context.get_fn('test/parameters_water.txt')
    return ForceField.generate(system, fn_pars, skin=2)
Ejemplo n.º 52
0
def test_nlist_water32_9A_shortest():
    system = get_system_water32()
    nlist = NeighborList(system)
    nlist.request_rcut(9 * angstrom)
    nlist.update()
    check_nlist_shortest(system, nlist)
Ejemplo n.º 53
0
def test_nlist_water32_6A_skin3A():
    system = get_system_water32()
    check_nlist_skin(system, 6 * angstrom, 3 * angstrom)
Ejemplo n.º 54
0
def test_nlist_water32_10A_skin2A():
    system = get_system_water32()
    check_nlist_skin(system, 10 * angstrom, 2 * angstrom)
Ejemplo n.º 55
0
def test_ffatypes():
    system = get_system_water32()
    assert (system.ffatypes == ['O', 'H']).all()
    assert (system.ffatype_ids[system.numbers == 8] == 0).all()
    assert (system.ffatype_ids[system.numbers == 1] == 1).all()
Ejemplo n.º 56
0
def get_ff_water32():
    system = get_system_water32()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_water.txt')
    return ForceField.generate(system, fn_pars, skin=2)
Ejemplo n.º 57
0
def test_vtens_pext_3():
    system = get_system_water32()
    part = ForcePartPressure(system, 1.0)
    check_vtens_part(system, part)