Exemplo n.º 1
0
def test_gpos_vtens_dihedral_cos_mil53():
    system = get_system_mil53()
    forbidden_dihedrals = [
        ["O_HY","AL","O_HY","AL"],
        ["O_HY","AL","O_HY","H_HY"],
        ["O_CA","AL","O_CA","C_CA"],
        ["O_CA","AL","O_HY","H_HY"],
        ["H_PH","C_PH","C_PC","C_PH"],
        ["H_PH","C_PH","C_PC","C_CA"],
        ["C_PH","C_PH","C_PC","C_PH"],
        ["C_PH","C_PH","C_PC","C_CA"],
        ["C_PC","C_PH","C_PH","H_PH"],
        ["C_PC","C_PH","C_PH","C_PC"],
        ["H_PH","C_PH","C_PH","H_PH"],
        ["C_PH","C_PC","C_CA","O_CA"],
    ]
    idih = -1
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0==i2: continue
            for i3 in system.neighs1[i2]:
                if i3==i1: continue
                types = [system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2), system.get_ffatype(i3)]
                if types in forbidden_dihedrals or types[::-1] in forbidden_dihedrals: continue
                idih += 1
                fc = 2.1 + 0.01*(0.3*i1 + 0.7*i2)
                part = ForcePartValence(system)
                part.add_term(PolyFour([-2.0*fc,0.0001,0.0,0.0],DihedCos(i0,i1,i2,i3)))
                check_gpos_part(system, part)
                check_vtens_part(system, part)
Exemplo n.º 2
0
def test_vlist_dihedral_cos_mil53():
    system = get_system_mil53()
    part = ForcePartValence(system)
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0 == i2: continue
            for i3 in system.neighs1[i2]:
                if i3 == i1: continue
                fc = 2.1 + 0.01 * (0.3 * i1 + 0.7 * i2)
                part.add_term(
                    PolyFour([0.0, -2.0 * fc, 0.0, 0.0],
                             DihedCos(i0, i1, i2, i3)))
    energy = part.compute()
    check_energy = 0.0
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0 == i2: continue
            for i3 in system.neighs1[i2]:
                if i3 == i1: continue
                fc = 2.1 + 0.01 * (0.3 * i1 + 0.7 * i2)
                delta0 = system.pos[i0] - system.pos[i1]
                delta1 = system.pos[i2] - system.pos[i1]
                delta2 = system.pos[i3] - system.pos[i2]
                system.cell.mic(delta0)
                system.cell.mic(delta1)
                system.cell.mic(delta2)
                cos = dihed_cos(
                    [delta0,
                     np.zeros(3, float), delta1, delta1 + delta2])[0]
                check_energy += -2.0 * fc * cos**2
    if not abs(energy - check_energy) < 1e-8:
        raise AssertionError("Energy should be %10.9e, instead it is %10.9e" %
                             (check_energy, energy))
Exemplo n.º 3
0
def test_gpos_vtens_dihedral_cos_mil53():
    system = get_system_mil53()
    forbidden_dihedrals = [
        ["O_HY","AL","O_HY","AL"],
        ["O_HY","AL","O_HY","H_HY"],
        ["O_CA","AL","O_CA","C_CA"],
        ["O_CA","AL","O_HY","H_HY"],
        ["H_PH","C_PH","C_PC","C_PH"],
        ["H_PH","C_PH","C_PC","C_CA"],
        ["C_PH","C_PH","C_PC","C_PH"],
        ["C_PH","C_PH","C_PC","C_CA"],
        ["C_PC","C_PH","C_PH","H_PH"],
        ["C_PC","C_PH","C_PH","C_PC"],
        ["H_PH","C_PH","C_PH","H_PH"],
        ["C_PH","C_PC","C_CA","O_CA"],
    ]
    idih = -1
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0==i2: continue
            for i3 in system.neighs1[i2]:
                if i3==i1: continue
                types = [system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2), system.get_ffatype(i3)]
                if types in forbidden_dihedrals or types[::-1] in forbidden_dihedrals: continue
                idih += 1
                fc = 2.1 + 0.01*(0.3*i1 + 0.7*i2)
                part = ForcePartValence(system)
                part.add_term(PolyFour([-2.0*fc,0.0001,0.0,0.0],DihedCos(i0,i1,i2,i3)))
                check_gpos_part(system, part)
                check_vtens_part(system, part)
Exemplo n.º 4
0
def test_vlist_dihedral_cos_mil53():
    system = get_system_mil53()
    part = ForcePartValence(system)
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0==i2: continue
            for i3 in system.neighs1[i2]:
                if i3==i1: continue
                fc = 2.1 + 0.01*(0.3*i1 + 0.7*i2)
                part.add_term(PolyFour([0.0,-2.0*fc,0.0,0.0],DihedCos(i0,i1,i2,i3)))
    energy = part.compute()
    check_energy = 0.0
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0==i2: continue
            for i3 in system.neighs1[i2]:
                if i3==i1: continue
                fc = 2.1 + 0.01*(0.3*i1 + 0.7*i2)
                delta0 = system.pos[i0] - system.pos[i1]
                delta1 = system.pos[i2] - system.pos[i1]
                delta2 = system.pos[i3] - system.pos[i2]
                system.cell.mic(delta0)
                system.cell.mic(delta1)
                system.cell.mic(delta2)
                cos = dihed_cos([delta0, np.zeros(3, float), delta1, delta1+delta2])[0]
                check_energy += -2.0*fc*cos**2
    if not abs(energy - check_energy) < 1e-8:
        raise AssertionError("Energy should be %10.9e, instead it is %10.9e" %(check_energy, energy))
Exemplo n.º 5
0
def test_scaling_mil53():
    system = get_system_mil53()
    try:
        scalings = Scalings(system)
        success = False
    except AssertionError:
        success = True
    assert success
Exemplo n.º 6
0
def test_scaling_mil53():
    system = get_system_mil53()
    try:
        scalings = Scalings(system)
        success = False
    except AssertionError:
        success = True
    assert success
Exemplo n.º 7
0
def test_iclist_grad_dihedral_cos_mil53():
    system = get_system_mil53()
    forbidden_dihedrals = [
        ["O_HY","AL","O_HY","AL"],
        ["O_HY","AL","O_HY","H_HY"],
        ["O_CA","AL","O_CA","C_CA"],
    ]
    idih = -1
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0==i2: continue
            for i3 in system.neighs1[i2]:
                if i3==i1: continue
                types = [system.get_ffatype(i0), system.get_ffatype(i1), system.get_ffatype(i2), system.get_ffatype(i3)]
                if types in forbidden_dihedrals or types[::-1] in forbidden_dihedrals: continue
                idih += 1
                dlist = DeltaList(system)
                iclist = InternalCoordinateList(dlist)
                iclist.add_ic(DihedCos(i0,i1,i2,i3))

                ic = iclist.ictab[0]
                dlist.forward()
                iclist.forward()
                ic['grad'] = 1.0
                iclist.back()
                cos = ic['value']
                grad_d0 = np.array([dlist.deltas[ic['i0']]['gx'], dlist.deltas[ic['i0']]['gy'], dlist.deltas[ic['i0']]['gz']])
                grad_d1 = np.array([dlist.deltas[ic['i1']]['gx'], dlist.deltas[ic['i1']]['gy'], dlist.deltas[ic['i1']]['gz']])
                grad_d2 = np.array([dlist.deltas[ic['i2']]['gx'], dlist.deltas[ic['i2']]['gy'], dlist.deltas[ic['i2']]['gz']])

                delta0 = system.pos[i0] - system.pos[i1]
                delta1 = system.pos[i2] - system.pos[i1]
                delta2 = system.pos[i3] - system.pos[i2]
                system.cell.mic(delta0)
                system.cell.mic(delta1)
                system.cell.mic(delta2)

                check_cos, check_grad = dihed_cos([delta0, np.zeros(3, float), delta1, delta1+delta2],deriv=1)
                check_grad_d0 = check_grad[0,:]
                check_grad_d1 = -check_grad[0,:] - check_grad[1,:]
                check_grad_d2 = check_grad[3,:]

                if not abs(ic['value'] - check_cos) < 1e-8:
                    raise AssertionError("Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have value %10.9e, instead it is %10.9e" %(
                        system.get_ffatype(i0),i0,
                        system.get_ffatype(i1),i1,
                        system.get_ffatype(i2),i2,
                        system.get_ffatype(i3),i3,
                        check_cos,
                        cos
                    ))
                if not np.sqrt(sum( (grad_d0 - check_grad_d0)**2 )) < 1e-8:
                    raise AssertionError("Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have delta0_grad [%12.9f,%12.9f,%12.9f], \n"
                                         "instead it is [%12.9f,%12.9f,%12.9f]" %(
                                            system.get_ffatype(i0),i0,
                                            system.get_ffatype(i1),i1,
                                            system.get_ffatype(i2),i2,
                                            system.get_ffatype(i3),i3,
                                            check_grad_d0[0], check_grad_d0[1], check_grad_d0[2],
                                            grad_d0[0], grad_d0[1], grad_d0[2],
                    ))
                if not np.sqrt(sum( (grad_d1 - check_grad_d1)**2 )) < 1e-8:
                    raise AssertionError("Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have delta1_grad [%12.9f,%12.9f,%12.9f], \n"
                                         "instead it is [%12.9f,%12.9f,%12.9f]" %(
                                            system.get_ffatype(i0),i0,
                                            system.get_ffatype(i1),i1,
                                            system.get_ffatype(i2),i2,
                                            system.get_ffatype(i3),i3,
                                            check_grad_d1[0], check_grad_d1[1], check_grad_d1[2],
                                            grad_d1[0], grad_d1[1], grad_d1[2],
                    ))
                if not np.sqrt(sum( (grad_d2 - check_grad_d2)**2 )) < 1e-8:
                    raise AssertionError("Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have delta2_grad [%12.9f,%12.9f,%12.9f], \n"
                                         "instead it is [%12.9f,%12.9f,%12.9f]" %(
                                            system.get_ffatype(i0),i0,
                                            system.get_ffatype(i1),i1,
                                            system.get_ffatype(i2),i2,
                                            system.get_ffatype(i3),i3,
                                            check_grad_d2[0], check_grad_d2[1], check_grad_d2[2],
                                            grad_d2[0], grad_d2[1], grad_d2[2],
                    ))
Exemplo n.º 8
0
def test_iclist_grad_dihedral_cos_mil53():
    system = get_system_mil53()
    forbidden_dihedrals = [
        ["O_HY", "AL", "O_HY", "AL"],
        ["O_HY", "AL", "O_HY", "H_HY"],
        ["O_CA", "AL", "O_CA", "C_CA"],
    ]
    idih = -1
    for i1, i2 in system.bonds:
        for i0 in system.neighs1[i1]:
            if i0 == i2: continue
            for i3 in system.neighs1[i2]:
                if i3 == i1: continue
                types = [
                    system.get_ffatype(i0),
                    system.get_ffatype(i1),
                    system.get_ffatype(i2),
                    system.get_ffatype(i3)
                ]
                if types in forbidden_dihedrals or types[::
                                                         -1] in forbidden_dihedrals:
                    continue
                idih += 1
                dlist = DeltaList(system)
                iclist = InternalCoordinateList(dlist)
                iclist.add_ic(DihedCos(i0, i1, i2, i3))

                ic = iclist.ictab[0]
                dlist.forward()
                iclist.forward()
                ic['grad'] = 1.0
                iclist.back()
                cos = ic['value']
                grad_d0 = np.array([
                    dlist.deltas[ic['i0']]['gx'], dlist.deltas[ic['i0']]['gy'],
                    dlist.deltas[ic['i0']]['gz']
                ])
                grad_d1 = np.array([
                    dlist.deltas[ic['i1']]['gx'], dlist.deltas[ic['i1']]['gy'],
                    dlist.deltas[ic['i1']]['gz']
                ])
                grad_d2 = np.array([
                    dlist.deltas[ic['i2']]['gx'], dlist.deltas[ic['i2']]['gy'],
                    dlist.deltas[ic['i2']]['gz']
                ])

                delta0 = system.pos[i0] - system.pos[i1]
                delta1 = system.pos[i2] - system.pos[i1]
                delta2 = system.pos[i3] - system.pos[i2]
                system.cell.mic(delta0)
                system.cell.mic(delta1)
                system.cell.mic(delta2)

                check_cos, check_grad = dihed_cos(
                    [delta0,
                     np.zeros(3, float), delta1, delta1 + delta2],
                    deriv=1)
                check_grad_d0 = check_grad[0, :]
                check_grad_d1 = -check_grad[0, :] - check_grad[1, :]
                check_grad_d2 = check_grad[3, :]

                if not abs(ic['value'] - check_cos) < 1e-8:
                    raise AssertionError(
                        "Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have value %10.9e, instead it is %10.9e"
                        % (system.get_ffatype(i0), i0, system.get_ffatype(i1),
                           i1, system.get_ffatype(i2), i2,
                           system.get_ffatype(i3), i3, check_cos, cos))
                if not np.sqrt(sum((grad_d0 - check_grad_d0)**2)) < 1e-8:
                    raise AssertionError(
                        "Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have delta0_grad [%12.9f,%12.9f,%12.9f], \n"
                        "instead it is [%12.9f,%12.9f,%12.9f]" % (
                            system.get_ffatype(i0),
                            i0,
                            system.get_ffatype(i1),
                            i1,
                            system.get_ffatype(i2),
                            i2,
                            system.get_ffatype(i3),
                            i3,
                            check_grad_d0[0],
                            check_grad_d0[1],
                            check_grad_d0[2],
                            grad_d0[0],
                            grad_d0[1],
                            grad_d0[2],
                        ))
                if not np.sqrt(sum((grad_d1 - check_grad_d1)**2)) < 1e-8:
                    raise AssertionError(
                        "Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have delta1_grad [%12.9f,%12.9f,%12.9f], \n"
                        "instead it is [%12.9f,%12.9f,%12.9f]" % (
                            system.get_ffatype(i0),
                            i0,
                            system.get_ffatype(i1),
                            i1,
                            system.get_ffatype(i2),
                            i2,
                            system.get_ffatype(i3),
                            i3,
                            check_grad_d1[0],
                            check_grad_d1[1],
                            check_grad_d1[2],
                            grad_d1[0],
                            grad_d1[1],
                            grad_d1[2],
                        ))
                if not np.sqrt(sum((grad_d2 - check_grad_d2)**2)) < 1e-8:
                    raise AssertionError(
                        "Dihed cos (%s[%i],%s[%i],%s[%i],%s[%i]) should have delta2_grad [%12.9f,%12.9f,%12.9f], \n"
                        "instead it is [%12.9f,%12.9f,%12.9f]" % (
                            system.get_ffatype(i0),
                            i0,
                            system.get_ffatype(i1),
                            i1,
                            system.get_ffatype(i2),
                            i2,
                            system.get_ffatype(i3),
                            i3,
                            check_grad_d2[0],
                            check_grad_d2[1],
                            check_grad_d2[2],
                            grad_d2[0],
                            grad_d2[1],
                            grad_d2[2],
                        ))
Exemplo n.º 9
0
def test_iclist_mil53_dihedral_angles():
    system = get_system_mil53()
    dlist = DeltaList(system)
    iclist = InternalCoordinateList(dlist)
    ic_values = []
    gpos = np.zeros(system.pos.shape)
    forbidden_dihedrals = [
        ["O_HY", "AL", "O_HY", "AL"],
        ["O_HY", "AL", "O_HY", "H_HY"],
        ["O_CA", "AL", "O_CA", "C_CA"],
    ]
    for i1, i2 in system.bonds:
        # Add bonds here to avoid that all ic signs are +1
        iclist.add_ic(Bond(i2, i1))
        for i0 in system.neighs1[i1]:
            if i0 == i2: continue
            for i3 in system.neighs1[i2]:
                if i3 == i1: continue
                # Compute using molmod
                delta0 = system.pos[i0] - system.pos[i1]
                delta1 = system.pos[i2] - system.pos[i1]
                delta2 = system.pos[i3] - system.pos[i2]
                system.cell.mic(delta0)
                system.cell.mic(delta1)
                system.cell.mic(delta2)
                pos = np.zeros((4, 3))
                pos[0] = system.pos[i1] + delta0
                pos[1] = system.pos[i1]
                pos[2] = system.pos[i1] + delta1
                pos[3] = pos[2] + delta2
                phi0, dphi0 = dihed_angle(pos, deriv=1)
                # Compute value using yaff
                iic = iclist.add_ic(DihedAngle(i0, i1, i2, i3))
                ic = iclist.ictab[iic]
                dlist.forward()
                iclist.forward()
                phi1 = ic['value']
                if np.abs(phi1 - phi0) > 1e-8:
                    raise AssertionError(
                        "DihedralAngle(%d,%d,%d,%d): molmod "
                        "value = %12.8f yaff value = %12.8f diff = %12.2e" %
                        (i0, i1, i2, i3, phi0, phi1, phi0 - phi1))
                # Compute derivative using yaff
                gpos[:] = 0.0
                ic['grad'] = 1.0
                iclist.back()
                dlist.back(gpos, None)
                # Derivative of DihedCos fails in these cases, and DihedAngle
                # derivatives are base on this
                types = [
                    system.get_ffatype(i0),
                    system.get_ffatype(i1),
                    system.get_ffatype(i2),
                    system.get_ffatype(i3)
                ]
                if types in forbidden_dihedrals or types[::
                                                         -1] in forbidden_dihedrals:
                    continue
                ddiff = gpos[[i0, i1, i2, i3]] - dphi0
                if np.any(np.abs(ddiff) > 1e-6):
                    raise AssertionError(
                        "DihedralAngle(%d,%d,%d,%d): largest "
                        "absolute derivative deviation =  %12.2e" %
                        (i0, i1, i2, i3, np.amax(np.abs(ddiff))))
Exemplo n.º 10
0
def test_scaling_mil53():
    system = get_system_mil53()
    with assert_raises(AssertionError):
        scalings = Scalings(system)
Exemplo n.º 11
0
def test_scaling_mil53():
    system = get_system_mil53()
    with assert_raises(AssertionError):
        scalings = Scalings(system)