Ejemplo n.º 1
0
def uniform_displace(stepsize, coords, indices=None):
    '''uniform random displacement
    
    Parameters
    ----------
    coords : array like x(:,3)
       coordinates
    indices : list, optional
       list of coordinates to displace, None for all coordinates in array
    '''
    if(indices):
        for i in indices:
            coords[i] += np.random.random()*stepsize*rotations.vec_random()
        return
    
    for x in coords:
        x += stepsize*rotations.vec_random()
Ejemplo n.º 2
0
def reduced_coordinates_displace(stepsize, lattice_matrix, coords, indices=None):
    '''uniform random displacement of reduced coordinates
    
    Parameters
    ----------
    coords : array like x(:,3)
       coordinates
    indices : list, optional
       list of coordinates to displace, None for all coordinates in array
    
    '''
    ilattice = vec3.invert3x3(lattice_matrix) # inverse_lattice
    if(indices):
        for i in indices:
            coords[i] += np.dot(ilattice, stepsize*rotations.vec_random())
        return
            
    for x in coords:
        x += np.dot(ilattice, stepsize*rotations.vec_random())
Ejemplo n.º 3
0
 def takeStep(self, coords, **kwargs):
     # easy access to coordinates
     ca = CoordsAdapter(nrigid=coords.size/6, coords = coords)
     
     backbone = np.zeros(3)
     
     # random rotation for angle-axis vectors
     for pos, rot in zip(ca.posRigid, ca.rotRigid):
         backbone = backbone + rotations.vec_random( )*0.7525            
         
         # choose a random rotation
         rot[:] = rotations.random_aa()
         
         # calcualte center of base from backgone
         a1 = np.dot(rotations.aa2mx(rot), np.array([1., 0., 0.]))
         pos[:]  = backbone + 0.4 * a1                        
Ejemplo n.º 4
0
    def __init__(self, dim=[4, 4], field_disorder=1.):
        """
        dim is an array giving the dimensions of the lattice
        
        phi is the magnitude of the randomness in the fields
        """
        self.dim = copy(dim)
        self.nspins = np.prod(dim)

        self.G = nx.grid_graph(dim, periodic=True)

        self.fields = np.zeros([self.nspins, 3])

        self.indices = dict()
        i = 0
        for node in self.G.nodes():
            self.indices[node] = i
            self.fields[i,:] = rotations.vec_random() * \
                field_disorder#np.random.uniform(0, field_disorder, [3])
            i += 1
Ejemplo n.º 5
0
 def __init__(self, dim = [4, 4], field_disorder = 1.):
     """
     dim is an array giving the dimensions of the lattice
     
     phi is the magnitude of the randomness in the fields
     """
     self.dim = copy(dim)
     self.nspins = np.prod(dim)
     
     self.G = nx.grid_graph(dim, periodic=True)
     
     self.fields = np.zeros([self.nspins, 3])
             
     self.indices = dict()
     i = 0
     for node in self.G.nodes():
         self.indices[node] = i
         self.fields[i,:] = rotations.vec_random() * \
             np.sqrt(field_disorder) #np.random.uniform(0, field_disorder, [3])
         i += 1 
Ejemplo n.º 6
0
    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] ) )


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])
#print np.shape(coords)
coordsinit = np.copy(coords)

#print "fields", pot.fields
print coords

e = pot.getEnergy(coords)
print "energy ", e

print "try a quench"
from pygmin.optimize import mylbfgs

ret = mylbfgs(coords, pot)
Ejemplo n.º 7
0
        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] ) )




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])
#print np.shape(coords)
coordsinit = np.copy(coords)

#print "fields", pot.fields
print coords


e = pot.getEnergy(coords)
print "energy ", e

print "try a quench"
from pygmin.optimize import mylbfgs
ret = mylbfgs(coords, pot)
Ejemplo n.º 8
0
def test():
    pi = np.pi
    L = 8
    nspins = L**2

    #phases = np.zeros(nspins)
    pot = HeisenbergModel(dim=[L, L], field_disorder=1.)  #, 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 False:
        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 pygmin.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)
Ejemplo n.º 9
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 pygmin.optimize.quench import mylbfgs
    ret = mylbfgs(coords, pot.getEnergyGradient)
    
    print "quenched e = ", ret[1], "funcalls", ret[3]
    print ret[0]
    with open("out.spins", "w") as fout:
        s = coords2ToCoords3( ret[0] )
        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[0] )
    m = np.linalg.norm( coords3.sum(0) ) / nspins
    print "magnetization after quench", m
    
    test_basin_hopping(pot, coords)
Ejemplo n.º 10
0
 def takeStep(self, coords, **kwargs):
     c = coords[self.srange]        
     for x in c.reshape(c.size/3,3):
         x += self.stepsize*rotations.vec_random()