def callback_edit(self, file_name,token,widget): if type(widget)==QLineEdit: a=undo_list_class() a.add([file_name, token, inp_get_token_value(self.file_name, token),widget]) inp_update_token_value(file_name, token, widget.text()) elif type(widget)==gtkswitch: inp_update_token_value(file_name, token, widget.get_value()) elif type(widget)==leftright: inp_update_token_value(file_name, token, widget.get_value()) elif type(widget)==gpvdm_select: inp_update_token_value(file_name, token, widget.text()) elif type(widget)==QComboBox: inp_update_token_value(file_name, token, widget.itemText(widget.currentIndex())) elif type(widget)==QComboBoxLang: inp_update_token_value(file_name, token, widget.currentText_english()) elif type(widget)==QColorPicker: inp_update_token_array(file_name, token, [str(widget.r),str(widget.g),str(widget.b)]) elif type(widget)==QChangeLog: a=undo_list_class() a.add([file_name, token, inp_get_token_value(self.file_name, token),widget]) inp_update_token_array(file_name, token, widget.toPlainText().split("\n")) elif type(widget)==QParasitic: inp_update_token_value(file_name, token, widget.text()) help_window().help_set_help(["document-save-as","<big><b>Saved to disk</b></big>\n"]) 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 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 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 scan_ml_both_bad(file_name, token0, token1): v0 = float(inp_get_token_value(file_name, token0)) v1 = float(inp_get_token_value(file_name, token1)) ret = token0 + "_" + token1[1:] + "_bad\n" vector = "0 1\n" if is_it_good(token0, v0) == False and is_it_good(token1, v1) == False: vector = "1 0\n" ret = ret + vector return ret
def init(self, sim_dir): self.terminate_on_finish = False self.mylock = False self.cpus = multiprocessing.cpu_count() self.jobs = [] self.status = [] self.jobs_running = 0 self.jobs_run = 0 self.sim_dir = sim_dir self.cluster = str2bool(inp_get_token_value("server.inp", "#cluster")) self.server_ip = inp_get_token_value("server.inp", "#server_ip") self.finished_jobs = []
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("light.inp", "#Psun")) voltage_bias=float(inp_get_token_value("pulse"+str(self.index)+".inp", "#pulse_bias")) seg=0 for i in range(0,self.tab.rowCount()): length=float(tab_get_value(self.tab,i, 0)) end_time=pos+length dt=float(tab_get_value(self.tab,i, 1)) voltage_start=float(tab_get_value(self.tab,i, 2)) voltage_stop=float(tab_get_value(self.tab,i, 3)) mul=float(tab_get_value(self.tab,i, 4)) sun=float(tab_get_value(self.tab,i, 5)) laser=float(tab_get_value(self.tab,i, 6)) #print("VOLTAGE=",line[SEG_VOLTAGE],end_time,pos) 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 build_mesh(self): self.laser=[] self.sun=[] self.voltage=[] self.time=[] self.fs_laser=[] pos=self.start_time fired=False laser_pulse_width=float(inp_get_token_value("optics.inp", "#laser_pulse_width")) sun_steady_state=float(inp_get_token_value("light.inp", "#Psun")) seg=0 for line in self.store: end_time=pos+float(line[SEG_LENGTH]) dt=float(line[SEG_DT]) voltage_start=float(line[SEG_VOLTAGE_START]) voltage_stop=float(line[SEG_VOLTAGE_STOP]) mul=float(line[SEG_MUL]) sun=float(line[SEG_SUN]) laser=float(line[SEG_LASER]) #print "VOLTAGE=",line[SEG_VOLTAGE],end_time,pos if dt!=0.0 and mul!=0.0: voltage=voltage_start while(pos<end_time): dv=(voltage_stop-voltage_start)*(dt/float(line[SEG_LENGTH])) self.time.append(pos) self.laser.append(laser) self.sun.append(sun+sun_steady_state) self.voltage.append(voltage) #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 #print self.voltage self.statusbar.push(0, str(len(self.time))+_(" mesh points"))
def callback_set_hpc_dir(self,widget,data): config_file=os.path.join(self.sim_dir,"server.inp") hpc_path=inp_get_token_value(config_file, "#hpc_dir") dialog = gtk.FileChooserDialog(_("Select HPC dir"), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER) if os.path.isdir(hpc_path): dialog.set_current_folder(hpc_path) filter = gtk.FileFilter() filter.set_name(_("All files")) filter.add_pattern("*") dialog.add_filter(filter) response = dialog.run() if response == gtk.RESPONSE_OK: inp_update_token_value(config_file, "#hpc_dir", dialog.get_filename(),1) dialog.destroy()
def cluster_run_jobs(self): exe_name = inp_get_token_value( os.path.join(get_sim_path(), "cluster.inp"), "#exe_name") data = tx_struct() data.id = "gpvdmrunjobs" data.exe_name = exe_name self.tx_packet(data)
def cluster_make(self): data = tx_struct() data.id = "gpvdmheadexe" data.dir_name = "src" data.command = inp_get_token_value( os.path.join(get_sim_path(), "cluster.inp"), "#make_command") self.tx_packet(data)
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") lines=[] inp_load_file(lines,os.path.join(get_inp_file_path(),"pulse"+str(self.index)+".inp")) token=inp_get_token_value("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 __init__(self): self.__gobject_init__() self.light = gtk.combo_box_entry_new_text() #self.sim_mode.set_size_request(-1, 20) sun_values=["0.0","0.01","0.1","1.0","10"] token=inp_get_token_value("light.inp", "#Psun") if sun_values.count(token)==0: sun_values.append(token) for i in range(0,len(sun_values)): self.light.append_text(sun_values[i]) liststore = self.light.get_model() for i in xrange(len(liststore)): if liststore[i][0] == token: self.light.set_active(i) self.light.child.connect('changed', self.call_back_light_changed) lable=gtk.Label(_("Light intensity (Suns):")) lable.show hbox = gtk.HBox(False, 2) hbox.pack_start(lable, False, False, 0) hbox.pack_start(self.light, False, False, 0) self.add(hbox) self.show_all()
def scan_gen_report(path): tokens = [] tokens.append(report_token("dos0.inp", "#Etrape")) tokens.append(report_token("dos0.inp", "#mueffe")) tokens.append(report_token("dos0.inp", "#Ntrape")) tokens.append(report_token("dos0.inp", "#srhsigman_e")) tokens.append(report_token("dos0.inp", "#srhsigmap_e")) tokens.append(report_token("dos0.inp", "#srhsigman_h")) tokens.append(report_token("dos0.inp", "#srhsigmap_h")) tokens.append(report_token("sim/thick_light/sim_info.dat", "#jv_pmax_tau")) tokens.append(report_token("sim/thick_light/sim_info.dat", "#jv_pmax_mue")) tokens.append(report_token("sim/thick_light/sim_info.dat", "#jv_pmax_muh")) tokens.append(report_token("jv1.inp", "#jv_Rcontact")) tokens.append(report_token("jv1.inp", "#jv_Rshunt")) simulation_dirs = tree_load_flat_list(path) for i in range(0, len(simulation_dirs)): for ii in range(0, len(tokens)): value = inp_get_token_value( os.path.join(simulation_dirs[i], tokens[ii].file_name), tokens[ii].token) #print(os.path.join(simulation_dirs[i],tokens[ii].file_name), tokens[ii].token,value) if value != None: tokens[ii].values.append(float(value)) for ii in range(0, len(tokens)): print(tokens[ii].token, tokens[ii].values, sum(tokens[ii].values) / len(tokens[ii].values), std(tokens[ii].values)) for ii in range(0, len(tokens)): print(tokens[ii].token, sum(tokens[ii].values) / len(tokens[ii].values), std(tokens[ii].values))
def tree_load_config(sim_dir): global copy_materials copy_materials=inp_get_token_value(os.path.join(sim_dir,"scan_config.inp"),"#copy_materials") if copy_materials==None: copy_materials="False" copy_materials=str2bool(copy_materials)
def __init__(self, path, token): QWidget.__init__(self) self.path = path self.token = token layout = QVBoxLayout() label = QLabel() label.setText(_("Use:")) layout.addWidget(label) self.mode = QComboBox(self) self.mode.setEditable(True) self.mode.clear() self.mode.addItem(_("Raw data")) self.mode.addItem(_("Equation")) value = inp_get_token_value(os.path.join(self.path, "mat.inp"), self.token) if value == "data": self.mode.setCurrentIndex(0) else: self.mode.setCurrentIndex(1) self.mode.currentIndexChanged.connect(self.call_back_mode_changed) layout.addWidget(self.mode) self.setLayout(layout) return
def add_page(self, index): print("here:", index) file_name = os.path.join(get_sim_path(), "laser" + str(index) + ".inp") laser_name = inp_get_token_value(file_name, "#laser_name") tab = tab_class() tab.init(file_name, laser_name) self.notebook.addTab(tab, laser_name)
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 save_combo(self): lines=[] print("write to",self.file_name) self.measure_name=inp_get_token_value(self.file_name, "#measure_name") lines.append("#measure_name") lines.append(str(self.measure_name)) lines.append("#measure_enable") lines.append(str(self.measure_enable)) lines.append("#measure_compile_to_vector") lines.append(str(self.compile_to_vector)) for i in range(0,self.tab.rowCount()): lines.append("#measure_file_"+str(i)) lines.append(str(self.tab.get_value(i, 0))) lines.append("#measure_pos_"+str(i)) lines.append(str(self.tab.get_value(i, 1))) lines.append("#measure_token_"+str(i)) lines.append(str(self.tab.get_value(i, 2))) lines.append("#measure_math_"+str(i)) lines.append(str(self.tab.get_value(i, 3))) lines.append("#ver") lines.append("1.0") lines.append("#end") inp_save_lines_to_file(self.file_name,lines)
def scan_ml_build_token_vector(file_name, token, vector): a = float(inp_get_token_value(file_name, token)) v = [] for i in range(0, len(vector)): v.append(0.0) if a <= vector[0]: v[0] = 1.0 elif a >= vector[len(vector) - 1]: v[len(v) - 1] = 1.0 else: for i in range(1, len(vector) - 1): if a < vector[i]: v[i] = 1.0 break s = token + "\n" for i in range(0, len(v)): if v[i] == 0.0: s = s + "0 " else: s = s + "1 " s = s[:-1] + "\n" vectors = [] return s
def cp_spectra(dest,src): src=os.path.join(src,"spectra") dest=os.path.join(dest,"spectra") for dirpath, dirnames, filenames in os.walk(src): for filename in [f for f in filenames if f=="mat.inp"]: mat_f_name=os.path.join(dirpath, filename) status=inp_get_token_value(mat_f_name, "#status") if status=="public_all" or status=="public": print("copy spectra",mat_f_name,status) src_mat_path=os.path.dirname(mat_f_name) delta_path=subtract_paths(src,src_mat_path) dst_mat_path=os.path.join(dest,delta_path) if not os.path.exists(dst_mat_path): os.makedirs(dst_mat_path) safe_cpy(dst_mat_path,src_mat_path,"spectra_gen.inp") safe_cpy(dst_mat_path,src_mat_path,"spectra.inp") safe_cpy(dst_mat_path,src_mat_path,"mat.inp") safe_cpy(dst_mat_path,src_mat_path,"spectra_eq.inp")
def load_tabs(self): progress_window = progress_class() progress_window.show() progress_window.start() process_events() file_list = zip_lsdir(os.path.join(get_sim_path(), "sim.gpvdm")) files = [] for i in range(0, len(file_list)): if file_list[i].startswith("pulse") and file_list[i].endswith( ".inp"): name = inp_get_token_value(file_list[i], "#sim_menu_name") files.append([name, file_list[i]]) files.sort() for i in range(0, len(files)): value = strextract_interger(files[i][1]) if value != -1: self.add_page(value) progress_window.set_fraction(float(i) / float(len(files))) progress_window.set_text(_("Loading") + " " + files[i][0]) process_events() progress_window.stop()
def update(self): self.sim_mode.get_model().clear() lines=[] self.store_list=[] files=inp_lsdir() if files!=False: for i in range(0,len(files)): if files[i].endswith(".inp"): inp_load_file(lines,files[i]) value=inp_search_token_value(lines, "#sim_menu_name") if value!=False: if value.count("@")==1: value=value.rstrip() command,module=value.split("@") self.sim_mode.append_text(command) self.store_list.append(store(command,module)) token=inp_get_token_value("sim.inp", "#simmode") command,module=token.split("@") liststore = self.sim_mode.get_model() for i in xrange(len(liststore)): if liststore[i][0] == command: self.sim_mode.set_active(i)
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 get_dir_type(path): if os.path.isfile(path)==True: return "file" if os.path.isdir(path)==True: if os.path.isfile(os.path.join(path,"snapshots.inp"))==True: return "snapshots" if os.path.isfile(os.path.join(path,"wavelengths.dat"))==True: return "light" if os.path.isfile(os.path.join(path,"scan_config.inp"))==True: return "scan_dir" mat_file=os.path.join(path,"mat.inp") token=inp_get_token_value(os.path.join(path,"mat.inp"), "#gpvdm_file_type") if token=="mat": return "material" elif token=="spectra": return "spectra" elif token=="shape": return "shape" elif token=="emission": return "emission" elif token=="backup_main": return "backup_main" elif token=="backup": return "backup" elif token=="cache": return "cache" elif token=="multi_plot_dir": return "multi_plot_dir" else: return "dir"
def update(self,config_file): self.config_file=config_file self.sim_mode.blockSignals(True) self.sim_mode.clear() lines=[] files=inp_lsdir("sim.gpvdm") if files!=False: for i in range(0,len(files)): if files[i].endswith(".inp"): lines=inp_load_file(files[i]) value=inp_search_token_value(lines, "#laser_name") if value!=False: value=value.rstrip() self.sim_mode.addItem(value) token=inp_get_token_value(self.config_file, "#pump_laser") 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) found=True self.sim_mode.blockSignals(False)
def recalculate(self): self.colors=[] lines=[] if dat_file_read(self.graph_data,self.graph_path)==True: #print(self.graph_path) self.graph_z_max,self.graph_z_min=dat_file_max_min(self.graph_data) #print(self.graph_z_max,self.graph_z_min) val=inp_get_token_value("light.inp", "#Psun") self.suns=float(val) l=epitaxy_get_layers()-1 for i in range(0,epitaxy_get_layers()): path=os.path.join(get_materials_path(),epitaxy_get_mat_file(l-i),"mat.inp") if inp_load_file(lines,path)==True: red=float(inp_search_token_value(lines, "#Red")) green=float(inp_search_token_value(lines, "#Green")) blue=float(inp_search_token_value(lines, "#Blue")) else: red=0.0 green=0.0 blue=0.0 self.colors.append(color(red,green,blue)) self.colors.reverse() self.update()
def init(self,index): self.index=index self.sim_mode = gtk.combo_box_entry_new_text() self.sim_mode.set_size_request(-1, 20) lines=[] inp_load_file(lines,find_data_file("pulse"+str(self.index)+".inp")) self.sim_mode.append_text("open_circuit") self.sim_mode.append_text("load") self.sim_mode.child.connect('changed', self.call_back_sim_mode_changed) token=inp_get_token_value("pulse"+str(self.index)+".inp", "#pulse_sim_mode") liststore = self.sim_mode.get_model() for i in xrange(len(liststore)): if liststore[i][0] == token: self.sim_mode.set_active(i) lable=gtk.Label("Load type:") #lable.set_width_chars(15) lable.show() hbox = gtk.HBox(False, 2) hbox.pack_start(lable, False, False, 0) hbox.pack_start(self.sim_mode, False, False, 0) self.add(hbox); self.show_all()
def copy_src_to_cluster(self): if self.cluster == True: path = get_src_path() if path == None: return banned_types = [ ".pdf", ".png", ".dll", ".o", ".so", ".so", ".a", ".dat", ".aprox", ".ods", ".rpm", ".deb" ] banned_types.extend([ ".xls", ".xlsx", ".log", ".pptx", ".dig", ".old", ".bak", ".opj", ".csv", ".jpg", ".so.3", ".so.5", "gpvdm_core" ]) banned_types.extend(["so.0", ".zip"]) banned_dirs = [ "equilibrium", "man_src", "images", "snapshots", "plot", "pub", "gui", "debian", "desktop", "device_lib", "sim", "cluster", "cluster_", "cluster_libs" ] files = self.gen_dir_list(path, banned_types=banned_types, banned_dirs=banned_dirs) self.send_files("src", path, files) path = inp_get_token_value(os.path.join(get_sim_path(), "cluster"), "#path_to_libs", search_active_file=True) if path == "autosearch": path = get_cluster_libs_path() self.send_dir(path, "src")
def connect(self): if self.cluster == False: encrypt_load() self.load_server_ip() self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port = int( inp_get_token_value(os.path.join(get_sim_path(), "cluster"), "#port", search_active_file=True)) try: self.socket.connect((self.server_ip, port)) except: print("Failed to connect to ", self.server_ip) return False self.cluster = True data = tx_struct() data.id = "gpvdmregistermaster" self.tx_packet(data) if self.running == False: self.mylock = False self.thread = threading.Thread(target=self.listen) self.thread.daemon = True self.thread.start() print("conected to cluster") return True
def init(self): self.tx_port = 8888 self.rx_port= 8887 self.server_ip=inp_get_token_value("server.inp", "#server_ip") otest_path="/dev/shm/otest" if not os.path.exists(otest_path): os.makedirs(otest_path) #with open("/home/rod/share/orig/debug.dat", "w") as myfile: # myfile.write("debug info") net_files=listen_for_files_on_network() net_files.init(otest_path,10000) net_files.respond(self.server_ip, self.tx_port) try: self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) except socket.error: print 'Failed to create socket' sys.exit() try: self.socket.bind(('', self.rx_port)) except socket.error , msg: print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] sys.exit()
def scan_push_to_hpc(base_dir, only_unconverged): config_file = os.path.join(os.getcwd(), "server.inp") #print(config_file) hpc_path = inp_get_token_value(config_file, "#hpc_dir") hpc_path = os.path.abspath(hpc_path) if os.path.isdir(hpc_path) == True: hpc_files = [] hpc_files = scan_list_simulations(hpc_path) #print("hpc files=",hpc_files) scan_delete_files(hpc_files) files = [] if only_unconverged == True: files = scan_list_unconverged_simulations(base_dir) else: files = scan_list_simulations(base_dir) #print("copy files=",files) for i in range(0, len(files)): dest_path = os.path.join(hpc_path, files[i][len(base_dir) + 1:]) #print(dest_path) shutil.copytree(files[i], dest_path, symlinks=True) else: print("HPC dir not found", hpc_path)
def scan_push_to_hpc(base_dir,only_unconverged): config_file=os.path.join(os.getcwd(),"server.inp") print config_file hpc_path=inp_get_token_value(config_file, "#hpc_dir") hpc_path=os.path.abspath(hpc_path) if os.path.isdir(hpc_path)==True: hpc_files=[] hpc_files=scan_list_simulations(hpc_path) print "hpc files=",hpc_files scan_delete_files(hpc_files) files=[] if only_unconverged==True: files=scan_list_unconverged_simulations(base_dir) else: files=scan_list_simulations(base_dir) print "copy files=",files for i in range(0,len(files)): dest_path=os.path.join(hpc_path,files[i][len(base_dir)+1:]) print dest_path shutil.copytree(files[i], dest_path,symlinks=True) else: print "HPC dir not found",hpc_path
def gen_plot_line(dirname,plot_token): print(plot_token.file0,plot_token.file1) if plot_token.file1=="": f = open(os.path.join(dirname,plot_token.file0),'r') values=f.readline() f.close() return values else: v0=inp_get_token_value(os.path.join(dirname,plot_token.file0), plot_token.tag0) v1=inp_get_token_value(os.path.join(dirname,plot_token.file1), plot_token.tag1) v2="" print(os.path.join(dirname,plot_token.file1),plot_token.tag1) #if plot_token.file2!="": # v2=inp_get_token_value(os.path.join(dirname,plot_token.file2), plot_token.tag2) values=v0+" "+v1+"\n" return values
def __init__(self): self.day = 80 #winter equinox self.lat = 51 #london self.hour = 12 self.min = 0 self.P = 1.0 #Preasure 1bar self.aod = 0.27 #AOD self.W = 1.42 #precip water self.No2_un = 0.0 self.lat = float(inp_get_token_value("spectral2.inp", "#spectral2_lat")) #51 london self.day = float(inp_get_token_value( "spectral2.inp", "#spectral2_day")) #80 winter equinox self.hour = int(inp_get_token_value("spectral2.inp", "#spectral2_hour")) self.min = int( inp_get_token_value("spectral2.inp", "#spectral2_minute")) self.P = float( inp_get_token_value("spectral2.inp", "#spectral2_preasure")) #Preasure 1bar self.aod = float(inp_get_token_value("spectral2.inp", "#spectral2_aod")) #AOD self.W = float(inp_get_token_value("spectral2.inp", "#spectral2_water")) #precip water self.No2_un = float( inp_get_token_value("spectral2.inp", "#spectral2_no2")) file_name = os.path.join(get_atmosphere_path(), "SPECTRAL2", "etr.inp") self.etr = dat_file() self.etr.y_mul = 1e9 self.etr.y_units = "nm" self.etr.data_mul = 1.0 self.etr.data_units = "W m^{-3} m^{-1}" self.etr.load(file_name) file_name = os.path.join(get_atmosphere_path(), "SPECTRAL2", "h2o.inp") self.aw = dat_file() self.aw.load(file_name) file_name = os.path.join(get_atmosphere_path(), "SPECTRAL2", "o3.inp") self.ao = dat_file() self.ao.load(file_name) file_name = os.path.join(get_atmosphere_path(), "SPECTRAL2", "uni_abs.inp") self.au = dat_file() self.au.load(file_name) file_name = os.path.join(get_atmosphere_path(), "SPECTRAL2", "no2.inp") self.no2_data = dat_file() self.no2_data.load(file_name)
def on_item_activated(self, item): text = item.text() if text == "..": self.set_path(os.path.dirname(self.path)) self.fill_store() return decode = self.decode_name(text) if self.decode_name(text).startswith("http"): webbrowser.open(decode) return full_path = os.path.join(self.path, decode) if os.path.isfile(full_path) == True: self.file_path = full_path if self.open_own_files == True: if isfiletype(full_path, "xls") == True or isfiletype( full_path, "xlsx") == True or isfiletype( full_path, "pdf") == True: desktop_open(full_path) self.reject.emit() return elif isfiletype(full_path, "jpg") == True: desktop_open(full_path) self.reject.emit() return elif os.path.basename(full_path) == "sim_info.dat": self.sim_info_window = sim_info(full_path) self.sim_info_window.show() self.reject.emit() return elif isfiletype(full_path, "dat") == True: plot_gen([full_path], [], "auto") self.reject.emit() return else: self.accept.emit() return else: if os.path.isfile(os.path.join(full_path, "mat.inp")) == True: self.file_path = full_path gpvdm_file_type = inp_get_token_value( os.path.join(full_path, "mat.inp"), "#gpvdm_file_type") if gpvdm_file_type == "spectra": from spectra_main import spectra_main self.mat_window = spectra_main(full_path) self.mat_window.show() elif gpvdm_file_type == "mat": from materials_main import materials_main self.mat_window = materials_main(full_path) self.mat_window.show() self.accept.emit() else: self.set_path(full_path) #self.path = full_path self.fill_store()
def callback_dbus(self,data_in): if data_in.startswith("hex"): data_in=data_in[3:] data=codecs.decode(data_in, 'hex') data=data.decode('ascii') if data.startswith("lock"): if len(self.jobs)==0: print(_("I did not think I was running any jobs")) self.stop() else: if self.finished_jobs.count(data)==0: job=int(data[4:]) self.base_job_finished(job) self.finished_jobs.append(data) make_work_book=inp_get_token_value(os.path.join(get_sim_path(),"dump.inp"),"#dump_workbook") if make_work_book!=None: if str2bool(make_work_book)==True: if gen_workbook(self.jobs[job].path,os.path.join(self.jobs[job].path,"data.xlsx"))==False: self.excel_workbook_gen_error=self.excel_workbook_gen_error or True self.progress_window.set_fraction(float(self.jobs_run)/float(len(self.jobs))) if (self.jobs_run==len(self.jobs)): self.stop() elif (data=="pulse"): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: text=data.split(":")[1] self.progress_window.set_text(text) #self.progress_window.progress.set_pulse_step(0.01) self.progress_window.pulse() elif (data.startswith("enable_pulse")): splitup=data.split(":") if len(splitup)>1: value=str2bool(data.split(":")[1]) self.progress_window.enable_pulse(value) elif (data.startswith("percent")): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: frac=float(data.split(":")[1]) self.progress_window.set_fraction(frac) elif (data.startswith("text")): if len(self.jobs)==1: splitup=data.split(":") if len(splitup)>1: self.progress_window.set_text(data.split(":")[1]) elif (data.startswith("fit_run")): elapsed_time = time.time() - self.gui_update_time if elapsed_time>5: self.gui_update_time=time.time() if self.fit_update!=None: self.fit_update()
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 copy_src_to_cluster(self): if self.cluster==True: path=get_src_path() if path==None: return self.send_dir(path,"src") path=inp_get_token_value("server.inp","#path_to_libs") self.send_dir(path,"src")
def copy_src_to_cluster_fast(self): if self.cluster==True: path=get_src_path() if path==None: return self.sync_dir(path,"src") path=inp_get_token_value(os.path.join(get_sim_path(),"cluster"),"#path_to_libs",search_active_file=True) self.sync_dir(path,"src")
def cluster_run_jobs(self): exe_name = inp_get_token_value(os.path.join(get_sim_path(), "cluster"), "#exe_name", search_active_file=True) data = tx_struct() data.id = "gpvdmrunjobs" data.exe_name = exe_name self.tx_packet(data)
def __init__(self, s, file_name, command, module): self.icon = False self.text = command self.icon_name = inp_get_token_value(file_name, "#icon") self.done = False if self.icon_name == None: self.icon_name = "plot" self.english_name = inp_get_token_value(file_name, "#english_name") if self.english_name != None: self.text = self.english_name.replace("\\n", "\n") self.command = command self.module = module QAction_lock.__init__(self, self.icon_name, self.text, s, self.module) self.clicked.connect(self.callback_click)
def callback_edit(self, widget, data=None): if type(widget)==gtk.Entry: a=undo_list_class() a.add([self.file_name, data, inp_get_token_value(self.file_name, data),widget]) inp_update_token_value(self.file_name, data, widget.get_text(),1) else: inp_update_token_value(self.file_name, data, widget.get_active_text(),1) my_help_class.help_set_help(["save.png","<big><b>Saved to disk</b></big>\n"])
def callback_run(self): dump_optics=inp_get_token_value("dump.inp", "#dump_optics") dump_optics_verbose=inp_get_token_value("dump.inp", "#dump_optics_verbose") inp_update_token_value("dump.inp", "#dump_optics","true",1) inp_update_token_value("dump.inp", "#dump_optics_verbose","true",1) cmd = get_exe_command()+' --simmode opticalmodel@optics' print(cmd) ret= os.system(cmd) inp_update_token_value("dump.inp", "#dump_optics",dump_optics,1) inp_update_token_value("dump.inp", "#dump_optics_verbose",dump_optics_verbose,1) self.update() self.update_cb() inp_update_token_value("dump.inp", "#dump_optics","true",1) inp_update_token_value("dump.inp", "#dump_optics_verbose","true",1)
def __init__(self): QWidget.__init__(self) self.complex_display=False self.hbox=QVBoxLayout() self.gl_cmp=gl_cmp(os.path.join(os.getcwd(),"snapshots")) toolbar=QToolBar() toolbar.setIconSize(QSize(42, 42)) self.tb_rotate = QAction(QIcon(os.path.join(get_image_file_path(),"rotate.png")), _("Rotate"), self) self.tb_rotate.triggered.connect(self.tb_rotate_click) toolbar.addAction(self.tb_rotate) self.tb_rotate.setEnabled(True) self.tb_contact = QAction(QIcon(os.path.join(get_image_file_path(),"contact.png")), _("Contacts"), self) self.tb_contact.triggered.connect(self.callback_contacts) toolbar.addAction(self.tb_contact) self.tb_mesh = QAction(QIcon(os.path.join(get_image_file_path(),"mesh.png")), _("Edit the electrical mesh"), self) self.tb_mesh.triggered.connect(self.callback_edit_mesh) toolbar.addAction(self.tb_mesh) self.tb_config = QAction(QIcon(os.path.join(get_image_file_path(),"cog.png")), _("Configuration"), self) self.tb_config.triggered.connect(self.callback_configure) toolbar.addAction(self.tb_config) self.hbox.addWidget(toolbar) enable_3d=inp_get_token_value(os.path.join(os.getcwd(),"config.inp") , "#gui_config_3d_enabled") if enable_3d==None: enable_3d="True" enable_3d=str2bool(enable_3d) if enable_3d==True: self.display=glWidget(self) self.hbox.addWidget(self.display) self.display.setMinimumSize(800, 600) self.timer=QTimer() self.timer.setSingleShot(True) self.timer.timeout.connect(self.timer_update) self.timer.start(2000) else: self.add_fallback() self.setLayout(self.hbox) self.electrical_mesh=tab_electrical_mesh() self.electrical_mesh.changed.connect(self.recalculate) self.contacts_window=contacts_window() self.contacts_window.changed.connect(self.recalculate) self.gl_cmp.slider.changed.connect(self.recalculate)
def tree_apply_mirror(program_list): print(program_list) for i in range(0, len(program_list)): if program_list[i][2]=="mirror": f=scan_items_get_file(program_list[i][3]) t=scan_items_get_token(program_list[i][3]) src_value=inp_get_token_value(f, t) inp_update_token_value(program_list[i][0], program_list[i][1], src_value,1) return True
def update_cb_model(self): models=find_models() for i in range(0, len(models)): self.cb_model.append_text(models[i]) used_model=inp_get_token_value("light.inp", "#light_model") if models.count(used_model)==0: used_model="exp" inp_update_token_value("light.inp", "#light_model","exp",1) self.cb_model.set_active(models.index(used_model)) scan_item_add("light.inp","#light_model","Optical model",1)
def update_light_source_model(self): models=find_light_source() for i in range(0, len(models)): self.light_source_model.append_text(models[i]) used_model=inp_get_token_value("optics.inp", "#sun") if models.count(used_model)==0: used_model="sun" inp_update_token_value("optics.inp", "#sun","sun",1) self.light_source_model.set_active(models.index(used_model)) scan_item_add("optics.inp","#sun","Light source",1)
def callback_edit(self, file_name, token, widget): if type(widget) == QLineEdit: a = undo_list_class() a.add([file_name, token, inp_get_token_value(self.file_name, token), widget]) inp_update_token_value(file_name, token, widget.text(), 1) elif type(widget) == gtkswitch: inp_update_token_value(file_name, token, widget.get_value(), 1) elif type(widget) == leftright: inp_update_token_value(file_name, token, widget.get_value(), 1) elif type(widget) == QComboBox: inp_update_token_value(file_name, token, widget.itemText(widget.currentIndex()), 1) help_window().help_set_help(["32_save.png", "<big><b>Saved to disk</b></big>\n"])
def update_light_source_model(self): self.light_source_model.blockSignals(True) models=find_light_source() for i in range(0, len(models)): self.light_source_model.addItem(models[i]) used_model=inp_get_token_value("light.inp", "#sun") print("models================",models,used_model) if models.count(used_model)==0: used_model="sun" inp_update_token_value("light.inp", "#sun","sun",1) self.light_source_model.setCurrentIndex(self.light_source_model.findText(used_model)) scan_item_add("light.inp","#sun","Light source",1) self.light_source_model.blockSignals(False)
def update(self): self.light.blockSignals(True) self.light.clear() sun_values=["0.0","0.01","0.1","1.0","10"] token=inp_get_token_value("light.inp", "#Psun") if sun_values.count(token)==0: sun_values.append(token) for i in range(0,len(sun_values)): self.light.addItem(sun_values[i]) all_items = [self.light.itemText(i) for i in range(self.light.count())] for i in range(0,len(all_items)): if all_items[i] == token: self.light.setCurrentIndex(i) self.light.blockSignals(False)
def scan_import_from_hpc(base_dir): config_file=os.path.join(os.getcwd(),"server.inp") hpc_path=inp_get_token_value(config_file, "#hpc_dir") hpc_path=os.path.abspath(hpc_path) if os.path.isdir(hpc_path)==True: hpc_files=scan_list_simulations(hpc_path) for i in range(0,len(hpc_files)): if hpc_files[i].endswith("orig")==False: src_path=hpc_files[i] dest_path=os.path.join(base_dir,hpc_files[i][len(hpc_path)+1:]) if os.path.isdir(dest_path): shutil.rmtree(dest_path) shutil.copytree(src_path, dest_path, symlinks=False, ignore=None) print src_path,dest_path else: print "HPC dir not found",hpc_path
def update(self): self.tab.clear() self.tab.setColumnCount(5) self.tab.setRowCount(0) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("material"), _("Volume (m^-3)"), _("Mass (kg)"), _("Cost ($)"), _("Energy (J)")]) self.tab.setColumnWidth(1, 200) self.tab.setColumnWidth(2, 200) self.tab.setColumnWidth(3, 200) self.tab.setColumnWidth(4, 200) energy_tot=0.0 cost_tot=0.0 for i in range(0,epitaxy_get_layers()): volume=epitaxy_get_width(i)*1.0*1.0 name=epitaxy_get_mat_file(i) xls_file_name=os.path.join(get_materials_path(),epitaxy_get_mat_file(i),"cost.xlsx") wb = load_workbook(xls_file_name) ws= wb.get_sheet_by_name("results") density = float(ws['B2'].value) mass=density*volume cost_per_kg = float(ws['B3'].value) cost=mass*cost_per_kg energy_per_kg = float(ws['B4'].value) energy=energy_per_kg*mass tab_add(self.tab,[name,str(volume),str(mass),str(cost),str(energy)]) energy_tot=energy_tot+energy cost_tot=cost_tot+cost pce=inp_get_token_value("sim_info.dat", "#pce") payback_time=-1.0 if pce!=None: pce=float(pce) gen_energy=1366.0*pce/100.0 payback_time=energy_tot/gen_energy/60.0/60.0/24/365 tab_add(self.tab,["sum","","",str(cost_tot),str(energy_tot)]) tab_add(self.tab,["","","pay back time=",str(payback_time),"years"])
def update(self): self.sim_mode.clear() lines=[] self.store_list=[] files=inp_lsdir() if files!=False: for i in range(0,len(files)): if files[i].endswith(".inp"): inp_load_file(lines,files[i]) value=inp_search_token_value(lines, "#sim_menu_name") if value!=False: if value.count("@")==1: value=value.rstrip() command,module=value.split("@") self.sim_mode.addItem(command) a=store(command,module) self.store_list.append(a) token=inp_get_token_value("sim.inp", "#simmode") if token.count("@")!=0: command,module=token.split("@") else: command=token found=False 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] == command: self.sim_mode.setCurrentIndex(i) found=True #if there is no known mode, just set it to jv mode if found==False: for i in range(0,len(self.store_list)): if self.store_list[i].token=="jv": self.sim_mode.activated(i) inp_update_token_value("sim.inp", "#simmode", "jv@jv",1) break
def tree_apply_mirror(program_list): param_list = scan_items_get_list() for i in range(0, len(program_list)): for ii in range(0, len(program_list)): if program_list[i][2] == program_list[ii][0]: # I have found two matching IDs pos_mirror_src = scan_items_index_item(program_list[i][2]) pos_mirror_dest = scan_items_index_item(program_list[i][0]) src_value = inp_get_token_value(param_list[pos_mirror_src].filename, param_list[pos_mirror_src].token) # pull out of the file the value if program_list[i][1] != "mirror": # find value in list orig_list = program_list[i][1].split() look_up = program_list[ii][1].split() src_value = orig_list[look_up.index(src_value.rstrip())] inp_update_token_value( param_list[pos_mirror_dest].filename, param_list[pos_mirror_dest].token, src_value, param_list[pos_mirror_dest].line, )
def copy_simulation(base_dir, cur_dir): param_list = scan_items_get_list() cache = int(inp_get_token_value("server.inp", "#use_cache")) if cache == True: cache_path = get_cache_path(cur_dir) d = os.path.dirname(cache_path) if os.path.isdir(cache_path) == True: shutil.rmtree(cache_path) # if there is something in the cache with this name remove it if not os.path.exists(cache_path): os.makedirs(cache_path) # make the folder in the cache if os.path.isdir(cur_dir): os.rmdir(cur_dir) # if the target exists remove it print cache_path, cur_dir os.symlink(cache_path, cur_dir) # copy fit dirs fit_file = os.path.join(base_dir, "fit.inp") if os.path.isfile(fit_file): fit_array = inp_get_token_array(fit_file, "#fitnames") do_fit = inp_get_token_array(fit_file, "#do_fit") if (int(fit_array[0]) > 0) and (do_fit == 1): exp_dir = os.path.join(cur_dir, "exp") if not os.path.exists(exp_dir): os.makedirs(exp_dir) for i in range(1, len(fit_array)): shutil.copytree(os.path.join(base_dir, "exp", fit_array[i]), os.path.join(exp_dir, fit_array[i])) f_list = glob.iglob(os.path.join(base_dir, "*.inp")) for inpfile in f_list: shutil.copy(inpfile, cur_dir) shutil.copy(os.path.join(base_dir, "sim.opvdm"), cur_dir)
def update(self): self.sim_mode.clear() lines=[] files=inp_lsdir() if files!=False: for i in range(0,len(files)): if files[i].endswith(".inp"): inp_load_file(lines,files[i]) value=inp_search_token_value(lines, "#laser_name") if value!=False: value=value.rstrip() self.sim_mode.addItem(value) token=inp_get_token_value(self.config_file, "#pump_laser") 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) found=True
def connect(self): if self.cluster==False: encrypt_load() print("conecting to:",self.server_ip) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) port=int(inp_get_token_value("server.inp","#port")) try: self.socket.connect((self.server_ip, port)) except: print("Failed to connect to ",self.server_ip) return False self.cluster=True data=tx_struct() data.id="gpvdmregistermaster" self.tx_packet(data) if self.running==False: self.mylock=False self.thread = threading.Thread(target = self.listen) self.thread.daemon = True self.thread.start() print("conected to cluster") else: self.socket.close() try: self.thread.stop() except: print("error stopping thread",sys.exc_info()[0]) self.cluster=False print("not conected to cluster") return True