def parser(self,): """ parse poscar to system @todo : handle coordinates acoording to Direct tag """ s = System() scale = float(self.scale) a = [scale*float(i) for i in self.a] b = [scale*float(i) for i in self.b] c = [scale*float(i) for i in self.c] s.name = self.name s.pbc = v2lattice(a, b, c) s.geotag = "XTLGRF 200" for i in range(len(self.atoms)): if i == 0: prev = 0 now = int(self.atoms[0]) else: prev = now now += int(self.atoms[i]) for j in range(prev, now): atom = Atom() atom.name = self.atomtypes[i] x = float(self.coords[j][0]) y = float(self.coords[j][1]) z = float(self.coords[j][2]) atom.x[0] = a[0]*x + b[0]*y + c[0]*z atom.x[1] = a[1]*x + b[1]*y + c[1]*z atom.x[2] = a[2]*x + b[2]*y + c[2]*z s.atoms.append(atom) return s
def parser(self): s = System() s.pbc = v2lattice(self.a, self.b, self.c) for i in self.coords: # n is used to distinguish the type of data file n = 0 for j in i: # ignore the comments if "#" in j: break n += 1 atom = Atom() atom.an = int(i[0]) if n == 7: # n = 7 is full type atom.name = self.atomtypes[int(i[2]) - 1] atom.x[0] = float(i[4]) atom.x[1] = float(i[5]) atom.x[2] = float(i[6]) s.atoms.append(atom) elif n == 5 or n == 8: # n = 5 is a charge type, n = 8 is a charge type generated # by restart2data atom.name = self.atomtypes[int(i[1]) - 1] atom.x[0] = float(i[3]) atom.x[1] = float(i[4]) atom.x[2] = float(i[5]) s.atoms.append(atom) return s
def parser(self): s = System() s.pbc = v2lattice(self.a, self.b, self.c) for i in self.coords: # n is used to distinguish the type of data file n = 0 for j in i: # ignore the comments if "#" in j: break n += 1 atom = Atom() atom.an = int(i[0]) if n == 7: # n = 7 is full type atom.name = self.atomtypes[int(i[2]) - 1] atom.x[0] = float(i[4]) atom.x[1] = float(i[5]) atom.x[2] = float(i[6]) s.atoms.append(atom) elif n == 6 or n == 9: # n = 5 is a charge type, n = 8 is a charge type generated # by restart2data atom.name = self.atomtypes[int(i[1]) - 1] atom.x[0] = float(i[3]) atom.x[1] = float(i[4]) atom.x[2] = float(i[5]) s.atoms.append(atom) return s
def parser(self, ): """ parse poscar to system @todo : handle coordinates acoording to Direct tag """ s = System() scale = float(self.scale) a = [scale * float(i) for i in self.a] b = [scale * float(i) for i in self.b] c = [scale * float(i) for i in self.c] s.name = self.name s.pbc = v2lattice(a, b, c) s.natoms = self.natoms s.atomtypes = self.atomtypes s.scaleFactor = self.scale s.geotag = "XTLGRF 200" for i in range(len(self.natoms)): if i == 0: prev = 0 now = int(self.natoms[0]) else: prev = now now += int(self.natoms[i]) for j in range(prev, now): atom = Atom() #print self.atomtypes, i atom.name = self.atomtypes[i] x = float(self.coords[j][0]) y = float(self.coords[j][1]) z = float(self.coords[j][2]) atom.xFrac = [x, y, z] atom.x[0] = a[0] * x + b[0] * y + c[0] * z atom.x[1] = a[1] * x + b[1] * y + c[1] * z atom.x[2] = a[2] * x + b[2] * y + c[2] * z if len(self.coords[j]) == 6 and self.sd == 1: xr = self.coords[j][3] yr = self.coords[j][4] zr = self.coords[j][5] if xr == "F": atom.xr[0] = 1 if yr == "F": atom.xr[1] = 1 if zr == "F": atom.xr[2] = 1 if len(self.coords[j]) == 3: atom.xr = [0, 0, 0] s.atoms.append(atom) return s
def parser(self,): """ parse poscar to system @todo : handle coordinates acoording to Direct tag """ s = System() scale = float(self.scale) a = [scale*float(i) for i in self.a] b = [scale*float(i) for i in self.b] c = [scale*float(i) for i in self.c] s.name = self.name s.pbc = v2lattice(a, b, c) s.natoms = self.natoms s.atomtypes = self.atomtypes s.scaleFactor = self.scale s.geotag = "XTLGRF 200" for i in range(len(self.natoms)): if i == 0: prev = 0 now = int(self.natoms[0]) else: prev = now now += int(self.natoms[i]) for j in range(prev, now): atom = Atom() #print self.atomtypes, i atom.name = self.atomtypes[i] x = float(self.coords[j][0]) y = float(self.coords[j][1]) z = float(self.coords[j][2]) atom.xFrac = [x, y, z] atom.x[0] = a[0]*x + b[0]*y + c[0]*z atom.x[1] = a[1]*x + b[1]*y + c[1]*z atom.x[2] = a[2]*x + b[2]*y + c[2]*z if len(self.coords[j]) == 6 and self.sd == 1: xr = self.coords[j][3] yr = self.coords[j][4] zr = self.coords[j][5] if xr == "F": atom.xr[0] = 1 if yr == "F": atom.xr[1] = 1 if zr == "F": atom.xr[2] = 1 s.atoms.append(atom) return s
def parser(self): s = System() s.pbc = v2lattice(self.a, self.b, self.c) s.atomtypes = self.atomtypes s.n_atoms = self.n_atoms s.n_bonds = self.n_bonds s.n_angles = self.n_angles s.n_dihedrals = self.n_dihedrals s.n_impropers = self.n_impropers s.n_atomtypes = self.n_atomtypes s.n_bondtypes = self.n_bondtypes s.n_angletypes = self.n_angletypes s.n_dihedraltypes = self.n_dihedraltypes s.n_impropertypes = self.n_impropertypes s.bonds = self.bonds s.angles = self.angles s.dihedrals = self.dihedrals s.ffparams = self.ffparams for i in self.coords: # n is used to distinguish the type of data file n = 0 for j in i: # ignore the comments if "#" in j: break n += 1 atom = Atom() atom.an = int(i[0]) if n == 7: # n = 7 is full type atom.resn = int(i[1]) atom.name = self.elements[int(i[2]) - 1] atom.element = self.elements[int(i[2]) - 1] atom.type2 = int(i[2]) atom.charge = float(i[3]) atom.x[0] = float(i[4]) atom.x[1] = float(i[5]) atom.x[2] = float(i[6]) s.atoms.append(atom) return s
def gen_scan(s, args): start = 0.7 end = 1.3 start = np.power(start, 1/3.0) end = np.power(end, 1/3.0) n = 11 x = np.linspace(start, end, n) for i in range(n): folder = "scan_%02d"%i if not os.path.exists(folder): os.mkdir(folder) os.chdir(folder) shutil.copy("../INCAR", ".") shutil.copy("../POTCAR", ".") shutil.copy("../KPOINTS", ".") if os.path.exists('../pbs'): shutil.copy("../pbs", ".") s_new = copy.copy(s) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = np.array([xx, 0.0, 0.0]) b = np.array([xy, yy, 0.0]) c = np.array([xz, yz, zz]) if args.xyz: tmp = args.xyz[0] if tmp == "xy": a = a * x[i] b = b * x[i] elif tmp == "z": c = c * x[i] else: a = a * x[i] b = b * x[i] c = c * x[i] pbc = v2lattice(a, b, c) s_new.pbc = pbc toPoscar(s_new, "POSCAR") os.chdir("..")
def gen_scan(s, args): start = 0.8 end = 1.2 start = np.power(start, 1/3.0) end = np.power(end, 1/3.0) n = 11 x = np.linspace(start, end, n) for i in range(n): folder = "scan_%02d"%i if not os.path.exists(folder): os.mkdir(folder) os.chdir(folder) shutil.copy("../INCAR", ".") shutil.copy("../POTCAR", ".") shutil.copy("../KPOINTS", ".") shutil.copy("../pbs", ".") s_new = copy.copy(s) xx, xy, xz, yy, yz, zz = lattice2v(s.pbc) a = np.array([xx, 0.0, 0.0]) b = np.array([xy, yy, 0.0]) c = np.array([xz, yz, zz]) if args.xyz: tmp = args.xyz[0] if tmp == "xy": a = a * x[i] b = b * x[i] elif tmp == "z": c = c * x[i] else: a = a * x[i] b = b * x[i] c = c * x[i] pbc = v2lattice(a, b, c) s_new.pbc = pbc toPoscar(s_new, "POSCAR") os.chdir("..")
def parser(self,): """ parse dump file into System """ s = System() s.name = self.name # transform a, b, c to [xx, xy, yz] # [yx, yy, yz] and [zx, zy, zz] # caution! A hard coded code for specified dump file a = [] # some dump file only have xl and xh. Normalize to three terms if len(self.a) == 2: self.a.append(0.0) if len(self.b) == 2: self.b.append(0.0) if len(self.c) == 2: self.c.append(0.0) #a.append(float(self.a[1]) - float(self.a[0])) #@ref: http://lammps.sandia.gov/doc/Section_howto.html#howto_12 xlo = float(self.a[0]) - min(0.0, float(self.a[2]), float(self.b[2]),\ float(self.a[2]) + float(self.c[2])) xhi = float(self.a[1]) - max(0.0, float(self.a[2]), float(self.b[2]),\ float(self.a[2]) + float(self.c[2])) a.append(xhi - xlo) a.append(0.0) a.append(0.0) #print a b = [] b.append(float(self.a[2])) ylo = float(self.b[0]) - min(0.0, float(self.c[2])) yhi = float(self.b[1]) - max(0.0, float(self.c[2])) b.append(yhi - ylo) b.append(0.0) #print b c = [] c.append(float(self.b[2])) c.append(float(self.c[2])) c.append(float(self.c[1]) - float(self.c[0])) s.pbc = v2lattice(a, b, c) #print c # begin to parse atoms flag = 0 if os.path.exists("inp"): flag = 1 n2a = self.parseInp() counter = 0 for i in self.coords: atom = Atom() if flag: atom.name = n2a[int(i[1])] else: atom.name = i[1] """ atom.x[0] = float(i[3]) atom.x[1] = float(i[4]) atom.x[2] = float(i[5]) """ atom.an = counter + 1 atom.x[0] = float(i[2]) atom.x[1] = float(i[3]) atom.x[2] = float(i[4]) s.atoms.append(atom) counter += 1 return s
def parser(self, ): """ parse dump file into System """ s = System() s.name = self.name # transform a, b, c to [xx, xy, yz] # [yx, yy, yz] and [zx, zy, zz] # caution! A hard coded code for specified dump file a = [] # some dump file only have xl and xh. Normalize to three terms if len(self.a) == 2: self.a.append(0.0) if len(self.b) == 2: self.b.append(0.0) if len(self.c) == 2: self.c.append(0.0) #a.append(float(self.a[1]) - float(self.a[0])) #@ref: http://lammps.sandia.gov/doc/Section_howto.html#howto_12 xlo = float(self.a[0]) - min(0.0, float(self.a[2]), float(self.b[2]),\ float(self.a[2]) + float(self.c[2])) xhi = float(self.a[1]) - max(0.0, float(self.a[2]), float(self.b[2]),\ float(self.a[2]) + float(self.c[2])) a.append(xhi - xlo) a.append(0.0) a.append(0.0) #print a b = [] b.append(float(self.a[2])) ylo = float(self.b[0]) - min(0.0, float(self.c[2])) yhi = float(self.b[1]) - max(0.0, float(self.c[2])) b.append(yhi - ylo) b.append(0.0) #print b c = [] c.append(float(self.b[2])) c.append(float(self.c[2])) c.append(float(self.c[1]) - float(self.c[0])) s.pbc = v2lattice(a, b, c) #print c # begin to parse atoms flag = 0 if os.path.exists("inp"): flag = 1 n2a = self.parseInp() counter = 0 for i in self.coords: atom = Atom() if flag: atom.name = n2a[int(i[1])] else: atom.name = i[1] """ atom.x[0] = float(i[3]) atom.x[1] = float(i[4]) atom.x[2] = float(i[5]) """ atom.an = counter + 1 atom.x[0] = float(i[2]) atom.x[1] = float(i[3]) atom.x[2] = float(i[4]) s.atoms.append(atom) counter += 1 return s