Exemple #1
0
def test_generator_glycine_fixq():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_glycine_fixq.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1 #Non-periodic, so only one part
    part_pair_ei = ff.part_pair_ei
    # check part settings
    assert part_pair_ei.pair_pot.alpha == 0.0
    # check charges and atomic radii
    ac = {1:0.2, 6:0.5, 7:-1.0, 8:-0.5 } #Charges
    ar = {1:1.2*angstrom, 6: 1.7*angstrom, 7: 1.55*angstrom, 8: 1.50*angstrom} #Radii
    for i in range(system.natom):
        assert abs(system.charges[i] - ac[system.numbers[i]]) < 1e-5
        assert abs(system.radii[i] - ar[system.numbers[i]]) < 1e-5

    system = get_system_glycine()
    log.set_level(log.silent)
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_glycine_fixq.txt')
    ff2 = ForceField.generate(system, fn_pars)
    log.set_level(log.debug)
    # check charges and atomic radii
    ac = {1:0.2, 6:0.5, 7:-1.0, 8:-0.5 } #Charges
    ar = {1:1.2*angstrom, 6: 1.7*angstrom, 7: 1.55*angstrom, 8: 1.50*angstrom} #Radii
    for i in range(system.natom):
        assert abs(system.charges[i] - ac[system.numbers[i]]) < 1e-5
        assert abs(system.radii[i] - ar[system.numbers[i]]) < 1e-5
    energy = ff.compute()
    energy2 = ff2.compute()
    assert abs(energy - energy2) < 1e-3
Exemple #2
0
def test_generator_glycine_exprep1():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_fake_exprep1.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.shape == (4, 4)
    assert (amp_cross > 0).all()
    assert (amp_cross == amp_cross.T).all()
    assert abs(amp_cross[0,0] - 4.9873214987e+00) < 1e-10
    assert abs(amp_cross[1,1] - 4.3843216584e+02) < 1e-10
    assert abs(amp_cross[2,2] - 4.2117588157e+02) < 1e-10
    assert abs(amp_cross[3,3] - 2.9875648798e+00) < 1e-10
    assert abs(amp_cross[1,3] - np.sqrt(4.3843216584e+02*2.9875648798e+00)) < 1e-10
    b_cross = part_pair_exprep.pair_pot.b_cross
    assert b_cross.shape == (4, 4)
    assert (b_cross > 0).all()
    assert (b_cross == b_cross.T).all()
    assert abs(b_cross[0,0] - 4.4265465464e+00/angstrom) < 1e-10
    assert abs(b_cross[1,1] - 4.4132795167e+00/angstrom) < 1e-10
    assert abs(b_cross[2,2] - 4.4654231357e+00/angstrom) < 1e-10
    assert abs(b_cross[3,3] - 4.4371927495e+00/angstrom) < 1e-10
    assert abs(b_cross[2,0] - 0.5*(4.4265465464e+00+4.4654231357e+00)/angstrom) < 1e-10
Exemple #3
0
def test_generator_glycine_torsioncospolysix():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_fake_torscpolysix.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_valence = ff.part_valence
    assert part_valence.vlist.nv == 12
    assert part_valence.dlist.ndelta == 9
    assert part_valence.iclist.nic == 12
    nv = part_valence.vlist.nv
    nic = part_valence.iclist.nic
    assert (part_valence.vlist.vtab['kind'][:nv] == 10).all()
    assert (part_valence.iclist.ictab['kind'][:nic] == 3).all()
    assert abs(part_valence.vlist.vtab['par0'][:nv] -
               1.0 * kjmol).all() < 1e-10
    assert abs(part_valence.vlist.vtab['par1'][:nv] -
               4.3 * kjmol).all() < 1e-10
    assert abs(part_valence.vlist.vtab['par2'][:nv] -
               2.1 * kjmol).all() < 1e-10
    assert abs(part_valence.vlist.vtab['par3'][:nv] +
               0.9 * kjmol).all() < 1e-10
    assert abs(part_valence.vlist.vtab['par4'][:nv] -
               12. * kjmol).all() < 1e-10
    assert abs(part_valence.vlist.vtab['par5'][:nv] -
               4.9 * kjmol).all() < 1e-10
Exemple #4
0
def test_nlist_glycine_9A():
    system = get_system_glycine()
    nlist = NeighborList(system)
    rcut = 9 * angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    nlist.check()
Exemple #5
0
def test_generator_fake_torsion2():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_fake_torsion2.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_valence = ff.part_valence
    assert part_valence.vlist.nv == 12
    m_counts = {}
    for row in part_valence.vlist.vtab[:12]:
        print(row['kind'])
        if row['kind'] == 5:
            key = 1
        elif row['kind'] == 6:
            key = 2
        elif row['kind'] == 7:
            key = 3
        elif row['kind'] == 8:
            key = 4
        elif row['kind'] == 9:
            key = 6
        else:
            raise AssertionError
        m_counts[key] = m_counts.get(key, 0) + 1
    assert len(m_counts) == 5
    assert m_counts[1] == 1
    assert m_counts[2] == 1
    assert m_counts[3] == 4
    assert m_counts[4] == 2
    assert m_counts[6] == 4
Exemple #6
0
def test_nlist_glycine_9A():
    system = get_system_glycine()
    nlist = NeighborList(system)
    rcut = 9*angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    nlist.check()
Exemple #7
0
def test_generator_fake_torsion1():
    system = get_system_glycine()
    fn_pars = context.get_fn('test/parameters_fake_torsion1.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_valence = ff.part_valence
    assert part_valence.vlist.nv == 12
    m_counts = {}
    for row in part_valence.vlist.vtab[:12]:
        print row['kind']
        if row['kind'] == 5:
            key = 1
        elif row['kind'] == 6:
            key = 2
        elif row['kind'] == 7:
            key = 3
        elif row['kind'] == 8:
            key = 4
        elif row['kind'] == 9:
            key = 6
        else:
            raise AssertionError
        m_counts[key] = m_counts.get(key, 0) + 1
    assert len(m_counts) == 5
    assert m_counts[1] == 4
    assert m_counts[2] == 2
    assert m_counts[3] == 4
    assert m_counts[4] == 1
    assert m_counts[6] == 1
Exemple #8
0
def test_generator_glycine_dampdisp1():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_fake_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 == (4, 4)
    assert abs(c6_cross[0,0] - 2.0121581791e+01) < 1e-10
    assert abs(c6_cross[1,1] - 2.5121581791e+01) < 1e-10
    assert abs(c6_cross[2,2] - 1.4633211522e+01) < 1e-10
    assert abs(c6_cross[3,3] - 2.4261074778e+00) < 1e-10
    vratio = 3.6001863542e+00/3.7957349423e+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 == (4, 4)
    assert abs(b_cross[0,0] - 5.13207980365e+00/angstrom) < 1e-10
    assert abs(b_cross[0,1] - 0.5*(5.13207980365e+00+5.01673173654e+00)/angstrom) < 1e-10
    assert abs(b_cross[1,1] - 5.01673173654e+00/angstrom) < 1e-10
    assert abs(b_cross[2,2] - 5.74321564987e+00/angstrom) < 1e-10
    assert abs(b_cross[3,3] - 3.13071058512e+00/angstrom) < 1e-10
    assert (b_cross == b_cross.T).all()
    assert (b_cross > 0).all()
Exemple #9
0
def test_detect_bonds_glycine():
    system = get_system_glycine()
    check_detect_bonds(system)
    system = System(system.numbers, system.pos)
    system.detect_bonds()
    assert hasattr(system, 'neighs1')
    assert hasattr(system, 'neighs2')
    assert hasattr(system, 'neighs3')
Exemple #10
0
def test_glycine_bond():
    system = get_system_glycine()
    groups = [
        (np.array([0, 2, 8, 1]), np.array([0.3, 0.2, 0.4, 0.3])),
        (np.array([3, 4, 5]), np.array([0.5, 0.2, 0.9])),
    ]
    comlist = COMList(system, groups)
    part = ForcePartValence(system, comlist)
    part.add_term(Harmonic(2.1, 0.5, Bond(0, 1)))
    check_gpos_part(system, part)
Exemple #11
0
def test_remove_angular_moment():
    sys = get_system_glycine()
    sys.set_standard_masses()
    masses = sys.masses
    vel = get_random_vel(300, False, masses)
    remove_com_moment(vel, masses)
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_mom).max() > 1e-10
    remove_angular_moment(sys.pos, vel, masses)
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_mom).max() < 1e-10
Exemple #12
0
def test_remove_angular_moment():
    sys = get_system_glycine()
    sys.set_standard_masses()
    masses = sys.masses
    vel = get_random_vel(300, False, masses)
    remove_com_moment(vel, masses)
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_mom).max() > 1e-10
    remove_angular_moment(sys.pos, vel, masses)
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_mom).max() < 1e-10
Exemple #13
0
def test_scaling_glycine():
    system = get_system_glycine()
    stab = Scalings(system, 1.0, 0.5, 0.2).stab # warning: absurd numbers
    assert (stab['a'] > stab['b']).all()
    assert len(stab) == sum(len(system.neighs2[i]) + len(system.neighs3[i]) for i in xrange(system.natom))/2
    for i0, i1, scale, nbond in stab:
        if i0 in system.neighs2[i1]:
            assert scale == 0.5
            assert nbond == 2
        elif i0 in system.neighs3[i1]:
            assert scale == 0.2
            assert nbond == 3
Exemple #14
0
def test_clean_momenta_0d():
    sys = get_system_glycine()
    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
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_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
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_mom).max() < 1e-10
Exemple #15
0
def test_cell_glycine():
    cell = get_system_glycine().cell
    assert cell.rvecs.shape == (0, 3)
    assert cell.gvecs.shape == (0, 3)
    assert cell.rspacings.shape == (0, )
    assert cell.gspacings.shape == (0, )
    vec1 = np.array([10.0, 0.0, 105.0]) * angstrom
    cell.mic(vec1)
    assert abs(vec1 - np.array([10.0, 0.0, 105.0]) * angstrom).max() < 1e-3
    vec2 = np.array([10.0, 0.0, 105.0]) * angstrom
    cell.add_vec(vec2, cell.to_center(vec2))
    assert abs(vec1 - vec2).max() < 1e-10
    cell.add_vec(vec1, np.array([], dtype=int))
    assert abs(vec1 - np.array([10.0, 0.0, 105.0]) * angstrom).max() < 1e-3
Exemple #16
0
def test_scaling_glycine():
    system = get_system_glycine()
    stab = Scalings(system, 1.0, 0.5, 0.2).stab  # warning: absurd numbers
    assert (stab['a'] > stab['b']).all()
    assert len(stab) == sum(
        len(system.neighs2[i]) + len(system.neighs3[i])
        for i in xrange(system.natom)) / 2
    for i0, i1, scale, nbond in stab:
        if i0 in system.neighs2[i1]:
            assert scale == 0.5
            assert nbond == 2
        elif i0 in system.neighs3[i1]:
            assert scale == 0.2
            assert nbond == 3
Exemple #17
0
def test_clean_momenta_0d():
    sys = get_system_glycine()
    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
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_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
    ang_mom = angular_moment(sys.pos, vel, masses)
    assert abs(ang_mom).max() < 1e-10
Exemple #18
0
def test_cell_glycine():
    cell = get_system_glycine().cell
    assert cell.rvecs.shape == (0, 3)
    assert cell.gvecs.shape == (0, 3)
    assert cell.rspacings.shape == (0,)
    assert cell.gspacings.shape == (0,)
    vec1 = np.array([10.0, 0.0, 105.0])*angstrom
    cell.mic(vec1)
    assert abs(vec1 - np.array([10.0, 0.0, 105.0])*angstrom).max() < 1e-3
    vec2 = np.array([10.0, 0.0, 105.0])*angstrom
    cell.add_vec(vec2, cell.to_center(vec2))
    assert abs(vec1 - vec2).max() < 1e-10
    cell.add_vec(vec1, np.array([], dtype=int))
    assert abs(vec1 - np.array([10.0, 0.0, 105.0])*angstrom).max() < 1e-3
Exemple #19
0
def test_generator_glycine_lj():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_fake_lj.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_lj = ff.part_pair_lj
    # check parameters
    assert part_pair_lj.pair_pot.sigmas.shape == (ff.system.natom,)
    assert part_pair_lj.pair_pot.epsilons.shape == (ff.system.natom,)
    assert abs(part_pair_lj.pair_pot.sigmas[0] - 1.7*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.sigmas[1] - 1.8*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.sigmas[3] - 1.6*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.sigmas[5] - 0.5*angstrom) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[0] - 0.18*kcalmol) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[1] - 0.22*kcalmol) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[3] - 0.12*kcalmol) < 1e-10
    assert abs(part_pair_lj.pair_pot.epsilons[5] - 0.05*kcalmol) < 1e-10
Exemple #20
0
def test_glycine():
    system = get_system_glycine()
    groups1 = [
        (np.array([0, 2, 8, 1]), np.array([0.3, 0.2, 0.4, 0.3])),
    ]
    groups2 = [
        (np.array([3]), np.array([0.5])),
    ]
    groups3 = [
        (np.array([0, 2, 8, 1]), np.array([0.3, 0.2, 0.4, 0.3])),
        (np.array([3]), np.array([0.5])),
    ]
    for groups in groups1, groups2, groups3:
        comlist = COMList(system, groups)
        comlist.forward()
        for igroup, (iatoms, weights) in enumerate(groups):
            np.testing.assert_almost_equal(
                np.dot(weights, system.pos[iatoms]) / weights.sum(),
                comlist.pos[igroup])
Exemple #21
0
def test_generator_glycine_ljcross():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_fake_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.1800 * kcalmol) < 1e-10
    assert abs(eps_cross[0, 1] - 0.1990 * kcalmol) < 1e-10
    assert abs(eps_cross[0, 2] - 0.1470 * kcalmol) < 1e-10
    assert abs(eps_cross[0, 3] - 0.0949 * kcalmol) < 1e-10
    assert abs(eps_cross[1, 1] - 0.2200 * kcalmol) < 1e-10
    assert abs(eps_cross[1, 2] - 0.1625 * kcalmol) < 1e-10
    assert abs(eps_cross[1, 3] - 0.1049 * kcalmol) < 1e-10
    assert abs(eps_cross[2, 2] - 0.1200 * kcalmol) < 1e-10
    assert abs(eps_cross[2, 3] - 0.0775 * kcalmol) < 1e-10
    assert abs(eps_cross[3, 3] - 0.0500 * 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] - 1.70 * angstrom) < 1e-10
    assert abs(sig_cross[0, 1] - 1.75 * angstrom) < 1e-10
    assert abs(sig_cross[0, 2] - 1.65 * angstrom) < 1e-10
    assert abs(sig_cross[0, 3] - 1.10 * angstrom) < 1e-10
    assert abs(sig_cross[1, 1] - 1.80 * angstrom) < 1e-10
    assert abs(sig_cross[1, 2] - 1.70 * angstrom) < 1e-10
    assert abs(sig_cross[1, 3] - 1.15 * angstrom) < 1e-10
    assert abs(sig_cross[2, 2] - 1.60 * angstrom) < 1e-10
    assert abs(sig_cross[2, 3] - 1.05 * angstrom) < 1e-10
    assert abs(sig_cross[3, 3] - 0.50 * angstrom) < 1e-10
    assert (sig_cross == sig_cross.T).all()
    assert (sig_cross > 0).all()

    energy_ljcross = ff.compute() / kcalmol
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_fake_lj.txt')
    ff = ForceField.generate(system, fn_pars)
    assert abs(ff.compute() / kcalmol - energy_ljcross) < 1e-4
Exemple #22
0
def test_generator_glycine_mm3():
    system = get_system_glycine()
    fn_pars = context.get_fn('test/parameters_fake_mm3.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_pair_mm3 = ff.part_pair_mm3
    # check parameters
    assert part_pair_mm3.pair_pot.sigmas.shape == (ff.system.natom,)
    assert part_pair_mm3.pair_pot.epsilons.shape == (ff.system.natom,)
    assert part_pair_mm3.pair_pot.onlypaulis.shape == (ff.system.natom,)
    assert abs(part_pair_mm3.pair_pot.sigmas[0] - 1.7*angstrom) < 1e-10
    assert abs(part_pair_mm3.pair_pot.sigmas[1] - 1.8*angstrom) < 1e-10
    assert abs(part_pair_mm3.pair_pot.sigmas[3] - 1.6*angstrom) < 1e-10
    assert abs(part_pair_mm3.pair_pot.sigmas[5] - 0.5*angstrom) < 1e-10
    assert abs(part_pair_mm3.pair_pot.epsilons[0] - 0.18*kcalmol) < 1e-10
    assert abs(part_pair_mm3.pair_pot.epsilons[1] - 0.22*kcalmol) < 1e-10
    assert abs(part_pair_mm3.pair_pot.epsilons[3] - 0.12*kcalmol) < 1e-10
    assert abs(part_pair_mm3.pair_pot.epsilons[5] - 0.05*kcalmol) < 1e-10
    assert part_pair_mm3.pair_pot.onlypaulis[0] == 0
    assert part_pair_mm3.pair_pot.onlypaulis[1] == 1
    assert part_pair_mm3.pair_pot.onlypaulis[3] == 1
    assert part_pair_mm3.pair_pot.onlypaulis[5] == 0
Exemple #23
0
def test_generator_glycine_torsion():
    system = get_system_glycine()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_glycine_torsion.txt')
    ff = ForceField.generate(system, fn_pars)
    assert len(ff.parts) == 1
    part_valence = ff.part_valence
    assert part_valence.vlist.nv == 11
    assert part_valence.dlist.ndelta == 9
    m_counts = {}
    for row in part_valence.vlist.vtab[:11]:
        if row['kind'] == 4:
            key = int(row['par0'])
        elif row['kind'] == 5:
            key = 1
        elif row['kind'] == 6:
            key = 2
        else:
            raise AssertionError
        m_counts[key] = m_counts.get(key, 0) + 1
    assert len(m_counts) == 3
    assert m_counts[1] == 5
    assert m_counts[2] == 2
    assert m_counts[3] == 4
Exemple #24
0
def test_nlist_inc_r0():
    cell = get_system_glycine().cell
    rmax = np.array([], dtype=int)
    r = np.array([], dtype=int)
    assert not nlist_inc_r(cell, r, rmax)
    assert (r == np.array([], dtype=int)).all()
Exemple #25
0
def test_dlist_glycine_random():
    system = get_system_glycine()
    dlist = get_dlist_random(system, 100)
    assert dlist.ndelta <= 45
    check_dlist(system, dlist)
Exemple #26
0
def test_dlist_glycine_bonds():
    system = get_system_glycine()
    dlist = get_dlist_bonds(system)
    check_dlist(system, dlist)
Exemple #27
0
def test_dlist_glycine_random():
    system = get_system_glycine()
    dlist = get_dlist_random(system, 100)
    assert dlist.ndelta <= 45
    check_dlist(system, dlist)
Exemple #28
0
def test_topology_glycine():
    system = get_system_glycine()
    check_topology_slow(system)
Exemple #29
0
def test_nlist_inc_r0():
    cell = get_system_glycine().cell
    rmax = np.array([], dtype=int)
    r = np.array([], dtype=int)
    assert not nlist_inc_r(cell, r, rmax)
    assert (r == np.array([], dtype=int)).all()
Exemple #30
0
def test_dlist_glycine_bonds():
    system = get_system_glycine()
    dlist = get_dlist_bonds(system)
    check_dlist(system, dlist)
Exemple #31
0
def test_topology_glycine():
    system = get_system_glycine()
    check_topology_slow(system)