def rotatefc3(t, direct=[0, 0, 1], file1='FORCE_CONSTANTS_3RD', file2='fc3new'): f = open(file1) g = open(file2, 'w') M = rotationMatrix(direct, t * np.pi / 180.0) nblock = int(f.next().split()[0]) print >> g, nblock print >> g, "" for i in range(nblock): f.next() print >> g, f.next(), r1 = np.array(map(float, f.next().split())) r1t = M.dot(r1) print >> g, tl.toString(r1t) r1 = np.array(map(float, f.next().split())) r1t = M.dot(r1) print >> g, tl.toString(r1t) print >> g, f.next(), fc = np.zeros([3, 3, 3]) for i in range(3): for j in range(3): for k in range(3): fc[i, j, k] = float(f.next().split()[3]) fc = np.einsum('ij,jkl->ikl', M, fc) fc = np.einsum('ij,kjl->kil', M, fc) fc = np.einsum('ij,klj->kli', M, fc) print >> g, matrix3Format(fc)
def phana(self): from aces.tools import read m = self.m bp = m.bandpath bpp = m.bandpoints v = "" for i in range(len(bp) - 1): v += "%s\n%s\n101\n" % (tl.toString(bpp[bp[i]]), tl.toString(bpp[bp[i + 1]])) s = """20 1 2 phana.band.txt %sq 0 """ % v s = s.replace(r'^\s+', '') tl.write(s, 'phana.in') tl.passthru(config.phana + 'phonon.bin.%d <phana.in' % m.Ctime) s = read('pdisp.gnuplot') s = s.replace('pdisp.eps', 'phana.band.eps') tl.write(s, 'phana.band.gnuplot') tl.passthru('rm pdisp.gnuplot') tl.passthru('gnuplot phana.band.gnuplot') tl.passthru('convert -rotate 90 phana.band.eps phana.band.png')
def maps2p(self, i, j, k): if not hasattr(self, 's2p'): self.s2p, c, self.celloffset = self.getS2p() v = self.celloffset s = tl.toString(v[j] - v[i]) + '\n' s += tl.toString(v[k] - v[i]) + '\n' s += '%d %d %d\n' % (self.s2p[i] + 1, self.s2p[j] + 1, self.s2p[k] + 1) return s
def refinefc3(): f = open('FORCE_CONSTANTS_3RD') g = open('fc3new', 'w') nblock = int(f.next().split()[0]) fc3 = [] r1t = [] r2t = [] idx = [] # print >>g,nblock for i in range(nblock): f.next() f.next() r1 = np.array(map(float, f.next().split())) r1t.append(r1) r2 = np.array(map(float, f.next().split())) r2t.append(r2) idx.append(map(int, f.next().split())) fc = np.zeros([3, 3, 3]) for i in range(3): for j in range(3): for k in range(3): fc[i, j, k] = float(f.next().split()[3]) fc3.append(fc) scale = np.amax(np.abs(fc3)) u = [] for i in range(nblock): if np.allclose(np.zeros([3, 3, 3]), fc3[i] / scale, atol=1e-01 * .3): u.append(False) else: u.append(True) u = np.array(u) fc3 = np.array(fc3)[u] r1t = np.array(r1t)[u] r2t = np.array(r2t)[u] idx = np.array(idx)[u] v = np.unique(idx[:, 0]) filters = np.array([idx[:, 0] == c for c in v]) for i, f in enumerate(filters): a = np.arange(len(idx))[f][0] fc3[a] -= fc3[f].sum(axis=0) v = np.unique(idx[:, 1]) filters = np.array([idx[:, 1] == c for c in v]) for i, f in enumerate(filters): a = np.arange(len(idx))[f][0] fc3[a] -= fc3[f].sum(axis=0) nblock = len(fc3) print >> g, nblock for i in range(nblock): print >> g, i + 1 print >> g, tl.toString(np.around(r1t[i], 3)) print >> g, tl.toString(np.around(r2t[i], 3)) print >> g, tl.toString(idx[i]) print >> g, matrix3Format(fc3[i])
def writedata(self, filename="structure", creatbonds=-1.0): a = data() a.title = self.atoms.get_chemical_formula() unit, rot = self.get_rotated_atoms() cell = unit.cell a.headers['xlo xhi'] = [0, cell[0, 0]] a.headers['ylo yhi'] = [0, cell[1, 1]] a.headers['zlo zhi'] = [0, cell[2, 2]] if (cell[1, 0] > cell[0, 0] * 0.5): cell[1, 0] = cell[0, 0] * 0.5 v = 1.0 if (cell[1, 0] < 0): v = -1.0 cell[1, 0] = v * int((abs(cell[1, 0])) * 10000) / 10000.0 #print [cell[1,0]/cell[0,0],cell[2,0]/cell[0,0],cell[2,1]/cell[1,1]]; if not np.allclose( [0, 0, 0], [ cell[1, 0] / cell[0, 0], cell[2, 0] / cell[0, 0], cell[2, 1] / cell[1, 1] ], atol=0.01): a.headers['xy xz yz'] = [cell[1, 0], cell[2, 0], cell[2, 1]] a.headers['atoms'] = len(self.atoms) a.headers['atom types'] = len(self.types) atomsdata = [] for i, atom in enumerate(unit): x = [i + 1, self.types.index(atom.symbol) + 1] + \ list(atom.position) if creatbonds > 0.0: x = [i + 1, 1, self.types.index(atom.symbol) + 1 ] + list(atom.position) atomsdata.append(x) a.sections['Atoms'] = [toString(x) + '\n' for x in atomsdata] if creatbonds > 0.0: dis = unit.get_all_distances(mic=True) bonds = [] n = 0 for i in range(len(unit)): for j in range(i): if dis[i, j] < creatbonds: n += 1 bonds.append([n, 1, i + 1, j + 1]) a.sections['Bonds'] = [toString(x) + '\n' for x in bonds] a.headers['bonds'] = len(bonds) a.headers['bond types'] = 1 a.write(filename) return rot
def writedata(self, filename="structure", creatbonds=-1.0): a = data() a.title = self.atoms.get_chemical_formula() unit, rot = self.get_rotated_atoms() cell = unit.cell a.headers['xlo xhi'] = [0, cell[0, 0]] a.headers['ylo yhi'] = [0, cell[1, 1]] a.headers['zlo zhi'] = [0, cell[2, 2]] if (cell[1, 0] > cell[0, 0] * 0.5): cell[1, 0] = cell[0, 0] * 0.5 v = 1.0 if (cell[1, 0] < 0): v = -1.0 cell[1, 0] = v * int((abs(cell[1, 0])) * 10000) / 10000.0 #print [cell[1,0]/cell[0,0],cell[2,0]/cell[0,0],cell[2,1]/cell[1,1]]; if not np.allclose([0, 0, 0], [ cell[1, 0] / cell[0, 0], cell[2, 0] / cell[0, 0], cell[2, 1] / cell[1, 1] ], atol=0.01): a.headers['xy xz yz'] = [cell[1, 0], cell[2, 0], cell[2, 1]] a.headers['atoms'] = len(self.atoms) a.headers['atom types'] = len(self.types) atomsdata = [] for i, atom in enumerate(unit): x = [i + 1, self.types.index(atom.symbol) + 1] + \ list(atom.position) if creatbonds > 0.0: x = [i + 1, 1, self.types.index(atom.symbol) + 1] + list( atom.position) atomsdata.append(x) a.sections['Atoms'] = [toString(x) + '\n' for x in atomsdata] if creatbonds > 0.0: dis = unit.get_all_distances(mic=True) bonds = [] n = 0 for i in range(len(unit)): for j in range(i): if dis[i, j] < creatbonds: n += 1 bonds.append([n, 1, i + 1, j + 1]) a.sections['Bonds'] = [toString(x) + '\n' for x in bonds] a.headers['bonds'] = len(bonds) a.headers['bond types'] = 1 a.write(filename) return rot
def phanados(self): from aces.tools import read m = self.m s = """20 1 1 %s 2 y 1000 y phana.dos.txt 0 """ % tl.toString(m.kpoints) s = s.replace(r'^\s+', '') tl.write(s, 'phana.dos.in') tl.passthru(config.phana + 'phonon.bin.%d <phana.dos.in' % m.Ctime) s = read('pdos.gnuplot') s = s.replace('pdos.eps', 'phana.dos.eps') tl.write(s, 'phana.dos.gnuplot') tl.passthru('rm pdos.gnuplot') tl.passthru('gnuplot phana.dos.gnuplot') tl.passthru('convert -rotate 90 phana.dos.eps phana.dos.png')
def generate_bandconf(self): # generate mesh.conf m = self.m bp = m.bandpoints bpath = ' '.join([toString(bp[x]) for x in m.bandpath]) band = """DIM = %s ATOM_NAME = %s BAND = %s BAND_POINTS = 101 FORCE_CONSTANTS = READ PRIMITIVE_AXIS = %s """ % (m.dim, ' '.join(m.elements), bpath, toString(m.premitive.flatten())) band = band.replace(r'^\s+', '') write(band, 'band.conf')
def generate_vqconf(self, q): # generate q.conf m = self.m mesh = """DIM = %s ATOM_NAME = %s FORCE_CONSTANTS = READ GROUP_VELOCITY=.TRUE. QPOINTS=.TRUE. PRIMITIVE_AXIS = %s """ % (m.dim, ' '.join(m.elements), toString(m.premitive.flatten())) mesh = mesh.replace(r'^\s+', '') write(mesh, 'q.conf') s = "%s\n" % len(q) for qq in q: s += "%s\n" % toString(qq) write(s, 'QPOINTS')
def generate_bandconf(self): # generate mesh.conf m = self.m bp = m.bandpoints bpath = ' '.join([toString(bp[x]) for x in m.bandpath]) band = """DIM = %s ATOM_NAME = %s BAND = %s BAND_POINTS = 101 FORCE_CONSTANTS = READ PRIMITIVE_AXIS = %s """ % (m.dim, ' '.join( m.elements), bpath, toString(m.premitive.flatten())) band = band.replace(r'^\s+', '') write(band, 'band.conf')
def dyinput(self): m = self.m f = open('in.dy', 'w') print >> f, "STRUCTURE FILE POSCAR" print >> f, tl.pwd() + "/POSCAR" print >> f, "FORCE SETS" print >> f, tl.pwd() + "/FORCE_SETS" # print >>f,"STRUCTURE FILE OUTCAR" # print >>f,pwd()+"/dynaphopy.lammpstrj" print >> f, "SUPERCELL MATRIX PHONOPY" print >> f, " %d 0 0 \n 0 %d 0\n 0 0 %d" % tuple(m.supercell) print >> f, "BANDS" bp = m.bandpath bpp = m.bandpoints for i in range(len(bp) - 1): u = "%s %s" % (tl.toString(bpp[bp[i]], ','), tl.toString(bpp[bp[i + 1]], ',')) print >> f, u f.close()
def getscfin(self): m = self.m tmpl = self.getscf_template() skpoints = "K_POINTS automatic\n%s 1 1 1" % tl.toString(m.ekpoints) a = """tprnfor = .true. tstress = .true. restart_mode = 'from_scratch' """ s = tmpl.replace('TYPE', 'scf').replace('CONTROL', a).replace( 'KPOINTS', skpoints) tl.write(s, 'scf.in')
def getscfin(self): m = self.m tmpl = self.getscf_template() skpoints = "K_POINTS automatic\n%s 1 1 1" % tl.toString(m.ekpoints) a = """tprnfor = .true. tstress = .true. restart_mode = 'from_scratch' """ s = tmpl.replace('TYPE', 'scf').replace('CONTROL', a).replace('KPOINTS', skpoints) tl.write(s, 'scf.in')
def get_structure(self): m = self.m atoms = m.atoms_from_dump('minimize/range') satoms = atoms.repeat(m.correlation_supercell) a = lammpsdata(satoms, m.elements) a.writedata('correlation_structure', self.m.creatbonds) # psm=premitiveSuperMapper(atoms,satoms) # s2p,v,=psm.getS2p() s = "%s %d\n#l1 l2 l3 k tag\n" % (tl.toString(m.correlation_supercell), len(atoms)) c = m.correlation_supercell n = 0 for i in range(c[0]): for j in range(c[1]): for k in range(c[2]): for p in range(len(atoms)): u = [i, j, k, p, n + 1] s += tl.toString(u) + "\n" n += 1 tl.write(s, 'phana.map.in')
def getscf_template(self): m = self.m pos = ' \n'.join([ '%s ' % (a.symbol) + m.toString(m.atoms.get_scaled_positions()[i]) for i, a in enumerate(m.atoms) ]) mmm = 1.0 # np.abs(m.atoms.cell).max()*2.0 cell = '\n '.join( [m.toString(m.atoms.cell[i] / mmm) for i in range(3)]) masses = m.getMassFromLabel(m.elements) pots = self.getPotName() potentials = [pots[a] for a in m.elements] atomspecies = '\n'.join( tl.toString(a) for a in zip(m.elements, masses, potentials)) path = config.qepot s = """ &control calculation = 'TYPE' prefix = 'diam' wf_collect = .true. pseudo_dir = '%s' outdir = './' CONTROL etot_conv_thr = 1.0d-5 forc_conv_thr = 1.0d-4 / &system ibrav = 0 celldm(1) =%f nat = %d ntyp = %d ecutwfc = 60 occupations = 'smearing' smearing = 'mp' degauss = 0.02 / &electrons diagonalization = 'david' mixing_beta = 0.7 conv_thr = 1.0d-10 / ATOMIC_SPECIES %s ATOMIC_POSITIONS crystal %s KPOINTS CELL_PARAMETERS alat %s """ % (path, mmm / 0.5291772083, len(m.atoms), len(m.elements), atomspecies, pos, cell) return s
def getscf_template(self): m = self.m pos = ' \n'.join([ '%s ' % (a.symbol) + m.toString(m.atoms.get_scaled_positions()[i]) for i, a in enumerate(m.atoms) ]) mmm = 1.0 # np.abs(m.atoms.cell).max()*2.0 cell = '\n '.join( [m.toString(m.atoms.cell[i] / mmm) for i in range(3)]) masses = m.getMassFromLabel(m.elements) pots = self.getPotName() potentials = [pots[a] for a in m.elements] atomspecies = '\n'.join( tl.toString(a) for a in zip(m.elements, masses, potentials)) path = config.qepot s = """ &control calculation = 'TYPE' prefix = 'diam' wf_collect = .true. pseudo_dir = '%s' outdir = './' CONTROL etot_conv_thr = 1.0d-5 forc_conv_thr = 1.0d-4 / &system ibrav = 0 celldm(1) =%f nat = %d ntyp = %d ecutwfc = 60 occupations = 'smearing' smearing = 'mp' degauss = 0.02 / &electrons diagonalization = 'david' mixing_beta = 0.7 conv_thr = 1.0d-10 / ATOMIC_SPECIES %s ATOMIC_POSITIONS crystal %s KPOINTS CELL_PARAMETERS alat %s """ % (path, mmm / 0.5291772083, len(m.atoms), len( m.elements), atomspecies, pos, cell) return s
def generate_vconf(self): # generate v.conf m = self.m mesh = """DIM = %s ATOM_NAME = %s MP = %s FORCE_CONSTANTS = READ MESH_SYMMETRY = .FALSE. GROUP_VELOCITY=.TRUE. PRIMITIVE_AXIS = %s """ % (m.dim, ' '.join(m.elements), ' '.join(map( str, m.kpoints)), toString(m.premitive.flatten())) mesh = mesh.replace(r'^\s+', '') write(mesh, 'v.conf')
def writevasp(atoms, file='POSCAR'): f = open(file, 'w') s = np.array(atoms.get_chemical_symbols()) ss = atoms.get_scaled_positions() print >> f, 'ACES POSCAR' print >> f, '1.0' for x in atoms.cell: print >> f, tl.toString(x) # ele=np.unique(s) ele = [] for a in s: if a in ele: continue ele.append(a) print >> f, tl.toString(ele) a = [] # len(s) = natom p = np.arange(len(s)) for e in ele: a.append(p[s == e]) # p= 0 1 2 3 4 5 # s= C N N C N C # a= [[0,3,5],[1,2,4]] ns = [len(x) for x in a] # ns =[3,3] print >> f, tl.toString(ns) print >> f, 'Direct' v = [] for x in a: for u in x: v.append(u) print >> f, tl.toString(ss[u]) # v= [0,3,5,1,2,4] f.close() x = np.array(v, dtype=np.int).argsort() np.savetxt('POSCARswap', x)
def generate_vconf(self): # generate v.conf m = self.m mesh = """DIM = %s ATOM_NAME = %s MP = %s FORCE_CONSTANTS = READ MESH_SYMMETRY = .FALSE. GROUP_VELOCITY=.TRUE. PRIMITIVE_AXIS = %s """ % (m.dim, ' '.join(m.elements), ' '.join(map(str, m.kpoints)), toString(m.premitive.flatten())) mesh = mesh.replace(r'^\s+', '') write(mesh, 'v.conf')
def writevasp(atoms, file='POSCAR'): f = open(file, 'w') s = np.array(atoms.get_chemical_symbols()) ss = atoms.get_scaled_positions() print >>f, 'ACES POSCAR' print >>f, '1.0' for x in atoms.cell: print >>f, tl.toString(x) # ele=np.unique(s) ele = [] for a in s: if a in ele: continue ele.append(a) print >>f, tl.toString(ele) a = [] # len(s) = natom p = np.arange(len(s)) for e in ele: a.append(p[s == e]) # p= 0 1 2 3 4 5 # s= C N N C N C # a= [[0,3,5],[1,2,4]] ns = [len(x) for x in a] # ns =[3,3] print >>f, tl.toString(ns) print >>f, 'Direct' v = [] for x in a: for u in x: v.append(u) print >>f, tl.toString(ss[u]) # v= [0,3,5,1,2,4] f.close() x = np.array(v, dtype=np.int).argsort() np.savetxt('POSCARswap', x)
def getControl(self): m = self.m f = open('CONTROL', 'w') atoms = io.read('../POSCAR') # m.atoms elements = m.elements # shengbte needs nelements <=natoms if len(elements) > len(atoms): elements = elements[:len(atoms)] allocations = """&allocations \tnelements=%d \tnatoms=%d \tngrid(:)=%s &end """ % (len(elements), len(atoms), toString(m.kpoints)) cell = atoms.cell types = toString( [m.elements.index(x) + 1 for x in atoms.get_chemical_symbols()]) pos = "" for i, atom in enumerate(atoms): tu = (i + 1, toString(atoms.get_scaled_positions()[i])) pos += " positions(:,%d)=%s\n" % tu crystal = """&crystal lfactor=0.1, lattvec(:,1)=%s lattvec(:,2)=%s lattvec(:,3)=%s elements=%s types=%s %s scell(:)=%s &end """ % (toString(cell[0]), toString(cell[1]), toString(cell[2]), ' '.join(map(lambda x: '"' + x + '"', elements)), types, pos, m.dim) parameters = """¶meters T=%f scalebroad=1.0 &end """ % (m.T) flags = """ &flags nonanalytic=.TRUE. nanowires=.FALSE. &end """ f.write(allocations) f.write(crystal) f.write(parameters) f.write(flags) f.close()
def life(self, k=[0, 0, 0]): self.pix("-pa -q %s --silent > dylife%s.txt" % tl.toString(k), str(k))
def nma(self, k=[0, 0, 0]): self.pix("-q %s -sp 'dvnma%s.txt' -r 0 16 2000" % (tl.toString(k), str(k)))
def atomdisp(self, direction=[1, 0, 0]): self.pix(" -sad %s dydisplacement.txt" % (tl.toString(direction)))
def sed(self, k=[0, 0, 0]): self.pix("-q %s -sw 'dvsed%s.txt' -r 0 50 2000" % (tl.toString(k), str(k)))
def __getattr__(self, attr): if attr == "dim": return tl.toString(self.supercell) if attr == "cores": return int(self.nodes) * int(self.procs)
def getcut(self): m = self.m cut = str(m.shengcut / 10.0) if m.shengcut < 0: cut = str(m.shengcut) return " %s %s " % (toString(m.supercell3), cut)