Beispiel #1
0
    def to_string(self, verbose=0):
        """
        Human-readable string with useful information on the object.

        Args:
            verbose: Verbosity level.
        """
        lines = []; app = lines.append

        app(self.structure.to_string(verbose=verbose, title="Structure"))
        app("")
        app(marquee(r"Fullfilment of \int dw g_ij(w) = \delta_ij", mark="="))
        app("")
        from scipy.integrate import simps
        for iatom, site in enumerate(self.structure):
            d = simps(self.values[iatom], x=self.wmesh)
            app("For site: %s" % site)
            app(str(d))
            app("Trace: %.4f, determinant: %.4f" % (d.trace(), np.linalg.det(d)))
            app("")

        for fmt in ("cartesian", "cif"):
            df = self.get_dataframe(temp=300, view="inequivalent", fmt=fmt, verbose=verbose)
            s = print_dataframe(df, title="Format: %s" % fmt, file="string")
            lines.extend(s.splitlines())

        title = marquee("Constraints on tensor components in reduced coords induced by site symmetries", mark="=")
        s = print_dataframe(self.structure.site_symmetries.get_tensor_rank2_dataframe(), file="string", title=title)
        lines.extend(s.splitlines())

        #if verbose > 1:
            #max_err = self.check_site_symmetries(verbose=verbose)

        return "\n".join(lines)
Beispiel #2
0
    def print_results(self, fmt="abivars", verbose=0, file=sys.stdout):
        """
        Print pandas dataframe, structures using format `fmt`, and data to file `file`.
        `fmt` is automaticall set to `cif` if structure is disordered.
        Set fmt to None or empty string to disable structure output.
        """
        print("\n# Found %s structures in %s database (use `verbose` to get further info)\n"
                % (len(self.structures), self.dbname), file=file)

        if self.dataframe is not None: print_dataframe(self.dataframe, file=file)
        if verbose and self.data is not None: pprint(self.data, stream=file)

        # Print structures
        print_structures = not (fmt is None or str(fmt) == "None")
        if print_structures:
            for i, structure in enumerate(self.structures):
                print(" ", file=file)
                print(marquee("%s input for %s" % (fmt, self.ids[i]), mark="#"), file=file)
                print("# " + structure.spget_summary(verbose=verbose).replace("\n", "\n# ") + "\n", file=file)
                if not structure.is_ordered:
                    print(structure.convert(fmt="cif"), file=file)
                else:
                    print(structure.convert(fmt=fmt), file=file)
                print(2 * "\n", file=file)

        if len(self.structures) > 10:
            # Print info again
            print("\n# Found %s structures in %s database (use `verbose` to get further info)\n"
                    % (len(self.structures), self.dbname), file=file)
Beispiel #3
0
    def print_results(self, fmt="abivars", verbose=0, file=sys.stdout):
        """
        Print pandas dataframe, structures using format `fmt`, and data to file `file`.
        `fmt` is automaticall set to `cif` if structure is disordered.
        Set fmt to None or empty string to disable structure output.
        """
        print("\n# Found %s structures in %s database (use `verbose` to get further info)\n"
                % (len(self.structures), self.dbname), file=file)

        if self.dataframe is not None: print_dataframe(self.dataframe, file=file)
        if verbose and self.data is not None: pprint(self.data, stream=file)

        # Print structures
        print_structures = not (fmt is None or str(fmt) == "None")
        if print_structures:
            for i, structure in enumerate(self.structures):
                print(" ", file=file)
                print(marquee("%s input for %s" % (fmt, self.ids[i]), mark="#"), file=file)
                print("# " + structure.spget_summary(verbose=verbose).replace("\n", "\n# ") + "\n", file=file)
                if not structure.is_ordered:
                    print(structure.convert(fmt="cif"), file=file)
                else:
                    print(structure.convert(fmt=fmt), file=file)
                print(2 * "\n", file=file)

        if len(self.structures) > 10:
            # Print info again
            print("\n# Found %s structures in %s database (use `verbose` to get further info)\n"
                    % (len(self.structures), self.dbname), file=file)
Beispiel #4
0
 def summarize(self, acc=4):
     self._consistency_check()
     for segment in self.segments:
         df = segment.get_dataframe_with_accuracies(acc_list=[acc])
         title = "k: %s, spin: %s, nbands: %d" % (repr(
             segment.k0), segment.spin, segment.nb)
         #label="direction: %s" % segment.kdir.tos(m="fracart") if ib == 0 else None)
         print_dataframe(df, title=title)
Beispiel #5
0
    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)
Beispiel #6
0
    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)
Beispiel #7
0
    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)
Beispiel #8
0
    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)
Beispiel #9
0
    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)