Ejemplo n.º 1
0
    def takeStep(self, coords, **kwargs):
        from pygmin.takestep import buildingblocks as bb
        
        ca = CoordsAdapter(nrigid=GMIN.getNRigidBody(), nlattice=6, coords=coords)
        
        #tmp = np.loadtxt("aligned.dat")
        #coords[-6:]=tmp[-6:]        
        #coords[:]=tmp[:]
        #return        
        conf_ok = False
        if(not self.overlap_cutoff is None):
            safe_coords = coords.copy()
        
        while conf_ok is False:        
            indices=None
            if(self.nmols):
                indices=[]
                indices = [np.random.randint(0,GMIN.getNRigidBody()) for i in xrange(self.nmols)]
            
            if(self.rotate != 0.):
                bb.rotate(self.rotate, ca.rotRigid, indices)
            if(self.translate != 0.):
                bb.uniform_displace(self.translate, ca.rotRigid, indices)
                
            #from pygmin.utils import lattice
            #bb.reduced_coordinates_displace(0.0, lattice.lowerTriangular(ca.lattice), ca.posRigid)
            ca.lattice[:]*=self.expand

            if(self.max_volume):
                vol = lattice.volume(ca.lattice)
                if(vol > self.max_volume):
                    ca.lattice[:]*=(self.max_volume / vol)**(1./3.)
            
            conf_ok = True
            if(self.overlap_cutoff):
                atomistic = np.zeros(3*GMIN.getNAtoms())
                GMIN.toAtomistic(atomistic, coords)                
                overlap =  crystals.has_overlap(atomistic, self.overlap_cutoff)
                if(overlap is True):
                    conf_ok = False
                    coords[:] = safe_coords           
Ejemplo n.º 2
0
 def draw(self, coords_rigid, index):
     from OpenGL import GL,GLUT
     coords=np.zeros([GMIN.getNAtoms(), 3])
     GMIN.toAtomistic(coords.reshape(coords.size), coords_rigid)
     #coords = coords.reshape(GMIN.getNAtoms, 3)
     com=np.mean(coords, axis=0)                  
     if index == 1:
         color = [[0.65, 0.0, 0.0, 1.], [0.35, 0.0, 0.0, 1.]]
     else:
         color = [[0.00, 0.65, 0., 1.], [0.00, 0.35, 0., 1.]]
         
     i=0
     for xx in coords[:-2]:
         GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, color[i%2])
         i+=1
         x = xx-com
         GL.glPushMatrix()            
         GL.glTranslate(x[0],x[1],x[2])
         GLUT.glutSolidSphere(0.5,30,30)
         GL.glPopMatrix()
     
     GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, [0.,0.,1.,1.])
     from pygmin.utils import lattice
     l = lattice.lowerTriangular(coords_rigid[-6:])
     mb = l[:,0] + l[:,1] + l[:,2]
     GL.glPushMatrix()            
     GL.glTranslate(-0.5*mb[0],-0.5*mb[1],-0.5*mb[2])
     
     for i in xrange(3):
         self.drawCylinder([0.,0.,0.], l[:,i])
     for i in xrange(1,3):
         self.drawCylinder(l[:,0], l[:,0] + l[:,i])
     mb = l[:,0] + l[:,1] + l[:,2]
     for i in xrange(0,3):
         self.drawCylinder(mb, mb - l[:,i])
     for i in xrange(1,3):
         self.drawCylinder(mb-l[:,0], mb - l[:,i]-l[:,0])
     self.drawCylinder(l[:,1], l[:,1] + l[:,0])            
     self.drawCylinder(l[:,2], l[:,2] + l[:,0])            
     GL.glPopMatrix()
Ejemplo n.º 3
0
 def takeStep(self, coords, **kwargs):
     ''' takeStep routine to generate random cell '''        
     ca = self.coordsadapter        
     ca.updateCoords(coords)
     
     atomistic = np.zeros(3*GMIN.getNAtoms())
     valid_configuration = False
     for i in xrange(50):
         volumeTarget = self.expand_current*lattice.volume(ca.lattice)
          
         # random box
         ca.lattice[[0,3,5]] = 1.0 + self.expand * np.random.random(3)  
         ca.lattice[[1,2,4]] = self.shear * np.random.random(3)
         
         if(self.volume != None):
             volumeTarget = self.volume[0] + (self.volume[1] - self.volume[0]) * np.random.random()
                     
         vol = lattice.volume(ca.lattice)
         ca.lattice[:] = ca.lattice * (volumeTarget / vol)**(1.0/3.0)
         GMIN.reduceCell(coords)
         
         for i in xrange(50):# first choose random positions and rotations
             for i in xrange(GMIN.getNRigidBody()):
                 ca.posRigid[i] = np.random.random()
                 ca.rotRigid[i] = rotations.random_aa()
     
             if self.overlap is None:
                 return
         
         
             GMIN.toAtomistic(atomistic, coords)
             if not crystals.has_overlap(atomistic, self.overlap):
                 return
                         
         print "Could generate valid configuration for current box, choose new box"
     raise Exception("GenRandomCrystal: failed to generate a non-overlapping configuration")