Skip to content

Commit

Permalink
Merge pull request #7 from molshape/using-casregnum
Browse files Browse the repository at this point in the history
Update v1.3.0
  • Loading branch information
molshape authored Sep 12, 2021
2 parents 892a517 + af44472 commit e7a0cba
Show file tree
Hide file tree
Showing 14 changed files with 691 additions and 697 deletions.
191 changes: 103 additions & 88 deletions README.md

Large diffs are not rendered by default.

69 changes: 0 additions & 69 deletions src/CASRegistryNumber.py

This file was deleted.

290 changes: 0 additions & 290 deletions src/ChemFormula.py

This file was deleted.

336 changes: 336 additions & 0 deletions src/chemformula.py

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/Elements.py → src/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
For radioactive elements the isotope with the longest half-life is quoted as an integer.
'''

def AtomicWeight(strElement):
dictAtomicWeightTable = {
def atomic_weight(element):
atomic_weight_table = {
"H": 1.008,
"He": 4.002602,
"Li": 6.94,
Expand Down Expand Up @@ -139,14 +139,14 @@ def AtomicWeight(strElement):
"Og": 294
}
# return atomic weight of the element symbol passed to the function, False if element symbol does not exist
return float(dictAtomicWeightTable[strElement]) if strElement in dictAtomicWeightTable else False
return float(atomic_weight_table[element]) if element in atomic_weight_table else False

def RadioactiveElement(strElement):
lstRadioactiveElements = [
def radioactive_element(element):
radioactive_elements = [
"Tc",
"Po", "At", "Rn",
"Fr", "Ra", "Pm", "Ac", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og",
"Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr"
]
# element is in the list of radioactive elements => True else False
return True if strElement in lstRadioactiveElements else False
return element in radioactive_elements
63 changes: 0 additions & 63 deletions tests/Example1.py

This file was deleted.

36 changes: 0 additions & 36 deletions tests/Example3.py

This file was deleted.

83 changes: 0 additions & 83 deletions tests/Test.py

This file was deleted.

63 changes: 63 additions & 0 deletions tests/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from chemformula import ChemFormula

tetraamminecoppersulfate = ChemFormula("[Cu(NH3)4]SO4.H2O")
ethylcinnamate = ChemFormula("(C6H5)CHCHCOOC2H5")
uranophane = ChemFormula("Ca(UO2)2(SiO3OH)2(H2O)5", name = "Uranophane")

print("\n--- Formula Depictions of Tetraamminecopper(II)-sulfate ---")
print(f" Formula: {tetraamminecoppersulfate.formula}")
print(f" Original: {tetraamminecoppersulfate}")
print(f" Charged: {tetraamminecoppersulfate.charged}")
print(f" Charge (int): {tetraamminecoppersulfate.charge}")
print(f" LaTeX: {tetraamminecoppersulfate.latex}")
print(f" HTML: {tetraamminecoppersulfate.html}")
print(f" Custom format: {tetraamminecoppersulfate.format_formula('--> ', '', '', '_<', '>', ' <--', '', '', ' * ')}")
print(f" Sum formula: {tetraamminecoppersulfate.sum_formula}")
print(f" Hill formula: {tetraamminecoppersulfate.hill_formula}")

print("\n--- Formula Weights Calculations with Ethyl Cinnamate ---")
print(f" The formula weight of ethyl cinnamate is {ethylcinnamate.formula_weight:.2f} g/mol.")
Mole = 1.4
print(f" {Mole:.1f} mol of ethyl cinnamate weight {Mole * ethylcinnamate.formula_weight:.1f} g.")
Mass = 24
print(f" {Mass:.1f} g of ethyl cinnamate corresponds to {Mass/ethylcinnamate.formula_weight * 1000:.1f} mmol.")
print(" The elemental composition of ethyl cinnamate is as follows:")
for stringElementSymbol, floatElementFraction in ethylcinnamate.mass_fraction.items():
print(f" {stringElementSymbol:<2}: {floatElementFraction * 100:>5.2f} %")

print("\n--- Is Uranophane Radioactive and Charged? ---")
print(f" Yes, {uranophane.name} is radioactive.") if uranophane.radioactive else print(f" No, {uranophane.name} is not radioactive.")
print(f" Yes, {uranophane.name} is charged.") if uranophane.charged else print(f" No, {uranophane.name} is not charged.")

print("\n--- Accessing Single Elements through FormulaObject.Element[\'Element_Symbol\'] ---")
print(f" Cupric sulfate contains {tetraamminecoppersulfate.element['N']} nitrogen atoms.\n")

### OUTPUT:
#
# --- Formula Depictions of Tetraamminecopper(II)-sulfate ---
# Formula: [Cu(NH3)4]SO4.H2O
# Original: [Cu(NH3)4]SO4.H2O
# Charged: False
# Charge (int): 0
# LaTeX: \[\textnormal{Cu}\(\textnormal{N}\textnormal{H}_{3}\)_{4}\]\textnormal{S}\textnormal{O}_{4}\cdot\textnormal{H}_{2}\textnormal{O}
# HTML: <span class='ChemFormula'>[Cu(NH<sub>3</sub>)<sub>4</sub>]SO<sub>4</sub>&sdot;H<sub>2</sub>O</span>
# Custom format: --> [Cu(NH_<3>)_<4>]SO_<4> * H_<2>O <--
# Sum formula: CuN4H14SO5
# Hill formula: CuH14N4O5S
#
# --- Formula Weights Calculations with Ethyl Cinnamate ---
# The formula weight of ethyl cinnamate is 176.21 g/mol.
# 1.4 mol of ethyl cinnamate weight 246.7 g.
# 24.0 g of ethyl cinnamate corresponds to 136.2 mmol.
# The elemental composition of ethyl cinnamate is as follows:
# C : 74.98 %
# H : 6.86 %
# O : 18.16 %
#
# --- Is Uranophane Radioactive and Charged? ---
# Yes, Uranophane is radioactive.
# No, Uranophane is not charged.
#
# --- Accessing Single Elements through FormulaObject.Element['Element_Symbol'] ---
# Cupric sulfate contains 4 nitrogen atoms.
#
Loading

0 comments on commit e7a0cba

Please sign in to comment.