|
| 1 | +import pytest |
| 2 | +import numpy as np |
| 3 | +from atomdb.periodic import num2sym, sym2num, name2num, num2name, Atom |
| 4 | + |
| 5 | + |
| 6 | +def test_num2sym(): |
| 7 | + assert num2sym[1] == "H" |
| 8 | + assert num2sym[6] == "C" |
| 9 | + assert num2sym[26] == "Fe" |
| 10 | + |
| 11 | + |
| 12 | +def test_sym2num(): |
| 13 | + assert sym2num["H"] == 1 |
| 14 | + assert sym2num["C"] == 6 |
| 15 | + assert sym2num["Fe"] == 26 |
| 16 | + |
| 17 | + |
| 18 | +def name2num(): |
| 19 | + assert sym2num["hydrogen"] == 1 |
| 20 | + assert sym2num["carbon"] == 6 |
| 21 | + assert sym2num["iron"] == 26 |
| 22 | + |
| 23 | + assert sym2num["Hydrogen"] == 1 |
| 24 | + assert sym2num["Carbon"] == 6 |
| 25 | + assert sym2num["Iron"] == 26 |
| 26 | + |
| 27 | + |
| 28 | +def num2name(): |
| 29 | + assert sym2num[1] == "Hydrogen" |
| 30 | + assert sym2num[6] == "Carbon" |
| 31 | + assert sym2num[26] == "Iron" |
| 32 | + |
| 33 | + |
| 34 | +def test_atom_invalid_element(): |
| 35 | + with pytest.raises(Exception): |
| 36 | + Atom("InvalidElement") |
| 37 | + |
| 38 | + |
| 39 | +def test_atom_invalid_symbol(): |
| 40 | + with pytest.raises(Exception): |
| 41 | + Atom("AA") |
| 42 | + |
| 43 | + |
| 44 | +def test_atom_invalid_atnum(): |
| 45 | + with pytest.raises(Exception): |
| 46 | + Atom(-2) |
| 47 | + |
| 48 | + |
| 49 | +def test_atom_invalid_charge(): |
| 50 | + with pytest.raises(Exception): |
| 51 | + Atom(1, charge=2) |
| 52 | + with pytest.raises(Exception): |
| 53 | + Atom(1, charge=1.5) |
| 54 | + with pytest.raises(Exception): |
| 55 | + Atom(112, charge=-10) |
| 56 | + |
| 57 | + |
| 58 | +def test_get_attributes(): |
| 59 | + # will test getting the attributes of the atom for Hydrogen and Carbon |
| 60 | + |
| 61 | + atom = Atom(1) |
| 62 | + assert atom.atnum == 1 |
| 63 | + assert atom.atsym == "H" |
| 64 | + assert atom.atname == "Hydrogen" |
| 65 | + assert atom.charge == 0 |
| 66 | + |
| 67 | + h_data = { |
| 68 | + "atnum": 1, |
| 69 | + "atsym": "H", |
| 70 | + "atname": "Hydrogen", |
| 71 | + "charge": 0, |
| 72 | + "group": 1, |
| 73 | + "period": 1, |
| 74 | + "multiplicity": 2, |
| 75 | + "cov_radius": {"cordero": 0.31, "bragg": np.nan, "slater": 0.25}, |
| 76 | + "vdw_radius": { |
| 77 | + "bondi": 1.2, |
| 78 | + "truhlar": np.nan, |
| 79 | + "rt": 1.1, |
| 80 | + "batsanov": np.nan, |
| 81 | + "dreiding": 3.195, |
| 82 | + "uff": 2.886, |
| 83 | + "mm3": 1.62, |
| 84 | + }, |
| 85 | + "at_radius": {"wc": 0.529192875, "cr": 0.53}, |
| 86 | + "eneg": {"pauling": 2.2}, |
| 87 | + "pold": {"crc": 0.666793, "chu": 4.5}, |
| 88 | + "c6": {"chu": 6.499026705}, |
| 89 | + "mass": {"stb": 1.007975}, |
| 90 | + } |
| 91 | + for i in h_data: |
| 92 | + assert getattr(atom, i) == h_data[i] |
| 93 | + |
| 94 | + atom = Atom(6) |
| 95 | + c_data = { |
| 96 | + "atnum": 6, |
| 97 | + "atsym": "C", |
| 98 | + "atname": "Carbon", |
| 99 | + "charge": 0, |
| 100 | + "group": 14, |
| 101 | + "period": 2, |
| 102 | + "multiplicity": 3, |
| 103 | + "cov_radius": {"cordero": 0.7445337366, "bragg": 0.77, "slater": 0.7}, |
| 104 | + "vdw_radius": { |
| 105 | + "bondi": 1.7, |
| 106 | + "truhlar": np.nan, |
| 107 | + "rt": 1.77, |
| 108 | + "batsanov": 1.7, |
| 109 | + "dreiding": 3.8983, |
| 110 | + "uff": 3.851, |
| 111 | + "mm3": 2.04, |
| 112 | + }, |
| 113 | + "at_radius": {"wc": 0.62, "cr": 0.67}, |
| 114 | + "eneg": {"pauling": 2.55}, |
| 115 | + "pold": {"crc": 1.76, "chu": 12.0}, |
| 116 | + "c6": {"chu": 46.6}, |
| 117 | + "mass": {"stb": 12.0106}, |
| 118 | + } |
| 119 | + |
| 120 | + for i in c_data: |
| 121 | + assert getattr(atom, i) == c_data[i] |
0 commit comments