Provides import/export functionalities.
To see history/git blame prior to the move to aiida.tools.importexport, explore tree: https://github.com/aiidateam/aiida-core/tree/eebef392c81e8b130834a92e1d7abf5e2e30b3ce Functionality: <tree>/aiida/orm/importexport.py Tests: <tree>/aiida/backends/tests/test_export_and_import.py
aiida.tools.importexport.
export
Export AiiDA data
Deprecated since version 1.2.1: Support for the parameters what and outfile will be removed in v2.0.0. Please use entities and filename instead, respectively.
entities (list) – a list of entity instances; they can belong to different models/entities.
filename (str) – the filename (possibly including the absolute path) of the file on which to export.
file_format (str, ExportFileFormat) – See ExportFileFormat for complete list of valid values (default: ‘zip’).
overwrite (bool) – if True, overwrite the output file without asking, if it exists. If False, raise an ArchiveExportError if the output file already exists.
ArchiveExportError
silent (bool) – suppress console prints and progress bar.
use_compression (bool) – Whether or not to compress the archive file (only valid for the zip file format).
allowed_licenses (list) – List or function. If a list, then checks whether all licenses of Data nodes are in the list. If a function, then calls function for licenses of Data nodes expecting True if license is allowed, False otherwise.
forbidden_licenses (list) – List or function. If a list, then checks whether all licenses of Data nodes are in the list. If a function, then calls function for licenses of Data nodes expecting True if license is allowed, False otherwise.
include_comments (bool) – In-/exclude export of comments for given node(s) in entities. Default: True, include comments in export (as well as relevant users).
entities
include_logs (bool) – In-/exclude export of logs for given node(s) in entities. Default: True, include logs in export.
kwargs – graph traversal rules. See aiida.common.links.GraphTraversalRules what rule names are toggleable and what the defaults are.
aiida.common.links.GraphTraversalRules
ArchiveExportError – if there are any internal errors when exporting.
LicensingException – if any node is licensed under forbidden license.
ExportFileFormat
Bases: str, enum.Enum
str
enum.Enum
Export file formats
TAR_GZIPPED
ZIP
__dict__
__module__
__weakref__
list of weak references to the object (if defined)
_generate_next_value_
_member_map_
_member_names_
_member_type_
alias of builtins.str
builtins.str
_value2member_map_
import_data
Import exported AiiDA archive to the AiiDA database and repository.
Proxy function for the backend-specific import functions. If in_path is a folder, calls extract_tree; otherwise, tries to detect the compression format (zip, tar.gz, tar.bz2, …) and calls the correct function.
in_path
in_path (str) – the path to a file or folder that can be imported in AiiDA.
group (Group) – Group wherein all imported Nodes will be placed.
Group
silent (bool) – suppress prints.
extras_mode_existing (str) – 3 letter code that will identify what to do with the extras import. The first letter acts on extras that are present in the original node and not present in the imported node. Can be either: ‘k’ (keep it) or ‘n’ (do not keep it). The second letter acts on the imported extras that are not present in the original node. Can be either: ‘c’ (create it) or ‘n’ (do not create it). The third letter defines what to do in case of a name collision. Can be either: ‘l’ (leave the old value), ‘u’ (update with a new value), ‘d’ (delete the extra), or ‘a’ (ask what to do if the content is different).
extras_mode_new (str) – ‘import’ to import extras of new nodes or ‘none’ to ignore them
comment_mode (str) – Comment import modes (when same UUIDs are found). Can be either: ‘newest’ (will keep the Comment with the most recent modification time (mtime)) or ‘overwrite’ (will overwrite existing Comments with the ones from the import file).
New and existing Nodes and Links.
dict
ArchiveImportError – if there are any internal errors when importing.
Archive
Bases: object
object
Utility class to operate on exported archive files or directories.
The main usage should be to construct the class with the filepath of the export archive as an argument. The contents will be lazily unpacked into a sand box folder which is constructed upon entering the instance within a context and which will be automatically cleaned upon leaving that context. Example:
with Archive('/some/path/archive.aiida') as archive: archive.version
FILENAME_DATA
FILENAME_METADATA
__enter__
Instantiate a SandboxFolder into which the archive can be lazily unpacked.
__exit__
Clean the sandbox folder if it was instatiated.
__init__
Initialize self. See help(type(self)) for accurate signature.
_read_json_file
Read the contents of a JSON file from the unpacked archive contents.
filename – the filename relative to the sandbox folder
a dictionary with the loaded JSON content
conversion_info
Return information about migration events that were applied to this archive.
list of conversion notifications
data
Return the loaded content of the data file
dictionary with contents of data file
ensure_unpacked
Decorator to ensure that the archive is unpacked before entering the decorated function.
ensure_within_context
Decorator to ensure that the instance is called within a context manager.
filepath
Return the filepath of the archive
the archive filepath
folder
Return the sandbox folder
sandbox folder aiida.common.folders.SandboxFolder
aiida.common.folders.SandboxFolder
get_data_statistics
Return dictionary with statistics about data content, i.e. how many entries of each entity type it contains.
a dictionary with basic details
get_info
Return a dictionary with basic information about the archive.
meta_data
Return the loaded content of the meta data file
dictionary with contents of meta data file
unpack
Unpack the archive and store the contents in a sandbox.
unpacked
Return whether the archive has been unpacked into the sandbox folder.
version_aiida
Return the version of AiiDA the archive was created with.
version number
version_format
Return the version of the archive format.
extract_zip
Extract the nodes to be imported from a zip file.
infile (str) – file path
folder (SandboxFolder) – a temporary folder used to extract the file tree
SandboxFolder
nodes_export_subfolder (str) – name of the subfolder for AiiDA nodes
silent (bool) – suppress progress bar
TypeError – if parameter types are not respected
CorruptArchive – if the archive misses files or files have incorrect formats
extract_tar
Extract the nodes to be imported from a (possibly zipped) tar file.
folder (SandboxFolder) – a temporary fodler used to extract the file tree
extract_tree
Prepare to import nodes from plain file system tree by copying in the given sandbox folder.
Note
the contents of the unpacked archive directory are copied into the sandbox folder, because the files will anyway haven to be copied to the repository at some point. By copying the contents of the source directory now and continuing operation only on the sandbox folder, we do not risk to modify the source files accidentally. During import then, the node files from the sandbox can be moved to the repository, so they won’t have to be copied again in any case.
infile (str) – absolute filepath point to the unpacked archive directory
folder (SandboxFolder) – a temporary folder to which the archive contents are copied
ExportImportException
Bases: aiida.common.exceptions.AiidaException
aiida.common.exceptions.AiidaException
Base class for all AiiDA export/import module exceptions.
Bases: aiida.tools.importexport.common.exceptions.ExportImportException
aiida.tools.importexport.common.exceptions.ExportImportException
Base class for all AiiDA export exceptions.
ArchiveImportError
Base class for all AiiDA import exceptions.
CorruptArchive
Raised when an operation is applied to a corrupt export archive, e.g. missing files or invalid formats.
IncompatibleArchiveVersionError
Raised when trying to import an export archive with an incompatible schema version.
ExportValidationError
Bases: aiida.tools.importexport.common.exceptions.ArchiveExportError
aiida.tools.importexport.common.exceptions.ArchiveExportError
Raised when validation fails during export, e.g. for non-sealed ProcessNode s.
ProcessNode
ImportUniquenessError
Bases: aiida.tools.importexport.common.exceptions.ArchiveImportError
aiida.tools.importexport.common.exceptions.ArchiveImportError
Raised when the user tries to violate a uniqueness constraint.
Similar to UniquenessError.
UniquenessError
ImportValidationError
Raised when validation fails during import, e.g. for parameter types and values.
ArchiveMigrationError
Base class for all AiiDA export archive migration exceptions.
MigrationValidationError
Bases: aiida.tools.importexport.common.exceptions.ArchiveMigrationError
aiida.tools.importexport.common.exceptions.ArchiveMigrationError
Raised when validation fails during migration of export archives.
DanglingLinkError
Bases: aiida.tools.importexport.common.exceptions.MigrationValidationError
aiida.tools.importexport.common.exceptions.MigrationValidationError
Raised when an export archive is detected to contain dangling links when importing.
ProgressBarError
Something is wrong with setting up the tqdm progress bar
get_progress_bar
Set up, cache and return cached tqdm progress bar
close_progress_bar
Close instantiated progress bar