def setUp(self): path = os.path.join(test_dir, "cohp", "complete_cohp_lobster.json") with open(os.path.join(path), "r") as f: self.cohp = CompleteCohp.from_dict(json.load(f)) path = os.path.join(test_dir, "cohp", "complete_coop_lobster.json") with open(os.path.join(path), "r") as f: self.coop = CompleteCohp.from_dict(json.load(f)) self.cohp_plot = CohpPlotter(zero_at_efermi=False) self.coop_plot = CohpPlotter(are_coops=True)
def setUp(self): path = os.path.join(test_dir, "cohp", "complete_cohp_lobster.json") with open(os.path.join(path), "r") as f: self.cohp = CompleteCohp.from_dict(json.load(f)) path = os.path.join(test_dir, "cohp", "complete_coop_lobster.json") with open(os.path.join(path), "r") as f: self.coop = CompleteCohp.from_dict(json.load(f)) self.cohp_plot = CohpPlotter(zero_at_efermi=False) self.coop_plot = CohpPlotter(are_coops=True) warnings.simplefilter("ignore")
def setUp(self): path = os.path.join(PymatgenTest.TEST_FILES_DIR, "cohp", "complete_cohp_lobster.json") with open(os.path.join(path)) as f: self.cohp = CompleteCohp.from_dict(json.load(f)) path = os.path.join(PymatgenTest.TEST_FILES_DIR, "cohp", "complete_coop_lobster.json") with open(os.path.join(path)) as f: self.coop = CompleteCohp.from_dict(json.load(f)) self.cohp_plot = CohpPlotter(zero_at_efermi=False) self.coop_plot = CohpPlotter(are_coops=True) warnings.simplefilter("ignore")
def setUp(self): filepath = os.path.join(test_dir, "complete_cohp_lobster.json") with open(filepath, "r") as f: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_coop_lobster.json") with open(filepath, "r") as f: self.coop_lobster_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_cohp_lmto.json") with open(filepath, "r") as f: self.cohp_lmto_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "COPL.BiSe") structure = os.path.join(test_dir, "CTRL.BiSe") self.cohp_lmto = CompleteCohp.from_file("lmto", filename=filepath, structure_file=structure) filepath = os.path.join(test_dir, "COHPCAR.lobster") structure = os.path.join(test_dir, "POSCAR") self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) filepath = os.path.join(test_dir, "COOPCAR.lobster.BiSe") structure = os.path.join(test_dir, "POSCAR.BiSe") self.coop_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure, are_coops=True)
def setUp(self): filepath = os.path.join(test_dir, "complete_cohp_lobster.json") with open(filepath, "r") as f: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_coop_lobster.json") with open(filepath, "r") as f: self.coop_lobster_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_cohp_lmto.json") with open(filepath, "r") as f: self.cohp_lmto_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_cohp_orbitalwise.json") with open(filepath, "r") as f: self.cohp_orb_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "COPL.BiSe") structure = os.path.join(test_dir, "CTRL.BiSe") self.cohp_lmto = CompleteCohp.from_file("lmto", filename=filepath, structure_file=structure) filepath = os.path.join(test_dir, "COHPCAR.lobster") structure = os.path.join(test_dir, "POSCAR") self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) filepath = os.path.join(test_dir, "COOPCAR.lobster.BiSe") structure = os.path.join(test_dir, "POSCAR.BiSe") self.coop_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure, are_coops=True) filepath = os.path.join(test_dir, "COHPCAR.lobster.orbitalwise") structure = os.path.join(test_dir, "POSCAR.orbitalwise") self.cohp_orb = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) filepath = os.path.join(test_dir, "COHPCAR.lobster.notot.orbitalwise") self.cohp_notot = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure)
def get_COOP_from_folder(folder, bond="O_O"): folders = check_valid_folder(folder, bond=bond) if len(folders) == 0: print("No COOP in this folder") return (None) os.chdir(folders[0]) complete_coop = CompleteCohp.from_file("LOBSTER", are_coops=True) print("cohp sucessfully read from {}".format(folders[0])) for key, bond_dict in complete_coop.bonds.items(): print(key, bond_dict) # for key, bond_dict in complete_coop.bonds.items(): # print(" /\/\/\ ") # print(key, bond_dict) # # \D matches non digit characters # [ind_a, ind_b] = [(int(re.sub(r"\D", "", ind_str)) - 1) # for ind_str in key.split("-")] # bond_dict["atom_pair"] = [ind_a, ind_b] # # print(complete_coop.bonds) return (complete_coop)
def setUp(self): filepath = os.path.join(test_dir, "complete_cohp_lobster.json") with open(filepath, "r") as f: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_coop_lobster.json") with open(filepath, "r") as f: self.coop_lobster_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_cohp_lmto.json") with open(filepath, "r") as f: self.cohp_lmto_dict = CompleteCohp.from_dict(json.load(f)) filepath = os.path.join(test_dir, "complete_cohp_orbitalwise.json") with open(filepath, "r") as f: self.cohp_orb_dict = CompleteCohp.from_dict(json.load(f)) # Lobster 3.0 filepath = os.path.join(test_dir, "complete_cohp_forb.json") with open(filepath, "r") as f: self.cohp_lobster_forb_dict = CompleteCohp.from_dict(json.load(f)) # Lobster 2.0 filepath = os.path.join(test_dir, "COPL.BiSe") structure = os.path.join(test_dir, "CTRL.BiSe") self.cohp_lmto = CompleteCohp.from_file( "lmto", filename=filepath, structure_file=structure ) filepath = os.path.join(test_dir, "COHPCAR.lobster") structure = os.path.join(test_dir, "POSCAR") self.cohp_lobster = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure ) filepath = os.path.join(test_dir, "COOPCAR.lobster.BiSe") structure = os.path.join(test_dir, "POSCAR.BiSe") self.coop_lobster = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure, are_coops=True ) filepath = os.path.join(test_dir, "COHPCAR.lobster.orbitalwise") structure = os.path.join(test_dir, "POSCAR.orbitalwise") self.cohp_orb = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure ) filepath = os.path.join(test_dir, "COHPCAR.lobster.notot.orbitalwise") self.cohp_notot = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure ) # Lobster 3.0 filepath = os.path.join(test_dir, "COHPCAR.lobster.Na2UO4") structure = os.path.join(test_dir, "POSCAR.Na2UO4") self.cohp_lobster_forb = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure )
""" Plot COHP """ from pymatgen.electronic_structure.plotter import CohpPlotter from pymatgen.electronic_structure.cohp import CompleteCohp from pymatgen.io.lobster import Icohplist file_list = [file for file in os.listdir() if file.endswith('.lobster')] if file_list != []: COHPCAR_path = os.getcwd() + "/COHPCAR.lobster" POSCAR_path = os.getcwd() + "/POSCAR" completecohp = CompleteCohp.from_file(fmt="LOBSTER", filename=COHPCAR_path, structure_file=POSCAR_path) # Read in ICOHPLIST.lobster and get lcohpcollection object icohplist = Icohplist(filename=os.getcwd() + '/ICOHPLIST.lobster') idx_list = [idx for idx in list(icohplist.icohplist)] # search for the number of the COHP you would like to plot in ICOHPLIST.lobster # (the numbers in COHPCAR.lobster are different!) cp = CohpPlotter() # make COHPs directory try: if not (os.path.isdir('COHPs')):
def get_info_cohps_to_neighbors( self, path_to_COHPCAR="COHPCAR.lobster", isites=[], only_bonds_to=None, onlycation_isites=True, per_bond=True, summed_spin_channels=False, ): """ will return info about the cohps from all sites mentioned in isites with neighbors Args: path_to_COHPCAR: str, path to COHPCAR isites: list of int that indicate the number of the site only_bonds_to: list of str, e.g. ["O"] to only show cohps of anything to oxygen onlycation_isites: if isites=[], only cation sites will be returned per_bond: will normalize per bond summed_spin_channels: will sum all spin channels Returns: label for cohp (str), CompleteCohp object which describes all cohps of the sites as given by isites and the other parameters """ # TODO: add options for orbital-resolved cohps summed_icohps, list_icohps, number_bonds, labels, atoms = self.get_info_icohps_to_neighbors( isites=isites, onlycation_isites=onlycation_isites ) import tempfile with tempfile.TemporaryDirectory() as t: path = os.path.join(t, "POSCAR.vasp") self.structure.to(filename=path, fmt="POSCAR") completecohp = CompleteCohp.from_file(fmt="LOBSTER", filename=path_to_COHPCAR, structure_file=path) # will check that the number of bonds in ICOHPLIST and COHPCAR are identical # further checks could be implemented if len(self.Icohpcollection._list_atom1) != len(completecohp.bonds.keys()): raise ValueError("COHPCAR and ICOHPLIST do not fit together") is_spin_completecohp = Spin.down in completecohp.get_cohp_by_label("1").cohp if self.Icohpcollection.is_spin_polarized != is_spin_completecohp: raise ValueError("COHPCAR and ICOHPLIST do not fit together") if only_bonds_to is None: # sort by anion type if per_bond: divisor = len(labels) else: divisor = 1 plotlabel = self._get_plot_label(atoms, per_bond) summed_cohp = completecohp.get_summed_cohp_by_label_list( label_list=labels, divisor=divisor, summed_spin_channels=summed_spin_channels ) else: # labels of the COHPs that will be summed! # iterate through labels and atoms and check which bonds can be included new_labels = [] new_atoms = [] for label, atompair in zip(labels, atoms): # durchlaufe only_bonds_to=[] und sage ja, falls eines der Labels in atompair ist, dann speichere # new_label present = False for atomtype in only_bonds_to: if atomtype in (self._split_string(atompair[0])[0], self._split_string(atompair[1])[0]): present = True if present: new_labels.append(label) new_atoms.append(atompair) if len(new_labels) > 0: if per_bond: divisor = len(new_labels) else: divisor = 1 plotlabel = self._get_plot_label(new_atoms, per_bond) summed_cohp = completecohp.get_summed_cohp_by_label_list( label_list=new_labels, divisor=divisor, summed_spin_channels=summed_spin_channels ) else: plotlabel = None summed_cohp = None return plotlabel, summed_cohp
def get_cohp(self, xlim=[-4, 4], ylim=[-10, 6]): cohp = CompleteCohp.from_file('LOBSTER', filename=os.path.join(self.path, "COHPCAR.lobster"), structure_file=os.path.join(self.path, "CONTCAR")) plotter = CohpPlotter() plotter.add_cohp(self.name, cohp) plotter.save_plot(f'{self.path}.png', xlim=xlim, ylim=ylim, img_format='png')