コード例 #1
0
ファイル: 2dRAHM.py プロジェクト: borislavujo/pele
def printspins(fout, pot, coords2):
    s = coords2ToCoords3( coords2 )
    h = pot.fields
    c = coords2ToCoords3( coordsinit )
    for node in pot.G.nodes():
        i = pot.indices[node]
        fout.write( "%g %g %g %g %g %g %g %g\n" % (node[0], node[1], \
            s[i,0], s[i,1], s[i,2], h[i,0], h[i,1], h[i,2] ) )
コード例 #2
0
def interpolate_spins(initial, final, t, i3=None, f3=None):
    if i3 is None:
        i3 = hs.coords2ToCoords3(initial)
    if f3 is None:
        f3 = hs.coords2ToCoords3(final)
    nspins = old_div(i3.size, 3)
    i3 = i3.reshape([-1,3])
    f3 = f3.reshape([-1,3])
    xnew = np.zeros(i3.shape)
    for i in range(nspins):
        xnew[i,:] = interpolate_spin(i3[i,:], f3[i,:], t)
    return hs.coords3ToCoords2(xnew.reshape(-1)).reshape(-1)
コード例 #3
0
def interpolate_spins(initial, final, t, i3=None, f3=None):
    if i3 is None:
        i3 = hs.coords2ToCoords3(initial)
    if f3 is None:
        f3 = hs.coords2ToCoords3(final)
    nspins = i3.size / 3
    i3 = i3.reshape([-1,3])
    f3 = f3.reshape([-1,3])
    xnew = np.zeros(i3.shape)
    for i in xrange(nspins):
        xnew[i,:] = interpolate_spin(i3[i,:], f3[i,:], t)
    return hs.coords3ToCoords2(xnew.reshape(-1)).reshape(-1)
コード例 #4
0
def spin3d_mindist_norot(xa, xb):
    """
    would be better to use the spherical law of cosines to compute
    the angle between the vectors
    http://en.wikipedia.org/wiki/Great-circle_distance
    """
    sa = hs.coords2ToCoords3(xa).reshape([-1,3])
    sb = hs.coords2ToCoords3(xb).reshape([-1,3])
    # get an array of the dot product between the spins
    dots = np.sum(sa * sb, axis=1)
    angles = np.arccos(dots)
    dist = old_div(angles.sum(), np.pi)
#    dist = np.linalg.norm(sb - sa)
    return dist, xa, xb
コード例 #5
0
def spin3d_mindist_norot(xa, xb):
    """
    would be better to use the spherical law of cosines to compute
    the angle between the vectors
    http://en.wikipedia.org/wiki/Great-circle_distance
    """
    sa = hs.coords2ToCoords3(xa).reshape([-1,3])
    sb = hs.coords2ToCoords3(xb).reshape([-1,3])
    # get an array of the dot product between the spins
    dots = np.sum(sa * sb, axis=1)
    angles = np.arccos(dots)
    dist = angles.sum() / np.pi
#    dist = np.linalg.norm(sb - sa)
    return dist, xa, xb
コード例 #6
0
    def getEnergyGradient(self, coords):
        """
        coords is a list of (theta, phi) spherical coordinates of the spins
        where phi is the azimuthal angle (angle to the z axis) 
        """
        coords3 = coords2ToCoords3(coords)
        coords2 = coords

        E = 0.
        grad3 = np.zeros([self.nspins, 3])
        for edge in self.G.edges():
            u = self.indices[edge[0]]
            v = self.indices[edge[1]]
            E -= np.dot(coords3[u, :], coords3[v, :])

            grad3[u, :] -= coords3[v, :]
            grad3[v, :] -= coords3[u, :]

        vdotf = np.sum(self.fields * coords3, axis=1)
        Efields = -np.sum(np.sum(self.fields * coords3, axis=1)**2)

        grad3 -= 2. * self.fields * vdotf[:, np.newaxis]

        grad2 = grad3ToGrad2(coords2, grad3)
        grad2 = np.reshape(grad2, self.nspins * 2)

        return E + Efields, grad2
コード例 #7
0
    def getEnergyGradient(self, coords):
        """
        coords is a list of (theta, phi) spherical coordinates of the spins
        where phi is the azimuthal angle (angle to the z axis) 
        """
        coords3 = coords2ToCoords3(coords)
        coords2 = coords

        E = 0.
        grad3 = np.zeros([self.nspins, 3])
        for edge in self.G.edges():
            u = self.indices[edge[0]]
            v = self.indices[edge[1]]
            E -= np.dot(coords3[u, :], coords3[v, :])

            grad3[u, :] -= coords3[v, :]
            grad3[v, :] -= coords3[u, :]

        vdotf = np.sum(self.fields * coords3, axis=1)
        Efields = - np.sum(np.sum(self.fields * coords3, axis=1) ** 2)

        grad3 -= 2. * self.fields * vdotf[:, np.newaxis]

        grad2 = grad3ToGrad2(coords2, grad3)
        grad2 = np.reshape(grad2, self.nspins * 2)

        return E + Efields, grad2
コード例 #8
0
ファイル: 2dRAHM.py プロジェクト: yangxi1209/pele
def printspins(fout, pot, coords2):
    s = coords2ToCoords3(coords2)
    h = pot.fields
    for node in pot.G.nodes():
        i = pot.indices[node]
        fout.write("%g %g %g %g %g %g %g %g\n" %
                   (node[0], node[1], s[i, 0], s[i, 1], s[i, 2], h[i, 0],
                    h[i, 1], h[i, 2]))
コード例 #9
0
    def getEnergy(self, coords):
        """
        coords is a list of (theta, phi) spherical coordinates of the spins
        where phi is the azimuthal angle (angle to the z axis) 
        """
        coords3 = coords2ToCoords3(coords)

        E = 0.
        for edge in self.G.edges():
            u = self.indices[edge[0]]
            v = self.indices[edge[1]]
            E -= np.dot(coords3[u, :], coords3[v, :])

        Efields = -np.sum(np.sum(self.fields * coords3, axis=1)**2)

        return E + Efields
コード例 #10
0
    def getEnergy(self, coords):
        """
        coords is a list of (theta, phi) spherical coordinates of the spins
        where phi is the azimuthal angle (angle to the z axis) 
        """
        coords3 = coords2ToCoords3(coords)

        E = 0.
        for edge in self.G.edges():
            u = self.indices[edge[0]]
            v = self.indices[edge[1]]
            E -= np.dot(coords3[u, :], coords3[v, :])

        Efields = - np.sum(np.sum(self.fields * coords3, axis=1) ** 2)

        return E + Efields
コード例 #11
0
ファイル: 2dRAHM.py プロジェクト: Mahdisadjadi/pele
def getm(coords2):
    coords3 = coords2ToCoords3(coords2)
    m = np.linalg.norm(coords3.sum(0)) / nspins
    return m
コード例 #12
0
def test():
    pi = np.pi
    L = 4
    nspins = L**2
    
    #phases = np.zeros(nspins)
    pot = HeisenbergModelRA( dim = [L,L], field_disorder = 2. ) #, phases=phases)
    
    coords = np.zeros([nspins, 2])
    for i in range(nspins): 
        vec = rotations.vec_random()
        coords[i,:] = make2dVector(vec)
    coords = np.reshape(coords, [nspins*2])
    if False:
        normfields = np.copy(pot.fields)
        for i in range(nspins): normfields[i,:] /= np.linalg.norm(normfields[i,:])
        coords = coords3ToCoords2( np.reshape(normfields, [nspins*3] ) )
        coords  = np.reshape(coords, nspins*2)
    #print np.shape(coords)
    coordsinit = np.copy(coords)
    
    #print "fields", pot.fields
    print coords
    
    if False:
        coords3 = coords2ToCoords3(coords)
        coords2 = coords3ToCoords2(coords3)
        print np.reshape(coords, [nspins,2])
        print coords2
        coords3new = coords2ToCoords3(coords2)
        print coords3
        print coords3new

    e = pot.getEnergy(coords)
    print "energy ", e
    if True:
        print "numerical gradient"
        ret = pot.getEnergyGradientNumerical(coords)
        print ret[1]
        if True:
            print "analytical gradient"
            ret2 = pot.getEnergyGradient(coords)
            print ret2[1]
            print ret[0]
            print ret2[0]
            #print "ratio"
            #print ret2[1] / ret[1]
            #print "inverse sin"
            #print 1./sin(coords)
            #print cos(coords)
    
    print "try a quench"
    from pele.optimize import mylbfgs
    ret = mylbfgs(coords, pot)
    
    print "quenched e = ", ret.energy, "funcalls", ret.nfev
    print ret.coords
    with open("out.spins", "w") as fout:
        s = coords2ToCoords3( ret.coords )
        h = pot.fields
        c = coords2ToCoords3( coordsinit )
        for node in pot.G.nodes():
            i = pot.indices[node]
            fout.write( "%g %g %g %g %g %g %g %g %g %g %g\n" % (node[0], node[1], \
                s[i,0], s[i,1], s[i,2], h[i,0], h[i,1], h[i,2], c[i,0], c[i,1], c[i,2] ) )
    
    coords3 = coords2ToCoords3( ret.coords )
    m = np.linalg.norm( coords3.sum(0) ) / nspins
    print "magnetization after quench", m
    
    test_basin_hopping(pot, coords)
コード例 #13
0
ファイル: 2dRAHM.py プロジェクト: yangxi1209/pele
def getm(coords2):
    coords3 = coords2ToCoords3(coords2)
    m = np.linalg.norm(coords3.sum(0)) / nspins
    return m
コード例 #14
0
ファイル: 2dRAHM.py プロジェクト: spraharsh/pele
def getm(coords2):
    coords3 = coords2ToCoords3(coords2)
    m = old_div(np.linalg.norm(coords3.sum(0)), nspins)
    return m