コード例 #1
0
def test_bias_multiple_terms():
    system = get_system_quartz()
    part = ForcePartBias(system)
    # Harmonic volume bias
    cv0 = CVVolume(system)
    K, q0 = 0.4, 0.9 * system.cell.volume
    bias0 = HarmonicBias(K, q0, cv0)
    part.add_term(bias0)
    # Cosine of bending angle
    cv1 = BendAngle(0, 1, 2)
    m, a, phi0 = 1, 2.0, np.pi / 4.0
    bias1 = Cosine(m, a, phi0, cv1)
    part.add_term(bias1)
    # Check energy
    e = part.compute()
    contributions = part.get_term_energies()
    assert np.abs(e - np.sum(contributions)) < 1e-5
    assert contributions[0] == bias0.compute()
    # Check derivatives
    check_gpos_part(system, part)
    check_vtens_part(system, part)
    # Check collective variable values
    cv_values0 = part.get_term_cv_values(0)
    assert cv_values0.shape[0] == 1
    assert cv_values0[0] == cv0.compute()
    cv_values1 = part.get_term_cv_values(1)
    assert cv_values1.shape[0] == 1
    delta0 = system.pos[1] - system.pos[0]
    system.cell.mic(delta0)
    delta2 = system.pos[1] - system.pos[2]
    system.cell.mic(delta2)
    phi = bend_angle([delta0, np.zeros(3, float), delta2])[0]
    assert np.abs(cv_values1[0] - phi) < 1e-5
コード例 #2
0
ファイル: test_nlist.py プロジェクト: tovrstra/yaff
def test_nlist_quartz_20A():
    system = get_system_quartz()
    nlist = NeighborList(system)
    rcut = 20*angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    nlist.check()
コード例 #3
0
def test_bias_gaussianhills_quartz():
    system = get_system_quartz()
    # Volume
    cv0 = CVVolume(system)
    q0 = system.cell.volume
    # Distance between 2 and 8
    cv1 = CVInternalCoordinate(system, Bond(2, 8))
    delta = system.pos[2] - system.pos[8]
    system.cell.mic(delta)
    q1 = np.linalg.norm(delta)
    # Widths of the Gaussians
    sigmas = np.array([10.0 * angstrom**3, 0.2 * angstrom])
    bias = GaussianHills([cv0, cv1], sigmas)
    # No hills added, energy should be zero
    e = bias.compute()
    assert e == 0.0
    # Add one hill
    K0 = 5 * kjmol
    bias.add_hill(np.array([q0 + sigmas[0], q1 - 2 * sigmas[1]]), K0)
    e = bias.compute()
    assert np.abs(e - K0 * np.exp(-2.5)) < 1e-10
    # Add another hill
    K1 = 2 * kjmol
    bias.add_hill(np.array([q0 - 3 * sigmas[0], q1 - 1 * sigmas[1]]), K1)
    e = bias.compute()
    assert np.abs(e - K0 * np.exp(-2.5) - K1 * np.exp(-5.0)) < 1e-10
    # Test derivatives
    bias.add_hill(np.array([q0 - 3 * sigmas[0], q1 - 1 * sigmas[1]]), K1)
    part = ForcePartBias(system)
    part.add_term(bias)
    check_gpos_part(system, part)
    check_vtens_part(system, part)
コード例 #4
0
def test_vlist_quartz_bonds():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    for i, j in system.bonds:
        vlist.add_term(Harmonic(2.3, 3.04 + 0.1 * i, Bond(i, j)))
    assert dlist.ndelta == len(system.bonds)
    assert iclist.nic == len(system.bonds)
    assert vlist.nv == len(system.bonds)
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for i, j in system.bonds:
        delta = system.pos[i] - system.pos[j]
        system.cell.mic(delta)
        d = np.linalg.norm(delta)
        check_term = 0.5 * 2.3 * (d - 3.04 - 0.1 * i)**2
        assert abs(check_term - vlist.vtab[counter]['energy']) < 1e-10
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #5
0
ファイル: test_vlist.py プロジェクト: molmod/yaff
def test_vlist_quartz_morse():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    for i, j in system.bonds:
        vlist.add_term(Morse(2.3+i, 0.5, 2.0, Bond(i, j)))
    assert dlist.ndelta == len(system.bonds)
    assert iclist.nic == len(system.bonds)
    assert vlist.nv == len(system.bonds)
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for i, j in system.bonds:
        delta = system.pos[i] - system.pos[j]
        system.cell.mic(delta)
        d = np.linalg.norm(delta)
        check_term = (2.3+i)*(np.exp(-2*0.5*(d-2.0)) - 2.0*np.exp(-0.5*(d-2.0)))
        assert abs(check_term - vlist.vtab[counter]['energy']) < 1e-10
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #6
0
def test_nlist_quartz_20A():
    system = get_system_quartz()
    nlist = NeighborList(system)
    rcut = 20 * angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    nlist.check()
コード例 #7
0
ファイル: test_vlist.py プロジェクト: molmod/yaff
def test_vlist_quartz_bend_angle():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    angles = []
    for i1 in range(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    vlist.add_term(Harmonic(1.5, 2.0+0.01*i2, BendAngle(i0, i1, i2)))
                    angles.append((i0, i1, i2))
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    for row, (i0, i1, i2) in enumerate(angles):
        delta0 = system.pos[i0] - system.pos[i1]
        system.cell.mic(delta0)
        delta2 = system.pos[i2] - system.pos[i1]
        system.cell.mic(delta2)
        angle = bend_angle([delta0, np.zeros(3, float), delta2])[0]
        check_energy += 0.5*1.5*(angle-(2.0+0.01*i2))**2
    assert abs(energy - check_energy) < 1e-8
コード例 #8
0
ファイル: test_ewald.py プロジェクト: boegel/yaff
def test_ewald_gpos_vtens_corr_quartz():
    system = get_system_quartz().supercell(2, 2, 2)
    scalings = Scalings(system, np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9))
    for alpha in 0.1, 0.2, 0.5:
        part_ewald_corr = ForcePartEwaldCorrection(system, alpha, scalings)
        check_gpos_part(system, part_ewald_corr)
        check_vtens_part(system, part_ewald_corr)
コード例 #9
0
ファイル: test_vlist.py プロジェクト: molmod/yaff
def test_vlist_quartz_bonds():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    for i, j in system.bonds:
        vlist.add_term(Harmonic(2.3, 3.04+0.1*i, Bond(i, j)))
    assert dlist.ndelta == len(system.bonds)
    assert iclist.nic == len(system.bonds)
    assert vlist.nv == len(system.bonds)
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for i, j in system.bonds:
        delta = system.pos[i] - system.pos[j]
        system.cell.mic(delta)
        d = np.linalg.norm(delta)
        check_term = 0.5*2.3*(d - 3.04-0.1*i)**2
        assert abs(check_term - vlist.vtab[counter]['energy']) < 1e-10
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #10
0
ファイル: test_ewald.py プロジェクト: tovrstra/yaff
def test_ewald_gpos_vtens_corr_quartz():
    system = get_system_quartz().supercell(2, 2, 2)
    scalings = Scalings(system, np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9))
    for alpha in 0.1, 0.2, 0.5:
        part_ewald_corr = ForcePartEwaldCorrection(system, alpha, scalings)
        check_gpos_part(system, part_ewald_corr)
        check_vtens_part(system, part_ewald_corr)
コード例 #11
0
ファイル: test_system.py プロジェクト: yfyh2013/yaff
def test_detect_ffatypes():
    system = get_system_quartz()
    rules = [
        ('Si', '14'),
        ('O', '8'),
    ]
    check_detect_ffatypes(system, rules)
コード例 #12
0
ファイル: test_ewald.py プロジェクト: boegel/yaff
def test_ewald_dd_quartz():
    system = get_system_quartz().supercell(2, 2, 2)
    system.radii = np.random.rand( system.natom)
    system.radii2 = np.random.rand( system.natom)
    dipoles = np.random.rand( system.natom, 3 )
    system.dipoles = dipoles
    check_alpha_dependence_dd(system)
コード例 #13
0
def test_vlist_quartz_bend_angle():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    angles = []
    for i1 in xrange(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    vlist.add_term(
                        Harmonic(1.5, 2.0 + 0.01 * i2, BendAngle(i0, i1, i2)))
                    angles.append((i0, i1, i2))
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    for row, (i0, i1, i2) in enumerate(angles):
        delta0 = system.pos[i0] - system.pos[i1]
        system.cell.mic(delta0)
        delta2 = system.pos[i2] - system.pos[i1]
        system.cell.mic(delta2)
        angle = bend_angle([delta0, np.zeros(3, float), delta2])[0]
        check_energy += 0.5 * 1.5 * (angle - (2.0 + 0.01 * i2))**2
    assert abs(energy - check_energy) < 1e-8
コード例 #14
0
def test_cvvolume_quartz():
    system = get_system_quartz()
    cv = CVVolume(system)
    value = cv.compute()
    assert np.abs(value - np.abs(np.linalg.det(system.cell.rvecs))) < 1e-10
    check_gpos_cv_fd(cv)
    check_vtens_cv_fd(cv)
コード例 #15
0
ファイル: test_vlist.py プロジェクト: molmod/yaff
def test_vlist_quartz_bonds_fues():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    for i, j in system.bonds:
        vlist.add_term(Fues(2.3, 3.04+0.1*i, Bond(i, j)))
    assert dlist.ndelta == len(system.bonds)
    assert iclist.nic == len(system.bonds)
    assert vlist.nv == len(system.bonds)
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for i, j in system.bonds:
        delta = system.pos[i] - system.pos[j]
        system.cell.mic(delta)
        d = np.linalg.norm(delta)
        rv = 3.04+0.1*i
        check_term = 0.5*2.3*rv**2*(1.0 + rv/d*(rv/d - 2.0))
        if not abs(check_term - vlist.vtab[counter]['energy']) < 1e-10:
            raise AssertionError("Error in energy of bond(%i,%i): energy = %.15f instead energy = %.15f" %(i,j,check_term,vlist.vtab[counter]['energy']))
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #16
0
ファイル: test_vlist.py プロジェクト: molmod/yaff
def test_vlist_quartz_bend_cos():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    angles = []
    for i1 in range(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    vlist.add_term(Harmonic(1.1+0.01*i0, -0.2, BendCos(i0, i1, i2)))
                    angles.append((i0, i1, i2))
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for row, (i0, i1, i2) in enumerate(angles):
        delta0 = system.pos[i0] - system.pos[i1]
        system.cell.mic(delta0)
        delta2 = system.pos[i2] - system.pos[i1]
        system.cell.mic(delta2)
        c = bend_cos([delta0, np.zeros(3, float), delta2])[0]
        check_term = 0.5*(1.1+0.01*i0)*(c+0.2)**2
        assert abs(check_term - vlist.vtab[counter]['energy']) < 1e-10
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #17
0
ファイル: test_vlist.py プロジェクト: molmod/yaff
def test_gpos_vtens_quartz():
    system = get_system_quartz()
    rv_table = {
        ('Si', 'O'):       3.24970,
        ('O', 'Si', 'O'):  2.06457,
        ('Si', 'O', 'Si'): 1.80173,
    }
    fc_table = {
        ('Si', 'O'):       0.30978,
        ('O', 'Si', 'O'):  0.19282,
        ('Si', 'O', 'Si'): 0.00751,
    }

    part = ForcePartValence(system)
    for i, j in system.bonds:
        key = system.get_ffatype(i), system.get_ffatype(j)
        part.add_term(Harmonic(fc_table[key], rv_table[key], Bond(i, j)))
    for i1 in range(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                key = system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2)
                if i0 > i2:
                    part.add_term(Harmonic(fc_table[key], rv_table[key], BendAngle(i0, i1, i2)))

    check_gpos_part(system, part)
    check_vtens_part(system, part)
コード例 #18
0
def test_vlist_quartz_morse():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    for i, j in system.bonds:
        vlist.add_term(Morse(2.3 + i, 0.5, 2.0, Bond(i, j)))
    assert dlist.ndelta == len(system.bonds)
    assert iclist.nic == len(system.bonds)
    assert vlist.nv == len(system.bonds)
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for i, j in system.bonds:
        delta = system.pos[i] - system.pos[j]
        system.cell.mic(delta)
        d = np.linalg.norm(delta)
        check_term = (2.3 + i) * (np.exp(-2 * 0.5 *
                                         (d - 2.0)) - 2.0 * np.exp(-0.5 *
                                                                   (d - 2.0)))
        assert abs(check_term - vlist.vtab[counter]['energy']) < 1e-10
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #19
0
ファイル: test_ewald.py プロジェクト: tovrstra/yaff
def test_ewald_dd_quartz():
    system = get_system_quartz().supercell(2, 2, 2)
    system.radii = np.random.rand(system.natom)
    system.radii2 = np.random.rand(system.natom)
    dipoles = np.random.rand(system.natom, 3)
    system.dipoles = dipoles
    check_alpha_dependence_dd(system)
コード例 #20
0
ファイル: test_nlist.py プロジェクト: tovrstra/yaff
def test_nlist_quartz_4A_shortest():
    raise SkipTest('The mic routine fails to find the shortest distance in small skewed unit cells.')
    system = get_system_quartz()
    nlist = NeighborList(system)
    nlist.request_rcut(4*angstrom)
    nlist.update()
    check_nlist_shortest(system, nlist)
コード例 #21
0
def test_cell_quartz():
    cell = get_system_quartz().cell
    assert cell.rvecs.shape == (3, 3)
    assert cell.gvecs.shape == (3, 3)
    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
コード例 #22
0
def test_vlist_quartz_bonds_fues():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    for i, j in system.bonds:
        vlist.add_term(Fues(2.3, 3.04 + 0.1 * i, Bond(i, j)))
    assert dlist.ndelta == len(system.bonds)
    assert iclist.nic == len(system.bonds)
    assert vlist.nv == len(system.bonds)
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for i, j in system.bonds:
        delta = system.pos[i] - system.pos[j]
        system.cell.mic(delta)
        d = np.linalg.norm(delta)
        rv = 3.04 + 0.1 * i
        check_term = 0.5 * 2.3 * rv**2 * (1.0 + rv / d * (rv / d - 2.0))
        if not abs(check_term - vlist.vtab[counter]['energy']) < 1e-10:
            raise AssertionError(
                "Error in energy of bond(%i,%i): energy = %.15f instead energy = %.15f"
                % (i, j, check_term, vlist.vtab[counter]['energy']))
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #23
0
def test_gpos_vtens_quartz():
    system = get_system_quartz()
    rv_table = {
        ('Si', 'O'): 3.24970,
        ('O', 'Si', 'O'): 2.06457,
        ('Si', 'O', 'Si'): 1.80173,
    }
    fc_table = {
        ('Si', 'O'): 0.30978,
        ('O', 'Si', 'O'): 0.19282,
        ('Si', 'O', 'Si'): 0.00751,
    }

    part = ForcePartValence(system)
    for i, j in system.bonds:
        key = system.get_ffatype(i), system.get_ffatype(j)
        part.add_term(Harmonic(fc_table[key], rv_table[key], Bond(i, j)))
    for i1 in xrange(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                key = system.get_ffatype(i0), system.get_ffatype(
                    i1), system.get_ffatype(i2)
                if i0 > i2:
                    part.add_term(
                        Harmonic(fc_table[key], rv_table[key],
                                 BendAngle(i0, i1, i2)))

    check_gpos_part(system, part)
    check_vtens_part(system, part)
コード例 #24
0
def test_vlist_quartz_bend_cos():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    angles = []
    for i1 in xrange(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    vlist.add_term(
                        Harmonic(1.1 + 0.01 * i0, -0.2, BendCos(i0, i1, i2)))
                    angles.append((i0, i1, i2))
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    # compute energy manually
    check_energy = 0.0
    counter = 0
    for row, (i0, i1, i2) in enumerate(angles):
        delta0 = system.pos[i0] - system.pos[i1]
        system.cell.mic(delta0)
        delta2 = system.pos[i2] - system.pos[i1]
        system.cell.mic(delta2)
        c = bend_cos([delta0, np.zeros(3, float), delta2])[0]
        check_term = 0.5 * (1.1 + 0.01 * i0) * (c + 0.2)**2
        assert abs(check_term - vlist.vtab[counter]['energy']) < 1e-10
        check_energy += check_term
        counter += 1
    assert abs(energy - check_energy) < 1e-8
コード例 #25
0
ファイル: test_pair_pot.py プロジェクト: tovrstra/yaff
def test_bks_vtens_gpos_parts():
    system = get_system_quartz()
    fn_pars = context.get_fn('test/parameters_bks.txt')
    ff = ForceField.generate(system, fn_pars, smooth_ei=True, reci_ei='ignore')
    for part in ff.parts:
        check_vtens_part(system, part, ff.nlist)
        check_gpos_part(system, part, ff.nlist)
コード例 #26
0
ファイル: test_ewald.py プロジェクト: jelle-w/yaff
def test_ewald_gpos_vtens_reci_quartz():
    system = get_system_quartz()
    for alpha in 0.1, 0.2, 0.5:
        part_ewald_reci = ForcePartEwaldReciprocal(system,
                                                   alpha,
                                                   gcut=alpha / 0.5)
        check_gpos_part(system, part_ewald_reci)
        check_vtens_part(system, part_ewald_reci)
コード例 #27
0
ファイル: test_scaling.py プロジェクト: tovrstra/yaff
def test_scaling_quartz():
    system = get_system_quartz().supercell(2, 2, 2)
    stab = Scalings(system).stab
    assert (stab['a'] > stab['b']).all()
    assert len(stab) == sum(len(system.neighs1[i]) + len(system.neighs2[i]) for i in xrange(system.natom))/2
    for i0, i1, scale, nbond in stab:
        assert scale == 0.0
        assert i0 in system.neighs1[i1] or i0 in system.neighs2[i1]
        assert nbond == 1 or nbond == 2
コード例 #28
0
ファイル: test_system.py プロジェクト: yfyh2013/yaff
def test_remove_duplicate1():
    system1 = get_system_quartz()
    system2 = system1.remove_duplicate()
    assert system1.natom == system2.natom
    assert system1.nbond == system2.nbond
    assert (system1.numbers == system2.numbers).all()
    assert (system1.pos == system2.pos).all()
    assert (system1.ffatype_ids == system2.ffatype_ids).all()
    assert system1.neighs1 == system2.neighs1
コード例 #29
0
def test_nlist_quartz_4A_shortest():
    raise SkipTest(
        'The mic routine fails to find the shortest distance in small skewed unit cells.'
    )
    system = get_system_quartz()
    nlist = NeighborList(system)
    nlist.request_rcut(4 * angstrom)
    nlist.update()
    check_nlist_shortest(system, nlist)
コード例 #30
0
ファイル: test_ewald.py プロジェクト: boegel/yaff
def test_ewald_quartz():
    # These are the energy contributions that one should get:
    # alpha           REAL            RECI            CORR
    # 0.05  -3.5696637e-02   6.8222205e-29  -2.5814534e-01
    # 0.10   1.3948043e-01   2.2254505e-08  -4.3332242e-01
    # 0.20   1.7482393e-01   2.9254105e-03  -4.7159132e-01
    # 0.50   5.6286111e-04   7.7869316e-01  -1.0730980e+00
    # 1.00   2.6807119e-12   4.6913539e+00  -4.9851959e+00
    system = get_system_quartz().supercell(2, 2, 2)
    check_alpha_depedence(system)
コード例 #31
0
ファイル: test_ewald.py プロジェクト: tovrstra/yaff
def test_ewald_quartz():
    # These are the energy contributions that one should get:
    # alpha           REAL            RECI            CORR
    # 0.05  -3.5696637e-02   6.8222205e-29  -2.5814534e-01
    # 0.10   1.3948043e-01   2.2254505e-08  -4.3332242e-01
    # 0.20   1.7482393e-01   2.9254105e-03  -4.7159132e-01
    # 0.50   5.6286111e-04   7.7869316e-01  -1.0730980e+00
    # 1.00   2.6807119e-12   4.6913539e+00  -4.9851959e+00
    system = get_system_quartz().supercell(2, 2, 2)
    check_alpha_depedence(system)
コード例 #32
0
def test_scaling_quartz():
    system = get_system_quartz().supercell(2, 2, 2)
    stab = Scalings(system).stab
    assert (stab['a'] > stab['b']).all()
    assert len(stab) == sum(
        len(system.neighs1[i]) + len(system.neighs2[i])
        for i in xrange(system.natom)) / 2
    for i0, i1, scale, nbond in stab:
        assert scale == 0.0
        assert i0 in system.neighs1[i1] or i0 in system.neighs2[i1]
        assert nbond == 1 or nbond == 2
コード例 #33
0
def test_quartz():
    system = get_system_quartz()
    groups = [
        (np.array([0, 2, 8, 1]), np.array([0.3, 0.2, 0.4, 0.3])),
    ]
    comlist = COMList(system, groups)
    comlist.forward()
    com_a = comlist.pos[0].copy()
    system.pos[2] += system.cell.rvecs[0]
    comlist.forward()
    np.testing.assert_almost_equal(com_a, comlist.pos[0])
コード例 #34
0
ファイル: test_system.py プロジェクト: yfyh2013/yaff
def test_remove_duplicate2():
    system1 = get_system_quartz()
    system2 = system1.supercell(1, 2, 1)
    system2.cell = system1.cell
    system3 = system2.remove_duplicate()
    assert system1.natom == system3.natom
    assert system1.nbond == system3.nbond
    assert system1.numbers.sum() == system3.numbers.sum()
    assert abs(system1.pos.mean(axis=0) -
               system3.pos.mean(axis=0)).max() < 1e-10
    assert system1.ffatype_ids.sum() == system3.ffatype_ids.sum()
コード例 #35
0
ファイル: test_system.py プロジェクト: yfyh2013/yaff
def test_subsystem():
    system1 = get_system_quartz()
    system1.dipoles = np.random.rand(system1.natom, 3)
    system2 = system1.subsystem((system1.numbers == 8).nonzero()[0])
    assert system2.natom == 6
    assert (system2.numbers == 8).all()
    assert len(system2.bonds) == 0
    assert system2.scopes is None
    assert system2.get_ffatype(0) == 'O'
    assert (system2.charges == -0.9).all()
    assert (system1.cell.rvecs == system2.cell.rvecs).all()
    assert np.shape(system2.dipoles)[1] == 3
コード例 #36
0
ファイル: common.py プロジェクト: molmod/yaff
def get_ff_bks(**kwargs):
    system = get_system_quartz()
    if kwargs.pop('align_ax', False):
        system.align_cell(np.array([[1, 0, 0], [0, 1, 1]]), True)
        rvecs = system.cell.rvecs.copy()
        rvecs[1, 0] = 0.0
        rvecs[2, 0] = 0.0
        rvecs[0, 1] = 0.0
        rvecs[0, 2] = 0.0
        system.cell.update_rvecs(rvecs)
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_bks.txt')
    return ForceField.generate(system, fn_pars, **kwargs)
コード例 #37
0
ファイル: common.py プロジェクト: tovrstra/yaff
def get_ff_bks(**kwargs):
    system = get_system_quartz()
    if kwargs.pop('align_ax', False):
        system.align_cell(np.array([[1, 0, 0], [0, 1, 1]]), True)
        rvecs = system.cell.rvecs.copy()
        rvecs[1, 0] = 0.0
        rvecs[2, 0] = 0.0
        rvecs[0, 1] = 0.0
        rvecs[0, 2] = 0.0
        system.cell.update_rvecs(rvecs)
    fn_pars = context.get_fn('test/parameters_bks.txt')
    return ForceField.generate(system, fn_pars, **kwargs)
コード例 #38
0
def test_nlist_quartz_110A():
    system = get_system_quartz()
    nlist = NeighborList(system)
    rcut = 110 * angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    assert (nlist.neighs['r0'][:nlist.nneigh] <= nlist.rmax[0]).all()
    assert (nlist.neighs['r0'][:nlist.nneigh] >= -nlist.rmax[0]).all()
    assert (nlist.neighs['r1'][:nlist.nneigh] <= nlist.rmax[1]).all()
    assert (nlist.neighs['r1'][:nlist.nneigh] >= -nlist.rmax[1]).all()
    assert (nlist.neighs['r2'][:nlist.nneigh] <= nlist.rmax[2]).all()
    assert (nlist.neighs['r2'][:nlist.nneigh] >= 0).all()
コード例 #39
0
def get_ff_bks(**kwargs):
    system = get_system_quartz()
    if kwargs.pop('align_ax', False):
        system.align_cell(np.array([[1, 0, 0], [0, 1, 1]]), True)
        rvecs = system.cell.rvecs.copy()
        rvecs[1, 0] = 0.0
        rvecs[2, 0] = 0.0
        rvecs[0, 1] = 0.0
        rvecs[0, 2] = 0.0
        system.cell.update_rvecs(rvecs)
    fn_pars = context.get_fn('test/parameters_bks.txt')
    return ForceField.generate(system, fn_pars, **kwargs)
コード例 #40
0
def test_cvinternalcoordinate_quartz():
    system = get_system_quartz()
    ic = Bond(1, 3)
    cv = CVInternalCoordinate(system, ic)
    value = cv.compute()
    assert value == cv.get_last_computed_value()
    delta = system.pos[3] - system.pos[1]
    system.cell.mic(delta)
    reference = bond_length([np.zeros(3, float), delta])[0]
    assert np.abs(value - reference) < 1e-8
    check_gpos_cv_fd(cv)
    check_vtens_cv_fd(cv)
コード例 #41
0
def test_iclist_quartz_bonds():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    for i, j in system.bonds:
        iclist.add_ic(Bond(i, j))
    dlist.forward()
    iclist.forward()
    for row, (i, j) in enumerate(system.bonds):
        delta = system.pos[j] - system.pos[i]
        system.cell.mic(delta)
        assert abs(iclist.ictab[row]['value'] - bond_length([np.zeros(3, float), delta])[0]) < 1e-5
コード例 #42
0
def test_bias_harmonicvolume_quartz():
    system = get_system_quartz()
    cv = CVVolume(system)
    K, q0 = 0.4, 0.9 * system.cell.volume
    bias = HarmonicBias(K, q0, cv)
    part = ForcePartBias(system)
    part.add_term(bias)
    e = part.compute()
    echeck = 0.5 * K * (system.cell.volume - q0)**2
    assert np.abs(e - echeck) < 1e-8
    check_gpos_part(system, part)
    check_vtens_part(system, part)
コード例 #43
0
ファイル: test_nlist.py プロジェクト: tovrstra/yaff
def test_nlist_quartz_110A():
    system = get_system_quartz()
    nlist = NeighborList(system)
    rcut = 110*angstrom
    nlist.request_rcut(rcut)
    nlist.update()
    assert (nlist.neighs['r0'][:nlist.nneigh] <= nlist.rmax[0]).all()
    assert (nlist.neighs['r0'][:nlist.nneigh] >= -nlist.rmax[0]).all()
    assert (nlist.neighs['r1'][:nlist.nneigh] <= nlist.rmax[1]).all()
    assert (nlist.neighs['r1'][:nlist.nneigh] >= -nlist.rmax[1]).all()
    assert (nlist.neighs['r2'][:nlist.nneigh] <= nlist.rmax[2]).all()
    assert (nlist.neighs['r2'][:nlist.nneigh] >= 0).all()
コード例 #44
0
ファイル: common.py プロジェクト: yfyh2013/yaff
def get_ff_bks(**kwargs):
    system = get_system_quartz()
    if kwargs.pop('align_ax', False):
        system.align_cell(np.array([[1, 0, 0], [0, 1, 1]]), True)
        rvecs = system.cell.rvecs.copy()
        rvecs[1, 0] = 0.0
        rvecs[2, 0] = 0.0
        rvecs[0, 1] = 0.0
        rvecs[0, 2] = 0.0
        system.cell.update_rvecs(rvecs)
    fn_pars = pkg_resources.resource_filename(
        __name__, '../../data/test/parameters_bks.txt')
    return ForceField.generate(system, fn_pars, **kwargs)
コード例 #45
0
def test_quartz_vtens():
    system = get_system_quartz()
    groups = [
        (np.array([0, 2, 8, 1]),
         np.array([0.3, 0.2, 0.4, 0.3])),
        (np.array([1, 3, 4, 5]),
         np.array([0.3, 0.4, 0.1, 0.2])),
    ]
    comlist = COMList(system, groups)
    part = ForcePartValence(system, comlist)
    part.add_term(Harmonic(2.1, 0.5, Bond(0, 1)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
コード例 #46
0
ファイル: test_iclist.py プロジェクト: mcoolsce/yaff
def test_iclist_quartz_bonds():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    for i, j in system.bonds:
        iclist.add_ic(Bond(i, j))
    dlist.forward()
    iclist.forward()
    for row, (i, j) in enumerate(system.bonds):
        delta = system.pos[j] - system.pos[i]
        system.cell.mic(delta)
        assert abs(iclist.ictab[row]['value'] -
                   bond_length([np.zeros(3, float), delta])[0]) < 1e-5
コード例 #47
0
ファイル: test_pair_pot.py プロジェクト: tovrstra/yaff
def test_bks_isfinite():
    system = get_system_quartz()
    fn_pars = context.get_fn('test/parameters_bks.txt')
    ff = ForceField.generate(system, fn_pars)
    assert np.isfinite(ff.part_pair_dampdisp.pair_pot.c6_cross).all()
    assert np.isfinite(ff.part_pair_dampdisp.pair_pot.b_cross).all()
    ff.compute()
    assert np.isfinite(ff.part_pair_exprep.energy)
    assert np.isfinite(ff.part_pair_ei.energy)
    assert np.isfinite(ff.part_ewald_reci.energy)
    assert np.isfinite(ff.part_ewald_cor.energy)
    assert np.isfinite(ff.part_ewald_neut.energy)
    assert np.isfinite(ff.part_pair_dampdisp.energy)
    assert np.isfinite(ff.energy)
コード例 #48
0
def test_plumed_quartz_volume():
    system = get_system_quartz()
    # Harmonic restraint of the volume
    kappa, V0 = 1.6 * kjmol / angstrom**6, 110 * angstrom**3
    # PLUMED input commands
    commands = "vol: VOLUME\n"
    commands += "RESTRAINT ARG=vol AT=%.20f KAPPA=%.20f LABEL=restraint\n"%\
        (V0/nanometer**3,kappa/kjmol*nanometer**6)

    # Reference calculation
    def reference(system):
        return 0.5 * kappa * (system.cell.volume - V0)**2

    check_plumed(system, commands, reference)
コード例 #49
0
def test_iclist_quartz_bend_angle():
    system = get_system_quartz()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    angles = []
    for i1 in xrange(system.natom):
        for i0 in system.neighs1[i1]:
            for i2 in system.neighs1[i1]:
                if i0 > i2:
                    iclist.add_ic(BendAngle(i0, i1, i2))
                    angles.append((i0, i1, i2))
    dlist.forward()
    iclist.forward()
    for row, (i0, i1, i2) in enumerate(angles):
        delta0 = system.pos[i1] - system.pos[i0]
        system.cell.mic(delta0)
        delta2 = system.pos[i1] - system.pos[i2]
        system.cell.mic(delta2)
        assert abs(iclist.ictab[row]['value'] - bend_angle([delta0, np.zeros(3, float), delta2])[0]) < 1e-5
コード例 #50
0
ファイル: test_ewald.py プロジェクト: tovrstra/yaff
def test_ewald_reci_volchange_quartz():
    system = get_system_quartz()
    dielectric = 1.2
    for alpha in 0.1, 0.2, 0.5:
        part_ewald_reci = ForcePartEwaldReciprocal(system, alpha, gcut=alpha / 0.5, dielectric=dielectric)
        # compute the energy
        energy1 = part_ewald_reci.compute()
        # distort the cell and restore to the original volume
        volume = system.cell.volume
        reduced = np.dot(system.pos, system.cell.gvecs.transpose())
        new_rvecs = system.cell.rvecs * np.random.uniform(0.9, 1.0)
        new_volume = np.linalg.det(new_rvecs)
        new_rvecs *= (volume / new_volume) ** (1.0 / 3.0)
        system.pos[:] = np.dot(reduced, new_rvecs)
        system.cell.update_rvecs(new_rvecs)
        # recompute the energy
        energy2 = part_ewald_reci.compute()
        # energies must be the same
        assert abs(energy1 - energy2) < 1e-5 * abs(energy1)
コード例 #51
0
ファイル: test_ewald.py プロジェクト: tovrstra/yaff
def test_ewald_corr_quartz():
    from scipy.special import erf

    system = get_system_quartz().supercell(2, 2, 2)
    for alpha in 0.05, 0.1, 0.2:
        scalings = Scalings(
            system, np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9), np.random.uniform(0.1, 0.9)
        )
        part_ewald_corr = ForcePartEwaldCorrection(system, alpha, scalings)
        energy1 = part_ewald_corr.compute()
        # self-interaction corrections
        energy2 = -alpha / np.sqrt(np.pi) * (system.charges ** 2).sum()
        # corrections from scaled interactions
        for i0, i1, scale, nbond in scalings.stab:
            delta = system.pos[i0] - system.pos[i1]
            system.cell.mic(delta)
            d = np.linalg.norm(delta)
            term = erf(alpha * d) / d * (1 - scale) * system.charges[i0] * system.charges[i1]
            energy2 -= term
        assert abs(energy1 - energy2) < 1e-10
コード例 #52
0
ファイル: test_dlist.py プロジェクト: tovrstra/yaff
def test_dlist_quartz_bonds():
    system = get_system_quartz()
    dlist = get_dlist_bonds(system)
    check_dlist(system, dlist)
コード例 #53
0
ファイル: test_dlist.py プロジェクト: tovrstra/yaff
def test_dlist_quartz_random():
    system = get_system_quartz()
    dlist = get_dlist_random(system)
    check_dlist(system, dlist)
コード例 #54
0
ファイル: test_ewald.py プロジェクト: tovrstra/yaff
def test_ewald_gpos_vtens_reci_quartz():
    system = get_system_quartz()
    for alpha in 0.1, 0.2, 0.5:
        part_ewald_reci = ForcePartEwaldReciprocal(system, alpha, gcut=alpha / 0.5)
        check_gpos_part(system, part_ewald_reci)
        check_vtens_part(system, part_ewald_reci)
コード例 #55
0
ファイル: test_topology.py プロジェクト: molmod/yaff
def test_topology_quartz():
    system = get_system_quartz()
    check_topology_slow(system)
コード例 #56
0
ファイル: test_nlist.py プロジェクト: tovrstra/yaff
def test_nlist_quartz_6A_skin3A():
    system = get_system_quartz()
    check_nlist_skin(system, 6*angstrom, 3*angstrom)
コード例 #57
0
ファイル: test_cell.py プロジェクト: tovrstra/yaff
def test_cell_quartz():
    cell = get_system_quartz().cell
    assert cell.rvecs.shape == (3, 3)
    assert cell.gvecs.shape == (3, 3)
    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