def read_akr(self,fname='akr0000'): f=open(fname,'r') # 1st: lattice constant self.alc= float(f.readline().split()[0]) # 2nd-4th: cell vectors self.a1= np.array([float(x) for x in f.readline().split()]) self.a2= np.array([float(x) for x in f.readline().split()]) self.a3= np.array([float(x) for x in f.readline().split()]) # 5th: num of atoms buff= f.readline().split()[0] natm= int(buff[0]) nauxd= int(buff[1]) if nauxd < 3: print '[Error] read_akr(): nauxd < 3 !!!' sys.exit() # 9th-: atom positions self.atoms= [] for i in range(natm): data= [float(x) for x in f.readline().split()] ai= Atom() ai.set_sid(data[0]) ai.set_pos(data[1],data[2],data[3]) # if there are less than 3 auxiliary data, there is not velocity ai.set_vel(data[4],data[5],data[6]) self.atoms.append(ai) f.close()
def fccBravaisCell(): s = AtomSystem() #...lattice alc = 1.0 a1 = np.array([1.0, 0.0, 0.0]) a2 = np.array([0.0, 1.0, 0.0]) a3 = np.array([0.0, 0.0, 1.0]) s.set_lattice(alc, a1, a2, a3) #...atom1 atom = Atom() atom.set_pos(0.0, 0.0, 0.0) atom.set_sid(1) s.add_atom(atom) #...atom2 atom = Atom() atom.set_pos(0.5, 0.5, 0.0) atom.set_sid(1) s.add_atom(atom) #...atom3 atom = Atom() atom.set_pos(0.5, 0.0, 0.5) atom.set_sid(1) s.add_atom(atom) #...atom4 atom = Atom() atom.set_pos(0.0, 0.5, 0.5) atom.set_sid(1) s.add_atom(atom) return s
def read_akr(self, fname='akr0000'): f = open(fname, 'r') # 1st: lattice constant self.alc = float(f.readline().split()[0]) # 2nd-4th: cell vectors for i in range(3): data = f.readline().split() self.a1[i] = float(data[0]) self.a2[i] = float(data[1]) self.a3[i] = float(data[2]) # 5th: num of atoms natm = int(f.readline().split()[0]) # 9th-: atom positions self.atoms = [] for i in range(natm): data = [float(x) for x in f.readline().split()] ai = Atom() ai.set_sid(data[0]) ai.set_pos(data[1], data[2], data[3]) ai.set_vel(data[4], data[5], data[6]) self.atoms.append(ai) f.close()
def read_POSCAR(self,fname='POSCAR'): f=open(fname,'r') # 1st: comment self.c1= f.readline() # 2nd: multiplying factor self.alc= float(f.readline().split()[0]) # 3-5: lattice vectors self.a1= np.array([float(x) for x in f.readline().split()]) self.a2= np.array([float(x) for x in f.readline().split()]) self.a3= np.array([float(x) for x in f.readline().split()]) # 6th: num of atoms par species data= f.readline().split() if( data[0].isdigit() ): natm_per_spcs= np.array([int(d) for d in data]) else: # skip one line and read next line data= f.readline().split() natm_per_spcs= np.array([int(d) for d in data]) # 7th: comment (in some cases, 8th line too) self.c7= f.readline() if self.c7[0] in ('s','S'): self.c8= f.readline() # hereafter: atom positions sid= 0 self.atoms=[] for ni in natm_per_spcs: sid += 1 for j in range(ni): line= f.readline().split() data= [ float(line[i]) for i in range(3)] ai= Atom() ai.set_sid(sid) ai.set_pos(data[0],data[1],data[2]) ai.set_auxd(line[3:]) ai.pbc() self.atoms.append(ai) f.close()
sysext = AtomSystem() sysext.set_lattice(sys0.alc, np.multiply(sys0.a1, r1), np.multiply(sys0.a2, r2), np.multiply(sys0.a3, r3)) hext = np.zeros((3, 3)) hext[0] = sysext.a1 * sysext.alc hext[1] = sysext.a2 * sysext.alc hext[2] = sysext.a3 * sysext.alc #...make extended system corresponding to the phonopy definition for ia in range(natm0): ai0 = sys0.atoms[ia] for i3 in range(r3): for i2 in range(r2): for i1 in range(r1): ai = Atom() ai.set_sid(ai0.sid) p1 = (ai0.pos[0] + i1) / r1 p2 = (ai0.pos[1] + i2) / r2 p3 = (ai0.pos[2] + i3) / r3 ai.set_pos(p1, p2, p3) sysext.add_atom(ai) sysext.reset_ids() natme = sysext.num_atoms() print ' sysext.num_atoms()=', natme # for ai in sysext.atoms: # print ai.pos #...loop for all atoms in the extended system fcmat = np.zeros((natme, natme, 3, 3)) for ia in range(natme):
def make_polycrystal(grns,uc,n1,n2,n3): u""" This routine is not that universal. Each grain has to have neighboring grains within a supercell, otherwise there will be some unexpecting grain boundries. In order to do so, the system should be large enough and the number of grains should be large enough. """ sv= shift_vector() system= AtomSystem() system.set_lattice(uc.alc,uc.a1*n1,uc.a2*n2,uc.a3*n3) hmat= np.zeros((3,3)) hmat[0]= system.a1 *system.alc hmat[1]= system.a2 *system.alc hmat[2]= system.a3 *system.alc hmati= np.linalg.inv(hmat) for ig in range(len(grns)): grain= grns[ig] rmat= grain.rmat pi= grain.point api= np.dot(hmat,pi) for ix in range(-n1/2-1,n1/2+2): print 'ix=',ix for iy in range(-n2/2-1,n2/2+2): for iz in range(-n3/2-1,n3/2+2): for m in range(len(uc.atoms)): rt= np.zeros((3,)) rt[0]= (uc.atoms[m].pos[0]+ix)/n1 rt[1]= (uc.atoms[m].pos[1]+iy)/n2 rt[2]= (uc.atoms[m].pos[2]+iz)/n3 #...rt to absolute position art= np.dot(hmat,rt) #...rotate ari= np.dot(rmat,art) ari[0]= ari[0]+api[0] ari[1]= ari[1]+api[1] ari[2]= ari[2]+api[2] # #...reduce into the supercell # ri= np.dot(hmati,ari) # ri[0]= pbc(ri[0]) # ri[1]= pbc(ri[1]) # ri[2]= pbc(ri[2]) # ari= np.dot(hmat,ri) #...check distance from all the grain points di= distance(ari,api) isOutside= False for jg in range(len(grns)): gj= grns[jg] for isv in range(27): pj= gj.point if jg == ig and isv == 13: continue svi= sv[isv] pj= pj +svi apj= np.dot(hmat,pj) dj= distance(ari,apj) if dj < di: isOutside= True break if isOutside: break if isOutside: break #...here ri is inside this grain, register it atom= Atom() ri= np.dot(hmati,ari) ri[0]= pbc(ri[0]) ri[1]= pbc(ri[1]) ri[2]= pbc(ri[2]) atom.set_pos(ri[0],ri[1],ri[2]) atom.set_sid(uc.atoms[m].sid) system.add_atom(atom) #...remove too-close atoms at the grain boundaries system.make_pair_list(rcut) ls_remove= [] dmin2= dmin**2 xij= np.zeros((3,)) for ia in range(system.num_atoms()): ai= system.atoms[ia] pi= ai.pos nlst= system.nlspr[ia] lst= system.lspr[ia] for j in range(nlst): ja= lst[j] aj= system.atoms[ja] pj= aj.pos xij[0]= pj[0]-pi[0] -anint(pj[0]-pi[0]) xij[1]= pj[1]-pi[1] -anint(pj[1]-pi[1]) xij[2]= pj[2]-pi[2] -anint(pj[2]-pi[2]) xij= np.dot(hmat,xij) d2= xij[0]**2 +xij[1]**2 +xij[2]**2 if d2 < dmin2: ls_remove.append(ia) ls_remove.append(ja) #...one of two will survive #print ls_remove count= [ ls_remove.count(ls_remove[i]) for i in range(len(ls_remove))] #print count for i in range(0,len(ls_remove),2): if count[i] > count[i+1]: ls_remove[i+1]= -1 elif count[i] < count[i+1]: ls_remove[i]= -1 else: n= int(random()*2.0) # 0 or 1 ls_remove[i+n]= -1 ls_remove.sort() for ia in range(len(ls_remove)-1,-1,-1): n= ls_remove[ia] if ia != len(ls_remove)-1: if n == nprev: continue system.atoms.pop(n) nprev= n return system