def __init__(self, dir, printlabel, Settings="empty"): from functions import fn_check_dir from GUI_mainframe import update_GUI update_GUI("Reading in experiment.", printlabel) self.dir = dir if Settings == "empty": from functions import fn_settings Settings = fn_settings() self.Settings = Settings self.printlabel = printlabel if fn_check_dir(dir[:dir.find('pdata')], "pulseprogram"): if "seldigpzs2d" in open( dir[:dir.find('pdata')] + r"\pulseprogram", "r").readlines()[0]: self.pp = "seldigpzs2d" self.init_seldigpzs2d(self.dir, self.printlabel) elif "dipsigpphzs" in open( dir[:dir.find('pdata')] + r"\pulseprogram", "r").readlines()[0]: self.pp = "dipsigpphzsbs" self.init_dipsigpphzsbs(self.dir, self.printlabel) else: update_GUI("error; no correct pulseprogram found", printlabel)
def check_exp_status(self): if type(self.experiment) == list: from functions import fn_check_dir if "pdata" in Settings["Experiment_Directory"] and fn_check_dir(Settings["Experiment_Directory"], "auditp.txt"): self.change_exp_status("blue") else: self.change_exp_status("red") else: self.change_exp_status("green")
def check_data_status(self): if type(self.database) == list: from functions import fn_check_dir status = fn_check_dir(Settings["Database_Directory"], "Database.p") if status: self.change_data_status("blue") else: self.change_data_status("red") else: if self.database.status: self.change_data_status("green") else: self.change_data_status("orange")
def fn_load(self): # load in the functions from pickle import load from functions import fn_check_dir from GUI_mainframe import update_GUI if (fn_check_dir(self.dir, r"\Database.p")): self.content = load(open(self.dir + r"\Database.p", "rb")) update_GUI("Loaded the Database from given location.", self.printlabel) self.fn_override_settings(self.Settings) else: self.content = [] update_GUI("No database file was found in the given location.", self.printlabel) return self
def fn_compile(self): from GUI_mainframe import update_GUI from functions import fn_check_folders # check if database exist and prompt user from functions import fn_check_dir, fn_progress_gen if fn_check_dir(self.dir, "Database.p"): import tkinter.messagebox as mg if self.printlabel == "testing": import tkinter as tk crap = tk.Tk() crap.withdraw() override = mg.askyesno( "Delete", "Override current database?\nIf you are missing items the database will not be complete." ) if not override: update_GUI("Not performing database compilation.", self.printlabel) return # check for all existing folders in the given location dir_list = fn_check_folders(self.dir) self.dir_list = dir_list #initialise all experiments and calculate progressbar progress = round(0.000000, 1) update_GUI("Performing database compilation.", self.printlabel) # wipe current self.content = [] for y in range(len(self.dir_list)): if round((1 + y) / (len(dir_list) + 1), 1) != progress: progress = round(y / len(dir_list), 1) update_GUI(fn_progress_gen(progress), self.printlabel) #load in the experiment exp = Experiment(dir_list[y] + "\\pdata\\1", "ignore") for chunk in exp.chunks: self.content.append(chunk) self.status = self.fn_save()
def init_seldigpzs2d(self, dir, printlabel): import nmrglue as ng import numpy as np from functions import fn_check_dir from GUI_mainframe import update_GUI self.dic, self.data = ng.bruker.read_pdata(dir) # read in the alternate data if possible - compenation for the NMRGlue chunk error # can be deleted once we fixed nmrglue!!! if self.dic["procs"]["XDIM"] != self.dic["procs"]["FTSIZE"]: self.data_file = "" if fn_check_dir(dir, "DATABASE.txt"): self.data_file = open(dir + r"\DATABASE.txt", 'r').readlines() elif fn_check_dir(dir, "SAMPLES.txt"): self.data_file = open(dir + r"\SAMPLES.txt", 'r').readlines() if self.data_file != "": self.data = [] for line in self.data_file: if ("row" in line): self.data.append([]) else: if "#" not in line: self.data[len(self.data) - 1].append( float(line.replace(r"\n", ""))) else: print("No extra data file was found...") print("This was not correctly processed using topspin!") quit() # reform the data for oversaving effect from copy import deepcopy test_data = deepcopy(self.data) self.data = [] for x in range(len(test_data)): if (test_data[x][0] != 0.0): self.data.append(test_data[x]) # collect the parameters from functions import fn_vclist, fn_fqlist, fn_parameters, fn_read_title self.dic2 = open(dir[:dir.find('pdata')] + r'\acqus', 'r').read() self.dic3 = open(dir[:dir.find('pdata')] + r'\acqu2s', 'r').read() self.B0_hz, self.SW_ppm, self.SW_hz, self.duplet_ppm, self.chunk_num, self.offset = fn_parameters( self.dic, self.dic2, self.dic3, self.pp) self.SW_ppm = 0.5 * self.SW_ppm self.SO1_ppm = 0.5 * self.SW_ppm - self.offset # collect the lists self.vclist = fn_vclist(dir) self.fqlist, self.fqlist_ppm = fn_fqlist(dir, self.B0_hz) self.mtlist = np.array(self.vclist) * 115.112 * 25 * 10**(-6) # colect the title self.sample_name, self.extra_info, self.order = fn_read_title(dir) # print out the title update_GUI("Working on %s sample." % self.sample_name, self.printlabel) # all data was read in now - end of initialisation of the sample # starting the chunkification if present import numpy as np from functions import fn_unique from GUI_mainframe import update_GUI # find the unique fqs self.fqlist_u = fn_unique(self.fqlist) # chunk up the data per fq and remove the minus signals (reduce data amount for calculations) self.chunks = [] update_GUI("Calculating peaks and integrals for each chunk.", self.printlabel) for x in range(self.chunk_num): chunk = self.data[x * len(self.vclist):((x + 1) * len(self.vclist))] max = np.max(chunk) row = chunk[0] keep = int(len(row) / 2) # remove negative half new_chunk, new_data = [], [] for row in chunk: new_chunk.append(row[:keep] / max) # create the title for the chunk if len(self.order) != 0: title = self.order[x] else: title = "%i-%s" % (x, self.sample_name) #initialise chunk and perform the functions that are needed chunk_temp = Chunk(new_chunk, title, self.fqlist[x], self.SW_ppm, self.duplet_ppm, self.mtlist, self.SO1_ppm, self.pp, self.printlabel, self.Settings) self.chunks.append(chunk_temp) #return self # list of all chunk objects if self.Settings["plot_exp"]: self.fn_plot()