Skip to content

Commit b04a6f0

Browse files
authored
Create metadata table for stored properties (#156)
* add metadata table * fix typos * fix typos * add metadata table with initial contents * add ParrPearson on hardness * update metadata schema and data * add documentation for PropertyMetadata class * update docstring * add propertymetadata to fetch tables * correct format * update units * render updated data docs * update isotope metadata * add isotope metadata to PropertyMetadata * docs * add PropertyMetadata to models.__all__
1 parent 3945030 commit b04a6f0

12 files changed

+379
-284
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ the `Element` object:
286286
>>> from mendeleev import element
287287

288288
The `element` method accepts unique identifiers: atomic number, atomic
289-
symbol or element\'s name in english. To retrieve the entries on Silicon
289+
symbol or element\'s name in English. To retrieve the entries on Silicon
290290
by symbol type
291291

292292
``` {.sourceCode .python}
@@ -340,7 +340,7 @@ following attributes per isotope
340340
The columns represent the attributes `atomic_number`, `mass`,
341341
`abundance` and `mass_number` respectively.
342342

343-
### Accesing data tables and the database
343+
### Accessing data tables and the database
344344

345345
[mendeleev](http://mendeleev.readthedocs.org) offers also methods for
346346
accessing whole tables of data, e.g. table with the data on all isotopes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""add PropertyMetadata table
2+
3+
Revision ID: 7d745d77a7c1
4+
Revises: 703682715347
5+
Create Date: 2024-05-21 13:11:24.427405
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '7d745d77a7c1'
11+
down_revision = '703682715347'
12+
branch_labels = None
13+
depends_on = None
14+
15+
from alembic import op
16+
import sqlalchemy as sa
17+
18+
19+
value_origin_enum = sa.Enum('STORED', 'COMPUTED', name='valueorigin')
20+
21+
def upgrade():
22+
23+
op.create_table(
24+
'propertymetadata',
25+
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
26+
sa.Column('table_name', sa.String, nullable=True),
27+
sa.Column('column_name', sa.String, nullable=True),
28+
sa.Column('class_name', sa.String, nullable=False),
29+
sa.Column('attribute_name', sa.String, nullable=False),
30+
sa.Column('category', sa.String, nullable=False),
31+
sa.Column('value_origin', value_origin_enum, nullable=False),
32+
sa.Column('description', sa.Text, nullable=False),
33+
sa.Column('unit', sa.String, nullable=True),
34+
sa.Column('annotations', sa.Text, nullable=True),
35+
sa.Column('citation_keys', sa.String, nullable=True)
36+
)
37+
38+
39+
def downgrade():
40+
op.drop_table('propertymetadata')
41+
value_origin_enum.drop(op.get_bind())

docs/source/api/mendeleev.cli.rst

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
mendeleev.cli
22
=============
33

4-
.. automodule:: mendeleev.cli
5-
6-
7-
8-
9-
10-
11-
12-
.. rubric:: Functions
13-
14-
.. autosummary::
15-
16-
clielement
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
4+
.. currentmodule:: mendeleev
295

6+
.. autodata:: cli

docs/source/api/mendeleev.ion.rst

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
mendeleev.ion
22
=============
33

4-
.. automodule:: mendeleev.ion
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
.. rubric:: Classes
17-
18-
.. autosummary::
19-
20-
Ion
21-
22-
23-
24-
25-
26-
27-
28-
4+
.. currentmodule:: mendeleev
295

6+
.. autodata:: ion

docs/source/api/mendeleev.models.rst

+2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
IsotopeDecayMode
3434
OxidationState
3535
PhaseTransition
36+
PropertyMetadata
3637
ScreeningConstant
3738
Series
39+
ValueOrigin
3840

3941

4042

docs/source/api/models.rst

+9
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ OxidationState
9595
.. autoclass:: mendeleev.models.OxidationState
9696
:members:
9797

98+
.. _propertymetadata-class:
99+
100+
PropertyMetadata
101+
----------------
102+
103+
.. currentmodule:: mendeleev.models
104+
105+
.. autoclass:: mendeleev.models.PropertyMetadata
106+
:members:
98107

99108
.. _econf-class:
100109

docs/source/data.rst

+255-230
Large diffs are not rendered by default.

docs/source/data_access.rst

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ tables are available:
3838
- :ref:`oxidationstates <oxidationstate-class>`
3939
- :ref:`screeningconstants <screeningconstant-class>`
4040
- :ref:`series <series-class>`
41+
- :ref:`propertymetadata <propertymetadata-class>`
4142

4243
.. autofunction:: fetch_table
4344

docs/source/references.bib

+12
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,15 @@ @book{haynes2016crc
845845
edition = {97th},
846846
pages = {2704}
847847
}
848+
@article{ParrPearson1983,
849+
author = {Parr, Robert G. and Pearson, Ralph G.},
850+
title = {Absolute hardness: companion parameter to absolute electronegativity},
851+
journal = {Journal of the American Chemical Society},
852+
volume = {105},
853+
number = {26},
854+
pages = {7512-7516},
855+
year = {1983},
856+
doi = {10.1021/ja00364a005},
857+
url = {https://doi.org/10.1021/ja00364a005},
858+
eprint = {https://doi.org/10.1021/ja00364a005}
859+
}

mendeleev/elements.db

0 Bytes
Binary file not shown.

mendeleev/fetch.py

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def fetch_table(table: str, **kwargs) -> pd.DataFrame:
5454
"isotopes",
5555
"oxidationstates",
5656
"phasetransitions",
57+
"propertymetadata",
5758
"screeningconstants",
5859
"series",
5960
}

mendeleev/models.py

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# -*- coding: utf-8 -*-
22

3-
"""module specifying the database models"""
3+
"""module defining the database models"""
44

55
from typing import Any, Callable, Dict, List, Tuple, Union
66
from operator import attrgetter
7+
import enum
78
import math
89
import urllib.parse
910

1011
import numpy as np
11-
from sqlalchemy import Column, Boolean, Integer, String, Float, ForeignKey
12+
from sqlalchemy import Column, Boolean, Integer, String, Float, ForeignKey, Text, Enum
1213
from sqlalchemy.orm import declarative_base, relationship, reconstructor
1314
from sqlalchemy.ext.associationproxy import association_proxy
1415
from sqlalchemy.ext.hybrid import hybrid_property, hybrid_method
@@ -34,6 +35,7 @@
3435
"IonicRadius",
3536
"OxidationState",
3637
"Isotope",
38+
"PropertyMetadata",
3739
"Series",
3840
"ScreeningConstant",
3941
]
@@ -731,6 +733,54 @@ def __repr__(self) -> str:
731733
)
732734

733735

736+
class ValueOrigin(enum.Enum):
737+
"Options for the origin of the property value."
738+
739+
STORED = "stored"
740+
COMPUTED = "computed"
741+
742+
743+
class PropertyMetadata(Base):
744+
"""Metadata for properties of elements and isotopes.
745+
746+
Args:
747+
annotations (str): Additional information about the property.
748+
attribute_name (str): Name of the attribute of the ORM class.
749+
category (str): Category of the property.
750+
citation_keys (str): Comma separated list of citation keys. See references.bib for full bibliography.
751+
class_name (str): Name of the ORM class.
752+
column_name (str): Name of the column in the database.
753+
description (str): Description of the property.
754+
table_name (str): Name of the table in the database.
755+
unit (str): Unit of the property.
756+
value_origin (ValueOrigin): Origin of the value, either stored or computed.
757+
"""
758+
759+
__tablename__ = "propertymetadata"
760+
761+
id = Column(Integer, primary_key=True)
762+
annotations = Column(Text)
763+
attribute_name = Column(String, nullable=False)
764+
category = Column(String)
765+
citation_keys = Column(String)
766+
class_name = Column(String, nullable=False)
767+
column_name = Column(String, nullable=True)
768+
description = Column(Text, nullable=False)
769+
table_name = Column(String, nullable=True)
770+
unit = Column(String)
771+
value_origin = Column(Enum(ValueOrigin), nullable=False)
772+
773+
def __repr__(self) -> str:
774+
return "%s(\n%s)" % (
775+
self.__class__.__name__,
776+
" ".join(
777+
"\t%s=%r,\n" % (key, getattr(self, key))
778+
for key in sorted(self.__dict__.keys())
779+
if not key.startswith("_")
780+
),
781+
)
782+
783+
734784
def fetch_attrs_for_group(attrs: List[str], group: int = 18) -> Tuple[List[Any]]:
735785
"""
736786
A convenience function for getting a specified attribute for all

0 commit comments

Comments
 (0)