{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Usage\n", "import the library with your chosen alias, here *e*" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import elementMass as e" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Calculate the atomic weight of an element or compound by with the function calculate_weight()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Si: 28.086, SiO2: 60.084, Fe1.5O: 99.7665\n" ] } ], "source": [ "wt_Si = e.calculate_weight(\"Si\")\n", "wt_SiO2 = e.calculate_weight(\"SiO2\")\n", "wt_Fe15O = e.calculate_weight(\"Fe1.5O\")\n", "print(f\"Si: {wt_Si}, SiO2: {wt_SiO2}, Fe1.5O: {wt_Fe15O}\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Calculate atomic weights of multiple elements or compounds by supplying a list of names as the argument to compound_weights(). Results are returned as a pandas Series." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SiO2 60.084\n", "Na2O 61.979\n", "P2O5 141.943\n", "Name: weights, dtype: float64\n" ] } ], "source": [ "element_names = [\"SiO2\", \"Na2O\", \"P2O5\"]\n", "print(e.compound_weights(element_names))" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Get cation or oxygen amounts with cation_numbers() and oxygen_numbers() respectively. Results are returned as a pandas Series." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "P2O5 2.0\n", "TiO2 1.0\n", "Name: cations, dtype: float64" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e.cation_numbers([\"P2O5\", \"TiO2\"])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Fe2O3 3.0\n", "K2O 1.0\n", "Name: oxygen, dtype: float64" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e.oxygen_numbers([\"Fe2O3\", \"K2O\"])" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note that cation_numbers() simply returns the amount of the first listed element and therefore only gives reasonable results for simple oxides. It will not work on more complex compounds:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MgFeSiO4 1.0\n", "Name: cations, dtype: float64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e.cation_numbers([\"MgFeSiO4\"])" ] } ], "metadata": { "kernelspec": { "display_name": "py310", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.10" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }