DbImporter documentation

Generic database importer class

This section describes the base class for the import of data from external databases.

aiida.tools.dbimporters.DbImporterFactory(pluginname)[source]

This function loads the correct DbImporter plugin class

class aiida.tools.dbimporters.baseclasses.CifEntry(db_name=None, db_uri=None, id=None, version=None, extras={}, uri=None)[source]

Represents an entry from the structure database (COD, ICSD, ...).

cif

Returns raw contents of a CIF file as string.

get_aiida_structure()[source]
Returns:AiiDA structure corresponding to the CIF file.
get_ase_structure()[source]

Returns ASE representation of the CIF.

Note

To be removed, as it is duplicated in aiida.orm.data.cif.CifData.

get_cif_node(store=False)[source]

Creates a CIF node, that can be used in AiiDA workflow.

Returns:aiida.orm.data.cif.CifData object
get_parsed_cif()[source]

Returns data structure, representing the CIF file. Can be created using PyCIFRW or any other open-source parser.

Returns:list of lists
get_raw_cif()[source]

Returns raw contents of a CIF file as string.

Returns:contents of a file as string
class aiida.tools.dbimporters.baseclasses.DbEntry(db_name=None, db_uri=None, id=None, version=None, extras={}, uri=None)[source]

Represents an entry from external database.

contents

Returns raw contents of a file as string.

class aiida.tools.dbimporters.baseclasses.DbImporter[source]

Base class for database importers.

get_supported_keywords()[source]

Returns the list of all supported query keywords.

Returns:list of strings
query(**kwargs)[source]

Method to query the database.

Parameters:
  • id – database-specific entry identificator
  • element – element name from periodic table of elements
  • number_of_elements – number of different elements
  • mineral_name – name of mineral
  • chemical_name – chemical name of substance
  • formula – chemical formula
  • volume – volume of the unit cell in cubic angstroms
  • spacegroup – symmetry space group symbol in Hermann-Mauguin notation
  • spacegroup_hall – symmetry space group symbol in Hall notation
  • a – length of lattice vector in angstroms
  • b – length of lattice vector in angstroms
  • c – length of lattice vector in angstroms
  • alpha – angles between lattice vectors in degrees
  • beta – angles between lattice vectors in degrees
  • gamma – angles between lattice vectors in degrees
  • z – number of the formula units in the unit cell
  • measurement_temp – temperature in kelvins at which the unit-cell parameters were measured
  • measurement_pressure – pressure in kPa at which the unit-cell parameters were measured
  • diffraction_temp – mean temperature in kelvins at which the intensities were measured
  • diffraction_pressure – mean pressure in kPa at which the intensities were measured
  • authors – authors of the publication
  • journal – name of the journal
  • title – title of the publication
  • year – year of the publication
  • journal_volume – journal volume of the publication
  • journal_issue – journal issue of the publication
  • first_page – first page of the publication
  • last_page – last page of the publication
  • doi – digital object identifyer (DOI), refering to the publication
Raises:

NotImplementedError – if search using given keyword is not implemented.

setup_db(**kwargs)[source]

Sets the database parameters. The method should reconnect to the database using updated parameters, if already connected.

class aiida.tools.dbimporters.baseclasses.DbSearchResults(results)[source]

Base class for database results.

All classes, inheriting this one and overriding at(), are able to benefit from having functions __iter__, __len__ and __getitem__.

class DbSearchResultsIterator(results, increment=1)[source]

Iterator for search results

DbSearchResults.__iter__()[source]

Instances of aiida.tools.dbimporters.baseclasses.DbSearchResults can be used as iterators.

DbSearchResults.at(position)[source]

Returns position-th result as aiida.tools.dbimporters.baseclasses.DbEntry.

Parameters:position – zero-based index of a result.
Raises:IndexError – if position is out of bounds.
DbSearchResults.fetch_all()[source]

Returns all query results as an array of aiida.tools.dbimporters.baseclasses.DbEntry.

DbSearchResults.next()[source]

Returns the next result of the query (instance of aiida.tools.dbimporters.baseclasses.DbEntry).

Raises:StopIteration – when the end of result array is reached.
class aiida.tools.dbimporters.baseclasses.UpfEntry(db_name=None, db_uri=None, id=None, version=None, extras={}, uri=None)[source]

Represents an entry from the pseudopotential database.

get_upf_node(store=False)[source]

Creates an UPF node, that can be used in AiiDA workflow.

Returns:aiida.orm.data.upf.UpfData object

Structural databases

COD database importer

class aiida.tools.dbimporters.plugins.cod.CodDbImporter(**kwargs)[source]

Database importer for Crystallography Open Database.

get_supported_keywords()[source]

Returns the list of all supported query keywords.

Returns:list of strings
query(**kwargs)[source]

Performs a query on the COD database using keyword = value pairs, specified in kwargs.

Returns:an instance of aiida.tools.dbimporters.plugins.cod.CodSearchResults.
query_sql(**kwargs)[source]

Forms a SQL query for querying the COD database using keyword = value pairs, specified in kwargs.

Returns:string containing a SQL statement.
setup_db(**kwargs)[source]

Changes the database connection details.

class aiida.tools.dbimporters.plugins.cod.CodEntry(uri, db_name='Crystallography Open Database', db_uri='http://www.crystallography.net', **kwargs)[source]

Represents an entry from COD.

class aiida.tools.dbimporters.plugins.cod.CodSearchResults(results)[source]

Results of the search, performed on COD.

ICSD database importer

exception aiida.tools.dbimporters.plugins.icsd.CifFileErrorExp[source]

Raised when the author loop is missing in a CIF file.

class aiida.tools.dbimporters.plugins.icsd.IcsdDbImporter(**kwargs)[source]

Importer for the Inorganic Crystal Structure Database, short ICSD, provided by FIZ Karlsruhe. It allows to run queries and analyse all the results. See the DbImporter documentation and tutorial page for more information.

Parameters:
  • server

    Server URL, the web page of the database. It is required in order to have access to the full database. I t should contain both the protocol and the domain name and end with a slash, as in:

    server = "http://ICSDSERVER.com/"
    
  • urladd – part of URL which is added between query and and the server URL (default: index.php?). only needed for web page query
  • querydb – boolean, decides whether the mysql database is queried (default: True). If False, the query results are obtained through the web page query, which is restricted to a maximum of 1000 results per query.
  • dl_db – icsd comes with a full (default: icsd) and a demo database (icsdd). This parameter allows the user to switch to the demo database for testing purposes, if the access rights to the full database are not granted.
  • host

    MySQL database host. If the MySQL database is hosted on a different machine, use “127.0.0.1” as host, and open a SSH tunnel to the host using:

    ssh -L 3306:localhost:3306 username@hostname.com
    

    or (if e.g. you get an URLError with Errno 111 (Connection refused) upon querying):

    ssh -L 3306:localhost:3306 -L 8010:localhost:80 username@hostname.com
    
  • user – mysql database username (default: dba)
  • passwd – mysql database password (default: sql)
  • db – name of the database (default: icsd)
  • port – Port to access the mysql database (default: 3306)
get_supported_keywords()[source]
Returns:List of all supported query keywords.
query(**kwargs)[source]

Depending on the db_parameters, the mysql database or the web page are queried. Valid parameters are found using IcsdDbImporter.get_supported_keywords().

Parameters:kwargs – A list of ‘’keyword = [values]’’ pairs.
setup_db(**kwargs)[source]

Change the database connection details. At least the host server has to be defined.

Parameters:kwargs – db_parameters for the mysql database connection (host, user, passwd, db, port)
class aiida.tools.dbimporters.plugins.icsd.IcsdEntry(uri, **kwargs)[source]

Represent an entry from Icsd.

Note:
  • Before July 2nd 2015, source[‘id’] contained icsd.IDNUM (internal icsd id number) and source[‘extras’][‘cif_nr’] the cif number (icsd.COLL_CODE).
  • After July 2nd 2015, source[‘id’] has been replaced by the cif number and source[‘extras’][‘idnum’] is icsd.IDNUM .
cif
Returns:cif file of Icsd entry.
get_aiida_structure()[source]
Returns:AiiDA structure corresponding to the CIF file.
get_ase_structure()[source]
Returns:ASE structure corresponding to the cif file.
get_cif_node()[source]

Create a CIF node, that can be used in AiiDA workflow.

Returns:aiida.orm.data.cif.CifData object
get_corrected_cif()[source]

Add quotes to the lines in the author loop if missing.

Note:ase raises an AssertionError if the quotes in the author loop are missing.
class aiida.tools.dbimporters.plugins.icsd.IcsdSearchResults(query, db_parameters)[source]

Result manager for the query performed on ICSD.

Parameters:
  • query – mysql query or webpage query
  • db_parameters – database parameter setup during the initialisation of the IcsdDbImporter.
at(position)[source]

Return position-th result as IcsdEntry.

next()[source]

Return next result as IcsdEntry.

query_db_version()[source]

Query the version of the icsd database (last row of RELEASE_TAGS).

query_page()[source]

Query the mysql or web page database, depending on the db_parameters. Store the number_of_results, cif file number and the corresponding icsd number.

Note:Icsd uses its own number system, different from the CIF file numbers.
exception aiida.tools.dbimporters.plugins.icsd.NoResultsWebExp[source]

Raised when a webpage query returns no results.

aiida.tools.dbimporters.plugins.icsd.correct_cif(cif)[source]

Correct the format of the CIF files. At the moment, it only fixes missing quotes in the authors field (ase.read.io only works if the author names are quoted, if not an AssertionError is raised).

Parameters:cif – A string containing the content of the CIF file.
Returns:a string containing the corrected CIF file.

MPOD database importer

class aiida.tools.dbimporters.plugins.mpod.MpodDbImporter(**kwargs)[source]

Database importer for Material Properties Open Database.

get_supported_keywords()[source]

Returns the list of all supported query keywords.

Returns:list of strings
query(**kwargs)[source]

Performs a query on the MPOD database using keyword = value pairs, specified in kwargs.

Returns:an instance of aiida.tools.dbimporters.plugins.mpod.MpodSearchResults.
query_get(**kwargs)[source]

Forms a HTTP GET query for querying the MPOD database. May return more than one query in case an intersection is needed.

Returns:a list containing strings for HTTP GET statement.
setup_db(query_url=None, **kwargs)[source]

Changes the database connection details.

class aiida.tools.dbimporters.plugins.mpod.MpodEntry(uri, **kwargs)[source]

Represents an entry from MPOD.

class aiida.tools.dbimporters.plugins.mpod.MpodSearchResults(results)[source]

Results of the search, performed on MPOD.

OQMD database importer

class aiida.tools.dbimporters.plugins.oqmd.OqmdDbImporter(**kwargs)[source]

Database importer for Open Quantum Materials Database.

get_supported_keywords()[source]

Returns the list of all supported query keywords.

Returns:list of strings
query(**kwargs)[source]

Performs a query on the OQMD database using keyword = value pairs, specified in kwargs.

Returns:an instance of aiida.tools.dbimporters.plugins.oqmd.OqmdSearchResults.
query_get(**kwargs)[source]

Forms a HTTP GET query for querying the OQMD database.

Returns:a strings for HTTP GET statement.
setup_db(query_url=None, **kwargs)[source]

Changes the database connection details.

class aiida.tools.dbimporters.plugins.oqmd.OqmdEntry(uri, **kwargs)[source]

Represents an entry from OQMD.

class aiida.tools.dbimporters.plugins.oqmd.OqmdSearchResults(results)[source]

Results of the search, performed on OQMD.

PCOD database importer

class aiida.tools.dbimporters.plugins.pcod.PcodDbImporter(**kwargs)[source]

Database importer for Predicted Crystallography Open Database.

query(**kwargs)[source]

Performs a query on the PCOD database using keyword = value pairs, specified in kwargs.

Returns:an instance of aiida.tools.dbimporters.plugins.pcod.PcodSearchResults.
query_sql(**kwargs)[source]

Forms a SQL query for querying the PCOD database using keyword = value pairs, specified in kwargs.

Returns:string containing a SQL statement.
class aiida.tools.dbimporters.plugins.pcod.PcodEntry(uri, db_name='Predicted Crystallography Open Database', db_uri='http://www.crystallography.net/pcod', **kwargs)[source]

Represents an entry from PCOD.

class aiida.tools.dbimporters.plugins.pcod.PcodSearchResults(results)[source]

Results of the search, performed on PCOD.

TCOD database importer

class aiida.tools.dbimporters.plugins.tcod.TcodDbImporter(**kwargs)[source]

Database importer for Theoretical Crystallography Open Database.

query(**kwargs)[source]

Performs a query on the TCOD database using keyword = value pairs, specified in kwargs.

Returns:an instance of aiida.tools.dbimporters.plugins.tcod.TcodSearchResults.
class aiida.tools.dbimporters.plugins.tcod.TcodEntry(uri, db_name='Theoretical Crystallography Open Database', db_uri='http://www.crystallography.net/tcod', **kwargs)[source]

Represents an entry from TCOD.

class aiida.tools.dbimporters.plugins.tcod.TcodSearchResults(results)[source]

Results of the search, performed on TCOD.

Other databases

NNINC database importer

class aiida.tools.dbimporters.plugins.nninc.NnincDbImporter(**kwargs)[source]

Database importer for NNIN/C Pseudopotential Virtual Vault.

get_supported_keywords()[source]

Returns the list of all supported query keywords.

Returns:list of strings
query(**kwargs)[source]

Performs a query on the NNIN/C Pseudopotential Virtual Vault using keyword = value pairs, specified in kwargs.

Returns:an instance of aiida.tools.dbimporters.plugins.nninc.NnincSearchResults.
query_get(**kwargs)[source]

Forms a HTTP GET query for querying the NNIN/C Pseudopotential Virtual Vault.

Returns:a string with HTTP GET statement.
setup_db(query_url=None, **kwargs)[source]

Changes the database connection details.

class aiida.tools.dbimporters.plugins.nninc.NnincEntry(uri, **kwargs)[source]

Represents an entry from NNIN/C Pseudopotential Virtual Vault.

class aiida.tools.dbimporters.plugins.nninc.NnincSearchResults(results)[source]

Results of the search, performed on NNIN/C Pseudopotential Virtual Vault.