def to_string(self, verbose=0): """String representation.""" lines = [ "ndtset: %d, completed: %s" % (self.ndtset, self.run_completed) ] app = lines.append # Different cases depending whether final structures are available # and whether structures are equivalent. if self.run_completed: if self.has_same_final_structures: if self.initial_structure != self.final_structure: # Structural relaxation. df = dataframes_from_structures( [self.initial_structure, self.final_structure], index=["initial", "final"]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) else: # initial == final. Print final structure. app(self.final_structure.to_string(verbose=verbose)) else: # Final structures are not available. if self.has_same_initial_structures: app(self.initial_structure.to_string(verbose=verbose)) else: df = dataframes_from_structures( self.initial_structures, index=[i + 1 for i in range(self.ndtset)]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) # Print dataframe with dimensions. dims_dataset, spginfo_dataset = self.get_dims_spginfo_dataset( verbose=verbose) rows = [] for dtind, dims in dims_dataset.items(): d = OrderedDict() d["dataset"] = dtind d.update(dims) d.update(spginfo_dataset[dtind]) rows.append(d) from abipy.tools.printing import print_dataframe df = pd.DataFrame(rows, columns=list(rows[0].keys()) if rows else None) df = df.set_index('dataset') strio = cStringIO() print_dataframe(df, file=strio) strio.seek(0) app("") app(marquee("Dimensions of calculation", mark="=")) app("".join(strio)) return "\n".join(lines)
def to_string(self, verbose=0): """String representation.""" lines = ["ndtset: %d, completed: %s" % (self.ndtset, self.run_completed)] app = lines.append # Different cases depending whether final structures are available # and whether structures are equivalent. if self.run_completed: if self.has_same_final_structures: if self.initial_structure != self.final_structure: # Structural relaxation. df = dataframes_from_structures([self.initial_structure, self.final_structure], index=["initial", "final"]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) else: # initial == final. Print final structure. app(self.final_structure.to_string(verbose=verbose)) else: # Final structures are not available. if self.has_same_initial_structures: app(self.initial_structure.to_string(verbose=verbose)) else: df = dataframes_from_structures(self.initial_structures, index=[i+1 for i in range(self.ndtset)]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) # Print dataframe with dimensions. dims_dataset, spginfo_dataset = self.get_dims_spginfo_dataset(verbose=verbose) rows = [] for dtind, dims in dims_dataset.items(): d = OrderedDict() d["dataset"] = dtind d.update(dims) d.update(spginfo_dataset[dtind]) rows.append(d) from abipy.tools.printing import print_dataframe df = pd.DataFrame(rows, columns=list(rows[0].keys()) if rows else None) df = df.set_index('dataset') strio = cStringIO() print_dataframe(df, file=strio) strio.seek(0) app("") app(marquee("Dimensions of calculation", mark="=")) app("".join(strio)) return "\n".join(lines)
def to_string(self, verbose=0): """String representation.""" lines = [] app = lines.append header = 10 * "=" + " Input File " + 10 * "=" app(header) app(self.string) app(len(header) * "=" + "\n") # Print info on structure(s). if self.structure is not None: app(self.structure.spget_summary()) else: structures = [dt.structure for dt in self.datasets] app("Input file contains %d structures:" % len(structures)) for i, structure in enumerate(structures): app(boxed("Dataset: %d" % (i + 1))) app(structure.spget_summary()) app("") dfs = dataframes_from_structures( structures, index=[i + 1 for i in range(self.ndtset)]) app( boxed( "Tabular view (each row corresponds to a dataset structure)" )) app("") app("Lattice parameters:") app(str(dfs.lattice)) app("") app("Atomic positions:") app(str(dfs.coords)) return "\n".join(lines)
def to_string(self, verbose=0): """String representation.""" lines = [] app = lines.append header = 10 * "=" + " Input File " + 10 * "=" app(header) app(self.string) app(len(header) * "=" + "\n") # Print info on structure(s). if self.structure is not None: app(self.structure.spget_summary()) else: structures = [dt.structure for dt in self.datasets] app("Input file contains %d structures:" % len(structures)) for i, structure in enumerate(structures): app(boxed("Dataset: %d" % (i+1))) app(structure.spget_summary()) app("") dfs = dataframes_from_structures(structures, index=[i+1 for i in range(self.ndtset)]) app(boxed("Tabular view (each row corresponds to a dataset structure)")) app("") app("Lattice parameters:") app(str(dfs.lattice)) app("") app("Atomic positions:") app(str(dfs.coords)) return "\n".join(lines)
def to_string(self, verbose=0): """String representation.""" lines = [ "ndtset: %d, completed: %s" % (self.ndtset, self.run_completed) ] app = lines.append # Different cases depending whether final structures are available # and whether structures are equivalent. if self.run_completed: if self.has_same_final_structures: if self.initial_structure != self.final_structure: # Structural relaxation. df = dataframes_from_structures( [self.initial_structure, self.final_structure], index=["initial", "final"]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) else: # initial == final. Print final structure. app(self.final_structure.to_string(verbose=verbose)) else: # Final structures are not available. if self.has_same_initial_structures: app(self.initial_structure.to_string(verbose=verbose)) else: df = dataframes_from_structures( self.initial_structures, index=[i + 1 for i in range(self.ndtset)]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) # Print dataframe with dimensions. df = self.get_dims_spginfo_dataframe(verbose=verbose) from abipy.tools.printing import print_dataframe strio = StringIO() print_dataframe(df, file=strio) strio.seek(0) app("") app(marquee("Dimensions of calculation", mark="=")) app("".join(strio)) return "\n".join(lines)
def to_string(self, verbose=0): """String representation.""" lines = [ "ndtset: %d, completed: %s" % (self.ndtset, self.run_completed) ] app = lines.append # Different cases depending whether final structures are available # and whether structures are equivalent. if self.run_completed: if self.has_same_final_structures: if self.initial_structure != self.final_structure: # Structural relaxation. df = dataframes_from_structures( [self.initial_structure, self.final_structure], index=["initial", "final"]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) else: # initial == final. Print final structure. app(self.final_structure.to_string(verbose=verbose)) else: # Final structures are not available. if self.has_same_initial_structures: app(self.initial_structure.to_string(verbose=verbose)) else: df = dataframes_from_structures( self.initial_structures, index=[i + 1 for i in range(self.ndtset)]) app("Lattice parameters:") app(str(df.lattice)) app("Atomic coordinates:") app(str(df.coords)) return "\n".join(lines)
def print_dataframes(self, with_spglib=False, file=sys.stdout, verbose=0): """ Print pandas dataframe to file `file`. Args: with_spglib: True to compute spacegroup with spglib. file: Output stream. verbose: Verbosity level. """ print_dataframe(self.dataframe, file=file) if verbose: from abipy.core.structure import dataframes_from_structures dfs = dataframes_from_structures(self.structures, index=self.mpids, with_spglib=with_spglib) print_dataframe(dfs.lattice, title="Lattice parameters:", file=file) if verbose > 1: print_dataframe(dfs.coords, title="Atomic positions (columns give the site index):", file=file)
def get_structure_dataframes(self, abspath=False, filter_abifile=None, **kwargs): """ Wrap dataframes_from_structures function. Args: abspath: True if paths in index should be absolute. Default: Relative to getcwd(). filter_abifile: Function that receives an ``abifile`` object and returns True if the file should be added to the plotter. """ from abipy.core.structure import dataframes_from_structures if "index" not in kwargs: index = list(self._abifiles.keys()) if not abspath: index = self._to_relpaths(index) kwargs["index"] = index abifiles = self.abifiles if filter_abifile is not None else list(filter(filter_abifile, self.abifiles)) return dataframes_from_structures(struct_objects=abifiles, **kwargs)
def structure_dataframes(self): """Pandas dataframes constructed from self.structures.""" from abipy.core.structure import dataframes_from_structures return dataframes_from_structures(self.structures, index=self.ids, with_spglib=True)