def update(self): self.cb.blockSignals(True) self.cb.clear() models = self.find_models() if len(models) == 0: error_dlg( self, _("I can't find any optical plugins, I think the model is not installed properly." )) return for i in range(0, len(models)): self.cb.addItem(models[i]) used_model = inp_get_token_value( os.path.join(get_sim_path(), "light.inp"), "#light_model") print(models, used_model) if models.count(used_model) == 0: used_model = "exp" inp_update_token_value(os.path.join(get_sim_path(), "light.inp"), "#light_model", "exp") self.cb.setCurrentIndex(self.cb.findText(used_model)) else: self.cb.setCurrentIndex(self.cb.findText(used_model)) self.cb.blockSignals(False)
def __init__(self, index): QWidget.__init__(self) self.index = index self.file_name = os.path.join(get_sim_path(), "fit_math" + str(self.index) + ".inp") self.exp_file_name = os.path.join( get_sim_path(), "fit_data" + str(self.index) + ".inp") self.fit_target = os.path.join(get_sim_path(), "fit_target" + str(self.index) + ".inp") self.vbox = QVBoxLayout() toolbar = QToolBar() toolbar.setIconSize(QSize(48, 48)) self.tb_run = QAction(icon_get("media-playback-start"), _("Run"), self) self.tb_run.triggered.connect(self.callback_run) toolbar.addAction(self.tb_run) self.vbox.addWidget(toolbar) self.text = QTextEdit() self.text.setFontPointSize(24) self.load() self.text.textChanged.connect(self.callback_edited) self.vbox.addWidget(self.text) self.setLayout(self.vbox)
def callback_copy_page(self): tab = self.notebook.currentWidget() old_index = tab.index new_sim_name = dlg_get_text( _("Clone the current experiment to a new experiment called:"), tab.tab_name.split("@")[0], "clone.png") new_sim_name = new_sim_name.ret if new_sim_name != None: new_sim_name = new_sim_name + "@" + tab.tab_name.split("@")[1] index = experiment_new_filename("pulse") if inp_copy_file( os.path.join(get_sim_path(), "pulse" + str(index) + ".inp"), os.path.join(get_sim_path(), "pulse" + str(old_index) + ".inp")) == False: print( _("Error copying file") + "pulse" + str(old_index) + ".inp") return if inp_copy_file( os.path.join(get_sim_path(), "time_mesh_config" + str(index) + ".inp"), os.path.join(get_sim_path(), "time_mesh_config" + str(old_index) + ".inp")) == False: print( _("Error copying file") + "pulse" + str(old_index) + ".inp") return inp_update_token_value( os.path.join(get_sim_path(), "pulse" + str(index) + ".inp"), "#sim_menu_name", new_sim_name) self.add_page(index) self.changed.emit()
def get_config(self): tab = self.notebook.currentWidget() file_name=tab.file_name self.user_name=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#cluster_user_name") self.ip=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#cluster_ip") self.cluster_dir=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#cluster_cluster_dir")
def __init__(self,file_name): QTabWidget.__init__(self) css_apply(self,"tab_default.css") lines=[] self.file_name=file_name self.index=int(extract_number_from_file_name(file_name)) lines=inp_load_file(os.path.join(get_sim_path(),"fit"+str(self.index)+".inp")) if lines!=False: self.tab_name=inp_search_token_value(lines, "#fit_name") else: self.tab_name="" #self.setTabsClosable(True) #self.setMovable(True) self.tmesh = fit_window_plot(self.index) self.addTab(self.tmesh,_("Fit error")) config=tab_class() config.init(os.path.join(get_sim_path(),"fit"+str(self.index)+".inp"),self.tab_name) self.addTab(config,_("Configure fit")) self.tmesh_real = fit_window_plot_real(self.index) self.addTab(self.tmesh_real,_("Experimental data")) self.fit_patch = fit_patch(self.index) self.addTab(self.fit_patch, _("Fit patch")) self.matlab_editor = matlab_editor(self.index) self.addTab(self.matlab_editor, _("MATLAB code"))
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 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.notebook.tab_main.three_d.update() get_watch().rebase()
def import_data(self): target = os.path.join(get_sim_path(), "fit_data" + str(self.index) + ".inp") config = os.path.join(get_sim_path(), "fit_import_config" + str(self.index) + ".inp") self.im = import_data(target, config) self.im.run() self.update()
def clone(self, file_name): output_dir = file_name if os.path.isdir(output_dir) == False: os.mkdir(output_dir) for f in os.listdir(get_sim_path()): if f.endswith(".inp") or f.endswith(".gpvdm"): copyfile(os.path.join(get_sim_path(), f), os.path.join(output_dir, f))
def callback_run(self): octave=inp_get_token_value(os.path.join(get_sim_path(),"config.inp"), "#matlab_interpreter") command=octave+" "+self.file_name+" "+self.exp_file_name+" "+self.fit_target print(command) old_path=os.getcwd() os.chdir(get_sim_path()) os.system(command) os.chdir(old_path)
def scan_items_populate_from_files(): name = os.path.join(get_sim_path(), "sim.gpvdm") if os.path.isfile(name) == True: file_list = zip_lsdir(name) for i in range(0, len(file_list)): print(file_list[i]) if file_list[i].startswith( "dos") == True and file_list[i].endswith(".inp") == True: name = epitaxy_dos_file_to_layer_name(file_list[i]) if name != False: scan_populate_from_file(file_list[i], human_name=os.path.join( "epitaxy", name, "dos")) if file_list[i].startswith("jv") == True and file_list[i].endswith( ".inp") == True: name = inp_get_token_value( os.path.join(get_sim_path(), file_list[i]), "#sim_menu_name") name = name.split("@")[0] scan_populate_from_file(file_list[i], human_name=os.path.join("jv", name)) if file_list[i].startswith( "time_mesh_config") == True and file_list[i].endswith( ".inp") == True: number = file_list[i][len("time_mesh_config"):-4] name = inp_get_token_value( os.path.join(get_sim_path(), "pulse" + number + ".inp"), "#sim_menu_name") name = name.split("@")[0] scan_populate_from_file(file_list[i], human_name=os.path.join( "time_domain", name)) #if my_token_lib[i].file_name!="": # scan_item_add(my_token_lib[i].file_name,my_token_lib[i].token,my_token_lib[i].info,1) #mat=find_materials() #for i in range(0,len(mat)): # scan_remove_file(os.path.join(get_materials_path(),mat[i])) # scan_item_add(os.path.join("materials",mat[i],"fit.inp"),"#wavelength_shift_alpha",os.path.join("materials",mat[i],"Absorption spectrum wavelength shift"),1) # scan_item_add(os.path.join("materials",mat[i],"fit.inp"),"#n_mul",os.path.join("materials",mat[i],"Refractive index spectrum multiplier"),1) # scan_item_add(os.path.join("materials",mat[i],"fit.inp"),"#alpha_mul",os.path.join("materials",mat[i],"Absorption spectrum multiplier"),1) epi = epitaxy_get_epi() for i in range(0, len(epi)): scan_item_add( "epitaxy.inp", "#layer_material_file" + str(i), os.path.join("epitaxy", str(epi[i].name), _("Material type")), 2) scan_item_add( "epitaxy.inp", "#layer_width" + str(i), os.path.join("epitaxy", str(epi[i].name), _("Layer width")), 1) scan_item_save("out.dat")
def build_mesh(self): self.laser = [] self.sun = [] self.voltage = [] self.time = [] self.fs_laser = [] pos = self.start_time fired = False laser_pulse_width = 0.0 sun_steady_state = float( inp_get_token_value(os.path.join(get_sim_path(), "light.inp"), "#Psun")) voltage_bias = float( inp_get_token_value( os.path.join(get_sim_path(), "pulse" + str(self.index) + ".inp"), "#pulse_bias")) seg = 0 for i in range(0, self.tab.rowCount()): length = float(self.tab.get_value(i, 0)) end_time = pos + length dt = float(self.tab.get_value(i, 1)) voltage_start = float(self.tab.get_value(i, 2)) voltage_stop = float(self.tab.get_value(i, 3)) mul = float(self.tab.get_value(i, 4)) sun = float(self.tab.get_value(i, 5)) laser = float(self.tab.get_value(i, 6)) #print("VOLTAGE=",line[SEG_VOLTAGE],end_time,pos) if (length / dt) > 100: dt = length / 100 if dt != 0.0 and mul != 0.0: voltage = voltage_start while (pos < end_time): dv = (voltage_stop - voltage_start) * (dt / length) self.time.append(pos) self.laser.append(laser) self.sun.append(sun + sun_steady_state) self.voltage.append(voltage + voltage_bias) #print(seg,voltage) self.fs_laser.append(0.0) pos = pos + dt voltage = voltage + dv if fired == False: if pos > self.fs_laser_time and self.fs_laser_time != -1: fired = True self.fs_laser[len(self.fs_laser) - 1] = laser_pulse_width / dt dt = dt * mul seg = seg + 1
def callback_circuit_diagram(self): f=inp() f.load(os.path.join(get_sim_path(),"math.inp")) solver_name=f.get_token("#newton_name") if inp().isfile(os.path.join(get_sim_path(),"diagram.inp"))==True and solver_name=="newton_simple": self.tb_electrical_editor.setEnabled(False) else: self.tb_electrical_editor.setEnabled(True)
def callback_import_from_lib(self): device_lib=device_lib_class() device_lib.exec_() path=device_lib.file_path if path != "": device_lib.destroy() import_archive(path,os.path.join(get_sim_path(),"sim.gpvdm"),False) self.change_dir_and_refresh_interface(get_sim_path()) print(_("file opened"),path)
def draw_graph(self): error_sim=os.path.join(get_sim_path(),"fit_error_sim"+str(self.index)+".dat") error_exp=os.path.join(get_sim_path(),"fit_error_exp"+str(self.index)+".dat") delta=os.path.join(get_sim_path(),"fit_error_delta"+str(self.index)+".dat") self.plot.load_data([error_sim,error_exp,delta]) self.plot.set_labels(["Simulation","Experiment","Delta"]) self.plot.do_plot()
def set_state(self, val): for token in self.tokens: inp_update_token_value(os.path.join(get_sim_path(), "dump.inp"), token, str(val).lower()) for token in self.const_tokens: inp_update_token_value(os.path.join(get_sim_path(), "dump.inp"), token[0], str(token[1]).lower())
def write_cluster_config(self): tab = self.notebook.currentWidget() file_name=tab.file_name cluster_ip=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#cluster_ip") inp_update_token_value(os.path.join(get_cluster_path(),"node.inp"),"#master_ip",cluster_ip) cluster_ip=inp_get_token_value(os.path.join(get_sim_path(),file_name), "#nodes") print(cluster_ip) inp_update_token_value(os.path.join(get_cluster_path(),"node_list.inp"),"#node_list",cluster_ip)
def callback_copy_page(self): tab = self.notebook.currentWidget() old_index = tab.index new_sim_name = dlg_get_text( _("Clone the current fit to a new fit called:"), tab.tab_name, "clone.png") if new_sim_name.ret != None: index = fit_new_filename() shutil.copy( os.path.join(get_sim_path(), "fit" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit" + str(index) + ".inp")) shutil.copy( os.path.join(get_sim_path(), "fit_data" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit_data" + str(index) + ".inp")) shutil.copy( os.path.join(get_sim_path(), "fit_patch" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit_patch" + str(index) + ".inp")) shutil.copy( os.path.join(get_sim_path(), "fit_math" + str(old_index) + ".inp"), os.path.join(get_sim_path(), "fit_math" + str(index) + ".inp")) inp_update_token_value( os.path.join(get_sim_path(), "fit" + str(index) + ".inp"), "#fit_name", new_sim_name.ret) self.add_page(index)
def export_archive(target,everything): if target.endswith(".gpvdm")==False: target=target+".gpvdm" file_list=[] progress_window=progress_class() progress_window.show() progress_window.start() process_events() if everything==True: for path, dirs, files in os.walk(get_sim_path()): for file_name in files: if file_name.endswith(".inp") or file_name.endswith(".dat") or file_name.endswith(".omat"): file_list.append(os.path.join(path,file_name)) else: files=os.listdir(get_sim_path()) for file_name in files: if file_name.endswith(".inp"): file_list.append(os.path.join(get_sim_path(),file_name)) zf = zipfile.ZipFile(target, 'a') for i in range(0,len(file_list)): cur_file=file_list[i] lines=[] if os.path.isfile(cur_file): try: f=open(cur_file, mode='rb') lines = f.read() f.close() zf.writestr(remove_simpathfrompath(cur_file), lines) except: print(_("Can't open file ")+cur_file) progress_window.set_fraction(float(i)/float(len(file_list))) progress_window.set_text("Adding"+cur_file[len(get_sim_path()):]) process_events() src_zf = zipfile.ZipFile(os.path.join(get_sim_path(),"sim.gpvdm"), 'r') for file_name in src_zf.namelist(): if file_name not in zf.namelist(): #print "adding from archive",file_name lines=src_zf.read(file_name) zf.writestr(file_name, lines) zf.close() src_zf.close() progress_window.stop()
def __init__(self): QWidgetSavePos.__init__(self, "cmpclass") self.setWindowTitle(_("Examine simulation results in time domain")) self.snapshots_hbox = QHBoxLayout() self.snapshots_label = QLabel("Snapshots") self.snapshots_hbox.addWidget(self.snapshots_label) self.snapshots_combobox = QComboBox() self.snapshots_hbox.addWidget(self.snapshots_combobox) self.snapshots_widget = QWidget() self.snapshot_dirs = self.find_snapshots() for i in range(0, len(self.snapshot_dirs)): self.snapshots_combobox.addItem(self.snapshot_dirs[i]) self.snapshots_combobox.currentIndexChanged.connect( self.callback_snapshots_combobox) self.snapshots_widget.setLayout(self.snapshots_hbox) self.main_vbox = QVBoxLayout() self.slider = snapshot_slider() print(self.snapshot_dirs) if len(self.snapshot_dirs) != 0: self.slider.set_path( os.path.join(get_sim_path(), self.snapshot_dirs[0])) self.slider.changed.connect(self.update) self.plot = plot_widget() self.plot.init() self.tb_video = QAction(icon_get("video"), _("Save video"), self) self.tb_video.triggered.connect(self.callback_save) self.plot.plot_ribbon.file_toolbar.addAction(self.tb_video) self.plot.plot_ribbon.plot_toolbar.addAction(self.slider.tb_play) self.main_vbox.addWidget(self.plot) self.main_vbox.addWidget(self.snapshots_widget) self.main_vbox.addWidget(self.slider) self.setLayout(self.main_vbox) if os.path.isfile( os.path.join(get_sim_path(), "snapshots", "0", "Ec.dat")) == False: help_window().help_append([ "warning.png", _("No electrical slice data has been stored in the snapshots directory. To turn this on set Simulation->Configure->Dump->Dump 1D Slices to on. This will dump a lot of data and slow down your simulations." ) ]) #self.light.currentIndexChanged.connect(self.call_back_light_changed) self.update()
def graph_from_tokens(self, output_file, path, file0, token0, file1, token1): output_file = os.path.join(get_sim_path(), path, output_file) plot = multiplot_from_tokens() print("here") plot.gen_plot(os.path.join(get_sim_path(), path), file0, token0, file1, token1, output_file=os.path.join(get_sim_path(), output_file))
def thumb_nail_gen(): if running_on_linux() == True: thumb_dir = os.path.join(get_sim_path(), "thumb") if os.path.isdir(thumb_dir) == False: os.mkdir(thumb_dir) for i in [16, 32, 48, 64, 128]: icon_path = os.path.join(thumb_dir, str(i) + "x" + str(i) + ".png") gen_icon(icon_path, i) archive_add_file(os.path.join(get_sim_path(), "sim.gpvdm"), icon_path, thumb_dir)
def callback_enable(self): file_list = zip_lsdir(os.path.join(get_sim_path(), "sim.gpvdm")) for i in range(0, len(file_list)): if inp_issequential_file(file_list[i], self.base_file_name[0]) == True: inp_update_token_value(file_list[i], "#tab_enabled", "false") tab = self.notebook_pointer.currentWidget() inp_update_token_value(os.path.join(get_sim_path(), tab.file_name), "#tab_enabled", "true") self.enabled.set_value(True)
def generate_keys(self): tab = self.notebook.currentWidget() file_name=tab.file_name iv = random.getrandbits(128) iv="%032x" % iv inp_update_token_value(os.path.join(get_sim_path(),"cluster","crypto.inp"),"#iv",iv) inp_update_token_value(os.path.join(get_sim_path(),file_name),"#iv",iv) key = random.getrandbits(128) key="%032x" % key inp_update_token_value(os.path.join(get_sim_path(),"cluster","crypto.inp"),"#key",key) inp_update_token_value(os.path.join(get_sim_path(),file_name),"#key",key) tab.update()
def callback_add_page(self): new_sim_name = dlg_get_text( _("New measurement name") + ":", _("measurement ") + str(self.notebook.count() + 1), "document-new.png") if new_sim_name.ret != None: index = measure_new_filename() inp_copy_file( os.path.join(get_sim_path(), "measure" + str(index) + ".inp"), os.path.join(get_sim_path(), "measure0.inp")) inp_update_token_value( os.path.join(get_sim_path(), "measure" + str(index) + ".inp"), "#measure_name", new_sim_name.ret) self.add_page(index)
def clean_sim_dir(): remove_bin("light") remove_bin("plugins") remove_bin("solvers") del_file=os.path.join(get_sim_path(),"pub") if os.path.isdir(del_file): print("Deleteing "+del_file) shutil.rmtree(del_file) del_file=os.path.join(get_sim_path(),"dynamic") if os.path.isdir(del_file): print("Deleteing "+del_file) shutil.rmtree(del_file) del_file=os.path.join(get_sim_path(),"snapshots") if os.path.isdir(del_file): print("Deleteing "+del_file) shutil.rmtree(del_file) files = os.listdir(get_sim_path()) for file in files: if file.startswith("snapshots_"): print("deleting dir",file) shutil.rmtree(file) files = os.listdir(get_sim_path()) for file in files: remove=False if file.endswith(".txt"): remove=True if file.endswith("~"): remove=True if file.endswith(".dat"): remove=True if file.endswith(".o"): remove=True if file.endswith(".orig"): remove=True if file.endswith(".back"): remove=True if file.endswith(".bak"): remove=True if file.endswith("gmon.out"): remove=True if remove==True: print("Deleting",file) os.remove(file)
def new_filenumber(self): for i in range(0, 20): new_filename = self.base_file_name[0] + str(i) + ".inp" if inp().isfile(os.path.join(get_sim_path(), new_filename)) == False: return str(i) return False
def contacts_save(): global store lines = [] lines.append("#contacts") lines.append(str(len(store))) i = 0 for s in store: lines.append("#contact_name" + str(i)) lines.append(str(s.name)) lines.append("#contact_position" + str(i)) lines.append(str(s.position)) lines.append("#contact_active" + str(i)) lines.append(str(s.active)) lines.append("#contact_start" + str(i)) lines.append(str(s.start)) lines.append("#contact_width" + str(i)) lines.append(str(s.width)) lines.append("#contact_depth" + str(i)) lines.append(str(s.depth)) lines.append("#contact_voltage" + str(i)) lines.append(str(s.voltage)) i = i + 1 lines.append("#ver") lines.append("1.1") lines.append("#end") inp_save(os.path.join(get_sim_path(), "contacts.inp"), lines)
def __init__(self, index): self.index = index QWidget.__init__(self) layout = QHBoxLayout() label = QLabel() label.setText(_("Load type") + ":") layout.addWidget(label) self.sim_mode = QComboBox(self) self.sim_mode.setEditable(True) layout.addWidget(self.sim_mode) self.setLayout(layout) self.sim_mode.addItem("open_circuit") self.sim_mode.addItem("load") self.sim_mode.addItem("ideal_diode_ideal_load") token = inp_get_token_value( os.path.join(get_sim_path(), "pulse" + str(self.index) + ".inp"), "#pulse_sim_mode") all_items = [ self.sim_mode.itemText(i) for i in range(self.sim_mode.count()) ] for i in range(0, len(all_items)): if all_items[i] == token: self.sim_mode.setCurrentIndex(i) self.sim_mode.currentIndexChanged.connect( self.call_back_sim_mode_changed)
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()