Exemplo n.º 1
0
    def read_xyz(self,modelfile):
        with open(modelfile) as f:
            content = f.readlines()

        self.comment = content.pop(0) # Comment line
        if('-1' in content[-1] and '.' not in content[-1]): # '-1' line
            content.pop(-1)
        self.lx,self.ly,self.lz = tuple([float(x) for x in content.pop(0).strip().split()])

        self.natoms = len(content)
        content = [x.strip().split() for x in content]
        for i in range(0,len(content)):
            for j in range(0,len(content[i])):
                try:
                    content[i][j] = int(content[i][j])
                except:
                    try:
                        content[i][j] = float(content[i][j])
                    except:
                        pass
        self.atoms = []
        for i,atom in enumerate(content):
            self.atoms.append(Atom(i,atom[0],atom[1],atom[2],atom[3]))
            if type(self.atoms[i].z) == type('hi'):
                self.atoms[i].z = znum2sym.sym2z(self.atoms[i].z)
Exemplo n.º 2
0
 def __init__(self, id, znum, x, y, z):
     self.id = id
     if(isinstance(znum,int)):
         self.z = znum
     elif(isinstance(znum,str)):
         self.z = znum2sym.sym2z(znum)
     self.coord = (x,y,z)
     self.vp = VoronoiPoly()
     self.neighs = None # Neighbors. List when set
     self.cn = None # Coordination number. int when set
     self.sym = znum2sym.z2sym(self.z) #atomic symbol
Exemplo n.º 3
0
 def generate_coord_numbers(self):
     """ atom.neighs must be defined first for all atoms """
     self.coord_numbers = {}
     # Form will be:
     #   {'Cu-Al': 4.5}, etc.
     for typea in self.atomtypes:
         self.coord_numbers[znum2sym.z2sym(typea)] = 0
         for typeb in self.atomtypes:
             self.coord_numbers[znum2sym.z2sym(typea)+'-'+znum2sym.z2sym(typeb)] = 0
     for atom in self.atoms:
         for n in atom.neighs:
             self.coord_numbers[znum2sym.z2sym(atom.z)] += 1
             self.coord_numbers[znum2sym.z2sym(atom.z)+'-'+znum2sym.z2sym(n.z)] += 1
     self.bonds = self.coord_numbers.copy()
     for key in self.coord_numbers:
         elem = znum2sym.sym2z(key.split('-')[0])
         self.coord_numbers[key] /= float(self.atomtypes[elem])
Exemplo n.º 4
0
 def generate_average_coord_numbers(self):
     """ atom.neighs must be defined first for all atoms
         Form will be:
             {'Cu-Al': 4.5, ... }
     """
     coord_numbers = {}
     for typea in self.atomtypes:
         coord_numbers[znum2sym.z2sym(typea)] = 0
         for typeb in self.atomtypes:
             coord_numbers[znum2sym.z2sym(typea)+'-'+znum2sym.z2sym(typeb)] = 0
     for atom in self.atoms:
         for n in atom.neighs:
             coord_numbers[znum2sym.z2sym(atom.z)] += 1
             coord_numbers[znum2sym.z2sym(atom.z)+'-'+znum2sym.z2sym(n.z)] += 1
     for key in coord_numbers:
         elem = znum2sym.sym2z(key.split('-')[0])
         coord_numbers[key] /= float(self.atomtypes[elem])
     return coord_numbers
Exemplo n.º 5
0
def generate_cutoffs(m):
    outcontent = []

    cutoff_types = []
    types = list(m.atomtypes)
    types.sort()
    for L in range(1, len(types)):
        # for L in range(1,len(types)+1):
        for subset in itertools.combinations(types, L):
            # print(subset)
            s = list(subset)
            xx, g = gr(m, types=s)
            g = list(g)
            s = [znum2sym.z2sym(y) for y in s]
            # g.insert(0,'gr_{0}'.format('_'.join(s)))
            outcontent.append(g)
            cutoff_types.append(s)
    cutoff_types = [[x[0], x[0]] if len(x) == 1 else x for x in cutoff_types]
    cutoff_types = [[znum2sym.sym2z(y) for y in x] for x in cutoff_types]
    cutoff_types = [[types.index(y) for y in x] for x in cutoff_types]
    # print(cutoff_types)

    cutoffs = np.zeros((len(m.atomtypes), len(m.atomtypes)))

    xx = list(xx)
    # xx.insert(0,'dr')
    outcontent.insert(0, xx)
    for i, arr in enumerate(outcontent[1:]):
        peak1 = arr.index(max(arr))
        # print('peak1',peak1,xx[peak1],arr[peak1])
        # print(arr[peak1:int(round(peak1*3.5))])
        min1 = peak1 + arr[peak1 : int(round(peak1 * 3.5))].index(min(arr[peak1 : int(round(peak1 * 3.5))]))
        # print('min1',min1,xx[min1],arr[min1])
        peak2 = min1 + arr[min1:].index(max(arr[min1:]))
        # print('peak2',peak2,xx[peak2],arr[peak2])
        # print('')
        cutoffs[cutoff_types[i][0]][cutoff_types[i][1]] = xx[min1]
        cutoffs[cutoff_types[i][1]][cutoff_types[i][0]] = xx[min1]
    # print(cutoffs)
    return cutoffs