DbImporter documentation

Generic database importer class

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

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

This function loads the correct DbImporter plugin class

class aiida.tools.dbimporters.baseclasses.DbEntry(db_source=None, db_url=None, db_id=None, db_version=None, extras={}, url=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-compatible structure, representing the crystal structure from the CIF file.

get_ase_structure()[source]

Returns ASE representation of the CIF.

get_cif_node()[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.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
  • b, c (a,) – length of lattice vectors in angstroms
  • beta, gamma (alpha,) – 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[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.

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(url, db_source='Crystallography Open Database', db_url='http://www.crystallography.net', **kwargs)[source]

Represents an entry from COD.

get_ase_structure()[source]

Returns ASE representation of the CIF.

Note:to be removed, as it is duplicated in aiida.orm.data.cif.CifData.
class aiida.tools.dbimporters.plugins.cod.CodSearchResults(results)[source]

Results of the search, performed on COD.

at(position)[source]

Returns position-th result as aiida.tools.dbimporters.plugins.cod.CodEntry.

Parameters:position – zero-based index of a result.
Raises IndexError:
 if position is out of bounds.

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(url, **kwargs)[source]

Represents an entry from TCOD.

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

Results of the search, performed on TCOD.

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(url, **kwargs)[source]

Represents an entry from MPOD.

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

Results of the search, performed on MPOD.

at(position)[source]

Returns position-th result as aiida.tools.dbimporters.plugins.mpod.MpodEntry.

Parameters:position – zero-based index of a result.
Raises IndexError:
 if position is out of bounds.

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.

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
    

    See the DbImporter documentation and tutorial page for more information.

  • 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(url, **kwargs)[source]

Represent an entry from Icsd.

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_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.