def change_dir_and_refresh_interface(self, new_dir): used_files_add(os.path.join(new_dir, "sim.gpvdm")) self.scan_human_labels.clear() inp_callbacks_clear() get_watch().reset() self.splash.inc_value() self.scan_human_labels.populate_from_known_tokens() self.splash.inc_value() self.splash.inc_value() set_sim_path(new_dir) self.splash.inc_value() calculate_paths() self.splash.inc_value() epi = get_epi() epi.load(get_sim_path()) self.splash.inc_value() self.splash.inc_value() if get_mesh().load(epi) == False: error_dlg( self, _("There was a problem loading the electrical mesh, I suspect you are trying to open a file generated in a very old version of gpvdm." )) return self.statusBar().showMessage(get_sim_path()) self.splash.inc_value() self.notebook.load() self.update_interface() self.enable_disable_buttons() self.splash.inc_value() if self.notebook.terminal != None: self.my_server.set_terminal(self.notebook.terminal) if self.notebook.update_display_function != None: self.my_server.set_display_function( self.notebook.update_display_function) self.scan_human_labels.add_item("sim.inp", "#simmode", "sim mode") self.scan_human_labels.add_item("light.inp", "#Psun", "light intensity") #scan_populate_from_file("light.inp") self.ribbon.update() self.splash.inc_value() if self.notebook.is_loaded() == True: self.l.run() self.notebook.tab_main.three_d.update() get_watch().rebase()
def load_sim(self, filename): new_path = os.path.dirname(filename) if filename.startswith(get_share_path()) == True: error_dlg( self, _("You should not try to open simulations in the root gpvdm directory." )) return if ver_check_compatibility(filename) == True: self.change_dir_and_refresh_interface(new_path) else: update = yes_no_dlg( self, _("The simulation you want to import looks like it was made on an old version of gpvdm, do you want to try to open it anyway?" )) if update == True: update_simulaton_to_new_ver(filename) self.change_dir_and_refresh_interface(new_path) if os.path.isdir(os.path.join(new_path, "materials")) == False: copy = yes_no_dlg( self, _("It looks like there is no materials database in the simulation directory should I import one?" )) if copy == True: clone_materials(new_path)
def callback_open(self): file_name = open_as_filter( self, "dat (*.dat);;csv (*.csv);;txt (*.txt);;inp (*.inp);;omat (*.omat)" ) if file_name != None: lines = [] lines = inp_load_file(file_name) begin = -1 end = -1 for i in range(0, len(lines)): if lines[i] == "#data": begin = i if lines[i] == "#end": end = i if begin == -1 or end == -1: error_dlg( self, _("The data file does not have a #begin or #end token indicating where the data starts and ends." )) return rel_path = os.path.relpath(file_name, get_sim_path()) self.tab.insertRow(self.tab.rowCount()) self.insert_row(self.tab.rowCount(), "true", rel_path, "#data", rel_path, str(end - begin), "1") self.save_combo()
def save(self): if self.update_contact_db()==True: contacts_save() self.changed.emit() global_object_run("gl_force_redraw") else: error_dlg(self,_("There are some non numeric values in the table"))
def run(self, run_simulation=True, generate_simulations=True, args=""): f = inp() f.load(os.path.join(self.scan_dir, "scan_config.inp")) args = f.get_token("#scan_config_args") if args == False: args = "" args = args + " --mindbustx" if self.scan_dir == "": error_dlg(self.parent_window, _("No sim dir name")) return self.make_dir() if generate_simulations == True: self.build_scan() if run_simulation == True: commands = tree_load_flat_list(self.scan_dir) if commands == False: error_dlg( self.parent_window, _("I can't load flat_list.inp. This usually means there is a problem with how you have set up your scan." )) return for i in range(0, len(commands)): self.myserver.add_job(commands[i], args) #print("Adding job"+commands[i]) self.myserver.start() gc.collect()
def update(self): self.lines=inp_load_file(self.file_name) if self.lines==False: error_dlg(self,_("File not found.")+" "+self.file_name) return for w in self.widget_list: values=inp_search_token_array(self.lines, w.token) w.edit_box.blockSignals(True) if w.widget=="gtkswitch": w.edit_box.set_value(str2bool(values[0])) elif w.widget=="leftright": w.edit_box.set_value(str2bool(values[0])) elif w.widget=="gpvdm_select": w.edit_box.setText(values[0]) elif w.widget=="QLineEdit": w.edit_box.setText(values[0]) elif w.widget=="QColorPicker": print() elif w.widget=="QComboBoxLang": print() elif w.widget=="QParasitic": w.edit_box.setValue(values[0]) elif w.widget=="QChangeLog": w.edit_box.setText(values[0]) w.edit_box.blockSignals(False)
def simulate(self, run_simulation, generate_simulations, args=""): run = True if self.tab.rowCount() == 0: error_dlg( self, _("You have not selected any parameters to scan through. Use the add button." )) return if self.sim_name == "": error_dlg(self, _("No sim dir name")) return self.make_sim_dir() tree_load_config(self.sim_dir) if generate_simulations == True: build_scan(self.sim_dir, get_sim_path(), parent_window=self) if run_simulation == True: self.scan_run(args=args) self.save_combo() os.chdir(get_sim_path()) gc.collect()
def callback_edit(self): print("updating lang file", self.file_path) inp_update_token_value(self.file_path, "#lang", self.lang_box.itemText( self.lang_box.currentIndex()), archive="base.gpvdm") error_dlg(self, "Please restart gpvdm for the changes to take effect.")
def on_cell_edited(self, x, y): if self.check_mesh() == False: error_dlg(self, _("You have entered a non numeric value.")) else: self.save_data() self.build_mesh() self.draw_graph() self.fig.canvas.draw()
def scan_run(self, args=""): commands = tree_load_flat_list(self.sim_dir) if commands == False: error_dlg( self, _("I can't load flat_list.inp. This usually means there is a problem with how you have set up your scan." )) return self.send_commands_to_server(commands, args)
def on_new_materials_clicked(self): new_sim_name=dlg_get_text( _("New material name:"), _("New material name"),"organic_material") new_sim_name=new_sim_name.ret if new_sim_name!=None: new_material=os.path.join(self.dialog.viewer.path,new_sim_name) ret=clone_material(new_material,os.path.join(get_base_material_path(),"generic","air")) if ret==False: error_dlg(self,_("I cant write to:")+new_material+" "+_("This means either the disk is full or your system administrator has not given you write permissions to that location.")) self.dialog.viewer.fill_store()
def build_mesh(self): self.x = [] self.y = [] data_min = 100.0 if self.tab.rowCount() != 0: for i in range(0, self.tab.rowCount()): val = float(tab_get_value(self.tab, i, 0)) if val < data_min: data_min = val #find max data_max = 0.0 for i in range(0, self.tab.rowCount()): val = float(tab_get_value(self.tab, i, 1)) if val > data_max: data_max = val w = data_min dx = (data_max - data_min) / (float(self.points)) for i in range(0, self.points): val = 0.0 for ii in range(0, self.tab.rowCount()): range_min = float(tab_get_value(self.tab, ii, 0)) range_max = float(tab_get_value(self.tab, ii, 1)) command = tab_get_value(self.tab, ii, 2) try: equ = eval(command) except: print(sys.exc_info()) error_dlg( self, _("You've made a mistake in the equation, use w for wavelength. " + command)) equ = -1 return if w >= range_min and w <= range_max: val = val + equ if val < 0.0: val = 1.0 self.x.append(w) self.y.append(val) w = w + dx f_name = os.path.join(self.path, self.out_file) try: a = open(f_name, "w") for i in range(0, len(self.y)): a.write(str(self.x[i]) + " " + str(self.y[i]) + "\n") a.close() except IOError: print("Could not read file:", f_name)
def update(self): if self.file_names!=None: file_name=self.file_names[0] data=self.transform(file_name) if data==False: error_dlg(self,_("Can not load file "+file_name)) return text="\n".join(data.gen_output_data()) self.out_data.setText(text)
def callback_examine(self): mycmp = cmp_class() #ret=mycmp.init(self.sim_dir,get_exe_command()) ret = mycmp.init() if ret == False: error_dlg( self, _("Re-run the simulation with 'dump all slices' set to one to use this tool." )) return
def cell_changed(self, y, x): epi = get_epi() if x == 0: epi.layers[y].name = self.tab.get_value(y, x) elif x == 1: ret = epi.layers[y].set_dy(self.tab.get_value(y, x)) if ret == False: error_dlg(self, _("You have entered a non numeric value.")) self.save_model() self.emit_structure_changed()
def tab_changed(self, y, x): val = self.tab.get_value(y, x) try: val = float(val) except: error_dlg(self, _(val + " is not a valid number.")) return self.build_mesh() self.draw_graph() self.fig.canvas.draw() self.save_data()
def callback_run_simulation(self): if self.tab.rowCount() == 0: error_dlg( self, _("You have not selected any parameters to scan through. Use the add button." )) return self.save_combo() self.scan_io.myserver = server_get() self.scan_io.myserver.callback = self.callback_build_plots self.scan_io.set_base_dir(get_sim_path()) self.scan_io.run()
def build_scan(scan_path,base_path,parent_window=None): scan_clean_dir(scan_path,parent_window=parent_window) flat_simulation_list=[] program_list=tree_load_program(scan_path) path=os.getcwd() if tree_gen(flat_simulation_list,program_list,base_path,scan_path)==False: error_dlg(parent_window,_("Problem generating tree.")) return False os.chdir(path) tree_save_flat_list(scan_path,flat_simulation_list)
def build_scan(self): self.clean_dir() flat_simulation_list = [] path = os.getcwd() #print(self.scan_dir,flat_simulation_list,self.program_list,self.base_dir) if tree_gen(self.scan_dir, flat_simulation_list, self.program_list, self.base_dir) == False: error_dlg(self.parent_window, _("Problem generating tree.")) return False os.chdir(path) tree_save_flat_list(self.scan_dir, flat_simulation_list)
def on_new_shape_clicked(self): new_sim_name = dlg_get_text(_("New shape name:"), _("New shape name"), "add_shape") new_sim_name = new_sim_name.ret if new_sim_name != None: new_shape = os.path.join(self.dialog.viewer.path, new_sim_name) ret = clone_material(new_shape, gpvdm_paths.get_shape_template_path()) if ret == False: error_dlg( self, _("I cant write to:") + new_shape + " " + _("This means either the disk is full or your system administrator has not given you write permissions to that location." )) self.dialog.viewer.fill_store()
def error_reported(self, sucess): self.label_reporting.hide() self.spin.hide() if sucess == True: error_dlg( self, "I have reported the error, for more information e-mail " + get_email()) self.close() else: error_dlg( self, "I could not report the error please send the error message to " + get_email()) self.close()
def on_new_spectra_clicked(self): new_sim_name = dlg_get_text(_("New spectra name:"), _("New spectra name"), "add_spectra") new_sim_name = new_sim_name.ret if new_sim_name != None: new_spectra = os.path.join(self.dialog.viewer.path, new_sim_name) ret = clone_spectra(new_spectra, os.path.join(get_base_spectra_path(), "sun")) if ret == False: error_dlg( self, _("I cant write to:") + new_spectra + " " + _("This means either the disk is full or your system administrator has not given you write permissions to that location." )) self.dialog.viewer.fill_store()
def error_reported(self, sucess): self.label_reporting.hide() self.spin.hide() if sucess == True: error_dlg( self, "I have reported the error, for more information e-mail [email protected]" ) self.close() else: error_dlg( self, "I could not report the error please send the error message to [email protected]" ) self.close()
def callback_fit(self): data = tab_get_selected(self.tab) if data == False: error_dlg(self, _("No items selected")) return d = fit_poly(float(data[0]), float(data[1]), self.data) d.run() if d.ret_math != None: a = self.tab.selectionModel().selectedRows() if len(a) > 0: a = a[0].row() tab_set_value(self.tab, a, 2, d.ret_math) print(d.ret_math)
def clone(self): old_name = self.currentItem().text() decode = self.decode_name(old_name) if decode.type == "scan_dir": new_sim_name = dlg_get_text(_("Clone the file to be called:"), old_name + "_new", "clone.png") new_sim_name = new_sim_name.ret if new_sim_name != None: scans = scans_io(self.path) if scans.clone(new_sim_name, old_name) == False: error_dlg(self, _("The file name already exists")) else: print(clone) self.fill_store()
def callback_trap_depth(self): lines = inp() lines.load(os.path.join(get_sim_path(), self.dos_file)) ret = dlg_get_text(_("Maximum trap depth (eV):"), lines.get_token("#srh_start"), "electrical.png") if ret.ret != None: depth = 0.0 try: depth = -abs(float(ret.ret)) except: error_dlg(self, _("That's not a number..")) lines.replace("#srh_start", str(depth)) lines.save() self.update_graph()
def change_dir_and_refresh_interface(self, new_dir): scan_items_clear() self.splash.inc_value() scan_items_populate_from_known_tokens() self.splash.inc_value() self.splash.inc_value() set_sim_path(new_dir) self.splash.inc_value() calculate_paths() self.splash.inc_value() epitaxy_load(get_sim_path()) self.splash.inc_value() contacts_load() self.splash.inc_value() if mesh_load_all() == False: error_dlg( self, _("There was a problem loading the electrical mesh, I suspect you are trying to open a file generated in a very old version of gpvdm." )) return self.statusBar().showMessage(get_sim_path()) self.splash.inc_value() self.update_interface() self.splash.inc_value() if self.notebook.terminal != None: self.my_server.set_terminal(self.notebook.terminal) if self.notebook.update_display_function != None: self.my_server.set_display_function( self.notebook.update_display_function) scan_item_add("sim.inp", "#simmode", "sim mode", 1) scan_item_add("light.inp", "#Psun", "light intensity", 1) #scan_populate_from_file("light.inp") self.ribbon.update() self.splash.inc_value()
def callback_examine(self, widget): help_window().help_set_help([ "plot_time.png", _("<big><b>Examine the results in time domain</b></big><br> After you have run a simulation in time domain, if is often nice to be able to step through the simulation and look at the results. This is what this window does. Use the slider bar to move through the simulation. When you are simulating a JV curve, the slider sill step through voltage points rather than time points." ) ]) self.my_cmp_class = cmp_class() self.my_cmp_class.show() return ret = mycmp.init() if ret == False: error_dlg( self, _("Re-run the simulation with 'dump all slices' set to one to use this tool." )) return
def callback_copy_page(self): tab = self.notebook.currentWidget() index=self.notebook.currentIndex() name=self.notebook.tabText(index) old_dir=os.path.join(self.sim_dir,name) new_sim_name=dlg_get_text( _("Clone the current simulation to a new simulation called:"), name,"clone.png") new_sim_name=new_sim_name.ret if new_sim_name!=None: new_sim_name=self.remove_invalid(new_sim_name) new_dir=os.path.join(self.sim_dir,new_sim_name) if os.path.isdir(new_dir)==True: error_dlg(self,_("This directory already exists.")) return copy_scan_dir(new_dir,old_dir) self.add_page(new_sim_name)
def build_mesh(self): data_min = 100.0 if self.tab.rowCount() != 0: for i in range(0, self.tab.rowCount()): val = float(self.tab.get_value(i, 0)) if val < data_min: data_min = val #find max data_max = 0.0 for i in range(0, self.tab.rowCount()): val = float(self.tab.get_value(i, 1)) if val > data_max: data_max = val w = data_min dx = (data_max - data_min) / (float(self.data.y_len)) for i in range(0, self.data.y_len): val = 0.0 for ii in range(0, self.tab.rowCount()): range_min = float(self.tab.get_value(ii, 0)) range_max = float(self.tab.get_value(ii, 1)) command = self.tab.get_value(self.tab, ii, 2) try: equ = eval(command) except: print(sys.exc_info()) error_dlg( self, _("You've made a mistake in the equation, use w for wavelength. " + command)) equ = -1 return if w >= range_min and w <= range_max: val = val + equ if val < 0.0: val = 1.0 self.data.y_scale[i] = w self.data.data[0][0][i] = val w = w + dx