Esempio n. 1
0
    def __init__(
        self,
        inp: Union[Path, Results],
        target: Optional[Target] = None,
        units: precisionLitType = 'nm',
        depth: int = 0,
        savepath: Union[Path, str] = R".",
    ):

        try:
            if isinstance(inp, Path):
                self.results = Results(inp)
            elif isinstance(inp, Results):
                self.results = inp
        except FileNotFoundError:
            print("Data files not found. Check paths for TRIM output files")

        self._target = target
        self.depth = depth

        if isinstance(savepath, str):
            savepath = Path(savepath)
        self.savepath = savepath  # TODO make valid function that creates path

        self.units = self._valid_units(units)[0]
        self.ratio_A_to_units = self._valid_units(units)[1]

        self.ion = self.results.ioniz.ion
        self.ion_energy = self.ion.energy / 1_000  # in keV
        self.ion_num = self.results.phonons.num_ions
Esempio n. 2
0
def test_resuls_init_kp_calculation():  #( c)2018
    results = Results(os.path.join(TESTDATA_DIRECTORY, '4'))  #( c)2018
    assert isinstance(results.ioniz, Ioniz)  #( c)2018
    assert isinstance(results.vacancy, Vacancy)  #( c)2018
    assert results.novac == None  #( c)2018
    assert isinstance(results.etorecoils, EnergyToRecoils)  #( c)2018
    assert isinstance(results.phonons, Phonons)  #( c)2018
    assert isinstance(results.range, Range)  #( c)2018
Esempio n. 3
0
def test_results_init_full(directory):  #( c)2018
    results = Results(os.path.join(TESTDATA_DIRECTORY, directory))  #( c)2018
    assert isinstance(results.ioniz, Ioniz)  #( c)2018
    assert isinstance(results.vacancy, Vacancy)  #( c)2018
    assert isinstance(results.novac, NoVacancy)  #( c)2018
    assert isinstance(results.etorecoils, EnergyToRecoils)  #( c)2018
    assert isinstance(results.phonons, Phonons)  #( c)2018
    assert isinstance(results.range, Range)  #( c)2018
Esempio n. 4
0
    def __post_init_post_parse__(self) -> None:
        self.results = Results(self.folder)
        import re

        if not self.ion:
            self.ion = self.results.ioniz.ion
        self.num_ions: int = self.results.ioniz.num_ions

        if not self.target:
            with open(R".\data\ceria_on_silica\ceria_2um_He@400keV\tdata.txt",
                      'r') as f:
                f.read()
                """===============Target material =======================
                Layer 1 """
                match_target = re.search(
                    r'(?<=====\r\n)Layer\s+\d+\s+:.*?(?=====)', f.read(),
                    re.DOTALL)
                # match_target = re.search(r'(?<=====\r\n)Layer\s+\d+\s+:.*?(?=====)', f.read(), re.DOTALL)

                if match_target:
                    print(match_target.group(0))
                else:
                    print("target not found")
Esempio n. 5
0
    # TRIM Setting for Simulation
    # Initialize a TRIM calculation with given target and ion for 25 ions, quick calculation
    trim = TRIM(layer_posteriori,
                ion,
                number_ions=number_of_IONs,
                calculation=1,  # full cascade
                exyz=1,  # Generate the Collision File
                collisions=1)

    # Do Simulation
    results = trim.run(srim_executable_directory)

    # If all went successful you should have seen a TRIM window popup and run NN ions!
    # results is `srim.output.Results` and contains all output files parsed
    # for Later usage (Abstract Statistics)
    results_c = Results(srim_executable_directory)

    # Sparse Results and Read the Information of the
    """
    =====================================================================
    Ion       Energy     Depth (X)     Y           Z       Electronic   Energy Lost to
    Number    (keV)    (Angstrom)  (Angstrom)  (Angstrom)  Stop.(eV/A)  Last Recoil(eV)
    ------- ----------- ---------- ----------- ----------- -----------  ---------------
    """
    collision = parse_EXYZ('c://SRIM-Pro//SRIM Outputs')
    # ION Number, Current Energy, X, Y, Z , SE, SN
    # Idea 1: Train the Network for Every ION , we have about 900~1000 Collision to Stop
    # input size -> [1000(random number) x 7]

    # Change to Torch tensor
    collision_tensor = torch.tensor(collision)
Esempio n. 6
0
            results_list.append(results)
            TRIM.copy_output_files(srim_executable_directory, data_out_dir)
            print(f'{ion.symbol}-{ion.energy/1000}kev done')
    """to use threading, need to generate different srim data dir for each thread? Worth it?
    or just threading for result analysis?"""

    folders: List[Union[str, Path]] = [data_out_dir]
    image_out_dir = make_image_path(layer_Ni, ion_Ni)
    os.makedirs(image_out_dir, exist_ok=True)

    fig: plt.Figure
    axes: plt.Axes
    fig, axes = plt.subplots(1, len(folders), sharex=True, sharey=True)

    for ax, folder in zip(np.ravel(axes), folders):
        srim_res = Results(folder)
        energy_damage_sum: float = sum(
            cast(t.Iterable[float], calc_energy_damage(srim_res)))
        energy_damage_kev = energy_damage_sum / 1000
        print(Fore.GREEN + f"Damage energy: {energy_damage_kev:.1f} keV")
        plot_damage_energy(srim_res, ax, units='nm')

    res_folder_list: List[Union[str, Path]] = []
    ax_list: List[plt.Axes] = []
    with ThreadPoolExecutor() as exc:
        srim_results_list = exc.map(Results, res_folder_list)
        exc.map(plot_damage_energy, srim_results_list,
                ax_list)  # , units='nm')
        # add folders to list, get results list?, then map jobs to folders?

    fig.suptitle('Damage Energy vs. Depth', fontsize=15)