def setUpClass(cls): cls.directory = Path(tempfile.gettempdir()) target = Target(layers=[ Layer("layer1", [ Element.from_string("Li 1.0") ], 0.01, 0.01, start_depth=0.0), Layer("layer2", [ Element.from_string("Li 0.048"), Element.from_string("O 0.649"), Element.from_string("Mn 0.303") ], 90.0, 4.0, start_depth=0.01), Layer("subtrate", [ Element.from_string("Si 1.0") ], 1000.0, 2.32, start_depth=90.01) ]) cls.mcerd = MCERD(101, { "recoil_element": mo.get_recoil_element(), "sim_dir": tempfile.gettempdir(), "simulation_type": SimulationType.ERD, "target": target, "detector": mo.get_detector(), "beam": mo.get_beam(), # Following simulation parameters have been determined by the # rigorous application of the Stetson-Harrison method. "minimum_scattering_angle": 5.5, "minimum_main_scattering_angle": 6.5, "minimum_energy_of_ions": 8.15, "number_of_recoils": 15, "simulation_mode": SimulationMode.NARROW, "number_of_scaling_ions": 14, "number_of_ions_in_presimu": 100, "number_of_ions": 1000 }, mo.get_element_simulation().get_full_name())
def setUp(self): beam = mo.get_beam() det = mo.get_detector() self.rec_file = Path(tempfile.gettempdir(), "rec") self.erd_file = Path(tempfile.gettempdir(), "erd") self.espe = GetEspe( beam.ion.get_prefix(), beam.energy, det.detector_theta, mo.get_target().target_theta, det.calculate_tof_length(), det.calculate_solid(), self.rec_file, self.erd_file)
def test_serialization(self): with tempfile.TemporaryDirectory() as tmp_dir: fp = Path(tmp_dir, "test.simu") sim = Simulation(Path(tmp_dir, "foo.simulation"), mo.get_request(), name="foo", description="bar", save_on_creation=False, run=mo.get_run(), detector=mo.get_detector(), target=mo.get_target(), enable_logging=False, use_request_settings=False) sim.to_file(fp) sim2 = Simulation.from_file(mo.get_request(), fp, detector=mo.get_detector(), target=mo.get_target(), run=mo.get_run(), enable_logging=False, save_on_creation=False) self.assertEqual(sim.name, sim2.name) self.assertEqual(sim.description, sim2.description) self.assertEqual(sim.measurement_setting_file_description, sim2.measurement_setting_file_description) self.assertEqual(sim.measurement_setting_file_name, sim2.measurement_setting_file_name) self.assertEqual(sim.use_request_settings, sim2.use_request_settings) self.assertEqual(sim.detector.name, sim2.detector.name) self.assertEqual(sim.detector.angle_offset, sim2.detector.angle_offset) self.assertEqual(sim.target.scattering_element, sim2.target.scattering_element) self.assertEqual(sim.target.target_type, sim2.target.target_type) self.assertEqual(sim.run.fluence, sim2.run.fluence)
def setUp(self): self.detector = mo.get_detector() self.request = mo.get_request() self.eff_files = [ "H.eff", "1H.eff", "1H-comment.eff", "2H.eff", "O.efff"] self.detector.update_directories(self.DETECTOR_DIR) for eff in self.eff_files: fp = self.DETECTOR_DIR / eff open(fp, "a").close() self.detector.add_efficiency_file(fp)
def setUp(self): self.beam = mo.get_beam() self.detector = mo.get_detector() self.target = mo.get_target() self.default_kwargs = { "beam_ion": self.beam.ion.get_prefix(), "energy": self.beam.energy, "theta": self.detector.detector_theta, "toflen": self.detector.calculate_tof_length(), "tangle": self.target.target_theta, "solid": self.detector.calculate_solid(), "recoil_file": _RECOIL_FILE, "erd_file": _ERD_FILE, "reference_density": 4.98e22, "ch": 0.025, "fluence": 5.00e+11, "timeres": self.detector.timeres, }
def test_initialization(self, mock_exec): """A simple test to see if various dialogs get initialized properly. """ e = ElementLossesDialog(Mock(), mo.get_measurement()) e.close() c = CalibrationDialog([mo.get_measurement()], mo.get_detector(), mo.get_run()) c.close() # AttributeError is raised if simulation has no sample self.assertRaises( AttributeError, lambda: OptimizationDialog(mo.get_simulation(), Mock())) sample = mo.get_sample() sim = mo.get_simulation() sim.sample = sample o = OptimizationDialog(sim, Mock()) self.assertFalse(o.pushButton_OK.isEnabled()) o.close() assert mock_exec.call_count == 3