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(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 plot_cohps_of_neighbors( self, path_to_COHPCAR="COHPCAR.lobster", isites=[], onlycation_isites=True, only_bonds_to=None, per_bond=False, summed_spin_channels=False, xlim=None, ylim=[-10, 6], integrated=False, ): """ will plot summed cohps (please be careful in the spin polarized case (plots might overlap (exactly!)) Args: isites: list of site ids, if isite==[], all isites will be used to add the icohps of the neighbors onlycation_isites: bool, will only use cations, if isite==[] only_bonds_to: list of str, only anions in this list will be considered per_bond: bool, will lead to a normalization of the plotted COHP per number of bond if True, otherwise the sum will be plotted xlim: list of float, limits of x values ylim: list of float, limits of y values integrated: bool, if true will show integrated cohp instead of cohp Returns: plt of the cohps """ # include COHPPlotter and plot a sum of these COHPs # might include option to add Spin channels # implement only_bonds_to cp = CohpPlotter() plotlabel, summed_cohp = self.get_info_cohps_to_neighbors( path_to_COHPCAR, isites, only_bonds_to, onlycation_isites, per_bond, summed_spin_channels=summed_spin_channels, ) cp.add_cohp(plotlabel, summed_cohp) plot = cp.get_plot(integrated=integrated) if xlim is not None: plot.xlim(xlim) if ylim is not None: plot.ylim(ylim) return plot
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')): os.makedirs(os.path.join('COHPs')) except OSError as e: if e.errno != errno.EEXIST: print("WARNING: COHPs directory already exists") raise for idx in idx_list: species1 = completecohp.bonds[idx]['sites'][0] species2 = completecohp.bonds[idx]['sites'][1] plotlabel = str(species1.species_string) + '-' + str( species2.species_string)
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')