Esempio n. 1
0
def abiview_ddb_ifc(options):
    """
    Visualize interatomic force constants in real space.
    """
    asr = 2
    chneut = 1
    dipdip = 1
    print("""
Computing interatomic force constants with
asr = {asr}, chneut = {chneut}, dipdip = {dipdip}
""".format(**locals()))

    with abilab.abiopen(options.filepath) as ddb:
        # Execute anaddb to compute the interatomic force constants.
        ifc = ddb.anaget_ifc(asr=asr, chneut=chneut, dipdip=dipdip)
        #print(ifc)
        with MplExpose(slide_mode=options.slide_mode,
                       slide_timeout=options.slide_timeout) as e:
            e(ifc.plot_longitudinal_ifc(title="Longitudinal IFCs", show=False))
            e(
                ifc.plot_longitudinal_ifc_short_range(
                    title="Longitudinal IFCs short range", show=False))
            e(
                ifc.plot_longitudinal_ifc_ewald(
                    title="Longitudinal IFCs Ewald", show=False))

    return 0
Esempio n. 2
0
File: mixins.py Progetto: w6ye/abipy
 def expose(self, slide_mode=False, slide_timeout=None, **kwargs):
     """
     Shows a predefined list of matplotlib figures with minimal input from the user.
     """
     from abipy.tools.plotting import MplExpose
     with MplExpose(slide_mode=slide_mode, slide_timeout=slide_mode, verbose=1) as e:
         e(self.yield_figs(**kwargs))
Esempio n. 3
0
def abiview_ddb(options):
    """
    Invoke Anaddb to compute phonon bands and DOS from the DDB, plot the results.
    """
    with abilab.abiopen(options.filepath) as ddb:
        print(ddb.to_string(verbose=options.verbose))

        # Don't need PHDOS if phononwebsite
        nqsmall = 0 if options.phononwebsite else 10
        ndivsm = 20; asr = 2; chneut = 1; dipdip = 1; dos_method = "tetra"; lo_to_splitting = "automatic"
        print("""
Computing phonon bands and DOS from DDB file with:
nqsmall: {nqsmall}, ndivsm: {ndivsm},
asr: {asr}, chneut: {chneut}, dipdip: {dipdip}, lo_to_splitting: {lo_to_splitting}, dos_method: {dos_method}
""".format(**locals()))

        print("Invoking anaddb ...  ", end="")
        phbst_file, phdos_file = ddb.anaget_phbst_and_phdos_files(
            nqsmall=nqsmall, ndivsm=ndivsm, asr=asr, chneut=chneut, dipdip=dipdip, dos_method=dos_method,
            lo_to_splitting=lo_to_splitting, verbose=options.verbose, mpi_procs=1)
        print("Calculation completed.\nResults available in:", os.path.dirname(phbst_file.filepath))

        phbands = phbst_file.phbands

        if options.xmgrace:
            outpath = options.filepath + ".agr"
            phbands.to_xmgrace(handle_overwrite(outpath, options))
            return 0
        #elif options.bxsf:
        #    outpath = options.filepath + ".bxsf"
        #    phbands.to_bxsf(handle_overwrite(outpath, options))
        #    return 0
        elif options.phononwebsite:
            return phbands.view_phononwebsite(browser=options.browser, verbose=options.verbose)
        else:
            phdos = phdos_file.phdos
            units = "mev"
            with MplExpose(slide_mode=options.slide_mode, slide_timeout=options.slide_timeout) as e:
                #e(phbst_file.expose())
                #e(phdos_file.expose())
                e(phbands.qpoints.plot(show=False))
                e(phbands.plot_with_phdos(phdos, units=units, show=False))
                e(phbands.plot_colored_matched(units=units, show=False))
                e(phbands.plot_fatbands(units=units, phdos_file=phdos_file, show=False))
                e(phdos.plot(units=units, show=False))
                e(phdos_file.plot_pjdos_type(units=units, show=False))
                #try
                #    msq_dos = phdos_file.msq_dos
                #except RuntimeError:
                #    msq_dos = None
                #if msq_dos is not None:
                #    e(msq_dos.plot_uiso(show=False))
                #    e(msq_dos.plot_uiso(show=False))

        phbst_file.close()
        phdos_file.close()

    return 0
Esempio n. 4
0
    def plot(self, tight_layout=True, with_timer=False, show=True):
        """
        Plot GS/DFPT SCF cycles and timer data found in the output file.

        Args:
            with_timer: True if timer section should be plotted
        """
        from abipy.tools.plotting import MplExpose
        with MplExpose(slide_mode=False, slide_timeout=5.0) as e:
            e(self.yield_figs(tight_layout=tight_layout, with_timer=with_timer))
Esempio n. 5
0
def main():
    def show_examples_and_exit(err_msg=None, error_code=1):
        """Display the usage of the script."""
        sys.stderr.write(get_epilog())
        if err_msg:
            sys.stderr.write("Fatal Error\n" + err_msg + "\n")
        sys.exit(error_code)

    parser = get_parser(with_epilog=True)

    # Parse the command line.
    try:
        options = parser.parse_args()
    except Exception:
        show_examples_and_exit(error_code=1)

    # loglevel is bound to the string value obtained from the command line argument.
    # Convert to upper case to allow the user to specify --loglevel=DEBUG or --loglevel=debug
    import logging
    numeric_level = getattr(logging, options.loglevel.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError('Invalid log level: %s' % options.loglevel)
    logging.basicConfig(level=numeric_level)

    if options.verbose > 2:
        print(options)

    if options.mpl_backend is not None:
        # Set matplotlib backend
        import matplotlib
        matplotlib.use(options.mpl_backend)

    if options.seaborn:
        # Use seaborn settings.
        import seaborn as sns
        sns.set(context=options.seaborn,
                style='darkgrid',
                palette='deep',
                font='sans-serif',
                font_scale=1,
                color_codes=False,
                rc=None)

    if not os.path.exists(options.filepath):
        raise RuntimeError("%s: no such file" % options.filepath)

    if not options.notebook:
        abifile = abilab.abiopen(options.filepath)

        if options.print:
            # Print object to terminal.
            if hasattr(abifile, "to_string"):
                print(abifile.to_string(verbose=options.verbose))
            else:
                print(abifile)
            return 0

        elif options.expose:
            # Generate matplotlib plots automatically.
            if hasattr(abifile, "to_string"):
                print(abifile.to_string(verbose=options.verbose))
            else:
                print(abifile)

            if hasattr(abifile, "expose"):

                abifile.expose(slide_mode=options.slide_mode,
                               slide_timeout=options.slide_timeout,
                               verbose=options.verbose)
            else:
                if not hasattr(abifile, "yield_figs"):
                    raise TypeError(
                        "Object of type `%s` does not implement (expose or yield_figs methods"
                        % type(abifile))
                from abipy.tools.plotting import MplExpose
                with MplExpose(slide_mode=options.slide_mode,
                               slide_timeout=options.slide_timeout,
                               verbose=options.verbose) as e:
                    e(abifile.yield_figs())

            return 0

        # Start ipython shell with namespace
        # Use embed because I don't know how to show a header with start_ipython.
        import IPython
        IPython.embed(
            header=
            "The Abinit file is bound to the `abifile` variable.\nTry `print(abifile)`"
        )

    else:
        # Call specialized method if the object is a NotebookWriter
        # else generate simple notebook by calling `make_and_open_notebook`
        cls = abilab.abifile_subclass_from_filename(options.filepath)
        if hasattr(cls, "make_and_open_notebook"):
            if hasattr(cls, "__exit__"):
                with abilab.abiopen(options.filepath) as abifile:
                    return abifile.make_and_open_notebook(
                        foreground=options.foreground)
            else:
                abifile = abilab.abiopen(options.filepath)
                return abifile.make_and_open_notebook(
                    foreground=options.foreground)
        else:
            return make_and_open_notebook(options)

    return 0