Beispiel #1
0
def tst():
    M = 10
    xy = []
    for ii in range(M):
        r = 10.0
        phi = ii * (math.pi * 2 / M)
        x = r * math.cos(phi)
        y = r * math.sin(phi)
        xy.append(flex.double([x, y]))
    # build distance matrix
    dmat = []
    for ii in range(M):
        tmp = []
        for jj in range(M):

            x1 = xy[ii][0]
            x2 = xy[jj][0]

            y1 = xy[ii][1]
            y2 = xy[jj][1]

            dd = math.sqrt((x1 - x2)**2.0 + (y1 - y2)**2.0)
            if jj != ii:
                tmp.append((jj, dd))
        dmat.append(tmp)
    spee = classic_spe_engine(dmat, l=1.0, max_cycle=5000)
    x, s = spee.embed(2, M)
    assert s < 1e-4
    print("OK")
Beispiel #2
0
def tst_dmatrix():
    # expected values are the d_jmn at beta=1.0 and j=2, m=-2, -2<=n<=2
    expect = [0.593133, 0.64806, 0.433605, 0.193411, 0.0528305]
    eps = 1e-4
    d2 = dmatrix(2, 1.0)  # dmatrix( max_L, beta )
    for n in range(-2, 3):
        assert abs(expect[n + 2] - d2.djmn(2, -2, n)) < eps

    d4 = dmatrix(4, 1.0)
    for n in range(-2, 3):
        assert abs(expect[n + 2] - d4.djmn(2, -2, n)) < eps

    d7 = dmatrix(2, 1.0)
    for n in range(-2, 3):
        assert abs(expect[n + 2] - d7.djmn(2, -2, n)) < eps

    # check agains d(2,2,1) = -(1+cos(beta))*sin(beta)/2.0
    for ii in range(10):
        expt = -(1.0 + math.cos(ii)) * math.sin(ii) / 2.0
        assert abs(dmatrix(2, ii).djmn(2, 2, 1) - expt) < eps
    # check beta= multiple of pi/2

    assert abs(dmatrix(20, math.pi).djmn(2, 2, 0)) < eps
    assert abs(dmatrix(2, math.pi * 2).djmn(2, 2, 0)) < eps
    assert abs(
        dmatrix(20, math.pi * 0.5).djmn(2, 2, 0) - math.sqrt(6.0) / 4.0) < eps
Beispiel #3
0
def rosca(m=9, hemisphere=True):
    """
  Regular grid on the unit sphere, Rosca (2010).
  """
    def truncate(x):
        if (abs(x) < 1.e-6): return 0
        else: return x

    def add(result, new):
        foud = False
        for s in result:
            d = math.sqrt((s[0] - new[0])**2 + (s[1] - new[1])**2 +
                          (s[2] - new[2])**2)
            if (d < 1.e-3): return
        result.append(new)
        return

    d_l = math.sqrt(2) / m
    result = flex.vec3_double()
    for m_ in xrange(m + 1):
        if (m_ == 0):
            add(result, [0, 0, 1])
        else:
            l_m = m_ * d_l
            d_phi = math.pi / (4 * m_)
            assert l_m >= 0 and l_m <= math.sqrt(2)
            for k in xrange(m_ + 1):
                arg1 = k * d_phi
                arg2 = l_m * math.sqrt(1 - l_m**2 / 4)
                x_km = truncate(math.cos(arg1) * arg2)
                y_km = truncate(math.sin(arg1) * arg2)
                z_m = truncate(1. - l_m**2 / 2)
                add(result, [x_km, y_km, z_m])
                add(result, [y_km, x_km, z_m])
                add(result, [-y_km, x_km, z_m])
                add(result, [-x_km, y_km, z_m])
                add(result, [x_km, -y_km, z_m])
                add(result, [y_km, -x_km, z_m])
                add(result, [-x_km, -y_km, z_m])
                add(result, [-y_km, -x_km, z_m])
                if (not hemisphere):
                    add(result, [x_km, y_km, -z_m])
                    add(result, [y_km, x_km, -z_m])
                    add(result, [-y_km, x_km, -z_m])
                    add(result, [-x_km, y_km, -z_m])
                    add(result, [x_km, -y_km, -z_m])
                    add(result, [y_km, -x_km, -z_m])
                    add(result, [-x_km, -y_km, -z_m])
                    add(result, [-y_km, -x_km, -z_m])
    for r in result:
        assert abs(1. - math.sqrt(r[0]**2 + r[1]**2 + r[2]**2)) < 1.e-6
    # XXX for debugging
    if (0):
        f = "HETATM%5d  O   HOH A%4d    %8.3f%8.3f%8.3f  1.00 23.99           O "
        o = open("junk.pdb", "w")
        for i, r in enumerate(result):
            print >> o, f % (i, i, r[0], r[1], r[2])
        o.close()
    return result