aiida.tools.ipython package#

Submodules#

File to be executed by IPython in order to register the line magic %aiida

This file can be put into the startup folder in order to have the line magic available at startup. The start up folder is usually at .ipython/profile_default/startup/

An IPython extension that provides a magic command to load basic aiida commands.

This makes it much easier to start.

Produces output in:

  • Plaintext (IPython [qt]console)

  • HTML (IPython notebook, nbconvert --to html, --to slides)

  • JSON (IPython notebook .ipynb files)

  • LaTeX (e.g. ipython nbconvert example.ipynb --to LaTeX --post PDF)

Notes on how to load it at start: https://ipython.org/ipython-doc/3/config/intro.html

Usage#

In [1]: %load_ext aiida_magic

In [2]: %aiida
class aiida.tools.ipython.ipython_magics.AiiDALoaderMagics(**kwargs: Any)[源代码]#

基类:Magics

AiiDA magic loader.

__annotations__ = {}#
__module__ = 'aiida.tools.ipython.ipython_magics'#
_all_trait_default_generators: dict[str, t.Any] = {'config': <bound method TraitType.default of <traitlets.traitlets.Instance object>>, 'parent': <bound method TraitType.default of <traitlets.traitlets.Instance object>>}#
_descriptors = [<traitlets.traitlets.ObserveHandler object>, <traitlets.traitlets.Instance object>, <traitlets.traitlets.Instance object>]#
_instance_inits = [<bound method ObserveHandler.instance_init of <traitlets.traitlets.ObserveHandler object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>]#
_repr_html_()[源代码]#

Output in HTML format.

_repr_json_()[源代码]#

Output in JSON format.

_repr_latex_()[源代码]#

Output in LaTeX format.

_repr_pretty_(pretty_print, cycle)[源代码]#

Output in text format.

_static_immutable_initial_values: dict[str, t.Any] = {'parent': None}#
_trait_default_generators = {}#
_traits: dict[str, t.Any] = {'config': <traitlets.traitlets.Instance object>, 'parent': <traitlets.traitlets.Instance object>}#
aiida(line='', local_ns=None)[源代码]#

Load AiiDA in ipython (checking if it was already loaded), and inserts in the namespace the main AiiDA classes (the same that are loaded in verdi shell.

Usage:

%aiida [optional parameters]
magics = {'cell': {}, 'line': {'aiida': 'aiida', 'verdi': 'verdi'}}#
registered = True#
verdi(line='', local_ns=None)[源代码]#

Run the AiiDA command line tool, using the currently loaded configuration and profile.

Invoking verdi normally through the command line follows a different code path, compared to calling it directly from within an active Python interpreter. Some of those code paths we actually need here, and others can actually cause problems:

  • The VerdiCommandGroup group ensures that the context obj is set with the loaded Config and Profile, but this is not done in this manual call, so we have to built it ourselves and pass it in with the obj keyword.

  • We cannot call the aiida.cmdline.commands.cmd_verdi.verdi command directly, as that will invoke the aiida.cmdline.parameters.types.profile.ProfileParamType parameter used for the -p/--profile option that is defined on the verdi command. This will attempt to load the default profile, but here a profile has actually already been loaded. In principle, reloading a profile should not be a problem, but this magic is often used in demo notebooks where a temporary profile was created and loaded, which is not properly added to the config file (since it is temporary) and so loading the profile would fail. The solution is to not call the top-level verdi command, but the subcommand, which is the first parameter in the command line arguments defined by the line argument.

aiida.tools.ipython.ipython_magics.add_to_ns(local_ns, name, obj)[源代码]#

Add a new variable with name name and value obj to the namespace local_ns, optionally showing a warning if we are hiding an existing variable.

Example:

# assuming that local_ns is a dictionary, e.g. from locals()
import sys
add_to_ns(local_ns, 'sys', sys)
aiida.tools.ipython.ipython_magics.load_ipython_extension(ipython)[源代码]#

Registers the %aiida IPython extension.

自 v3.0.0 版本弃用: Use register_ipython_extension() instead.

aiida.tools.ipython.ipython_magics.register_ipython_extension(ipython=None)[源代码]#

Registers the %aiida IPython extension.

The %aiida IPython extension provides the same environment as the verdi shell.

参数:

ipython – InteractiveShell instance. If omitted, the global InteractiveShell is used.