Beispiel #1
0
def test_equality():
    a = Simulator()
    b = Simulator()
    assert a == b

    assert a != {}

    c = Simulator(spin_systems=[SpinSystem()], label="test")
    assert a != c

    result = {
        "label": "test",
        "spin_systems": [{
            "abundance": "100 %",
            "sites": []
        }],
        "config": {
            "decompose_spectrum": "none",
            "integration_density": 70,
            "integration_volume": "octant",
            "number_of_sidebands": 64,
        },
    }
    assert c.json(include_methods=True) == result

    assert c.reduced_dict() == {
        "label": "test",
        "spin_systems": [{
            "abundance": 100,
            "sites": []
        }],
        "methods": [],
        "config": {
            "number_of_sidebands": 64,
            "integration_volume": "octant",
            "integration_density": 70,
            "decompose_spectrum": "none",
        },
    }
Beispiel #2
0
def test_simulator_1():
    sim = Simulator()
    sim.spin_systems = [
        SpinSystem(sites=[Site(
            isotope="1H"), Site(isotope="23Na")])
    ]
    sim.methods = [BlochDecaySpectrum()]
    sim.name = "test"
    sim.label = "test0"
    sim.description = "testing-testing 1.2.3"

    red_dict = sim.reduced_dict()
    _ = [item.pop("description") for item in red_dict["methods"]]

    assert red_dict == {
        "name":
        "test",
        "label":
        "test0",
        "description":
        "testing-testing 1.2.3",
        "spin_systems": [{
            "sites": [
                {
                    "isotope": "1H",
                    "isotropic_chemical_shift": 0
                },
                {
                    "isotope": "23Na",
                    "isotropic_chemical_shift": 0
                },
            ],
            "abundance":
            100,
        }],
        "methods": [{
            "channels": ["1H"],
            "name":
            "BlochDecaySpectrum",
            "spectral_dimensions": [{
                "count":
                1024,
                "events": [{
                    "fraction": 1.0,
                    "freq_contrib": freq_default,
                    "magnetic_flux_density": 9.4,
                    "rotor_angle": 0.955316618,
                    "rotor_frequency": 0.0,
                    "transition_query": {
                        "P": {
                            "channel-1": [[-1]]
                        }
                    },
                }],
                "reference_offset":
                0.0,
                "spectral_width":
                25000.0,
            }],
        }],
        "config": {
            "decompose_spectrum": "none",
            "integration_density": 70,
            "integration_volume": "octant",
            "number_of_sidebands": 64,
        },
    }

    # save
    sim.save("test_sim_save.temp")
    sim_load = sim.load("test_sim_save.temp")

    assert sim_load.spin_systems == sim.spin_systems
    assert sim_load.methods == sim.methods
    assert sim_load.name == sim.name
    assert sim_load.description == sim.description
    assert sim_load == sim

    # without units
    sim.save("test_sim_save_no_unit.temp", with_units=False)
    sim_load = sim.load("test_sim_save_no_unit.temp", parse_units=False)
    assert sim_load == sim