def _vasp_potcar_setup(self, my_poscar): """Set up the POTCAR file.""" name = self.keywords['name'] if 'mast_xc' in self.keywords['program_keys'].keys(): myxc = self.keywords['program_keys']['mast_xc'].upper() #Uppercase else: raise MASTError("vasp_checker, _vasp_potcar_setup","Exchange correlation functional needs to be specified in ingredients keyword mast_xc") if ('mast_pp_setup' in self.keywords['program_keys'].keys()): sites = my_poscar.site_symbols setup = self.keywords['program_keys']['mast_pp_setup'] pp_sites = list() for site in sites: try: pp_sites.append(setup[site]) except KeyError: pp_sites.append(site) my_potcar = Potcar(symbols=pp_sites, functional=myxc, sym_potcar_map=None) else: my_potcar = Potcar(symbols=my_poscar.site_symbols, functional=myxc, sym_potcar_map=None) dirutil.lock_directory(name) my_potcar.write_file(name + "/POTCAR") dirutil.unlock_directory(name) return my_potcar
def gen_potcar(dirname, filename): if filename == "POTCAR.spec": fullpath = os.path.join(dirname, filename) f = open(fullpath, "r") elements = f.readlines() f.close() symbols = [el.strip() for el in elements if el.strip() != ""] potcar = Potcar(symbols) potcar.write_file(os.path.join(dirname, "POTCAR"))
def scaleCell(path,volume): poscar = os.path.join(path,'POSCAR') refcar = os.path.join(path,'REFCAR') potcar = Potcar() assert os.path.isfile(poscar) struct = read_structure(poscar) struct.scale_lattice(volume) species = [ pot.element for pot in potcar.from_file('POTCAR') ] reprule = { old:new for old,new in zip(struct.composition.elements,species) } struct.replace_species(reprule) p = Poscar(struct) with open(poscar) as f: poscomment = f.readline().strip() p.comment = poscomment p.write_file(poscar,vasp4_compatible=True) if os.path.isfile(refcar): tmp = os.path.join(path,'POSCARtmp') # copy Poscar to temporary file and refcar to poscar copyfile(poscar,tmp) copyfile(refcar,poscar) struct = read_structure(poscar) struct.scale_lattice(volume) species = [ pot.element for pot in potcar.from_file('POTCAR') ] reprule = { old:new for old,new in zip(struct.composition.elements,species) } struct.replace_species(reprule) r = Poscar(struct) with open(poscar) as f: poscomment = f.readline().strip() r.comment = poscomment r.write_file(poscar,vasp4_compatible=True) with open(refcar) as f: poscomment = f.readline().strip() r.comment = poscomment r.write_file(refcar,vasp4_compatible=True) # replace poscar with its original move(tmp,poscar) else: print 'No REFCAR found.'
def __init__(self, acf_path='./ACF.dat', chgcar_filename="./CHGCAR", aecar0="./AECCAR0", aecar2="./AECCAR2", potcar_filename="./POTCAR", bader_path="./bader CHGCAR -ref Charge_sum"): print "Reading CHGCAR" self.chgcar = Chgcar.from_file(chgcar_filename) ##uncomment if you have to run from scratch## # self.contcar = Structure.from_file(contcar_filename) # print "Reading AECCAR0" # Vol_obj_1 = Chgcar.from_file(aecar0) # print "Reading AECCAR2" # Vol_obj_2 = Chgcar.from_file(aecar2) # print "Summing" # Vol_obj_sum = Vol_obj_1.linear_add(Vol_obj_2) # print "Writing Combined Sum" # Vol_obj_sum.write_file("./Charge_sum") # self.exe = bader_path # os.system(self.exe) self.potcar = Potcar.from_file( potcar_filename) if potcar_filename is not None else None self.natoms = self.chgcar.poscar.natoms chgcarpath = os.path.abspath(chgcar_filename) data = [] with open(acf_path) as f: print "Reading ACF" raw = f.readlines() headers = [s.lower() for s in raw.pop(0).split()] raw.pop(0) while True: l = raw.pop(0).strip() if l.startswith("-"): break vals = map(float, l.split()[1:]) data.append(dict(zip(headers[1:], vals))) for l in raw: toks = l.strip().split(":") if toks[0] == "VACUUM CHARGE": self.vacuum_charge = float(toks[1]) elif toks[0] == "VACUUM VOLUME": self.vacuum_volume = float(toks[1]) elif toks[0] == "NUMBER OF ELECTRONS": self.nelectrons = float(toks[1]) self.data = data
def process_killed_run(cls, dir_name): """ Process a killed vasp run. """ fullpath = os.path.abspath(dir_name) logger.info("Processing Killed run " + fullpath) d = {"dir_name": fullpath, "state": "killed", "oszicar": {}} for f in os.listdir(dir_name): filename = os.path.join(dir_name, f) if fnmatch(f, "INCAR*"): try: incar = Incar.from_file(filename) d["incar"] = incar.to_dict d["is_hubbard"] = incar.get("LDAU", False) if d["is_hubbard"]: us = incar.get("LDAUU", []) js = incar.get("LDAUJ", []) if sum(us) == 0 and sum(js) == 0: d["is_hubbard"] = False d["hubbards"] = {} else: d["hubbards"] = {} if d["is_hubbard"]: d["run_type"] = "GGA+U" elif incar.get("LHFCALC", False): d["run_type"] = "HF" else: d["run_type"] = "GGA" except Exception as ex: print str(ex) logger.error("Unable to parse INCAR for killed run {}.".format(dir_name)) elif fnmatch(f, "KPOINTS*"): try: kpoints = Kpoints.from_file(filename) d["kpoints"] = kpoints.to_dict except: logger.error("Unable to parse KPOINTS for killed run {}.".format(dir_name)) elif fnmatch(f, "POSCAR*"): try: s = Poscar.from_file(filename).structure comp = s.composition el_amt = s.composition.get_el_amt_dict() d.update( { "unit_cell_formula": comp.to_dict, "reduced_cell_formula": comp.to_reduced_dict, "elements": list(el_amt.keys()), "nelements": len(el_amt), "pretty_formula": comp.reduced_formula, "anonymous_formula": comp.anonymized_formula, "nsites": comp.num_atoms, "chemsys": "-".join(sorted(el_amt.keys())), } ) d["poscar"] = s.to_dict except: logger.error("Unable to parse POSCAR for killed run {}.".format(dir_name)) elif fnmatch(f, "POTCAR*"): try: potcar = Potcar.from_file(filename) d["pseudo_potential"] = {"functional": "pbe", "pot_type": "paw", "labels": potcar.symbols} except: logger.error("Unable to parse POTCAR for killed run in {}.".format(dir_name)) elif fnmatch(f, "OSZICAR"): try: d["oszicar"]["root"] = Oszicar(os.path.join(dir_name, f)).to_dict except: logger.error("Unable to parse OSZICAR for killed run in {}.".format(dir_name)) elif re.match("relax\d", f): if os.path.exists(os.path.join(dir_name, f, "OSZICAR")): try: d["oszicar"][f] = Oszicar(os.path.join(dir_name, f, "OSZICAR")).to_dict except: logger.error("Unable to parse OSZICAR for killed " "run in {}.".format(dir_name)) return d
def process_killed_run(cls, dir_name): """ Process a killed vasp run. """ fullpath = os.path.abspath(dir_name) logger.info("Processing Killed run " + fullpath) d = {"dir_name": fullpath, "state": "killed", "oszicar": {}} for f in os.listdir(dir_name): filename = os.path.join(dir_name, f) if fnmatch(f, "INCAR*"): try: incar = Incar.from_file(filename) d["incar"] = incar.to_dict d["is_hubbard"] = incar.get("LDAU", False) if d["is_hubbard"]: us = incar.get("LDAUU", []) js = incar.get("LDAUJ", []) if sum(us) == 0 and sum(js) == 0: d["is_hubbard"] = False d["hubbards"] = {} else: d["hubbards"] = {} if d["is_hubbard"]: d["run_type"] = "GGA+U" elif incar.get("LHFCALC", False): d["run_type"] = "HF" else: d["run_type"] = "GGA" except Exception as ex: print str(ex) logger.error( "Unable to parse INCAR for killed run {}.".format( dir_name)) elif fnmatch(f, "KPOINTS*"): try: kpoints = Kpoints.from_file(filename) d["kpoints"] = kpoints.to_dict except: logger.error( "Unable to parse KPOINTS for killed run {}.".format( dir_name)) elif fnmatch(f, "POSCAR*"): try: s = Poscar.from_file(filename).structure comp = s.composition el_amt = s.composition.get_el_amt_dict() d.update({ "unit_cell_formula": comp.to_dict, "reduced_cell_formula": comp.to_reduced_dict, "elements": list(el_amt.keys()), "nelements": len(el_amt), "pretty_formula": comp.reduced_formula, "anonymous_formula": comp.anonymized_formula, "nsites": comp.num_atoms, "chemsys": "-".join(sorted(el_amt.keys())) }) d["poscar"] = s.to_dict except: logger.error( "Unable to parse POSCAR for killed run {}.".format( dir_name)) elif fnmatch(f, "POTCAR*"): try: potcar = Potcar.from_file(filename) d["pseudo_potential"] = { "functional": "pbe", "pot_type": "paw", "labels": potcar.symbols } except: logger.error( "Unable to parse POTCAR for killed run in {}.".format( dir_name)) elif fnmatch(f, "OSZICAR"): try: d["oszicar"]["root"] = \ Oszicar(os.path.join(dir_name, f)).to_dict except: logger.error( "Unable to parse OSZICAR for killed run in {}.".format( dir_name)) elif re.match("relax\d", f): if os.path.exists(os.path.join(dir_name, f, "OSZICAR")): try: d["oszicar"][f] = Oszicar( os.path.join(dir_name, f, "OSZICAR")).to_dict except: logger.error("Unable to parse OSZICAR for killed " "run in {}.".format(dir_name)) return d
def test_init(self): filepath = os.path.join(test_dir, 'POTCAR') potcar = Potcar.from_file(filepath) self.assertEqual(potcar.symbols, ["Fe", "P", "O"], "Wrong symbols read in for POTCAR")