コード例 #1
0
ファイル: dmagmin.py プロジェクト: wwwtyro/PyGMIN
 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")
コード例 #2
0
ファイル: dmagmin.py プロジェクト: wwwtyro/PyGMIN
    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