Exemplo n.º 1
0
def test_oop_dist_formaldehyde():
    # All atoms in the y-z plane
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopDist(2,3,1,0))
    dlist.forward()
    iclist.forward()
    assert abs( iclist.ictab[0]['value'] - 0.0 ) < 1e-8
    # Put the C atom out of the plane
    system = get_system_formaldehyde()
    system.pos[0,0] += 1.2*angstrom
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    # Add a dummy ic to the iclist, so some delta vectors are stored with a
    # minus sign. This enables to check that the (*ic).signs are implemented
    # correctly.
    iclist.add_ic(OopDist(1,3,2,0))
    iclist.add_ic(OopDist(2,3,1,0))
    dlist.forward()
    iclist.forward()
    assert abs( iclist.ictab[1]['value'] - 1.2*angstrom ) < 1e-8
    # Check if the distance is invariant for permutations of the first three atoms
    from itertools import permutations
    for perm in permutations((1,2,3)):
        iclist.add_ic(OopDist(perm[0],perm[1],perm[2],0))
    dlist.forward()
    iclist.forward()
    for ic in iclist.ictab:
        if ic['kind']==8:
            assert abs( abs(ic['value']) - 1.2*angstrom ) < 1e-8
Exemplo n.º 2
0
def test_oop_dist_formaldehyde():
    # All atoms in the y-z plane
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopDist(2,3,1,0))
    dlist.forward()
    iclist.forward()
    assert abs( iclist.ictab[0]['value'] - 0.0 ) < 1e-8
    # Put the C atom out of the plane
    system = get_system_formaldehyde()
    system.pos[0,0] += 1.2*angstrom
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopDist(2,3,1,0))
    dlist.forward()
    iclist.forward()
    assert abs( iclist.ictab[0]['value'] - 1.2*angstrom ) < 1e-8
    # Check if the distance is invariant for permutations of the first three atoms
    from itertools import permutations
    for perm in permutations((1,2,3)):
        iclist.add_ic(OopDist(perm[0],perm[1],perm[2],0))
    dlist.forward()
    iclist.forward()
    for ic in iclist.ictab:
        if ic['kind']==8:
            assert abs( abs(ic['value']) - 1.2*angstrom ) < 1e-8
Exemplo n.º 3
0
def test_oop_dist_formaldehyde():
    # All atoms in the y-z plane
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopDist(2, 3, 1, 0))
    dlist.forward()
    iclist.forward()
    assert abs(iclist.ictab[0]['value'] - 0.0) < 1e-8
    # Put the C atom out of the plane
    system = get_system_formaldehyde()
    system.pos[0, 0] += 1.2 * angstrom
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    # Add a dummy ic to the iclist, so some delta vectors are stored with a
    # minus sign. This enables to check that the (*ic).signs are implemented
    # correctly.
    iclist.add_ic(OopDist(1, 3, 2, 0))
    iclist.add_ic(OopDist(2, 3, 1, 0))
    dlist.forward()
    iclist.forward()
    assert abs(iclist.ictab[1]['value'] - 1.2 * angstrom) < 1e-8
    # Check if the distance is invariant for permutations of the first three atoms
    from itertools import permutations
    for perm in permutations((1, 2, 3)):
        iclist.add_ic(OopDist(perm[0], perm[1], perm[2], 0))
    dlist.forward()
    iclist.forward()
    for ic in iclist.ictab:
        if ic['kind'] == 8:
            assert abs(abs(ic['value']) - 1.2 * angstrom) < 1e-8
Exemplo n.º 4
0
def get_ff_formaldehyde():
    # This forcefield is based on UFF, but we only really care about
    # out-of-plane angles
    system = get_system_formaldehyde()
    # Move the C atom to make the molecule non-planar
    system.pos[0, 0] += 0.2 * angstrom
    # Valence part
    part_valence = ForcePartValence(system)
    # Harmonic bonds
    part_valence.add_term(
        Harmonic(3.371456e3 * kjmol / angstrom**2, 1.219 * angstrom,
                 Bond(0, 1)))
    part_valence.add_term(
        Harmonic(1.484153e3 * kjmol / angstrom**2, 1.084 * angstrom,
                 Bond(0, 2)))
    part_valence.add_term(
        Harmonic(1.484153e3 * kjmol / angstrom**2, 1.084 * angstrom,
                 Bond(0, 3)))
    # Harmonic bends
    part_valence.add_term(
        Harmonic(6.91928e2 * kjmol, np.cos(120.0 * deg), BendCos(1, 0, 2)))
    part_valence.add_term(
        Harmonic(6.91928e2 * kjmol, np.cos(120.0 * deg), BendCos(1, 0, 3)))
    part_valence.add_term(
        Harmonic(2.57789e2 * kjmol, np.cos(120.0 * deg), BendCos(2, 0, 3)))
    # Out-of-plane angles
    part_valence.add_term(Chebychev1(6.978 * kjmol, OopCos(2, 3, 1, 0)))
    part_valence.add_term(Chebychev1(6.978 * kjmol, OopCos(1, 2, 3, 0)))
    part_valence.add_term(Chebychev1(6.978 * kjmol, OopCos(1, 3, 2, 0)))
    return ForceField(system, [part_valence], None)
Exemplo n.º 5
0
def test_gpos_vtens_oopdist_formaldehyde():
    system = get_system_formaldehyde()
    system.pos[0, 0] += 0.0 * angstrom
    part = ForcePartValence(system)
    part.add_term(Harmonic(0.0, 0.0 * angstrom, OopDist(2, 3, 1, 0)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Exemplo n.º 6
0
def test_inversion_formaldehyde():
    # Test for an inversion term made by combining a Chebychev1 energy term with
    # an out-of-plane cosine.
    oop_fc = 1.0
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    #Add a term for all out-of-plane angles with the carbon as center
    vlist.add_term(Chebychev1(oop_fc, OopCos(2, 3, 1, 0)))
    vlist.add_term(Chebychev1(oop_fc, OopCos(1, 2, 3, 0)))
    vlist.add_term(Chebychev1(oop_fc, OopCos(1, 3, 2, 0)))
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    #For a planar molecule the energy should be zero
    check_energy = 0.0
    assert abs(energy - check_energy) < 1e-8
    #Now put the carbon out of the plane; the energy shoud rise
    system.pos[0, 0] += 1.00000000 * angstrom
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    #Calculate the energy manually
    check_energy = 0.0
    for term in iclist.ictab:
        #Select the terms corresponding to oop cosines
        if term[0] == 6:
            check_energy += 0.5 * oop_fc * (1.0 - term['value'])
    assert abs(energy - check_energy) < 1e-8
Exemplo n.º 7
0
def test_gpos_vtens_oopdist_formaldehyde():
    system = get_system_formaldehyde()
    system.pos[0,0] += 0.0*angstrom
    part = ForcePartValence(system)
    part.add_term(Harmonic(0.0,0.0*angstrom,OopDist(2,3,1,0)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Exemplo n.º 8
0
def test_inversion_formaldehyde():
    # Test for an inversion term made by combining a Chebychev1 energy term with
    # an out-of-plane cosine.
    oop_fc = 1.0
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    vlist = ValenceList(iclist)
    #Add a term for all out-of-plane angles with the carbon as center
    vlist.add_term(Chebychev1(oop_fc, OopCos(2,3,1,0)))
    vlist.add_term(Chebychev1(oop_fc, OopCos(1,2,3,0)))
    vlist.add_term(Chebychev1(oop_fc, OopCos(1,3,2,0)))
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    #For a planar molecule the energy should be zero
    check_energy = 0.0
    assert abs(energy - check_energy) < 1e-8
    #Now put the carbon out of the plane; the energy shoud rise
    system.pos[0,0] += 1.00000000*angstrom
    dlist.forward()
    iclist.forward()
    energy = vlist.forward()
    #Calculate the energy manually
    check_energy = 0.0
    for term in iclist.ictab:
        #Select the terms corresponding to oop cosines
        if term[0]==6:
            check_energy += 0.5*oop_fc*(1.0-term['value'])
    assert abs(energy - check_energy) < 1e-8
Exemplo n.º 9
0
def test_generator_formaldehyde_cross_consistency():
    system = get_system_formaldehyde()
    fn_pars1 = pkg_resources.resource_filename(__name__, '../../data/test/parameters_formaldehyde_cross.txt')
    ff1 = ForceField.generate(system, fn_pars1)
    fn_pars2 = pkg_resources.resource_filename(__name__, '../../data/test/parameters_formaldehyde_cross_alt.txt')
    ff2 = ForceField.generate(system, fn_pars2)
    energy1 = ff1.compute()
    energy2 = ff2.compute()
    np.testing.assert_allclose(energy1, energy2)
Exemplo n.º 10
0
def test_oop_angle_formaldehyde():
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopCos(2,3,1,0))
    iclist.add_ic(OopAngle(2,3,1,0))
    dlist.forward()
    iclist.forward()
    assert abs( iclist.ictab[0]['value'] - 1.0 ) < 1e-8
    assert abs( iclist.ictab[1]['value'] - 0.0 ) < 1e-8
Exemplo n.º 11
0
def test_oop_angle_formaldehyde():
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopCos(2, 3, 1, 0))
    iclist.add_ic(OopAngle(2, 3, 1, 0))
    dlist.forward()
    iclist.forward()
    assert abs(iclist.ictab[0]['value'] - 1.0) < 1e-8
    assert abs(iclist.ictab[1]['value'] - 0.0) < 1e-8
Exemplo n.º 12
0
def test_generator_formaldehyde_oopangle():
    system = get_system_formaldehyde()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_formaldehyde_inversion.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 == 3
    assert (part_valence.iclist.ictab['kind'][0:3] == 6).all()
    assert part_valence.iclist.nic == 3
    assert (part_valence.vlist.vtab['kind'][0:3] == 5).all()
    assert abs(part_valence.vlist.vtab['par0'] - 1.0*kjmol).all() < 1e-10
    assert part_valence.vlist.nv == 3
Exemplo n.º 13
0
def test_oop_meanangle_formaldehyde():
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopMeanAngle(2,3,1,0))
    iclist.add_ic(OopAngle(1,2,3,0))
    iclist.add_ic(OopAngle(2,3,1,0))
    iclist.add_ic(OopAngle(3,1,2,0))
    dlist.forward()
    iclist.forward()
    mean = 0.0
    for i in xrange(4):
        assert abs( iclist.ictab[i]['value'] - 0.0) < 1e-8
        if i > 0: mean += iclist.ictab[i]['value']
    mean /= 3
    assert abs(iclist.ictab[0]['value'] - mean) < 1e-8
Exemplo n.º 14
0
def test_oop_meanangle_formaldehyde():
    system = get_system_formaldehyde()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    iclist.add_ic(OopMeanAngle(2, 3, 1, 0))
    iclist.add_ic(OopAngle(1, 2, 3, 0))
    iclist.add_ic(OopAngle(2, 3, 1, 0))
    iclist.add_ic(OopAngle(3, 1, 2, 0))
    dlist.forward()
    iclist.forward()
    mean = 0.0
    for i in range(4):
        assert abs(iclist.ictab[i]['value'] - 0.0) < 1e-8
        if i > 0: mean += iclist.ictab[i]['value']
    mean /= 3
    assert abs(iclist.ictab[0]['value'] - mean) < 1e-8
Exemplo n.º 15
0
def get_ff_formaldehyde():
    # This forcefield is based on UFF, but we only really care about
    # out-of-plane angles
    system = get_system_formaldehyde()
    # Move the C atom to make the molecule non-planar
    system.pos[0,0] += 0.2*angstrom
    # Valence part
    part_valence = ForcePartValence(system)
    # Harmonic bonds
    part_valence.add_term(Harmonic(3.371456e3*kjmol/angstrom**2, 1.219*angstrom, Bond(0, 1)))
    part_valence.add_term(Harmonic(1.484153e3*kjmol/angstrom**2, 1.084*angstrom, Bond(0, 2)))
    part_valence.add_term(Harmonic(1.484153e3*kjmol/angstrom**2, 1.084*angstrom, Bond(0, 3)))
    # Harmonic bends
    part_valence.add_term(Harmonic(6.91928e2*kjmol, np.cos(120.0*deg), BendCos(1,0,2)))
    part_valence.add_term(Harmonic(6.91928e2*kjmol, np.cos(120.0*deg), BendCos(1,0,3)))
    part_valence.add_term(Harmonic(2.57789e2*kjmol, np.cos(120.0*deg), BendCos(2,0,3)))
    # Out-of-plane angles
    part_valence.add_term(Chebychev1(6.978*kjmol, OopCos(2,3,1,0)))
    part_valence.add_term(Chebychev1(6.978*kjmol, OopCos(1,2,3,0)))
    part_valence.add_term(Chebychev1(6.978*kjmol, OopCos(1,3,2,0)))
    return ForceField(system, [part_valence], None)
Exemplo n.º 16
0
def test_generator_formaldehyde_cross():
    system = get_system_formaldehyde()
    fn_pars = pkg_resources.resource_filename(__name__, '../../data/test/parameters_formaldehyde_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 == 3
    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 == 5
    vlist = part_valence.vlist
    iclist = vlist.iclist
    assert part_valence.vlist.nv == 6
    for irow in range(vlist.nv):
        row = vlist.vtab[irow]
        assert row['kind'] == 3
        atoms = vlist.lookup_atoms(irow)
        if atoms in ( [[[2, 0]], [[0, 1]]], [[[3, 0]], [[0, 1]]] ):
            # Bond-Bond H-C-O
            np.testing.assert_allclose(row['par0'], 20.0*(kjmol/angstrom**2), rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par1'], 0.947*angstrom, rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par2'], 1.23*angstrom, rtol=0.0, atol=1e-10)
        elif atoms in ( [[[2, 0]], [[0, 2], [0, 1]]], [[[3, 0]], [[0, 3], [0, 1]]] ):
            # Bond-Angle H-C-O
            np.testing.assert_allclose(row['par0'], 10.0*(kjmol/angstrom/rad), rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par1'], 0.947*angstrom, rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par2'], 121.0*deg, rtol=0.0, atol=1e-10)
        elif atoms in ( [[[0, 1]], [[0, 2], [0, 1]]], [[[0, 1]], [[0, 3], [0, 1]]] ):
            # Bond-Angle O-C-H
            np.testing.assert_allclose(row['par0'], 15.0*(kjmol/angstrom/rad), rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par1'], 1.23*angstrom, rtol=0.0, atol=1e-10)
            np.testing.assert_allclose(row['par2'], 121.0*deg, rtol=0.0, atol=1e-10)
        else:
            raise AssertionError('Some internal coordinates were missing.')
Exemplo n.º 17
0
def test_gpos_vtens_oopcos_formaldehyde():
    system = get_system_formaldehyde()
    part = ForcePartValence(system)
    part.add_term(Harmonic(2.1, 0.0 * angstrom, OopCos(2, 3, 1, 0)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)
Exemplo n.º 18
0
def test_gpos_vtens_oopcos_formaldehyde():
    system = get_system_formaldehyde()
    part = ForcePartValence(system)
    part.add_term(Harmonic(2.1,0.0*angstrom,OopCos(2,3,1,0)))
    check_gpos_part(system, part)
    check_vtens_part(system, part)