def test_site_object_methods(): good_json_2 = {"isotope": "14N", "isotropic_chemical_shift": "-10 ppm"} the_site = Site.parse_dict_with_units(good_json_2) # testing method dict() result = { "isotope": {"symbol": "14N"}, "isotropic_chemical_shift": -10.0, "property_units": {"isotropic_chemical_shift": "ppm"}, "name": None, "label": None, "description": None, "quadrupolar": None, "shielding_symmetric": None, "shielding_antisymmetric": None, } assert the_site.dict() == result, "Failed Site.dict()" # Deprecated `to_freq_dict` # testing method to_freq_dict() # result = { # "isotope": "14N", # "isotropic_chemical_shift": -1 * 3.077706 * 9.4 * -10.0, # -gamma * B0 * iso # "name": None, # "label": None, # "description": None, # "quadrupolar": None, # "shielding_symmetric": None, # "shielding_antisymmetric": None, # } # assert the_site.to_freq_dict(B0=9.4) == result, "Failed Site.to_freq_dict()" # testing method json() result = {"isotope": "14N", "isotropic_chemical_shift": "-10.0 ppm"} assert the_site.json() == result, "Failed Site.json()" result = { "isotope": "27Al", "isotropic_chemical_shift": "10.0 ppm", "shielding_symmetric": {"zeta": "12.1 ppm", "eta": 0.1, "alpha": "2.1 rad"}, "shielding_antisymmetric": { "zeta": "-1.1 ppm", "alpha": "0.1 rad", "beta": "2.5 rad", }, "quadrupolar": {"Cq": "10000000.0 Hz", "eta": 0.6}, } the_site = Site( isotope="27Al", isotropic_chemical_shift=10, shielding_symmetric={"zeta": 12.1, "eta": 0.1, "alpha": 2.1}, shielding_antisymmetric={"zeta": -1.1, "alpha": 0.1, "beta": 2.5}, quadrupolar={"Cq": 10e6, "eta": 0.6}, ) assert the_site.json() == result, "Failed Site.json()"
def test_direct_init_spin_system(): # test-1 # empty spin system the_spin_system = SpinSystem(sites=[], abundance=10, transition_pathways=None) assert the_spin_system.sites == [] assert the_spin_system.abundance == 10.0 assert the_spin_system.transition_pathways is None assert the_spin_system.json() == {"abundance": "10.0 %"} assert the_spin_system.json(units=False) == { "abundance": 10.0, } # test-2 # site test_site = Site(isotope="29Si", isotropic_chemical_shift=10) assert test_site.isotope.symbol == "29Si" assert test_site.isotropic_chemical_shift == 10.0 assert test_site.property_units["isotropic_chemical_shift"] == "ppm" assert test_site.json() == { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm", } assert test_site.json(units=False) == { "isotope": "29Si", "isotropic_chemical_shift": 10.0, } # test-3 # one site spin system the_spin_system = SpinSystem(sites=[test_site], abundance=10) assert isinstance(the_spin_system.sites[0], Site) assert the_spin_system.abundance == 10.0 assert the_spin_system.json() == { "sites": [{ "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }], "abundance": "10.0 %", } assert the_spin_system.json(units=False) == { "sites": [{ "isotope": "29Si", "isotropic_chemical_shift": 10.0 }], "abundance": 10, } # test-4 # two sites spin system the_spin_system = SpinSystem(sites=[test_site, test_site], abundance=10) assert isinstance(the_spin_system.sites[0], Site) assert isinstance(the_spin_system.sites[1], Site) assert id(the_spin_system.sites[0]) != id(the_spin_system.sites[1]) assert the_spin_system.abundance == 10.0 assert the_spin_system.json() == { "sites": [ { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }, { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }, ], "abundance": "10.0 %", } assert the_spin_system.json(units=False) == { "sites": [ { "isotope": "29Si", "isotropic_chemical_shift": 10.0 }, { "isotope": "29Si", "isotropic_chemical_shift": 10.0 }, ], "abundance": 10, } # test-5 # coupling test_coupling = Coupling(site_index=[0, 1], isotropic_j=10, dipolar={"D": 100}) assert test_coupling.site_index == [0, 1] assert test_coupling.isotropic_j == 10.0 assert test_coupling.property_units["isotropic_j"] == "Hz" assert test_coupling.dipolar.D == 100.0 assert test_coupling.dipolar.property_units["D"] == "Hz" assert test_coupling.json() == { "site_index": [0, 1], "isotropic_j": "10.0 Hz", "dipolar": { "D": "100.0 Hz" }, } assert test_coupling.json(units=False) == { "site_index": [0, 1], "isotropic_j": 10.0, "dipolar": { "D": 100.0 }, } # test-6 # two sites and one coupling spin system the_spin_system = SpinSystem(sites=[test_site, test_site], couplings=[test_coupling], abundance=10) assert isinstance(the_spin_system.sites[0], Site) assert isinstance(the_spin_system.sites[1], Site) assert isinstance(the_spin_system.couplings[0], Coupling) assert id(the_spin_system.sites[0]) != id(the_spin_system.sites[1]) assert the_spin_system.abundance == 10.0 assert the_spin_system.json() == { "sites": [ { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }, { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }, ], "couplings": [{ "site_index": [0, 1], "isotropic_j": "10.0 Hz", "dipolar": { "D": "100.0 Hz" }, }], "abundance": "10.0 %", } assert the_spin_system.json(units=False) == { "sites": [ { "isotope": "29Si", "isotropic_chemical_shift": 10.0 }, { "isotope": "29Si", "isotropic_chemical_shift": 10.0 }, ], "couplings": [{ "site_index": [0, 1], "isotropic_j": 10.0, "dipolar": { "D": 100.0 } }], "abundance": 10, } # test-5 the_spin_system = SpinSystem( name="Just a test", description="The same", sites=[ { "isotope": "1H", "isotropic_chemical_shift": 0 }, { "isotope": "17O", "isotropic_chemical_shift": -10, "quadrupolar": { "Cq": 5.1e6, "eta": 0.5 }, }, ], couplings=[{ "site_index": [0, 1], "isotropic_j": 34 }], abundance=4.23, ) assert the_spin_system.name == "Just a test" assert the_spin_system.description == "The same" assert the_spin_system.sites[0].isotope.symbol == "1H" assert the_spin_system.sites[0].isotropic_chemical_shift == 0 assert the_spin_system.sites[1].isotope.symbol == "17O" assert the_spin_system.sites[1].isotropic_chemical_shift == -10 assert the_spin_system.sites[1].quadrupolar.Cq == 5.1e6 assert the_spin_system.sites[1].quadrupolar.eta == 0.5 assert the_spin_system.couplings[0].site_index == [0, 1] assert the_spin_system.couplings[0].isotropic_j == 34.0 assert the_spin_system.abundance == 4.23 serialize = the_spin_system.json() assert serialize == { "name": "Just a test", "description": "The same", "sites": [ { "isotope": "1H", "isotropic_chemical_shift": "0.0 ppm" }, { "isotope": "17O", "isotropic_chemical_shift": "-10.0 ppm", "quadrupolar": { "Cq": "5100000.0 Hz", "eta": 0.5 }, }, ], "couplings": [{ "site_index": [0, 1], "isotropic_j": "34.0 Hz" }], "abundance": "4.23 %", } assert the_spin_system == SpinSystem.parse_dict_with_units(serialize) json_no_unit = the_spin_system.json(units=False) assert json_no_unit == { "name": "Just a test", "description": "The same", "sites": [ { "isotope": "1H", "isotropic_chemical_shift": 0 }, { "isotope": "17O", "isotropic_chemical_shift": -10.0, "quadrupolar": { "Cq": 5100000, "eta": 0.5 }, }, ], "couplings": [{ "site_index": [0, 1], "isotropic_j": 34.0 }], "abundance": 4.23, } assert the_spin_system == SpinSystem(**json_no_unit)
def test_direct_init_spin_system(): # test-1 the_spin_system = SpinSystem(sites=[], abundance=10) assert the_spin_system.sites == [] assert the_spin_system.abundance == 10.0 assert the_spin_system.json() == {"sites": [], "abundance": "10.0 %"} assert the_spin_system.reduced_dict() == { "sites": [], "abundance": 10.0, } # test-2 test_site = Site(isotope="29Si", isotropic_chemical_shift=10) assert test_site.isotope.symbol == "29Si" assert test_site.isotropic_chemical_shift == 10.0 assert test_site.property_units["isotropic_chemical_shift"] == "ppm" assert test_site.json() == { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm", } assert test_site.reduced_dict() == { "isotope": "29Si", "isotropic_chemical_shift": 10.0, } # test-3 the_spin_system = SpinSystem(sites=[test_site], abundance=10) assert isinstance(the_spin_system.sites[0], Site) assert the_spin_system.abundance == 10.0 assert the_spin_system.json() == { "sites": [{ "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }], "abundance": "10.0 %", } assert the_spin_system.reduced_dict() == { "sites": [{ "isotope": "29Si", "isotropic_chemical_shift": 10.0 }], "abundance": 10, } # test-4 the_spin_system = SpinSystem(sites=[test_site, test_site], abundance=10) assert isinstance(the_spin_system.sites[0], Site) assert isinstance(the_spin_system.sites[1], Site) assert id(the_spin_system.sites[0]) != id(the_spin_system.sites[1]) assert the_spin_system.abundance == 10.0 assert the_spin_system.json() == { "sites": [ { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }, { "isotope": "29Si", "isotropic_chemical_shift": "10.0 ppm" }, ], "abundance": "10.0 %", } assert the_spin_system.reduced_dict() == { "sites": [ { "isotope": "29Si", "isotropic_chemical_shift": 10.0 }, { "isotope": "29Si", "isotropic_chemical_shift": 10.0 }, ], "abundance": 10, } # test-5 the_spin_system = SpinSystem( name="Just a test", description="The same", sites=[ { "isotope": "1H", "isotropic_chemical_shift": 0 }, { "isotope": "17O", "isotropic_chemical_shift": -10, "quadrupolar": { "Cq": 5.1e6, "eta": 0.5 }, }, ], abundance=4.23, ) assert the_spin_system.name == "Just a test" assert the_spin_system.description == "The same" assert the_spin_system.sites[0].isotope.symbol == "1H" assert the_spin_system.sites[0].isotropic_chemical_shift == 0 assert the_spin_system.sites[1].isotope.symbol == "17O" assert the_spin_system.sites[1].isotropic_chemical_shift == -10 assert the_spin_system.sites[1].quadrupolar.Cq == 5.1e6 assert the_spin_system.sites[1].quadrupolar.eta == 0.5 assert the_spin_system.abundance == 4.23 assert the_spin_system.json() == { "name": "Just a test", "description": "The same", "sites": [ { "isotope": "1H", "isotropic_chemical_shift": "0.0 ppm" }, { "isotope": "17O", "isotropic_chemical_shift": "-10.0 ppm", "quadrupolar": { "Cq": "5100000.0 Hz", "eta": 0.5 }, }, ], "abundance": "4.23 %", } assert the_spin_system.reduced_dict() == { "name": "Just a test", "description": "The same", "sites": [ { "isotope": "1H", "isotropic_chemical_shift": 0 }, { "isotope": "17O", "isotropic_chemical_shift": -10.0, "quadrupolar": { "Cq": 5100000, "eta": 0.5 }, }, ], "abundance": 4.23, }