def get_string(self, sort_keys=False, pretty=False): """ Returns a string representation of the input file. The reason why this method is different from the __str__ method is to provide options for pretty printing. Args: sort_keys (bool): Set to True to sort the INCAR parameters alphabetically. Defaults to False. pretty (bool): Set to True for pretty aligned output. Defaults to False. """ keys = self.keys() lines = [] for k in keys: if isinstance(self[k], list): lines.append([k, " ".join([str(i) for i in self[k]])]) else: lines.append([k, self[k]]) if pretty: return str( tabulate([[l[0], "", l[1]] for l in lines], tablefmt="plain")) return str_delimited(lines, None, "\t") + "\n"
def get_string(self, sort_keys=False, pretty=False, comment='#'): """ Returns a string representation of the INCAR. The reason why this method is different from the __str__ method is to provide options for pretty printing. Args: sort_keys (bool): Set to True to sort the INCAR parameters alphabetically. Defaults to False. pretty (bool): Set to True for pretty aligned output. Defaults to False. """ keys = self.keys() if sort_keys: keys = sorted(keys) lines = [] for k in keys: if k == "MAGMOM" and isinstance(self[k], list): value = [] if (isinstance(self[k][0], list) or isinstance(self[k][0], Magmom)) and \ (self.get("LSORBIT") or self.get("LNONCOLLINEAR")): value.append(" ".join(str(i) for j in self[k] for i in j)) elif self.get("LSORBIT") or self.get("LNONCOLLINEAR"): for m, g in itertools.groupby(self[k]): value.append("3*{}*{}".format(len(tuple(g)), m)) else: # float() to ensure backwards compatibility between # float magmoms and Magmom objects for m, g in itertools.groupby(self[k], lambda x: float(x)): value.append("{}*{}".format(len(tuple(g)), m)) lines.append([k, " ".join(value)]) elif isinstance(self[k], list): lines.append([k, " ".join([str(i) for i in self[k]])]) else: lines.append([k, self[k]]) if pretty: return comment + str( tabulate([[l[0], "=", l[1]] for l in lines], tablefmt="plain")) else: return comment + str_delimited(lines, None, " = ") + "\n"
def get_string(self, sort_keys=False, pretty=False): """ Returns a string representation of the Tags. The reason why this method is different from the __str__ method is to provide options for pretty printing. Args: sort_keys: Set to True to sort the Feff parameters alphabetically. Defaults to False. pretty: Set to True for pretty aligned output. Defaults to False. Returns: String representation of Tags. """ keys = self.keys() if sort_keys: keys = sorted(keys) lines = [] for k in keys: if isinstance(self[k], dict): if k in ["ELNES", "EXELFS"]: lines.append([k, self._stringify_val(self[k]["ENERGY"])]) beam_energy = self._stringify_val(self[k]["BEAM_ENERGY"]) beam_energy_list = beam_energy.split() if int(beam_energy_list[1] ) == 0: # aver=0, specific beam direction lines.append([beam_energy]) lines.append( [self._stringify_val(self[k]["BEAM_DIRECTION"])]) else: # no cross terms for orientation averaged spectrum beam_energy_list[2] = str(0) lines.append([self._stringify_val(beam_energy_list)]) lines.append([self._stringify_val(self[k]["ANGLES"])]) lines.append([self._stringify_val(self[k]["MESH"])]) lines.append([self._stringify_val(self[k]["POSITION"])]) else: lines.append([k, self._stringify_val(self[k])]) if pretty: return tabulate(lines) else: return str_delimited(lines, None, " ")
def get_string(self, sort_keys=False, pretty=False): """ Returns a string representation of the Tags. The reason why this method is different from the __str__ method is to provide options for pretty printing. Args: sort_keys: Set to True to sort the Feff parameters alphabetically. Defaults to False. pretty: Set to True for pretty aligned output. Defaults to False. Returns: String representation of Tags. """ keys = self.keys() if sort_keys: keys = sorted(keys) lines = [] for k in keys: if isinstance(self[k], dict): if k in ["ELNES", "EXELFS"]: lines.append([k, self._stringify_val(self[k]["ENERGY"])]) beam_energy = self._stringify_val(self[k]["BEAM_ENERGY"]) beam_energy_list = beam_energy.split() if int(beam_energy_list[1]) == 0: # aver=0, specific beam direction lines.append([beam_energy]) lines.append([self._stringify_val(self[k]["BEAM_DIRECTION"])]) else: # no cross terms for orientation averaged spectrum beam_energy_list[2] = str(0) lines.append([self._stringify_val(beam_energy_list)]) lines.append([self._stringify_val(self[k]["ANGLES"])]) lines.append([self._stringify_val(self[k]["MESH"])]) lines.append([self._stringify_val(self[k]["POSITION"])]) else: lines.append([k, self._stringify_val(self[k])]) if pretty: return tabulate(lines) else: return str_delimited(lines, None, " ")