Skip to content

Commit

Permalink
[ENH] Add price per kg for elements (#221)
Browse files Browse the repository at this point in the history
* add price per kg data for elements

* 🦆

* 💄

* update docs

* add tests

* add missing footnotemark
  • Loading branch information
lmmentel authored Jan 3, 2025
1 parent 231b5a6 commit 824c503
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""add price_per_kg column to elements
Revision ID: 6b61728951ad
Revises: c36c01e33842
Create Date: 2025-01-03 21:49:02.101851
"""

# revision identifiers, used by Alembic.
revision = '6b61728951ad'
down_revision = 'c36c01e33842'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column("elements", sa.Column("price_per_kg", sa.Float, nullable=True))


def downgrade():
with op.batch_alter_table("elements") as batch_op:
batch_op.drop_column("price_per_kg")
34 changes: 28 additions & 6 deletions docs/source/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ The following data are currently available:
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``en_robles_bartolotti`` | Robles-Bartolotti's scale of electronegativity | eV | stored | :cite:`RoblesBartolotti1984` |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``evaporation_heat`` | Evaporation heat | kJ/mol | stored | |
| ``evaporation_heat`` | Evaporation heat ([#f_evaporation_heat]_) | kJ/mol | stored | |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``fusion_heat`` | Fusion heat | kJ/mol | stored | |
| ``fusion_heat`` | Fusion heat ([#f_fusion_heat]_) | kJ/mol | stored | |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``gas_basicity`` | Gas basicity | kJ/mol | stored | :cite:`haynes2014crc` |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
Expand Down Expand Up @@ -185,6 +185,8 @@ The following data are currently available:
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``political_stability_of_top_reserve_holder`` | A percentile rank for the political stability of the country with the largest reserves, derived from World Bank governance indicators. | | stored | :cite:`RSC_periodic_table` |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``price_per_kg`` | Price per kg in USD ([#f_price_per_kg]_) | USD/kg | stored | :cite:`enwiki:1262554464` |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``production_concentration`` | The percentage of an element produced in the top producing country. The higher the value, the larger risk there is to supply. | % | stored | :cite:`RSC_periodic_table` |
+-----------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+--------------+------------------------------------------------------+
| ``proton_affinity`` | Proton affinity | kJ/mol | stored | :cite:`haynes2014crc` |
Expand Down Expand Up @@ -569,10 +571,6 @@ Class: :py:class:`ScreeningConstant <mendeleev.models.ScreeningConstant>`
- Tennessine
- Oganesson
.. [#f_melting_point] **melting_point**
Melting points for carbon from the original source are not included since they are not at standard pressure.
.. [#f_electron_affinity] **electron_affinity**
Electron affinities were taken from :cite:`haynes2014crc` for the elements for which the data was available. For He, Be, N, Ar and Xe affinities were taken from :cite:`Andersen2004` where they were specified for metastable ions and therefore the values are negative.
Expand All @@ -587,6 +585,22 @@ Class: :py:class:`ScreeningConstant <mendeleev.models.ScreeningConstant>`
The values of configurational energies from refs. :cite:`Mann2000a` and :cite:`Mann2000` were taken as reported in eV without converting to Pauling units.
.. [#f_evaporation_heat] **evaporation_heat**
- H: evaporation heat of H-H
- F: evaporation heat of F-F
- Cl: evaporation heat of Cl-Cl
- Br: evaporation heat of Br-Br
- I: evaporation heat of I-I
.. [#f_fusion_heat] **fusion_heat**
- H: fusion heat of H-H
- F: fusion heat of F-F
- Cl: fusion heat of Cl-Cl
- Br: fusion heat of Br-Br
- I: fusion heat of I-I
.. [#f_mendeleev_number] **mendeleev_number**
Mendeleev numbers were sourced from :cite:`Villars2004` but the range was extended to cover the whole periodic table following the prescription in the article of increasing the numbers going from top to bottom in each group and group by group from left to right in the periodic table.
Expand Down Expand Up @@ -631,3 +645,11 @@ Class: :py:class:`ScreeningConstant <mendeleev.models.ScreeningConstant>`
specific data references available at cited data source
.. [#f_melting_point] **melting_point**
Melting points for carbon from the original source are not included since they are not at standard pressure
.. [#f_price_per_kg] **price_per_kg**
In cases where a range was provided in the source, the lower value was used. In cases of multiple isotopes the lower priced isotope's price was used.
7 changes: 7 additions & 0 deletions docs/source/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -931,4 +931,11 @@ @misc{RSC_periodic_table
howpublished = {{[Online]. Available: {\tt{https://www.rsc.org/periodic-table/}} [2024, November 12]. Royal Society of Chemistry}},
year = {2024},
note = {Accessed: 2024-11-12}
}
@misc{enwiki:1262554464,
author = {{Wikipedia contributors}},
title = {Prices of chemical elements --- {Wikipedia}{,} The Free Encyclopedia},
year = {2024},
url = {https://en.wikipedia.org/w/index.php?title=Prices_of_chemical_elements&oldid=1262554464},
note = {[Online; accessed 3-January-2025]}
}
Binary file modified mendeleev/elements.db
Binary file not shown.
2 changes: 2 additions & 0 deletions mendeleev/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Element(Base):
nist_webbook_url (str): URL for the NIST Chemistry WebBook
period (int): Period in periodic table
pettifor_number (int): Pettifor scale
price_per_kg (float): Price per kg in USD
proton_affinity (float): Proton affinity
series (int): Index to chemical series
sources (str): Sources of the element
Expand Down Expand Up @@ -215,6 +216,7 @@ class Element(Base):
name_origin = Column(String)
period = Column(Integer)
pettifor_number = Column(Integer)
price_per_kg = Column(Float)
proton_affinity = Column(Float)
series = association_proxy("_series", "name")
sources = Column(String)
Expand Down
17 changes: 11 additions & 6 deletions tests/test_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ def test__ne__():
assert e1 != e2


@pytest.mark.parametrize("e", ELEMENTS)
def test_melting_points_float_or_none(e):
assert isinstance(e.melting_point, (float, type(None)))
@pytest.mark.parametrize("element_obj", ELEMENTS)
def test_melting_points_float_or_none(element_obj):
assert isinstance(element_obj.melting_point, (float, type(None)))


@pytest.mark.parametrize("e", ELEMENTS)
def test_boiling_points_float_or_none(e):
assert isinstance(e.boiling_point, (float, type(None)))
@pytest.mark.parametrize("element_obj", ELEMENTS)
def test_boiling_points_float_or_none(element_obj):
assert isinstance(element_obj.boiling_point, (float, type(None)))


@pytest.mark.parametrize("element_obj", ELEMENTS)
Expand All @@ -130,3 +130,8 @@ def test_protons(element_obj):
@pytest.mark.parametrize("element_obj", ELEMENTS)
def test_electrons(element_obj):
assert element_obj.electrons == element_obj.atomic_number


@pytest.mark.parametrize("element_obj", ELEMENTS)
def test_price_per_kg_float_or_none(element_obj):
assert isinstance(element_obj.price_per_kg, (float, type(None)))

0 comments on commit 824c503

Please sign in to comment.