-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide functions for reference data #312
Changes from all commits
a0d5c55
dc43179
86a1645
e141423
035d69d
fe58857
9f01b57
6de6fed
be84a5d
a013161
8b339c6
7cfd7c9
d4d94a7
9830680
d221132
e820d3f
fa0929b
dcb287a
fe3c0d7
031632d
92cf77a
d9d4a83
c744330
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from atomistics.referencedata.wikipedia import ( | ||
get_elastic_properties as get_elastic_properties_from_wikipedia, | ||
) | ||
|
||
try: | ||
from atomistics.referencedata.mendeleev import ( | ||
get_chemical_information as get_chemical_information_from_mendeleev, | ||
) | ||
from atomistics.referencedata.wolframalpha import ( | ||
get_chemical_information as get_chemical_information_from_wolframalpha, | ||
) | ||
except ImportError: | ||
__all__ = [] | ||
else: | ||
__all__ = [ | ||
get_chemical_information_from_mendeleev, | ||
get_chemical_information_from_wolframalpha, | ||
] | ||
|
||
|
||
__all__ += [get_elastic_properties_from_wikipedia] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
from mendeleev.fetch import fetch_table | ||
|
||
|
||
def get_chemical_information(chemical_symbol: str) -> dict: | ||
""" | ||
Get information of a given chemical element | ||
|
||
Args: | ||
chemical_symbol: Chemical Element like Au for Gold | ||
|
||
Returns: | ||
dict: Dictionary with the following keys | ||
abundance_crust: Abundance in the Earth’s crust in mg/kg | ||
abundance_sea: Abundance in the seas in mg/L | ||
atomic_number: Atomic number | ||
atomic_radius_rahm: Atomic radius by Rahm et al. in pm | ||
atomic_radius: Atomic radius in pm | ||
atomic_volume: Atomic volume in cm^3/mol | ||
atomic_weight_uncertainty: Atomic weight uncertainty in Da | ||
atomic_weight: Relative atomic weight in Da | ||
block: Block in periodic table | ||
boiling_point: Boiling point in K | ||
c6_gb: C_6 dispersion coefficient according to Gould & Bučko in hartree/bohr^6 | ||
c6: C_6 dispersion coefficient in hartree/bohr^6 | ||
cas: Chemical Abstracts Serice identifier | ||
covalent_radius_bragg: Covalent radius by Bragg in pm | ||
covalent_radius_cordero: Covalent radius by Cerdero et al. in pm | ||
covalent_radius_pyykko_double: Double bond covalent radius by Pyykko et al. in pm | ||
covalent_radius_pyykko_triple: Triple bond covalent radius by Pyykko et al. in pm | ||
covalent_radius_pyykko: Single bond covalent radius by Pyykko et al. in pm | ||
cpk_color: Element color in CPK convention | ||
critical_pressure: Critical pressure in MPa | ||
critical_temperature: Critical temperature in K | ||
density: Density at 295K in g/cm^3 | ||
description: Short description of the element | ||
dipole_polarizability_unc: Uncertainty of the dipole polarizability in bohr^3 | ||
dipole_polarizability: Dipole polarizability in bohr^3 | ||
discoverers: The discoverers of the element | ||
discovery_location: The location where the element was discovered | ||
discovery_year: The year the element was discovered | ||
econf: Ground state electronic configuration | ||
electron_affinity: Electron affinity in eV | ||
electronegativity_allen: Allen’s scale of electronegativity in eV | ||
electronegativity_allred_rochow: Allred and Rochow’s scale of electronegativity in e^2/pm^2 | ||
electronegativity_cottrell_sutton: Cottrell and Sutton’s scale of electronegativity in e^0.5/pm^0.5 | ||
electronegativity_ghosh: Ghosh’s scale of electronegativity in 1/pm | ||
electronegativity_gordy: Gordy’s scale of electronegativity in e/pm | ||
electronegativity_li_xue: Li and Xue’s scale of electronegativity in 1/pm | ||
electronegativity_martynov_batsanov: Martynov and Batsanov’s scale of electronegativity in eV^0.5 | ||
electronegativity_mulliken: Mulliken’s scale of electronegativity in eV | ||
electronegativity_nagle: Nagle’s scale of electronegativity in 1/bohr | ||
electronegativity_pauling: Pauling’s scale of electronegativity | ||
electronegativity_sanderson: Sanderson’s scale of electronegativity | ||
electrons: Number of electrons | ||
electrophilicity: Parr’s electrophilicity index | ||
evaporation_heat: Evaporation heat in kJ/mol | ||
fusion_heat: Fusion heat in kJ/mol | ||
gas_basicity: Gas basicity in kJ/mol | ||
geochemical_class: Geochemical classification | ||
glawe_number: Glawe’s number (scale) | ||
goldschmidt_class: Goldschmidt classification | ||
group: Group in the periodic table | ||
hardness: Absolute hardness. Can also be calcualted for ions. in eV | ||
heat_of_formation: Heat of formation in kJ/mol | ||
inchi: International Chemical Identifier | ||
ionenergy: See IonizationEnergy class documentation | ||
ionic_radii: See IonicRadius class documentation | ||
is_monoisotopic: Is the element monoisotopic | ||
is_radioactive: Is the element radioactive | ||
isotopes: See Isotope class documentation | ||
jmol_color: Element color in Jmol convention | ||
lattice_constant: Lattice constant | ||
lattice_structure: Lattice structure code | ||
mass_number: Mass number of the most abundant isotope | ||
melting_point: Melting point in K | ||
mendeleev_number: Mendeleev’s number | ||
metallic_radius_c12: Metallic radius with 12 nearest neighbors in pm | ||
metallic_radius: Single-bond metallic radius in pm | ||
molar_heat_capacity: Molar heat capacity @ 25 C, 1 bar in J/mol/K | ||
molcas_gv_color: Element color in MOCAS GV convention | ||
name_origin: Origin of the name | ||
name: Name in English | ||
neutrons: Number of neutrons | ||
nist_webbook_url: URL for the NIST Chemistry WebBook | ||
nvalence: Number of valence electrons | ||
oxides: Possible oxides based on oxidation numbers | ||
oxistates: See OxidationState class documentation | ||
period: Period in periodic table | ||
pettifor_number: Pettifor scale | ||
proton_affinity: Proton affinity in kJ/mol | ||
protons: Number of protons | ||
sconst: See ScreeningConstant class documentation | ||
series: Series in the periodic table | ||
softness: Absolute softness. Can also be calculated for ions. in 1/eV | ||
sources: Sources of the element | ||
specific_heat_capacity: Specific heat capacity @ 25 C, 1 bar in J/g/K | ||
symbol: Chemical symbol | ||
thermal_conductivity: Thermal conductivity @25 C in W/m/K | ||
triple_point_pressure: Presseure of the triple point in kPa | ||
triple_point_temperature: Temperature of the triple point in K | ||
uses: Main applications of the element | ||
vdw_radius_alvarez: Van der Waals radius according to Alvarez in pm | ||
vdw_radius_batsanov: Van der Waals radius according to Batsanov in pm | ||
vdw_radius_bondi: Van der Waals radius according to Bondi in pm | ||
vdw_radius_dreiding: Van der Waals radius from the DREIDING FF in pm | ||
vdw_radius_mm3: Van der Waals radius from the MM3 FF in pm | ||
vdw_radius_rt: Van der Waals radius according to Rowland and Taylor in pm | ||
vdw_radius_truhlar: Van der Waals radius according to Truhlar in pm | ||
vdw_radius_uff: Van der Waals radius from the UFF in pm | ||
vdw_radius: Van der Waals radius in pm | ||
zeff: Effective nuclear charge | ||
""" | ||
df = fetch_table("elements") | ||
return df[df.symbol == chemical_symbol].squeeze(axis=0).to_dict() | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||||||||||||||
import pandas | ||||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
def get_elastic_properties(chemical_symbol: str) -> dict: | ||||||||||||||||||||
""" | ||||||||||||||||||||
Looks up elastic properties for a given chemical symbol from the Wikipedia: https://en.wikipedia.org/wiki/Elastic_properties_of_the_elements_(data_page) | ||||||||||||||||||||
sourced from webelements.com. | ||||||||||||||||||||
|
||||||||||||||||||||
Args: | ||||||||||||||||||||
chemical_symbol (str): Chemical symbol of the element. | ||||||||||||||||||||
|
||||||||||||||||||||
Returns: | ||||||||||||||||||||
dict: Dictionary with the following keys | ||||||||||||||||||||
youngs_modulus: Young's modulus (or Young modulus) in GPa is a mechanical property of solid materials that | ||||||||||||||||||||
measures the tensile or compressive stiffness when the force is applied lengthwise. | ||||||||||||||||||||
poissons_ratio: In materials science and solid mechanics, Poisson's ratio ν (nu) is a measure of the Poisson | ||||||||||||||||||||
effect, the deformation (expansion or contraction) of a material in directions perpendicular | ||||||||||||||||||||
to the specific direction of loading. | ||||||||||||||||||||
jan-janssen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
bulk_modulus: The bulk modulus (K or B or k) in GPa of a substance is a measure of the resistance of a | ||||||||||||||||||||
substance to bulk compression. | ||||||||||||||||||||
shear_modulus: In materials science, shear modulus or modulus of rigidity in GPa, denoted by G, or sometimes | ||||||||||||||||||||
S or μ, is a measure of the elastic shear stiffness of a material and is defined as the ratio | ||||||||||||||||||||
of shear stress to the shear strain. | ||||||||||||||||||||
""" | ||||||||||||||||||||
property_lst = [ | ||||||||||||||||||||
"youngs_modulus", | ||||||||||||||||||||
"poissons_ratio", | ||||||||||||||||||||
"bulk_modulus", | ||||||||||||||||||||
"shear_modulus", | ||||||||||||||||||||
] | ||||||||||||||||||||
df_lst = pandas.read_html( | ||||||||||||||||||||
"https://en.wikipedia.org/wiki/Elastic_properties_of_the_elements_(data_page)" | ||||||||||||||||||||
) | ||||||||||||||||||||
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential errors during data retrieval. The function does not handle potential errors that may occur during the data retrieval process. Add error handling to manage cases where the URL might be inaccessible or the data format changes. + try:
+ df_lst = pandas.read_html(
+ "https://en.wikipedia.org/wiki/Elastic_properties_of_the_elements_(data_page)"
+ )
+ except Exception as e:
+ raise ValueError(f"Error retrieving data from Wikipedia: {e}") Committable suggestion
Suggested change
|
||||||||||||||||||||
property_dict = {} | ||||||||||||||||||||
for i, p in enumerate(property_lst): | ||||||||||||||||||||
df_tmp = df_lst[i] | ||||||||||||||||||||
property_dict[p] = float( | ||||||||||||||||||||
df_tmp[df_tmp.symbol == chemical_symbol].squeeze(axis=0).to_dict()["WEL[1]"] | ||||||||||||||||||||
) | ||||||||||||||||||||
return property_dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle cases where the chemical symbol is not found.
The function does not handle cases where the chemical symbol is not found in the table. Add error handling to manage this scenario.
Committable suggestion