HOME ESR EXPERIMENTS LABS etc
E121 E127 E132 E125 E143 laser_cooling_2021 E142 128 E146 E0052 E0018 E0028 E0038 E0075 E0203_E0018
  masses & isomeres 2025  Not logged in ELOG logo
Message ID: 2     Entry time: Thu Mar 27 09:42:04 2025
Author: Ruijiu Chen 
Category: Simulations 
Subject: Simulation Results for 194Pb and 188Hf 
Summary:

1.Simulated spectra for 194Pb and 188Hf.
2.The results are attached.
3. For the 188Hf simulation, some nuclides in the fragments are missing from the AME database, causing errors in the LiseReader program.
To fix this, please download the attached reader.py file and replace your local file at lisereader-main\lisereader\reader.py.
After replacing the file, recompile the program. Once recompiled, you should be able to simulate the 188Hf spectrum without issues.
Attachment 1: simulation_194Pb_1.png  234 kB  | Hide | Hide all | Show all
simulation_194Pb_1.png
Attachment 2: simulation_194Pb_2.png  195 kB  | Hide | Hide all | Show all
simulation_194Pb_2.png
Attachment 3: exercise_194Pb_Exp_2025.tar.gz  242 kB
Attachment 4: simulation_result_-_194Pb.out  169 kB  | Show | Hide all | Show all
Attachment 5: simulation_188Hf_1.png  206 kB  | Hide | Hide all | Show all
simulation_188Hf_1.png
Attachment 6: simulation_188Hf_2.png  182 kB  | Hide | Hide all | Show all
simulation_188Hf_2.png
Attachment 7: simulation_result_-_188Hf.out  161 kB  | Show | Hide all | Show all
Attachment 8: exercise_188Hf_Exp_2025.tar.gz  234 kB
Attachment 9: reader.py  4 kB  | Hide | Hide all | Show all
import numpy as np
from barion.amedata import *
from re import sub


class LISEreader:
    def __init__(self, filename):
        ame = AMEData()
        ame.init_ame_db
        self.ame_data = ame.ame_table
        self._read(filename)

    def _read(self, filename):
        with open(filename,encoding='latin1') as f:
            lines = f.readlines()

        for (i, line) in enumerate(lines):
            if '[Calculations]' in line:
                file_start = i+1
    
        # finds point in line where separator changes from space to comma
        self.centre_index = len(lines[file_start].split()) - 1

        # splits lines and adds to list of all data
        self.data = [line.replace('+', '').split()[0:self.centre_index] 
                     + line.replace('=', '').split()[self.centre_index].split(',')
                     for line in lines[file_start:]]

    def get_index(self, name):
        returned_queries = []
        for i, element in enumerate(self.data):
            if element[0] + '+' + element[1] == name:
                returned_queries.append(i)
            elif element[0] + element[1] + '+' == name:
                returned_queries.append(i)
                
        if len(returned_queries) == 1:
            return returned_queries[0]
        
        elif len(returned_queries) > 1:
            print('get_index() returned multiple queries, returning first')
            return returned_queries[0]
        
        else:
            print(element[0] + element[1] + '+')
            raise ValueError('get_index() returned nothing. Check formatting (e.g. \"80Kr35+\")')

    def get_info(self, name):
        try:
            index = self.get_index(name)
            from_lise = [list(map(int, self.data[index][1:self.centre_index])),
                         float(self.data[index][self.centre_index])]
    
            # Extract element and mass number
            element = sub('[^a-zA-Z]', '', name)
            aux = sub('[a-zA-Z]', '', name)
            aux2 = aux.index('+')
            mass_number = int(aux[:aux2])
    
            # Match to AME data
            from_ame_candidates = [[line[6], line[5], line[4], line[3]]
                                   for line in self.ame_data
                                   if (element == line[6] and mass_number == line[5])]
    
            if not from_ame_candidates:
                raise ValueError(
                    f"⚠️ Nuclide {element}-{mass_number} not found in AME database.\n"
                    f"→ Please check if the AME data needs to be updated, or verify the formatting/spelling (e.g., 'Os' vs 'OS')."
                )
    
            from_ame = from_ame_candidates[0]
            return from_ame + from_lise
    
        except Exception as e:
            print(f"❌ Error in get_info({name}): {e}")
            raise


    def get_lise_all(self):
        data = np.array(self.data)
        return np.transpose([data[:, 0], data[:, 5], data[:, 6]])

    def get_info_all(self):
        #return [self.get_info(line[0] + '+' + line[1]) for line in self.data]
        result = []
        for line in self.data:
            if len(line) >= 2:
                ion_name = line[0] + '+' + line[1]
                try:
                    info = self.get_info(ion_name)
                    result.append(info)
                except Exception as e:
                    print(f"⚠️ Skipping {ion_name} due to error: {e}")
        return result    

    def get_info_specific(self,param_index_list):
        return_list = [[LISEreader.float_check(line[i]) for i in param_index_list]
                       for line in self.data]
        return return_list

    def get_yield_sorted(self):
        name_yield = [[str(line[0]) + '+' + str(line[1]), LISEreader.float_check(line[7])] for line in self.data]
        sorted_by_yield = sorted(name_yield, key=lambda x: x[1])[::-1]
        return sorted_by_yield
        
    @staticmethod
    def float_check(value): #returns float if not string
        if value.replace('.','').replace('e-','').replace('e+','').isdigit():
            return float(value)
        else:
            return value
        
# ================== testing =====================

def test1():
    print(f"get_info(\'80Kr\'): {lise_data.get_info('80Kr')}")
    
def test2():
    print(f'get_info_all() snippet[:3]: {lise_data.get_info_all()[:3]}')
    
def test3():
    print(f"get_info_specific([0,1,10]) snippet[:3]: {lise_data.get_info_specific([0,1,10])[:3]}")

if __name__ == '__main__':
    filename = 'E143_TEline-ESR-72Ge.lpp'
    lise_data = LISEreader(filename)
    try:
        test1()
        test2()
        test3()
    except:
        raise
ELOG V3.1.5-fc6679b