def scan_archive(sim_dir): progress_window = progress_class() progress_window.show() progress_window.start() archive_path = os.path.join(sim_dir, "build_archive.zip") if os.path.isfile(archive_path) == True: os.remove(archive_path) zf = zipfile.ZipFile(archive_path, 'a', zipfile.ZIP_DEFLATED) l = os.listdir(sim_dir) for i in range(0, len(l)): dir_to_zip = os.path.join(sim_dir, l[i]) if os.path.isdir(dir_to_zip) == True: archive_add_dir(archive_path, dir_to_zip, sim_dir, zf=zf, remove_src_dir=True, exclude=["gmon.out"]) progress_window.set_fraction(float(i) / float(len(l))) progress_window.set_text(_("Adding: ") + l[i]) #if server_break()==True: # break process_events() zf.close() os.rename(archive_path, os.path.join(sim_dir, scan_next_archive(sim_dir))) progress_window.stop()
def __init__(self): self.running = False self.progress_window = progress_class() self.stop_work = False self.update_cpu_number() self.clear_jobs() self.callback = None
def clone_materials(dest,src_dir,file_type): if running_on_linux()==False: progress_window=progress_class() progress_window.show() progress_window.start() process_events() if os.path.isdir(dest)==False: os.makedirs(dest) files=find_materials(mat_path=src_dir,file_type=file_type) for i in range(0,len(files)): src_file=os.path.join(src_dir,files[i]) dest_file=os.path.join(dest,files[i]) clone_material(dest_file,src_file) progress_window.set_fraction(float(i)/float(len(files))) progress_window.set_text("Configuring "+files[i]) process_events() progress_window.stop() else: os.symlink(src_dir, dest)
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)): self.add_page(files[i][1]) progress_window.set_fraction(float(i) / float(len(files))) progress_window.set_text(_("Loading") + " " + files[i][0]) process_events() progress_window.stop()
def __init__(self): QWidget.__init__(self) self.name = "" self.ip = "" self.cpus = -1 self.load = -1 self.max_cpus = -1 self.last_seen = -1 self.setMinimumSize(300, 80) self.hbox = QHBoxLayout() self.bar = progress_class() self.bar.spinner.stop() self.bar.spinner.hide() self.label = QLabel() self.slider = QSlider(Qt.Horizontal) self.slider.setTickPosition(QSlider.TicksBelow) self.slider.setTickInterval(1) #self.slider.valueChanged.connect(self.slider0_change) self.slider.setMinimumSize(300, 80) self.slider.valueChanged.connect(self.slider_changed) self.slider.setTickPosition(QSlider.TicksBelow) self.hbox.addWidget(self.label) self.bar.hide_time() self.hbox.addWidget(self.bar) self.hbox.addWidget(self.slider)
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(".gmat"): 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 tree_gen_random_files(sim_path,flat_simulation_list,program_list,base_dir): length=0 for program_line in program_list: if program_line.opp=="random_file_name": length=int(program_line.values) progress_window=progress_class() progress_window.show() progress_window.start() process_events() print("length",length) for i in range(0,length): rand=codecs.encode(os.urandom(int(16 / 2)), 'hex').decode() cur_dir=os.path.join(sim_path,rand) if not os.path.exists(cur_dir): os.makedirs(cur_dir) gpvdm_clone(cur_dir,src_archive=os.path.join(base_dir, "sim.gpvdm"),dest="file") os.chdir(cur_dir) archive_decompress(os.path.join(cur_dir,"sim.gpvdm")) t=scan_tree_leaf() t.program_list=program_list t.directory=cur_dir if t.apply_constants()==False: return False if t.apply_python_scripts()==False: return False t.duplicate_params() #tree_apply_duplicate(cur_dir,program_list) archive_compress(os.path.join(cur_dir,"sim.gpvdm")) flat_simulation_list.append(cur_dir) progress_window.set_fraction(float(i)/float(length)) progress_window.set_text("Adding "+cur_dir) process_events() progress_window.stop()
def send_files(self, target, src, files): progress_window = progress_class() progress_window.show() progress_window.start() process_events() count = 0 banned = [] for i in range(0, len(files)): data = tx_struct() progress_window.set_fraction(float(i) / float(len(files))) progress_window.set_text("Sending " + files[i]) process_events() full_path = os.path.normpath(os.path.join(src, files[i])) data.stat = os.stat(full_path)[ST_MODE] f = open(full_path, 'rb') bytes = f.read() f.close() orig_size = len(bytes) print("tx file:", full_path) if target == "": data.target = src else: data.target = target data.id = "gpvdmfile" data.uzipsize = len(bytes) data.data = bytes data.zip = True data.file_name = strip_slash(files[i]) count = count + 1 self.tx_packet(data) #if count>2: # break print("status>>>>>>>>", i, len(files)) progress_window.stop() print("total=", count)
def scan_build_nested_simulation(root_simulation, nest_simulation): if os.path.isdir(nest_simulation) == False: print("Path ", nest_simulation, "does not exist") sys.exit(0) progress_window = progress_class() progress_window.show() progress_window.start() process_events() nest_simulation_name = os.path.basename(nest_simulation) program_list = tree_load_program(nest_simulation) files = os.listdir(root_simulation) simulations = [] for i in range(0, len(files)): if os.path.isfile(os.path.join(root_simulation, files[i], "sim.gpvdm")) == True: simulations.append(files[i]) flat_simulation_list = [] path = os.getcwd() for i in range(0, len(simulations)): dest_name = os.path.join(root_simulation, simulations[i], nest_simulation_name) base_dir = os.path.join(root_simulation, simulations[i]) #print(">>>",dest_name,base_dir,"<<",nest_simulation_name) tree_gen(dest_name, flat_simulation_list, program_list, base_dir) progress_window.set_fraction(float(i) / float(len(simulations))) progress_window.set_text(simulations[i]) process_events() progress_window.stop() os.chdir(path) flat_simulation_list = tree_gen_flat_list(root_simulation, level=1) #print(flat_simulation_list) tree_save_flat_list(root_simulation, flat_simulation_list) return
def scan_delete_files(dirs_to_del, parent_window=None): if parent_window != None: progress_window = progress_class() progress_window.show() progress_window.start() process_events() for i in range(0, len(dirs_to_del)): gpvdm_delete_file(dirs_to_del[i]) if parent_window != None: progress_window.set_fraction(float(i) / float(len(dirs_to_del))) progress_window.set_text("Deleting" + dirs_to_del[i]) process_events() if parent_window != None: progress_window.stop()
def export_materials(target): if target.endswith(".zip") == False: target = target + ".zip" file_list = [] progress_window = progress_class() progress_window.show() progress_window.start() process_events() mat_files = [ "alpha_eq.inp", "alpha.gmat", "cost.xlsx", "dos.inp", "fit.inp", "mat.inp", "n_eq.inp", "n.gmat", "pl.inp" ] for path, dirs, files in os.walk(os.path.join(os.getcwd(), "materials")): for file_name in files: if file_name in mat_files: file_list.append(os.path.join(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): f = open(cur_file, mode='rb') lines = f.read() f.close() zf.writestr(remove_cwdfrompath(cur_file), lines) progress_window.set_fraction(float(i) / float(len(file_list))) progress_window.set_text("Adding" + cur_file[len(os.getcwd()):]) process_events() zf.close() progress_window.stop()
def __init__(self): QWidgetSavePos.__init__(self, "optics") self.setWindowIcon(icon_get("optics")) self.setMinimumSize(1000, 600) self.setWindowTitle( _("Optical simulation editor") + " (https://www.gpvdm.com)") self.ribbon = optics_ribbon() self.edit_list = [] self.line_number = [] self.articles = [] input_files = [] input_files.append( os.path.join(get_sim_path(), "optical_output", "light_2d_photons.dat")) input_files.append( os.path.join(get_sim_path(), "optical_output", "light_2d_photons_asb.dat")) plot_labels = [] plot_labels.append(_("Photon distribution")) plot_labels.append(_("Photon distribution absorbed")) self.setWindowIcon(icon_get("optics")) self.main_vbox = QVBoxLayout() self.ribbon.optics.run.start_sim.connect(self.callback_run) self.ribbon.optics.fx_box.cb.currentIndexChanged.connect( self.mode_changed) self.ribbon.optics.help.triggered.connect(self.callback_help) self.ribbon.tb_save.clicked.connect(self.callback_save) self.ribbon.optics.configwindow.triggered.connect( self.callback_configwindow) self.ribbon.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) self.main_vbox.addWidget(self.ribbon) self.progress_window = progress_class() self.notebook = QTabWidget() css_apply(self.notebook, "tab_default.css") self.notebook.setMovable(True) self.plot_widgets = [] self.progress_window.start() for i in range(0, len(input_files)): self.plot_widgets.append(plot_widget(enable_toolbar=False)) self.plot_widgets[i].hide_title = True self.plot_widgets[i].set_labels([plot_labels[0]]) self.plot_widgets[i].load_data([input_files[i]]) #self.plot_widgets[i].watermark_alpha=0.5 self.plot_widgets[i].do_plot() #self.plot_widgets[i].show() self.notebook.addTab(self.plot_widgets[i], plot_labels[i]) self.fig_photon_density = band_graph() self.fig_photon_density.set_data_file("light_1d_photons_tot_norm.dat") self.notebook.addTab(self.fig_photon_density, _("Photon density")) #self.fig_photon_abs = band_graph() #self.fig_photon_abs.set_data_file("light_1d_photons_tot_abs_norm.dat") #self.notebook.addTab(self.fig_photon_abs,_("Photon absorbed")) self.fig_gen_rate = band_graph() self.fig_gen_rate.set_data_file("light_1d_Gn.dat") self.notebook.addTab(self.fig_gen_rate, _("Generation rate")) self.fig_photon_density.draw_graph() #self.fig_photon_abs.draw_graph() self.fig_gen_rate.draw_graph() self.progress_window.stop() self.notebook.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.main_vbox.addWidget(self.notebook) self.setLayout(self.main_vbox) if os.path.isfile( os.path.join(get_sim_path(), "optical_output", "light_2d_photons.dat")) == False: response = yes_no_dlg( self, "You have not yet run a full optical simulation, to use this feature you need to. Would you run one now?" ) if response == True: self.callback_run() else: self.close()
def merge_archives(src_archive,dest_archive,only_over_write): debug=False progress_window=progress_class() progress_window.show() progress_window.start() process_events() # src_dir=os.path.dirname(src_archive) # dest_dir=os.path.dirname(dest_archive) dest_path=os.path.dirname(dest_archive) template_archive=gpvdm_paths.get_inp_template_path() remove_non_used_index_files(dest_archive,src_archive) ls=zip_lsdir(src_archive) #copy files without checking ver for i in range(0,len(ls)): info=get_file_info(ls[i]) if info!=False: if info.copy_opp==file_type().JUST_COPY: #print(ls[i]) archive_copy_file(dest_archive,ls[i],src_archive,ls[i],dest=info.dest) #src_ver=inp_get_file_ver(src_archive,ls[i]) if info.copy_opp==file_type().CHECK_VER_THEN_COPY: template_ver=inp().get_ver(os.path.join(template_archive,info.base_file)) src_ver=inp_get_file_ver(src_archive,ls[i]) if template_ver!=False and src_ver!="": if template_ver==src_ver: archive_copy_file(dest_archive,ls[i],src_archive,ls[i]) #print("complex copy") if info.copy_opp==file_type().MERGE: if only_over_write==False: if archive_isfile(dest_archive,ls[i])==False: if archive_copy_file(dest_archive,ls[i],template_archive,info.base_file)==False: print("problem copying",template_archive,info.base_file) #if info.base_file=="dump.inp": # sys.exit(0) #print("made new file",dest_archive,ls[i]) ret=archive_merge_file(dest_archive,src_archive,ls[i],ls[i]) progress_window.set_fraction(float(i)/float(len(ls))) progress_window.set_text("Importing "+ls[i]) process_events() #if you find a materials directory in the archive try to merge it for i in range(0,len(ls)): zip_dir_name=ls[i].split("/") if zip_dir_name[0]=="materials": dest=os.path.join(os.path.dirname(get_materials_path())) #print("Try to read",src_archive,ls[i],dest) extract_file_from_archive(dest,src_archive,ls[i]) if zip_dir_name[0]=="sim": extract_file_from_archive(dest_path,src_archive,ls[i]) if zip_dir_name[0]=="calibrate": extract_file_from_archive(dest_path,src_archive,ls[i]) #search for scan directories scan_dirs=[] for i in range(0,len(ls)): if ls[i].endswith("gpvdm_gui_config.inp"): scan_dirs.append(os.path.dirname(ls[i])) #extract scan directories for i in range(0,len(ls)): for ii in range(0,len(scan_dirs)): if ls[i].startswith(scan_dirs[ii])==True: #print("Try to read",src_archive,ls[i]) extract_file_from_archive(dest_path,src_archive,ls[i]) print("search",scan_dirs) progress_window.stop()
def build_vector(self): output_file = os.path.join(self.scan_dir, "vectors.dat") if os.path.isfile(output_file) == True: response = yes_no_cancel_dlg( None, "The file " + output_file + " already exists. Continue? ") if response != "yes": sys.exit(0) out = open(output_file, 'wb') progress_window = progress_class() progress_window.show() progress_window.start() tot_archives = 0 for archive_name in os.listdir(self.scan_dir): if archive_name.startswith( "archive") == True and archive_name.endswith( ".zip") == True: tot_archives = tot_archives + 1 done = 0 errors = 0 for archive_name in os.listdir(self.scan_dir): if archive_name.startswith( "archive") == True and archive_name.endswith( ".zip") == True: archive_path = os.path.join(self.scan_dir, archive_name) if done == 0: #on the first archive search it for sub sims and build a list sub_sims = self.get_sub_sims(archive_path) zf = zipfile.ZipFile(archive_path, 'r') simulations = zip_lsdir(archive_path, zf=zf, sub_dir="/") for simulation in simulations: tmp_dir = self.make_tmp_dir() extract_dir_from_archive(tmp_dir, "", simulation, zf=zf) written = False #print(simulation) error = False v = [] v.append("#ml_id") v.append(simulation) sub_sim_folder = None for scan_folder in sub_sims: sub_sim_folder = os.path.join(tmp_dir, scan_folder) #print(sub_sim_folder,tmp_dir) dolog = False div = 1.0 mul = 1.0 do_fabs = False sim_mode = inp_get_token_value( os.path.join(sub_sim_folder, "sim.inp"), "#simmode") if sim_mode == None: error = True break sim_mode = sim_mode.lower() light = float( inp_get_token_value( os.path.join(tmp_dir, scan_folder, "light.inp"), "#Psun")) scan_folder_token = scan_folder.replace("/", "_") if sim_mode.endswith("jv") or sim_mode.startswith( "jv"): file_name = ["jv.dat"] sim_mode = "jv" vector = [self.jv_sample_points] token_ext = [scan_folder_token] #if light>0.0: # div=1e2 #if light==0.0: # dolog=True elif sim_mode.startswith("eqe") or sim_mode.endswith( "qe"): file_name = ["qe.dat"] sim_mode = "eqe" vector = [self.eqe_sample_points] token_ext = [scan_folder_token] elif sim_mode == "sun_voc": file_name = ["suns_voc.dat"] vector = [[0.02, 0.04, 0.05, 0.1, 0.5, 0.7, 1.0]] token_ext = [scan_folder_token] #dolog=True #mul=-10.0 elif sim_mode.startswith("cv"): file_name = ["cv.dat"] vector = [[ -2.0, -1.8, -1.6, -1.4, -1.2, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4 ]] token_ext = [scan_folder_token] elif sim_mode.startswith("is"): file_name = ["fx_imag.dat"] vector = [self.fx_points] token_ext = [scan_folder_token + "_fx_imag"] file_name.append("fx_real.dat") vector.append(self.fx_points) token_ext.append(scan_folder_token + "_fx_real") elif sim_mode.startswith("imps"): file_name = ["fx_imag.dat"] vector = [None] token_ext = [scan_folder_token + "_fx_imag"] file_name.append("fx_real.dat") vector.append(None) token_ext.append(scan_folder_token + "_fx_real") file_name.append("fx_phi.dat") vector.append(None) token_ext.append(scan_folder_token + "_fx_phi") elif sim_mode.startswith("imvs"): file_name = ["fx_imag.dat"] vector = [self.fx_points] token_ext = [scan_folder_token + "_fx_imag"] file_name.append("fx_real.dat") vector.append(self.fx_points) token_ext.append(scan_folder_token + "_fx_real") elif sim_mode.startswith("tpc") == True: file_name = ["time_i.dat"] vector = [[1.1e-6, 2e-6, 2e-5, 1e-4, 0.02, 0.1]] token_ext = [scan_folder_token] #dolog=True #do_fabs=True elif sim_mode.startswith("celiv") == True: file_name = ["time_i.dat"] vector = [[ 2e-6, 3e-6, 4e-6, 5e-6, 6e-6, 7e-6, 8e-6 ]] token_ext = [scan_folder_token] #do_fabs=True #mul=1000.0 elif sim_mode.startswith("tpv") == True: file_name = ["time_v.dat"] vector = [[ 10e-6, 20e-6, 30e-6, 40e-6, 50e-6, 60e-6, 80e-6 ]] token_ext = [scan_folder_token] #do_fabs=True #mul=10.0 else: print(sim_mode) asdas for c in range(0, len(file_name)): ret = get_vectors(os.path.join( tmp_dir, scan_folder, file_name[c]), vector[c], dolog=dolog, div=div, mul=mul, fabs=do_fabs) #print(file_name[c],ret) if ret == False: error = True break v.append("#ml_input_" + token_ext[c]) v.append(ret) if sim_mode == "jv" and light > 0.0: for t in ["#jv_pmax_tau", "#jv_pmax_mue", "#pce"]: ret = inp_get_token_value( os.path.join(tmp_dir, scan_folder, "sim_info.dat"), t) if ret == False: error = True break v.append(t + "_" + scan_folder) v.append(ret) for p in self.scan.program_list: if p.values.count("random") > 0: full_inp_file_name = os.path.join( tmp_dir, sub_sims[0], p.file) temp = inp_get_token_value(full_inp_file_name, p.token) if temp == False: error = True break else: v.append(p.token) v.append(temp) #print(v,error) if error == False: out.write(str.encode("\n".join(v) + "\n")) written = True else: errors = errors + 1 done = done + 1 progress_window.set_fraction( float(done) / float(len(simulations) * tot_archives)) if written == True: progress_window.set_text(simulation) else: progress_window.set_text( " /Last error: " + simulation + " tot errors=" + str(errors) + " " + str(round(100.0 * errors / done, 1)) + "%") progress_window.set_text(simulation) #if server_break()==True: # break process_events() #return shutil.rmtree(tmp_dir) out.close() progress_window.stop()