Accessing data

Individual Elements

The easiest way to access individual elements is simply by importing them from the mendeleev directly using their symbols:

>>> from mendeleev import H, C, O, Og
>>> [x.name for x in [H, C, O, Og]]
['Hydrogen', 'Carbon', 'Oxygen', 'Oganesson']

An alternative method of access is through the element() function that returns either a single Element instance or a tuple of those instances depending on the input. It provides a more flexible interface since it accepts element names, atomic numbers and symbols as well as their combinations.

Fetching data in bulk

If you want a whole set of data you can retrieve one of the tables from the database as pandas DataFrame through the fetch_table(). The following tables are available:

fetch_table(table: str, **kwargs) DataFrame[source]

Return a table from the database as pandas.DataFrame

Parameters:
  • table – Name of the table from the database

  • kwargs – A dictionary of keyword arguments to pass to the pandas.read_qsl()

Returns:

Pandas DataFrame with the contents of the table

Return type:

df (pandas.DataFrame)

Example

>>> from mendeleev.fetch import fetch_table
>>> df = fetch_table('elements')
>>> type(df)
pandas.core.frame.DataFrame
fetch_ionization_energies(degree: List[int] | int = 1) DataFrame[source]

Fetch a pandas.DataFrame with ionization energies for all elements indexed by atomic number.

Parameters:

degree – Degree of ionization, either as int or a list of ints. If a list is passed then the output will contain ionization energies corresponding to particalr degrees in columns.

Returns:

ionization energies, indexed by atomic number

Return type:

df (pandas.DataFrame)

fetch_ionic_radii(radius: str = 'ionic_radius') DataFrame[source]

Fetch a pandas DataFrame with ionic radii for all the elements.

Parameters:

radius – The radius to be returned either ionic_radius or crystal_radius

Returns:

a table with atomic numbers, symbols and ionic radii for all

coordination numbers

Return type:

df (pandas.DataFrame)

Computed properties

Some properties need to be computed rather than directly retrieved from the database. Electronegativities

fetch_electronegativities(scales: List[str] = None) DataFrame[source]

Fetch electronegativity scales for all elements as pandas.DataFrame

Parameters:

scales – list of scale names, defaults to all available scales

Returns:

Pandas DataFrame with the contents of the table

Return type:

df (pandas.DataFrame)

Database session and engine

For those how want to interact with the database through a layer of SQLAlchemy there are methods for getting the session or the engine:

get_session(dbpath: str = None, read_only: bool = True) Session[source]

Return the database session connection.

get_engine(dbpath: str = None, read_only: bool = True) Engine[source]

Return the db engine

Export data

The data can be exported to a number of formats using the CLI by invoking inv export command. The following formats are supported:

  • csv

  • json

  • html

  • markdown

The command will export all the tables from the database to a set of files in the specified format.

In order to use this functionality you’ll need to clone the mendeleev repository and install the package in the development mode. Here’s how you can do it:

gh clone lmmentel/mendeleev
cd mendeleev
poetry install
poetry run inv export

After the command is executed you’ll find the exported files in the data directory. The contents should look like this:

data
├── csv
│   ├── elements.csv
│   ├── groups.csv
│   ├── ionicradii.csv
│   ├── ionizationenergies.csv
│   ├── isotopedecaymodes.csv
│   ├── isotopes.csv
│   ├── oxidationstates.csv
│   ├── phasetransitions.csv
│   ├── screeningconstants.csv
│   └── series.csv
├── html
│   ├── elements.html
│   ├── groups.html
│   ├── ionicradii.html
│   ├── ionizationenergies.html
│   ├── isotopedecaymodes.html
│   ├── isotopes.html
│   ├── oxidationstates.html
│   ├── phasetransitions.html
│   ├── screeningconstants.html
│   └── series.html
├── json
│   ├── elements.json
│   ├── groups.json
│   ├── ionicradii.json
│   ├── ionizationenergies.json
│   ├── isotopedecaymodes.json
│   ├── isotopes.json
│   ├── oxidationstates.json
│   ├── phasetransitions.json
│   ├── screeningconstants.json
│   └── series.json
└── markdown
    ├── elements.markdown
    ├── groups.markdown
    ├── ionicradii.markdown
    ├── ionizationenergies.markdown
    ├── isotopedecaymodes.markdown
    ├── isotopes.markdown
    ├── oxidationstates.markdown
    ├── phasetransitions.markdown
    ├── screeningconstants.markdown
    └── series.markdown