def add_the_unit_cell(material, buffer): name = material.get_name() cell = material.get_cell() atoms = material.get_atom_list() if cell: return material # Don't do anything for now newname = "%s_cell" % name newmaterial = Material(newname) if not buffer: buffer = 2. # Can still set to a small value like 0.01 xmin, xmax, ymin, ymax, zmin, zmax = bbox_atoms(atoms, buffer) for atom in atoms: atno = atom.get_atno() xyz = atom.get_position() xyznew = array((xyz[0] - xmin, xyz[1] - ymin, xyz[2] - zmin)) newmaterial.add_atom(Atom(atno, xyznew)) newmaterial.set_cell( Cell((xmax - xmin, 0, 0), (0, ymax - ymin, 0), (0, 0, zmax - zmin))) opts = getattr(material, "seqquest_options", {}) if opts: newmaterial.seqquest_options = opts.copy() opts = getattr(material, "socorro_options", {}) if opts: newmaterial.socorro_options = opts.copy() newmaterial.bonds_from_distance() return newmaterial
def build_the_supercell(material, ass, bss, css): if ass == 1 and bss == 1 and css == 1: return material name = material.get_name() cell = material.get_cell() atomlist = material.get_atom_list() axyz = cell.axyz bxyz = cell.bxyz cxyz = cell.cxyz newname = "%s%d%d%d" % (name, ass, bss, css) newmaterial = Material(newname) naxyz = ass * axyz nbxyz = bss * bxyz ncxyz = css * cxyz for atom in atomlist: atno = atom.get_atno() sym = atom.get_symbol() xyz = atom.get_position() for i in range(ass): for j in range(bss): for k in range(css): xyznew = xyz + i * axyz + j * bxyz + k * cxyz newmaterial.add_atom(Atom(atno, xyznew, sym)) newmaterial.set_cell(Cell(naxyz, nbxyz, ncxyz)) opts = getattr(material, "seqquest_options", {}) if opts: newmaterial.seqquest_options = opts.copy() opts = getattr(material, "socorro_options", {}) if opts: newmaterial.socorro_options = opts.copy() newmaterial.bonds_from_distance() return newmaterial
def build_the_slab(material, cleave_dir, depth, vacuum): name = material.get_name() cell = material.get_cell() atomlist = material.get_atom_list() if not cleave_dir: cleave_dir = 'C' axyz = cell.axyz bxyz = cell.bxyz cxyz = cell.cxyz if depth == 1 and vacuum == 0: return material # do nothing newname = "%s_slab" % name newmaterial = Material(newname) # # Replace abc -> uvw (w is the cleave direction) so we can # cleave in more general ways: # if cleave_dir == "C": uxyz = axyz vxyz = bxyz wxyz = cxyz idir = 2 elif cleave_dir == "B": uxyz = cxyz vxyz = axyz wxyz = bxyz idir = 1 elif cleave_dir == "A": uxyz = bxyz vxyz = cxyz wxyz = axyz idir = 0 wlength = sqrt(dot(wxyz, wxyz)) wscale = (wlength * depth + vacuum) / wlength nwxyz = wxyz * wscale for atom in atomlist: atno = atom.get_atno() xyz = atom.get_position() for k in range(depth): xyznew = xyz + k * wxyz xyznew[idir] += vacuum / 2. newmaterial.add_atom(Atom(atno, xyznew)) if abs(xyz[idir]) < 1e-2: # Periodic image of bottom: xyznew = xyz + depth * wxyz xyznew[idir] += vacuum / 2. newmaterial.add_atom(Atom(atno, xyznew)) # I can't tell whether I have to do the cyclic permutations here # i.e. output w,u,v in some cases. newmaterial.set_cell(Cell(uxyz, vxyz, nwxyz)) opts = getattr(material, "seqquest_options", {}) if opts: newmaterial.seqquest_options = opts.copy() opts = getattr(material, "socorro_options", {}) if opts: newmaterial.socorro_options = opts.copy() newmaterial.center() newmaterial.bonds_from_distance() return newmaterial
def load(fullfilename): gstep = 0 filedir, fileprefix, fileext = path_split(fullfilename) file=open(fullfilename, 'r') # Initialize atom data material = Material(fileprefix) opts = {} material.seqquest_options = opts dconv = 1. # default to Angstroms, which don't need conversion cell = None while 1: line = file.readline() if not line: break line = line.strip() if line == '@=KEYCHAR': continue # ignore other keychars for now elif line == '@DISTANCE UNIT': line = file.readline().strip() if line == 'ANGSTROM': continue elif line == 'BOHR': dconv = bohr2ang else: print "Warning: unknown distance unit ",line elif line == '@DIMENSION': line = file.readline().strip() opts['ndim'] = int(line) elif line == '@NUMBER OF ATOMS': line = file.readline().strip() opts['nat'] = int(line) opts['attypes'] = [] nread = int(ceil(opts['nat']/20.)) for i in range(nread): line = file.readline().strip() opts['attypes'].extend(map(int,line.split())) assert len(opts['attypes']) == opts['nat'] elif line == '@TYPES': line = file.readline().strip() opts['ntyp'] = int(line) opts['types'] = [] for i in range(opts['ntyp']): line = file.readline().strip() opts['types'].append(cleansym(line)) elif line == '@CELL VECTORS': line = file.readline() axyz = map(float,line.split()) line = file.readline() bxyz = map(float,line.split()) line = file.readline() cxyz = map(float,line.split()) if abs(dconv-1) > 1e-4: # careful when comparing floats axyz = axyz[0]*dconv,axyz[1]*dconv,axyz[2]*dconv bxyz = bxyz[0]*dconv,bxyz[1]*dconv,bxyz[2]*dconv cxyz = cxyz[0]*dconv,cxyz[1]*dconv,cxyz[2]*dconv cell = Cell(axyz,bxyz,cxyz) elif line == '@GSTEP': line = file.readline().strip() gstep = int(line) elif line == '@COORDINATES': atoms = [] for i in range(opts['nat']): line = file.readline() xyz = map(float,line.split()) if abs(dconv-1) > 1e-4: # careful when comparing floats xyz = xyz[0]*dconv,xyz[1]*dconv,xyz[2]*dconv isym = opts['attypes'][i] sym = opts['types'][isym-1] atoms.append((sym,xyz)) if gstep > 1: material.new_geo() for i in range(opts['nat']): sym,xyz = atoms[i] atno = sym2no[sym] xyz = array(xyz) material.add_atom(Atom(atno,xyz)) if cell: material.set_cell(cell) elif line == '@ESCF': line = file.readline().strip() escf = float(line) # Consider saving these for plotting elif line == '@FORCES': forces = [] for i in range(opts['nat']): line = file.readline() forces.append(map(float,line.split())) elif line == '@FMAX': line = file.readline().strip() fmax = float(line) elif line == '@FRMS': line = file.readline().strip() frms = float(line) else: print "Unknown line ",line material.bonds_from_distance() return material
def load(fullfilename): filedir, fileprefix, fileext = path_split(fullfilename) file = open(fullfilename, 'r') # Initialize atom data material = Material(fileprefix) opts = {} material.seqquest_options = opts line = file.readline() # start reading # Read in the run options while 1: if line[:8] == 'output l': line = file.readline() opts['lvlout'] = int(line.strip()) line = file.readline() elif line[:8] == 'do setup': opts['dosetup'] = True line = file.readline() elif line[:8] == 'no setup': opts['dosetup'] = False line = file.readline() elif line[:8] == 'do iters': opts['doiters'] = True line = file.readline() elif line[:8] == 'no iters': opts['doiters'] = False line = file.readline() elif line[:8] == 'do force': opts['doforce'] = True line = file.readline() elif line[:8] == 'no force': opts['doforce'] = False line = file.readline() elif line[:8] == 'do relax': opts['dorelax'] = True line = file.readline() elif line[:8] == 'no relax': opts['dorelax'] = False line = file.readline() elif line[:7] == 'do cell': opts['docell'] = True line = file.readline() elif line[:7] == 'no cell': opts['docell'] = False line = file.readline() elif line[:6] == 'do neb': opts['doneb'] = True line = file.readline() elif line[:6] == 'no neb': opts['doneb'] = False line = file.readline() elif line[:5] == 'do md': opts['domd'] = True line = file.readline() elif line[:5] == 'no md': opts['domd'] = False line = file.readline() elif line[:7] == 'do post': opts['dopost'] = True line = file.readline() elif line[:7] == 'no post': opts['dopost'] = False line = file.readline() elif line[:7] == 'do blas': opts['doblas3'] = True line = file.readline() elif line[:7] == 'no blas': opts['doblas3'] = False line = file.readline() else: # Comment this out when debugged: print "Unknown line from command section" print line, print "Assuming end of Input Options Section" break # end of run options # Beginning of setup info if line[:6] == 'input ': line = file.readline() # skip line # Title if line[:5] == 'title': opts['title'] = [] try: ntitl = int(line[5]) except: ntitl = 1 for i in range(ntitl): line = file.readline() opts['title'].append(line.strip()) line = file.readline() if line[:5] == 'scale': line = file.readline() opts['scalep'] = float(line.strip()) line = file.readline() # DFT fcnal if line[:6] == 'functi': line = file.readline() opts['dft_func'] = line.strip() line = file.readline() # Spin polarization if line[:6] == 'spin p': line = file.readline() opts['spinpol'] = int(line.strip()) #should put an error condition here if dft requires # spin and no spinpol input line = file.readline() # External electric field if line[:6] == 'efield': line = file.readline() ex, ey, ez = map(float, line.split()) opts['efield'] = (ex, ey, ez) # in Ry/au line = file.readline() # External dielectric constant if line[:6] == 'dielec': line = file.readline() opts['dielec'] = float(line.split()) line = file.readline() # Problem dimension if line[:6] == 'dimens' or line[:6] == 'lattic': line = file.readline() opts['ndim'] = int(line.strip()) line = file.readline() else: print line raise "Dimension must be specified in Quest input" # Coordinates (lattice or cartesian) if line[:6] == 'coordi': line = file.readline() opts['coordi'] = line.strip() line = file.readline() # Problem scaling # RPM: Need to do a better job of this: #if line[:6] == 'scalep' or (line[:5] == 'scale' and len(line) == 5): if line[:6] == 'scalep' or line[:6] == 'scale\n': line = file.readline() opts['scalep'] = float(line.strip()) line = file.readline() if line[:6] == 'scaleu': line = file.readline() opts['scaleu'] = float(line.strip()) line = file.readline() if line[:6] == 'scalex': line = file.readline() opts['scalex'] = float(line.strip()) line = file.readline() if line[:6] == 'scaley': line = file.readline() opts['scaley'] = float(line.strip()) line = file.readline() if line[:6] == 'scalez': line = file.readline() opts['scalez'] = float(line.strip()) line = file.readline() # Strain if line[:6] == 'strain': line = file.readline() xx, xy, xz = map(float, line.split()) line = file.readline() yx, yy, yz = map(float, line.split()) line = file.readline() zx, zy, zz = map(float, line.split()) opts['strain'] = (xx, xy, xz, yx, yy, yz, zx, zy, zz) line = file.readline() if line[:6] == 'strfac': line = file.readline() opts['strfac'] = float(line.strip()) line = file.readline() # Lattice vectors: if line[:6] == 'primit': line = file.readline() ax, ay, az = map(float, line.split()) axyz = ax * bohr2ang, ay * bohr2ang, az * bohr2ang line = file.readline() bx, by, bz = map(float, line.split()) bxyz = bx * bohr2ang, by * bohr2ang, bz * bohr2ang line = file.readline() cx, cy, cz = map(float, line.split()) cxyz = cx * bohr2ang, cy * bohr2ang, cz * bohr2ang cell = Cell(axyz, bxyz, cxyz) line = file.readline() # grid dimensions if line[:6] == 'grid d' or line[:6] == 'points': line = file.readline() opts['griddim'] = map(int, line.split()) line = file.readline() # nearby function if line[:6] == 'nearby': line = file.readline() opts['nearby'] = int(line.strip()) line = file.readline() # number of atom types if line[:6] == 'atom t': line = file.readline() opts['ntyp'] = int(line.strip()) opts['types'] = [] line = file.readline() else: print line, len(line) raise "Number of atom types must be specified" # atom types: for i in range(opts['ntyp']): if line[:6] == 'atom f': line = file.readline() opts['types'].append(line.strip()) line = file.readline() else: raise "Error: expecting another atom file" # number of atoms if line[:6] == 'number': line = file.readline() opts['nat'] = int(line.strip()) line = file.readline() if line[:6] == 'atom, ': for i in range(opts['nat']): line = file.readline() words = line.split() inum = int(words[0]) ityp = int(words[1]) x, y, z = map(float, words[2:5]) xyz = x * bohr2ang, y * bohr2ang, z * bohr2ang xyz = array(xyz) sym = cleansym(opts['types'][ityp - 1]) atno = sym2no[sym] material.add_atom(Atom(atno, xyz)) line = file.readline() material.set_cell(cell) material.bonds_from_distance() else: raise "Error: expected atom listing here" # to lattice/to cartesian if line[:6] == 'to_lat': opts['to_lat'] = True line = file.readline() elif line[:6] == 'to_car': opts['to_car'] = True line = file.readline() # origin offset if line[:6] == 'origin': line = file.readline() opts['dorig'] = map(float, line.split()) line = file.readline() # wigner-seitz origin if line[:6] == 'wigner': line = file.readline() opts['rchrg'] = map(float, line.split()) line = file.readline() # center of symmetry if line[:6] == 'symmet': line = file.readline() opts['rsym'] = map(float, line.split()) line = file.readline() # bloch info if line[:5] == 'kgrid': line = file.readline() opts['kgrid'] = map(int, line.split()) line = file.readline() elif line[:4] == 'khex': line = file.readline() opts['khex'] = map(int, line.split()) line = file.readline() # skipping more detailed bloch info for now if line[:6] == 'n bloc': line = file.readline() opts['nk'] = int(line.strip()) line = file.readline() if line[:6] == 'scalin': line = file.readline() opts['scalin'] = map(float, line.split()) line = file.readline() if line[:6] == 'lattic': line = file.readline() opts['bloch_lattic'] = map(float, line.split()) line = file.readline() elif line[:6] == 'cartes': line = file.readline() opts['bloch_cartes'] = map(float, line.split()) line = file.readline() if line[:6] == 'bloch ': opts['bloch_vecs'] = [] for i in range(opts['nk']): line = file.readline() opts['bloch_vecs'].append(map(float, line.split())) line = file.readline() # symmetry info if line[:6] == 'symops': line = file.readline() opts['nsymi'] = int(line.strip()) line = file.readline() if line[:6] == 'defini': opts['symvecs'] = [] for i in range(opts['nsymi']): line = file.readline() words = line.split() type = int(words[0]) s1, s2, s3, s4, s5, s6 = map(float, words[1:]) opts['symvecs'].append((type, s1, s2, s3, s4, s5, s6)) line = file.readline() if line[:6] == 'end se': line = file.readline() else: raise "Expected end setup phase tag" # End of setup info # Beginning of Run Data if line[:6] == 'run ph': while 1: line = file.readline() if not line: break if line[:6] == 'end ru' or line[:6] == 'end of': break elif line[:6] == 'do fla': opts['doflag'] = True elif line[:6] == 'no fla': opts['doflag'] = False elif line[:6] == 'first ': line = file.readline() opts['itstart'] = int(line.strip()) elif line[:6] == 'last i': line = file.readline() opts['itstop'] = int(line.strip()) elif line[:6] == 'histor': line = file.readline() opts['nhiste'] = int(line.strip()) elif line[:6] == 'restar': line = file.readline() opts['itrst'] = int(line.strip()) elif line[:6] == 'states': line = file.readline() opts['nstate'] = int(line.strip()) elif line[:6] == 'temper': line = file.readline() opts['etemp'] = float(line.strip()) elif line[:6] == 'blend ' or line[:6] == 'percen': line = file.readline() opts['scfblnd'] = float(line.strip()) elif line[:6] == 'scfbl2': line = file.readline() opts['scfbl2'] = float(line.strip()) elif line[:6] == 'conver': line = file.readline() opts['scfconv'] = float(line.strip()) elif line[:6] == 'alfast': line = file.readline() opts['alfast'] = float(line.strip()) elif line[:6] == 'cutii ': line = file.readline() opts['convii'] = float(line.strip()) elif line[:6] == 'cutslo': line = file.readline() opts['convsl'] = float(line.strip()) elif line[:6] == 'cut2s ': line = file.readline() opts['conv2s'] = float(line.strip()) elif line[:6] == 'cutset': line = file.readline() opts['cutset'] = float(line.strip()) elif line[:6] == 'cutfrc': line = file.readline() opts['cutfrc'] = float(line.strip()) elif line[:6] == 'cutgrd': line = file.readline() opts['convgr'] = float(line.strip()) elif line[:6] == 'cut1c ': line = file.readline() opts['conv1c'] = float(line.strip()) elif line[:6] == 'geomet': # Jump into Geometry Data opts['write_geo_sect'] = True while 1: line = file.readline() if line[:4] == 'stop' or line[:3] == 'end': break elif line[:6] == 'relax ': opts['dorelax'] = True opts['geo_dorelax'] = True elif line[:6] == 'grelax': line = file.readline() opts['relax_range'] = map(int, line.split()) elif line[:6] == 'gfixed': line = file.readline() opts['fixed_range'] = map(int, line.split()) elif line[:6] == 'only r': line = file.readline() opts['only_relax'] = int(line.strip()) elif line[:6] == 'frame ': line = file.readline() opts['relax_frame'] = map(int, line.split()) elif line[:6] == 'defect': line = file.readline() opts['defect'] = int(line.strip()) elif line[:6] == 'gblend': line = file.readline() opts['gblend'] = float(line.strip()) elif line[:5] == 'gconv': line = file.readline() opts['gconv'] = float(line.strip()) elif line[:6] == 'gstart': line = file.readline() opts['gstart'] = int(line.strip()) elif line[:6] == 'gsteps': line = file.readline() opts['gsteps'] = int(line.strip()) elif line[:6] == 'ghisto': line = file.readline() opts['nhistg'] = int(line.strip()) elif line[:6] == 'no ges': opts['igges'] = 0 elif line[:6] == 'guess ': line = file.readline() opts['igges'] = int(line.strip()) elif line[:6] == 'gmetho': line = file.readline() opts['gmethod'] = line.strip() elif line[:6] == 'timest': line = file.readline() opts['gtstep'] = float(line.strip()) else: print "Unknown geomdata line:" print line # End of Geometry Data elif line[:5] == 'cell ': # Jump into Cell Data opts['write_cell_sect'] = True while 1: line = file.readline() if line[:6] == 'end ce': break elif line[:6] == 'ucstep': line = file.readline() opts['maxucsteps'] = int(line.strip()) elif line[:6] == 'ucconv': line = file.readline() opts['ucconv'] = float(line.strip()) elif line[:6] == 'pressu': line = file.readline() opts['pressure'] = float(line.strip()) elif line[:6] == 'uniaxi': line = file.readline() opts['uniaxial'] = map(float, line.split()) elif line[:6] == 'stress': opts['stress'] = [] for i in range(opts['ndim']): line = file.readline() opts['stress'].append(map(float, line.split())) elif line[:6] == 'uchist': line = file.readline() opts['nhistuc'] = int(line.strip()) elif line[:6] == 'ucmeth': line = file.readline() opts['ucmeth'] = line.strip() elif line[:6] == 'str_br': line = file.readline() opts['strsbroy'] = float(line.strip()) elif line[:6] == 'max_st': line = file.readline() opts['strnmax'] = float(line.strip()) elif line[:6] == 'cell_f': line = file.readline() opts['cell_f'] = float(line.strip()) elif line[:6] == 'bulk_m': line = file.readline() opts['bmod'] = float(line.strip()) elif line[:6] == 'uc_ble': line = file.readline() opts['ucblend'] = float(line.strip()) else: print "Unknown celldata line:" print line # End of Cell Data else: print "Unknown rundata line:" print line # End of Run Data # Start of MD Data line = file.readline() if line[:6] == 'md dat': while 1: line = file.readline() if line[:3] == 'end': break elif line[:6] == 'temper': line = file.readline() opts['mdtemp'] = float(line.strip()) elif line[:6] == 'time s': line = file.readline() opts['ntstep'] = int(line.strip()) elif line[:6] == 'equil ': line = file.readline() opts['neqsteps'] = int(line.strip()) elif line[:6] == 'step s': line = file.readline() opts['md_dt'] = float(line.strip()) elif line[:6] == 'md typ': line = file.readline() opts['mdtype'] = line.strip() else: print "Unknown md flag" print line return material