def plot_chgint(args): chgcar = Chgcar.from_file(args.filename[0]) s = chgcar.structure if args.inds: atom_ind = map(int, args.inds[0].split(",")) else: finder = SymmetryFinder(s, symprec=0.1) sites = [ sites[0] for sites in finder.get_symmetrized_structure().equivalent_sites ] atom_ind = [s.sites.index(site) for site in sites] from pymatgen.util.plotting_utils import get_publication_quality_plot plt = get_publication_quality_plot(12, 8) for i in atom_ind: d = chgcar.get_integrated_diff(i, args.radius, 30) plt.plot(d[:, 0], d[:, 1], label="Atom {} - {}".format(i, s[i].species_string)) plt.legend(loc="upper left") plt.xlabel("Radius (A)") plt.ylabel("Integrated charge (e)") plt.tight_layout() plt.show()
def read_structure(filename): """ Reads a structure based on file extension. For example, anything ending in a "cif" is assumed to be a Crystallographic Information Format file. Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT, vasprun.xml, CSSR and pymatgen's JSON serialized structures. Args: filename (str): A filename to read from. Returns: A Structure object. """ fname = os.path.basename(filename) if fnmatch(fname.lower(), "*.cif*"): parser = CifParser(filename) return parser.get_structures(True)[0] elif fnmatch(fname, "POSCAR*") or fnmatch(fname, "CONTCAR*"): return Poscar.from_file(filename, False).structure elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"): return Chgcar.from_file(filename).structure elif fnmatch(fname, "vasprun*.xml*"): return Vasprun(filename).final_structure elif fnmatch(fname.lower(), "*.cssr*"): cssr = Cssr.from_file(filename) return cssr.structure elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"): with zopen(filename) as f: s = json.load(f, cls=PMGJSONDecoder) if type(s) != Structure: raise IOError("File does not contain a valid serialized " "structure") return s raise ValueError("Unrecognized file extension!")
def read_structure(filename): """ Reads a structure based on file extension. For example, anything ending in a "cif" is assumed to be a Crystallographic Information Format file. Args: filename: A filename to read from. Returns: A Structure object. """ lower_filename = os.path.basename(filename).lower() if re.search("\.cif", lower_filename): parser = CifParser(filename) return parser.get_structures(True)[0] elif lower_filename.startswith("poscar") \ or lower_filename.startswith("contcar"): return Poscar.from_file(filename, False).structure elif lower_filename.startswith("chgcar") \ or lower_filename.startswith("locpot"): return Chgcar.from_file(filename).structure elif re.search("vasprun", lower_filename) \ and re.search("xml", lower_filename): return Vasprun(filename).final_structure elif re.search("\.cssr", lower_filename): cssr = Cssr.from_file(filename) return cssr.structure raise ValueError("Unrecognized file extension!")
def read_structure(filename): """ Reads a structure based on file extension. For example, anything ending in a "cif" is assumed to be a Crystallographic Information Format file. Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT, vasprun.xml, CSSR and pymatgen's JSON serialized structures. Args: filename: A filename to read from. Returns: A Structure object. """ fname = os.path.basename(filename) if fnmatch(fname.lower(), "*.cif*"): parser = CifParser(filename) return parser.get_structures(True)[0] elif fnmatch(fname, "POSCAR*") or fnmatch(fname, "CONTCAR*"): return Poscar.from_file(filename, False).structure elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"): return Chgcar.from_file(filename).structure elif fnmatch(fname, "vasprun*.xml*"): return Vasprun(filename).final_structure elif fnmatch(fname.lower(), "*.cssr*"): cssr = Cssr.from_file(filename) return cssr.structure elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"): with zopen(filename) as f: s = json.load(f, cls=PMGJSONDecoder) if type(s) != Structure: raise IOError("File does not contain a valid serialized " "structure") return s raise ValueError("Unrecognized file extension!")
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 read_structure(filename, primitive=True, sort=False): """ Reads a structure based on file extension. For example, anything ending in a "cif" is assumed to be a Crystallographic Information Format file. Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT, vasprun.xml, CSSR and pymatgen's JSON serialized structures. Args: filename (str): A filename to read from. primitive (bool): Whether to convert to a primitive cell for cifs. Defaults to True. sort (bool): Whether to sort sites. Default to False. Returns: A Structure object. """ fname = os.path.basename(filename) if fnmatch(fname.lower(), "*.cif*"): parser = CifParser(filename) s = parser.get_structures(primitive=primitive)[0] elif fnmatch(fname, "POSCAR*") or fnmatch(fname, "CONTCAR*"): s = Poscar.from_file(filename, False).structure elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"): s = Chgcar.from_file(filename).structure elif fnmatch(fname, "vasprun*.xml*"): s = Vasprun(filename).final_structure elif fnmatch(fname.lower(), "*.cssr*"): cssr = Cssr.from_file(filename) s = cssr.structure elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"): with zopen(filename) as f: s = json.load(f, cls=MontyDecoder) if type(s) != Structure: raise IOError("File does not contain a valid serialized " "structure") else: raise ValueError("Unrecognized file extension!") if sort: s = s.get_sorted_structure() return s
def read_structure(filename, primitive=True, sort=False): """ Reads a structure based on file extension. For example, anything ending in a "cif" is assumed to be a Crystallographic Information Format file. Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT, vasprun.xml, CSSR and pymatgen's JSON serialized structures. Args: filename (str): A filename to read from. primitive (bool): Whether to convert to a primitive cell for cifs. Defaults to False. sort (bool): Whether to sort sites. Default to False. Returns: A Structure object. """ fname = os.path.basename(filename) if fnmatch(fname.lower(), "*.cif*"): parser = CifParser(filename) s = parser.get_structures(primitive=primitive)[0] elif fnmatch(fname, "POSCAR*") or fnmatch(fname, "CONTCAR*"): s = Poscar.from_file(filename, False).structure elif fnmatch(fname, "CHGCAR*") or fnmatch(fname, "LOCPOT*"): s = Chgcar.from_file(filename).structure elif fnmatch(fname, "vasprun*.xml*"): s = Vasprun(filename).final_structure elif fnmatch(fname.lower(), "*.cssr*"): cssr = Cssr.from_file(filename) s = cssr.structure elif fnmatch(fname, "*.json*") or fnmatch(fname, "*.mson*"): with zopen(filename) as f: s = json.load(f, cls=PMGJSONDecoder) if type(s) != Structure: raise IOError("File does not contain a valid serialized " "structure") else: raise ValueError("Unrecognized file extension!") if sort: s = s.get_sorted_structure() return s
def plot_chgint(args): chgcar = Chgcar.from_file(args.filename[0]) s = chgcar.structure if args.inds: atom_ind = map(int, args.inds[0].split(",")) else: finder = SymmetryFinder(s, symprec=0.1) sites = [sites[0] for sites in finder.get_symmetrized_structure().equivalent_sites] atom_ind = [s.sites.index(site) for site in sites] from pymatgen.util.plotting_utils import get_publication_quality_plot plt = get_publication_quality_plot(12, 8) for i in atom_ind: d = chgcar.get_integrated_diff(i, args.radius, 30) plt.plot(d[:, 0], d[:, 1], label="Atom {} - {}".format(i, s[i].species_string)) plt.legend(loc="upper left") plt.xlabel("Radius (A)") plt.ylabel("Integrated charge (e)") plt.tight_layout() plt.show()
def read_structure(filename): """ Reads a structure based on file extension. For example, anything ending in a "cif" is assumed to be a Crystallographic Information Format file. Supported formats include CIF, POSCAR/CONTCAR, CHGCAR, LOCPOT, vasprun.xml, CSSR and pymatgen's JSON serialized structures. Args: filename: A filename to read from. Returns: A Structure object. """ lower_filename = os.path.basename(filename).lower() if re.search("\.cif", lower_filename): parser = CifParser(filename) return parser.get_structures(True)[0] elif lower_filename.startswith("poscar") \ or lower_filename.startswith("contcar"): return Poscar.from_file(filename, False).structure elif lower_filename.startswith("chgcar") \ or lower_filename.startswith("locpot"): return Chgcar.from_file(filename).structure elif re.search("vasprun", lower_filename) \ and re.search("xml", lower_filename): return Vasprun(filename).final_structure elif re.search("\.cssr", lower_filename): cssr = Cssr.from_file(filename) return cssr.structure elif re.search("\.[mj]son", lower_filename): with zopen(lower_filename) as f: s = json.load(f, cls=PMGJSONDecoder) if type(s) != Structure: raise IOError("File does not contain a valid serialized " "structure") return s raise ValueError("Unrecognized file extension!")
def chgcar_test(): from pymatgen.io.vaspio import Chgcar c = Chgcar.from_file("../test_files/CHGCAR.noncubic") print c.get_integrated_diff(1, 2.5, 3)
def run_task(self, fw_spec): MyDB.db_access().connect() collection = MyDB.db_access().collection(fw_spec['collection']) with open('vasp.out', 'r') as output: content = output.readlines() examine = content[-2].strip() if examine[0:3] == '1 F': chgcar = Chgcar.from_file('CHGCAR') s1 = self['struct_s1'] s2 = self['struct_s2'] relax_sites = [] for site_i, site in enumerate(s1.sites): if site.specie == fw_spec['moving_cation']: relax_sites.append(site_i) pf = NEBPathfinder(s1, s2, relax_sites=relax_sites, v=ChgcarPotential(chgcar).get_v(), n_images=8) images = pf.images doc = collection.find_one({ 'mp-id': fw_spec["mp-id"], 'pair_index': fw_spec["pair_index"] }) path = [] coordination_number = [] for image in images: struct = Structure.from_dict(doc["gamma_structure"]) site_index = image.species.index(fw_spec['moving_cation']) cation_site = image[site_index] struct.insert(0, cation_site.specie, cation_site.frac_coords, properties=cation_site.properties) path.append(image[site_index].as_dict()) voro_cn = VoronoiCoordFinder(struct) cn = voro_cn.get_coordination_number(0) coordination_number.append(cn) collection.update( { "mp-id": fw_spec["mp-id"], "pair_index": fw_spec["pair_index"] }, { "$set": { "status": "success", "CN_path": coordination_number, "path": path } }) else: collection.update( { "mp-id": fw_spec["mp-id"], "pair_index": fw_spec["pair_index"] }, {"$set": { "status": "error" }}) MyDB.db_access().close() return FWAction()
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-s1', type=str, help='starting point CONTCAR') parser.add_argument('-s2', type=str, help='ending point CONTCAR') parser.add_argument('-e', type=str, help='diffusing cation') parser.add_argument('-n', type=int, default=8, help='number of interpolated images') parser.add_argument('-chg', type=str, help='CHGCAR for pathFinder') arg = parser.parse_args() s1 = Poscar.from_file(arg.s1).structure s2 = Poscar.from_file(arg.s2).structure chg = Chgcar.from_file(arg.chg) relax_sites = [] for i, site in enumerate(s1.sites): if site.specie == Element(arg.e): relax_sites.append(i) pf = NEBPathfinder(s1, s2, relax_sites=relax_sites, v=ChgcarPotential(chg).get_v(), n_images=(3 * arg.n)) images = pf.images for i, image in enumerate(images):
__email__ = '*****@*****.**' from PathFinder.pathFinder import NEBPathfinder, ChgcarPotential if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-s1', type=str, help='starting point CONTCAR') parser.add_argument('-s2', type=str, help='ending point CONTCAR') parser.add_argument('-e', type=str, help='diffusing cation') parser.add_argument('-n', type=int, default=8, help='number of interpolated images') parser.add_argument('-chg', type=str, help='CHGCAR for pathFinder') arg = parser.parse_args() s1 = Poscar.from_file(arg.s1).structure s2 = Poscar.from_file(arg.s2).structure chg = Chgcar.from_file(arg.chg) relax_sites = [] for i, site in enumerate(s1.sites): if site.specie == Element(arg.e): relax_sites.append(i) pf = NEBPathfinder(s1, s2, relax_sites=relax_sites, v=ChgcarPotential(chg).get_v(), n_images=(3*arg.n)) images = pf.images for i, image in enumerate(images): if i % 3 == 0: p = Poscar(image) directory = "0" + str(i/3) if not os.path.exists(directory):