def remove_non_used_index_files(dest_archive,src_archive): ls_dest=zip_lsdir(dest_archive) if ls_dest==False: print("File ",ls_dest, "not found") return ls_src=zip_lsdir(src_archive) if ls_src==False: print("File ",ls_src, "not found") for my_file in ls_dest: if my_file.endswith(".inp"): if my_file.startswith("dos"): if ls_src.count(my_file)==0: zip_remove_file(dest_archive,my_file) if my_file.startswith("pulse"): if ls_src.count(my_file)==0: zip_remove_file(dest_archive,my_file) if my_file.startswith("pl"): if ls_src.count(my_file)==0: zip_remove_file(dest_archive,my_file) if my_file.startswith("time_mesh_config"): if ls_src.count(my_file)==0: zip_remove_file(dest_archive,my_file) if my_file.startswith("laser"): if ls_src.count(my_file)==0: zip_remove_file(dest_archive,my_file)
def import_archive(src_archive,dest_archive,only_over_write): if src_archive.endswith('.opvdm')==False: print "I can only import from .opvdm files" return if dest_archive.endswith('.opvdm')==False: print "I can only import to .opvdm files" return src_dir=os.path.dirname(src_archive) dest_dir=os.path.dirname(dest_archive) files=[ "sim.inp", "device.inp", "stark.inp" ,"shg.inp" ,"jv.inp" , "optics.inp", "math.inp", "dump.inp" , "light.inp", "server.inp", "light_exp.inp" ] for my_file in files: print "Importing",my_file,"to",dest_archive copy_check_ver(dest_archive,src_archive,my_file,only_over_write,True) files=["info.inp"] print src_archive ls=zip_lsdir(src_archive) for i in range(0,len(ls)): if inp_issequential_file(ls[i],"dos"): files.append(ls[i]) if inp_issequential_file(ls[i],"pl"): files.append(ls[i]) if inp_issequential_file(ls[i],"time_mesh_config"): files.append(ls[i]) if inp_issequential_file(ls[i],"pulse"): files.append(ls[i]) for my_file in files: print "Importing",my_file,"to",dest_archive copy_check_ver(dest_archive,src_archive,my_file,False,True) files=[ "epitaxy.inp", "fit.inp", "constraints.inp","duplicate.inp", "thermal.inp","mesh.inp" ] ls=zip_lsdir(src_archive) for i in range(0,len(ls)): if inp_issequential_file(ls[i],"h**o"): files.append(ls[i]) if inp_issequential_file(ls[i],"lumo"): files.append(ls[i]) for my_file in files: print "Importing",my_file copy_check_ver(dest_archive,src_archive,my_file,only_over_write,False) import_scan_dirs(dest_dir,src_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)): if file_list[i].startswith( "dos") == True and file_list[i].endswith(".inp") == True: scan_populate_from_file(file_list[i]) if file_list[i].startswith("jv") == True and file_list[i].endswith( ".inp") == True: scan_populate_from_file(file_list[i]) #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", "Absorption spectrum wavelength shift", 1) scan_item_add(os.path.join("materials", mat[i], "fit.inp"), "#n_mul", "Refractive index spectrum multiplier", 1) scan_item_add(os.path.join("materials", mat[i], "fit.inp"), "#alpha_mul", "Absorption spectrum multiplier", 1)
def gpvdm_clone(dest,copy_dirs,materials=["all"]): src_dir=get_inp_file_path() src_archive=os.path.join(src_dir,"sim.gpvdm") dest_archive=os.path.join(dest,"sim.gpvdm") print(src_archive) files=zip_lsdir(src_archive) lines=[] archive_make_empty(dest_archive) for i in range(0,len(files)): if files[i].endswith(".inp"): read_lines_from_archive(lines,src_archive,files[i]) write_lines_to_archive(dest_archive,files[i],lines) if copy_dirs==True: if os.path.isdir(os.path.join(src_dir,"plot")): shutil.copytree(os.path.join(src_dir,"plot"), os.path.join(dest,"plot")) if os.path.isdir(os.path.join(src_dir,"exp")): shutil.copytree(os.path.join(src_dir,"exp"), os.path.join(dest,"exp")) if os.path.isdir(os.path.join(src_dir,"materials")): shutil.copytree(os.path.join(src_dir,"materials"), os.path.join(dest,"materials")) clone_materials(dest,materials)
def gpvdm_clone(path, src_archive="", copy_dirs=False, dest="archive"): #print("Cloning from",get_inp_file_path()) if src_archive == "": src_dir = get_inp_file_path() src_archive = os.path.join(src_dir, "base.gpvdm") dest_archive = os.path.join(path, "sim.gpvdm") files = zip_lsdir(src_archive) lines = [] archive_make_empty(dest_archive) for i in range(0, len(files)): if files[i].endswith(".inp"): lines = read_lines_from_archive(src_archive, files[i], mode="b") write_lines_to_archive(dest_archive, files[i], lines, dest=dest, mode="b") #if (files[i]=="dos0.inp"): # asdsa if copy_dirs == True: if os.path.isdir(os.path.join(src_dir, "plot")): shutil.copytree(os.path.join(src_dir, "plot"), os.path.join(path, "plot")) if os.path.isdir(os.path.join(src_dir, "exp")): shutil.copytree(os.path.join(src_dir, "exp"), os.path.join(path, "exp"))
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 gpvdm_clone(path,src_archive="",copy_dirs=False,dest="archive"): if src_archive=="": src_dir=get_inp_file_path() src_archive=os.path.join(src_dir,"base.gpvdm") dest_archive=os.path.join(path,"sim.gpvdm") files=zip_lsdir(src_archive) lines=[] archive_make_empty(dest_archive) for i in range(0,len(files)): if files[i].endswith(".inp"): lines=read_lines_from_archive(src_archive,files[i]) write_lines_to_archive(dest_archive,files[i],lines,dest=dest) if copy_dirs==True: if os.path.isdir(os.path.join(src_dir,"plot")): shutil.copytree(os.path.join(src_dir,"plot"), os.path.join(path,"plot")) if os.path.isdir(os.path.join(src_dir,"exp")): shutil.copytree(os.path.join(src_dir,"exp"), os.path.join(path,"exp")) #if os.path.isdir(os.path.join(src_dir,"materials")): # shutil.copytree(os.path.join(src_dir,"materials"), os.path.join(path,"materials")) #clone_materials(path) clone_spectras(path)
def next_sequential_file(self, prefix): files = zip_lsdir(self.zip_file_path) for i in range(0, 100): new_name = prefix + str(i) + ".inp" if new_name not in files: return new_name return False
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 remove_non_used_index_files(dest_archive, src_archive): ls_dest = zip_lsdir(dest_archive) if ls_dest == False: print("File ", ls_dest, "not found") return ls_src = zip_lsdir(src_archive) if ls_src == False: print("File ", src_archive, "not found") for my_file in ls_dest: if my_file.endswith(".inp"): file_info = get_file_info(my_file) if file_info != False: if file_info.index_file == True: if ls_src.count(my_file) == 0: zip_remove_file(dest_archive, my_file)
def device_lib_set_color(): archives=find_device_libs() for arch in archives: files=zip_lsdir(arch) for file_name in files: if file_name.startswith("shape")==True: f=inp().load(os.path.join(arch,file_name)) f.replace("#red_green_blue",["0.0","0.8","0.0"]) print(f.lines) f.save()
def is_name(self, name): file_list = zip_lsdir(os.path.join(get_sim_path(), "sim.gpvdm")) files = [] for i in range(0, len(file_list)): if inp_issequential_file(file_list[i], self.base_file_name[0]) == True: sim_name = inp_get_token_value(file_list[i], self.name_token) sim_name = sim_name.split("@")[0] if sim_name == name: return True return False
def inp_find_active_file(file_path): """if you are looking for /path/to/file/cluster0.inp it will expect /path/to/file/cluster""" path=os.path.dirname(file_path) root=os.path.basename(file_path) files=zip_lsdir(os.path.join(path,"sim.gpvdm")) for f in files: if inp_issequential_file(f,root)==True: ret=str2bool(inp_get_token_value(os.path.join(path,f), "#tab_enabled")) if ret==True: return f return False
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 load_tabs(self): 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("laser") and file_list[i].endswith( ".inp"): files.append(file_list[i]) for i in range(0, len(files)): value = strextract_interger(files[i]) if value != -1: self.add_page(value)
def load_tabs(self): file_list=zip_lsdir(os.path.join(os.getcwd(),"sim.opvdm")) files=[] for i in range(0,len(file_list)): if file_list[i].startswith("pulse") and file_list[i].endswith(".inp"): files.append(file_list[i]) print "load tabs",files for i in range(0,len(files)): value=strextract_interger(files[i]) if value!=-1: self.add_page(value)
def load_tabs(self): files = [] 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: name = inp_get_token_value(file_list[i], self.name_token) name = name.split("@")[0] files.append([name, file_list[i]]) files.sort() for i in range(0, len(files)): self.added.emit(files[i][1])
def apply_constants(self): for program_line in self.program_list: if program_line.opp=="constant": if program_line.file.endswith("*"): search_file=program_line.file[:-1] file_list=zip_lsdir(os.path.join(self.directory,"sim.gpvdm")) #print(self.directory,file_list) for f in file_list: if f.startswith(search_file)==True: inp_update_token_value(os.path.join(self.directory,f), program_line.token, program_line.values) #print(">>> edited",f) else: inp_update_token_value(os.path.join(self.directory,program_line.file), program_line.token, program_line.values) return True
def create_model(self): self.tab.clear() self.tab.setColumnCount(3) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("File name"), _("Device type"), _("Description")]) self.tab.setColumnWidth(0, 150); self.tab.setColumnWidth(2, 500); self.tab.verticalHeader().setDefaultSectionSize(80); files=glob.glob(os.path.join(get_device_lib_path(),"*.gpvdm")) for i in range(0,len(files)): print("working on",files[i],zip_lsdir(files[i])) lines=read_lines_from_archive(lines,files[i],"info.inp") if lines!=False: tab_add(self.tab,[os.path.basename(files[i]), " ".join(inp_search_token_value_multiline(lines,"#info_device_type"))," ".join(inp_search_token_value_multiline(lines,"#info_description"))])
def create_model(self): self.tab.clear() self.tab.setColumnCount(3) self.tab.setSelectionBehavior(QAbstractItemView.SelectRows) self.tab.setHorizontalHeaderLabels([_("File name"), _("Device type"), _("Description")]) self.tab.setColumnWidth(0, 150); self.tab.setColumnWidth(2, 500); self.tab.verticalHeader().setDefaultSectionSize(80); files=glob.glob(os.path.join(get_device_lib_path(),"*.gpvdm")) for i in range(0,len(files)): print("working on",files[i],zip_lsdir(files[i])) lines=[] if read_lines_from_archive(lines,files[i],"info.inp")==True: tab_add(self.tab,[os.path.basename(files[i]), " ".join(inp_search_token_value_multiline(lines,"#info_device_type"))," ".join(inp_search_token_value_multiline(lines,"#info_description"))])
def load_tabs(self): 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("measure") and file_list[i].endswith( ".inp"): name = inp_get_token_value(file_list[i], "#measurement_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)
def load_tabs(self): file_list=zip_lsdir(os.path.join(os.getcwd(),"sim.gpvdm")) files=[] for i in range(0,len(file_list)): if file_list[i].startswith("fit") and file_list[i].endswith(".inp"): num=file_list[i][3:-4] if num.isdigit()==True: files.append(file_list[i]) print("load tabs",files) for i in range(0,len(files)): value=strextract_interger(files[i]) if value!=-1: self.add_page(value)
def inp_encrypt(file_name): global enable_encrypt if enable_encrypt == Ture: iv = "reallybadiv" ls = zip_lsdir(file_name) files_to_encrypt = [] bs = 32 password = inp_get_token_value("info.inp", "#info_password", archive=file_name) if password == "": return False for i in range(0, len(ls)): if ls[i].endswith(".inp") == True and ls[i] != "info.inp": lines = [] lines = inp_load_file(ls[i], archive=file_name, mode="b") m = hashlib.md5() m.update(password.encode('utf-8')) key_hash = m.digest() m = hashlib.md5() m.update(iv.encode('utf-8')) iv_hash = m.digest() encryptor = AES.new(key_hash, AES.MODE_CBC, IV=iv_hash) start = "encrypt" start = start.encode('utf-8') s = (int((len(lines)) / 16.0) + 1) * 16 data = bytearray(int(s)) for ii in range(0, len(lines)): data[ii] = lines[ii] ret = encryptor.encrypt(bytes(data)) data = start + ret replace_file_in_zip_archive(file_name, ls[i], data, mode="b") inp_update_token_value("info.inp", "#info_password", "encrypted", archive=file_name)
def device_lib_check(file_to_check=""): from import_archive import get_file_info src_archive=os.path.join(get_sim_path(),"sim.gpvdm") files=zip_lsdir(src_archive) archives=find_device_libs() for file_name in files: #scan local sim.gpvdm if file_name.endswith(".inp")==True and (file_name==file_to_check or file_to_check==""): print(file_name) for archive_file in archives: f_orig=inp() f_orig.load(file_name) print("Report for",archive_file,file_name) sim_file_name=os.path.join(os.path.dirname(archive_file),file_name) archive=os.path.basename(archive_file) f_archive=inp() f_archive.load(sim_file_name, archive=archive_file) if f_archive.lines!=False: if f_archive.lines[0]!="#sections" and file_name!="dump_file.inp": delta=f_orig.delta_tokens(f_archive) if len(delta)==0: print(col.green+"OK"+col.black) else: print(col.red+"Delta found"+col.black) print(col.red+"local:"+col.black,f_orig) print(col.blue+"archive:"+col.black,f_archive) f_orig.import_tokens(f_archive) print("change to:",f_orig) print(delta) response = yes_no_cancel_dlg(None,"Should I repair the file"+f_archive.get_file_name()+"\n") if response == "yes": f_archive.lines=f_orig.lines f_archive.save() else: print(os.path.basename(sim_file_name)) info=get_file_info(os.path.basename(sim_file_name)) if info.needed==True: print(col.red+"Not found"+col.black) response = yes_no_cancel_dlg(None,"Should I copy the origonal file in?") print(response) if response == "yes": archive_copy_file(archive_file,file_name,src_archive,file_name)
def load_tabs(self): 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("fit") and file_list[i].endswith( ".inp"): num = file_list[i][3:-4] if num.isdigit() == True: files.append(file_list[i]) for i in range(0, len(files)): value = strextract_interger(files[i]) if value != -1: token = inp_get_token_value( os.path.join(get_sim_path(), files[i]), "#fit_hidden") if str2bool(token) == False: self.add_page(value) self.fit_progress = fit_progress() self.notebook.addTab(self.fit_progress, "Fit progress")
def __create_model(self): # create list store model = gtk.ListStore(str, str, str) # add items files = glob.glob(os.path.join(get_device_lib_path(), "*.opvdm")) for i in range(0, len(files)): print "working on", files[i], zip_lsdir(files[i]) iter = model.append() lines = [] if read_lines_from_archive(lines, files[i], "info.inp") == True: print lines model.set( iter, COLUMN_FILENAME, os.path.basename(files[i]), COLUMN_TYPE, " ".join(inp_search_token_value_multiline(lines, "#info_device_type")), COLUMN_INFO, " ".join(inp_search_token_value_multiline(lines, "#info_description")), ) return model
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 is_numbered_file(file_list[i], "is"): 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 fill_store(self): self.file_list = [] path = self.path all_files = self.listdir() #all_files.sort() if path.endswith("dynamic") == True: self.set_list_view() else: self.set_grid_view() for itm in all_files: #print(fl) #if it is a directory file_name = os.path.join(path, itm.file_name) if itm.isdir == True: if itm.type == "spectra": itm.icon = "spectra" elif itm.type == "shape": itm.icon = "shape" elif itm.type == "snapshots": itm.icon = "cover_flow" elif itm.type == "light": itm.icon = "optics2" elif itm.type == "material": itm.icon = "organic_material" elif itm.type == "emission": itm.icon = "emission" elif itm.type == "backup_main": itm.icon = "backup" elif itm.type == "multi_plot_dir": itm.icon = "multi_plot_dir" elif itm.type == "backup": itm.icon = "backup" elif itm.type == "scan_dir": itm.icon = "scan" elif itm.type == "parameter_dir": itm.icon = "star" elif itm.type == "cache": itm.hidden = True else: itm.icon = "folder" else: #append=False ext = os.path.splitext(file_name) if len(ext) > 1: ext = ext[1].lower() else: ext = "" if (ext == ".dat"): text = peek_data(file_name) if itm.file_name in [ "theta_small_x.dat", "theta_small_z.dat", "theta_Y.dat", "theta_small_y.dat", "theta_X.dat", "theta_Z.dat", "theta_RGB.dat" ]: itm.icon = "color" elif text.startswith(b"#multiplot"): itm.icon = "multiplot" elif str(text).count("#type poly") > 0: itm.icon = "vector" elif str(text).count("#gobj") > 0: itm.icon = "vector" elif text.startswith(b"#"): itm.icon = "dat_file" else: itm.hidden = True if (ext == ".chk"): itm.hidden = True elif (ext == ".inp"): if self.show_inp_files == True: itm.icon = "text-x-generic" else: itm.hidden = True elif (ext == ".gmat"): itm.icon = "gmat" elif os.path.basename(file_name) == "sim_info.dat": itm.icon = "info" elif file_name.endswith( "default.gpvdm") == False and file_name.endswith( ".gpvdm"): text = peek_data(file_name) if text.startswith(b"gpvdmenc"): itm.hidden = True itm.icon = "sim_lock" else: lines = [] lines = inp_load_file("info.inp", archive=file_name) if lines != False: itm.display_name = inp_get_token_value_from_list( lines, "#info_name") icon_name = inp_get_token_value_from_list( lines, "#info_icon") itm.icon = icon_name itm.hidden = str2bool( inp_get_token_value_from_list( lines, "#info_hidden")) a = zip_lsdir( file_name, sub_dir="fs/") #,zf=None,sub_dir=None if len(a) != 0: for fname in a: lines = ret = read_lines_from_archive( file_name, "fs/" + fname) if lines != False: web_link = inp_get_token_value_from_list( lines, "#web_link") name = inp_get_token_value_from_list( lines, "#name") sub_itm = file_store() sub_itm.icon = "internet-web-browser" sub_itm.display_name = name sub_itm.file_name = web_link sub_itm.hidden = False self.file_list.append(sub_itm) if itm.icon == "": if icon_get(ext) != False: itm.icon = ext else: itm.icon = "misc" if itm.display_name == "": itm.display_name = itm.file_name if len(self.show_only) != 0: if itm.type not in self.show_only: itm.hidden = True self.file_list.append(itm) for i in range(0, len(self.file_list)): if self.file_list[i].file_name == "p3htpcbm.gpvdm": self.file_list.insert(0, self.file_list.pop(i)) if self.file_list[i].file_name == "perovskite.gpvdm": self.file_list.insert(1, self.file_list.pop(i)) if self.file_list[i].file_name == "ofet.gpvdm": self.file_list.insert(2, self.file_list.pop(i)) if self.file_list[i].file_name == "oled.gpvdm": self.file_list.insert(3, self.file_list.pop(i)) self.paint()
def lsdir(self): return zip_lsdir(self.zip_file_path)
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()
def inp_lsdir(): return zip_lsdir("sim.gpvdm")
def scan_ml_build_vector(sim_dir): output_file=os.path.join(sim_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(sim_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(sim_dir): if archive_name.startswith("archive")==True and archive_name.endswith(".zip")==True: archive_path=os.path.join(sim_dir,archive_name) if done==0: #Find the measurment files and determine which ones are needed found=[] zf = zipfile.ZipFile(archive_path, 'r') items=zf.namelist() for l in items: parts=l.split("/") fname=parts[-1] if fname.endswith("scan.inp")==True: found_item=os.path.join(parts[-2],parts[-1]) a=parts[-2] #measurment() #a.experiment=parts[-2] #a.measurement_file=parts[-1] #a.token="#ml_input_"+parts[-1][8:-4]+"_"+parts[-2] if found.count(a)==False: found.append(a) zf = zipfile.ZipFile(archive_path, 'r') dirs=zip_lsdir(archive_path,zf=zf,sub_dir="/") items=len(dirs) for i in range(0,len(dirs)): rnd = [random.choice(string.ascii_letters + string.digits) for n in range(0,32)] rnd = "".join(rnd) tmp_dir="/dev/shm/gpvdm_"+rnd if os.path.isdir(tmp_dir)==True: shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) extract_dir_from_archive(tmp_dir,"",dirs[i],zf=zf) full_name=tmp_dir written=False #print(dirs[i]) error=False v="#ml_id\n" v=v+dirs[i]+"\n" for scan_folder in found: token="#ml_input_"+scan_folder v=v+token+"\n" dolog=False div=1.0 mul=1.0 do_fabs=False sim_mode=inp_get_token_value(os.path.join(full_name,scan_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(full_name,scan_folder,"light.inp"), "#Psun")) if sim_mode.endswith("jv") or sim_mode.startswith("jv"): file_name="jv.dat" sim_mode="jv" vector=[0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0] #np.linspace(0.2,1.0,20)# if light>0.0: div=1e2 if light==0.0: dolog=True 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] dolog=True mul=-10.0 elif sim_mode.startswith("tpc")==True: file_name="pulse_i.dat" vector=[1.1e-6,2e-6,2e-5,1e-4,0.02,0.1] dolog=True do_fabs=True elif sim_mode.startswith("celiv")==True: file_name="pulse_i.dat" vector=[2e-6,3e-6,4e-6,5e-6,6e-6,7e-6,8e-6] do_fabs=True mul=1000.0 elif sim_mode.startswith("tpv")==True: file_name="pulse_v.dat" vector=[10e-6,20e-6,30e-6,40e-6,50e-6,60e-6,80e-6] do_fabs=True mul=10.0 else: print(sim_mode) asdas ret=get_vectors(os.path.join(full_name,scan_folder,file_name),vector,dolog=dolog,div=div,mul=mul,fabs=do_fabs) #print(ret) if ret==False: error=True break v=v+ret+"\n" if sim_mode=="jv" and light>0.0: ret=scan_ml_build_token_abs(os.path.join(full_name,scan_folder,"sim_info.dat"),"#jv_pmax_tau","#jv_pmax_tau",min_max="avg",dolog=True) if ret==False: error=True break v=v+ret ret=scan_ml_build_token_abs(os.path.join(full_name,scan_folder,"sim_info.dat"),"#jv_pmax_mue","#jv_pmax_mue",min_max="avg",dolog=True) if ret==False: error=True break v=v+ret ret=scan_ml_build_token_abs(os.path.join(full_name,scan_folder,"sim_info.dat"),"#pce","#pce",min_max="avg",lim=0.1) if ret==False: error=True break v=v+ret #print(a.experiment,a.measurement_file,a.token) for min_max in ["min","max","avg"]: a=scan_ml_build_token_abs(os.path.join(full_name,"dos0.inp"),"#Etrape","#Etraph",min_max=min_max,mul=1e3) if a==False: error=True break v=v+a a=scan_ml_build_token_abs(os.path.join(full_name,"dos0.inp"),"#mueffe","#mueffh",min_max=min_max,dolog=True) if a==False: error=True break v=v+a a=scan_ml_build_token_abs(os.path.join(full_name,"dos0.inp"),"#Ntraph","#Ntrape",min_max=min_max,dolog=True) if a==False: error=True break v=v+a a=scan_ml_build_token_abs(os.path.join(full_name,"parasitic.inp"),"#Rshunt","#Rshunt",min_max="avg",dolog=True) if a==False: error=True break v=v+a a=scan_ml_build_token_abs(os.path.join(full_name,"parasitic.inp"),"#Rcontact","#Rcontact",min_max="avg") if a==False: error=True break v=v+a v=v+"#break\n" if error==False: out.write(str.encode(v)) written=True else: errors=errors+1 done=done+1 progress_window.set_fraction(float(done)/float(len(dirs)*tot_archives)) if written==True: progress_window.set_text(dirs[i]) else: progress_window.set_text(" /Last error: "+dirs[i]+" tot errors="+str(errors)+" "+str(round(100.0*errors/done,1))+"%") progress_window.set_text(dirs[i]) #if server_break()==True: # break process_events() #return shutil.rmtree(tmp_dir) out.close() progress_window.stop() tindex_dump(os.path.join(sim_dir,"index.dat"))
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 inp_lsdir(file_name): full_path = default_to_sim_path(file_name) return zip_lsdir(full_path)
def merge_archives(src_archive,dest_archive,only_over_write): # src_dir=os.path.dirname(src_archive) # dest_dir=os.path.dirname(dest_archive) template_archive=os.path.join(get_inp_file_path(),"sim.gpvdm") remove_non_used_index_files(dest_archive,src_archive) files=[ "sim.inp", "device.inp", "led.inp","stark.inp" ,"shg.inp" ,"jv.inp" , "math.inp", "dump.inp", "dump_file.inp" , "light.inp", "server.inp", "light_exp.inp","info.inp","config.inp" ] base_file=files[:] print(src_archive) ls=zip_lsdir(src_archive) for i in range(0,len(ls)): if inp_issequential_file(ls[i],"dos"): files.append(ls[i]) base_file.append(os.path.join(get_materials_path(),"generic","dos.inp")) if inp_issequential_file(ls[i],"pl"): files.append(ls[i]) base_file.append(os.path.join(get_materials_path(),"generic","pl.inp")) if inp_issequential_file(ls[i],"pulse"): files.append(ls[i]) base_file.append("pulse0.inp") if inp_issequential_file(ls[i],"laser"): files.append(ls[i]) base_file.append("laser0.inp") for i in range(0,len(files)): print("Importing",files[i],"to",dest_archive,template_archive,base_file[i]) if only_over_write==False: if archive_isfile(dest_archive,files[i])==False: if archive_copy_file(dest_archive,files[i],template_archive,base_file[i])==False: print("problem copying",template_archive,base_file[i]) print("made new file",dest_archive,files[i]) ret=archive_merge_file(dest_archive,src_archive,files[i]) print("merged",dest_archive,src_archive,files[i],ret) files=[ "epitaxy.inp", "fit.inp", "constraints.inp","duplicate.inp", "thermal.inp","mesh_x.inp","mesh_y.inp","mesh_z.inp" ] base_file=files[:] ls=zip_lsdir(src_archive) for i in range(0,len(ls)): if inp_issequential_file(ls[i],"time_mesh_config"): files.append(ls[i]) base_file.append("time_mesh_config0.inp") if inp_issequential_file(ls[i],"h**o"): files.append(ls[i]) base_file.append("homo0.inp") if inp_issequential_file(ls[i],"lumo"): files.append(ls[i]) base_file.append("lumo0.inp") for i in range(0,len(files)): print("Importing",files[i]) template_ver=archive_get_file_ver(template_archive,base_file[i]) src_ver=archive_get_file_ver(src_archive,files[i]) print(template_ver,src_ver,template_ver==src_ver,template_archive,files[i],src_archive) if template_ver!="" and src_ver!="": if template_ver==src_ver: archive_copy_file(dest_archive,files[i],src_archive,files[i]) print("complex copy",dest_archive,files[i],src_archive,files[i])
def populate_from_files(self): 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 is_numbered_file(file_list[i], "dos") == True: #print("oops>>>",file_list[i],epitaxy_dos_file_to_layer_name(file_list[i])) name = epitaxy_dos_file_to_layer_name(file_list[i]) if name != False: self.populate_from_file(file_list[i], human_name=os.path.join( "epitaxy", name, "dos")) if is_numbered_file(file_list[i], "lumo") == True: index = self.epi.find_layer_index_from_file_name( file_list[i]) if index != False: name = self.epi.layers[index].name self.populate_from_file(file_list[i], human_name=os.path.join( "epitaxy", name, "lumo")) if is_numbered_file(file_list[i], "h**o") == True: index = self.epi.find_layer_index_from_file_name( file_list[i]) if index != False: name = self.epi.layers[index].name self.populate_from_file(file_list[i], human_name=os.path.join( "epitaxy", name, "h**o")) if is_numbered_file(file_list[i], "jv") == True: name = inp_get_token_value( os.path.join(get_sim_path(), file_list[i]), "#sim_menu_name") name = name.split("@")[0] self.populate_from_file(file_list[i], human_name=os.path.join( "jv", name)) if is_numbered_file(file_list[i], "laser") == True: name = inp_get_token_value( os.path.join(get_sim_path(), file_list[i]), "#laser_name") self.populate_from_file(file_list[i], human_name=os.path.join( "laser", name)) if is_numbered_file(file_list[i], "time_mesh_config") == 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] self.populate_from_file(file_list[i], human_name=os.path.join( "time_domain", name)) for i in range(0, len(self.epi.layers)): l = self.epi.layers[i] self.add_item( "epitaxy.inp", "#layer_material_file" + str(i), os.path.join("epitaxy", str(l.name), _("Material type"))) self.add_item(l.file_name + ".inp", "#shape_dy", os.path.join("epitaxy", str(l.name), _("dy"))) for s in l.shapes: if s.shape_dos != "none": print(s.shape_dos) self.populate_from_file(s.shape_dos, human_name=os.path.join( "epitaxy", str(l.name), s.name, "DoS")) contacts = self.epi.contacts.contacts for i in range(0, len(contacts)): self.add_item( "contacts.inp", "#contact_charge_density" + str(i), os.path.join("contacts", str(contacts[i].name), _("Charge density"))) self.add_item( "contacts.inp", "#contact_applied_voltage" + str(i), os.path.join("contacts", str(contacts[i].name), _("Voltage"))) self.add_item( "contacts.inp", "#shunt_resistance_sq" + str(i), os.path.join("contacts", str(contacts[i].name), _("Shunt resistance"))) for i in range(0, len(self.mesh.y.layers)): self.add_item( "mesh_y.inp", "#mesh_layer_length" + str(i), os.path.join("mesh", "y", _("Layer") + " " + str(i), _("dy"))) self.add_item( "mesh_y.inp", "#mesh_layer_points" + str(i), os.path.join("mesh", "y", _("Layer") + " " + str(i), _("Points"))) self.add_item( "mesh_y.inp", "#mesh_layer_mul" + str(i), os.path.join("mesh", "y", _("Layer") + " " + str(i), _("Multiplier"))) self.add_item( "mesh_y.inp", "#mesh_layer_left_right" + str(i), os.path.join("mesh", "y", _("Layer") + " " + str(i), _("Left or Right")))
def fill_store(self): #partitions = #for p in partitions: # print(p.mountpoint, psutil.disk_usage(p.mountpoint).percent) #print(expanduser("~")) self.file_list=[] #print(self.path) if self.path=="/gpvdmroot": itm=file_store() itm.file_name="simulation_dir" itm.icon="si" itm.display_name=_("Simulation") self.file_list.append(itm) itm=file_store() itm.file_name="home_dir" itm.icon="user-home" itm.display_name=_("Home") self.file_list.append(itm) if get_desktop_path()!=False: itm=file_store() itm.file_name="desktop_dir" itm.icon="desktop" itm.display_name=_("Desktop") self.file_list.append(itm) if get_downloads_path()!=False: itm=file_store() itm.file_name="downloads_dir" itm.icon="folder-download" itm.display_name=_("Downloads") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_configure" itm.icon="cog" itm.display_name=_("Configure") self.file_list.append(itm) for p in psutil.disk_partitions(): name=p.mountpoint if running_on_linux()==True: name=os.path.basename(name) if name=="": name="/" itm=file_store() itm.file_name="mount_point::::"+p.mountpoint itm.icon="drive-harddisk" itm.display_name=name self.file_list.append(itm) elif self.path=="/gpvdmroot/gpvdm_configure": itm=file_store() itm.file_name="gpvdm_cluster_config" itm.icon="server" itm.display_name=_("Cluster") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_language_config" itm.icon="internet-chat" itm.display_name=_("Language") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_solver_config" itm.icon="accessories-calculator" itm.display_name=_("Solver") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_led_config" itm.icon="oled" itm.display_name=_("LED") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_dump_config" itm.icon="hdd_custom" itm.display_name=_("Output files") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_gui_config" itm.icon="applications-interfacedesign" itm.display_name=_("GUI configuration") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_thermal_config" itm.icon="thermal" itm.display_name=_("Thermal") self.file_list.append(itm) itm=file_store() itm.file_name="gpvdm_server_config" itm.icon="cpu" itm.display_name=_("Server") self.file_list.append(itm) else: path=self.path if os.path.isdir(path)==False: error_dlg(self,_("The directory is gone, so I can't open it. Did you delete it?")+" "+path) return else: all_files=os.listdir(path) all_files.sort() for fl in all_files: #print(fl) file_name=os.path.join(path, fl) itm=file_store() if is_mat_file(file_name)==True: if fl.endswith(".zip"): fl=fl[:-4] itm.file_name=fl itm.icon="organic_material" #if it is a directory if os.path.isdir(file_name): gpvdm_file_type=inp_get_token_value(os.path.join(file_name,"mat.inp"), "#gpvdm_file_type") if gpvdm_file_type=="spectra": itm.file_name=fl itm.icon="spectra" else: show_dir=True if os.path.isfile(os.path.join(file_name,"gpvdm_gui_config.inp"))==True: show_dir=False if show_dir==True: itm.file_name=fl itm.icon="folder" else: #append=False ext=os.path.splitext(file_name) if len(ext)>1: ext=ext[1].lower() else: ext="" if (ext==".dat"): read_ok=False try: f = open(file_name, 'rb') text = f.readline() f.close() read_ok=True except: pass if read_ok==True: if len(text)>0: if text[len(text)-1]==10: text=text[:-1] if text==b"#gpvdm": itm.file_name=fl itm.icon="dat_file" elif (ext==".inp") and self.show_inp_files==True: itm.file_name=fl itm.icon="text-x-generic" elif (ext==".omat"): itm.file_name=fl itm.icon="omat" elif os.path.basename(file_name)=="sim_info.dat": itm.file_name=fl itm.icon="info" elif file_name.endswith("default.gpvdm")==False and file_name.endswith(".gpvdm"): lines=[] lines=inp_load_file("info.inp",archive=file_name) if lines!=False: itm.file_name=fl itm.display_name=inp_get_token_value_from_list(lines, "#info_name")+" ("+fl+")" icon_name=inp_get_token_value_from_list(lines, "#info_icon") itm.icon=icon_name itm.hidden=str2bool(inp_get_token_value_from_list(lines, "#info_hidden")) a=zip_lsdir(file_name,sub_dir="fs/") #,zf=None,sub_dir=None if len(a)!=0: for fname in a: lines=ret=read_lines_from_archive(file_name,"fs/"+fname) if lines!=False: web_link=inp_get_token_value_from_list(lines, "#web_link") name=inp_get_token_value_from_list(lines, "#name") sub_itm=file_store() sub_itm.icon="internet-web-browser" sub_itm.display_name=name sub_itm.file_name=web_link sub_itm.hidden=False self.file_list.append(sub_itm) if itm.icon=="": if icon_get(ext)!=False: itm.icon=ext itm.file_name=fl else: itm.icon="misc" itm.file_name=fl if itm.display_name=="": itm.display_name=itm.file_name if file_name.endswith("sim.gpvdm")==False: self.file_list.append(itm) for i in range(0,len(self.file_list)): if self.file_list[i].file_name=="p3htpcbm.gpvdm": self.file_list.insert(0, self.file_list.pop(i)) break self.paint()
def fill_store(self): self.file_list = [] if os.path.isdir(self.path) == False: error_dlg( self, _("The directory is gone, so I can't open it. Did you delete it?" ) + " " + self.path) return all_files = os.listdir(self.path) #all_files.sort() for fl in all_files: file_name = os.path.join(self.path, fl) itm = file_store() #if it is a directory if os.path.isdir(file_name): gpvdm_file_type = inp_get_token_value( os.path.join(file_name, "mat.inp"), "#gpvdm_file_type") if gpvdm_file_type == "spectra": itm.file_name = fl itm.icon = "spectra" elif gpvdm_file_type == "mat": itm.file_name = fl itm.icon = "organic_material" else: show_dir = True if os.path.isfile( os.path.join(file_name, "gpvdm_gui_config.inp")) == True: show_dir = False if show_dir == True: itm.file_name = fl itm.icon = "folder" else: #append=False if (file_name.endswith(".dat") == True): f = open(file_name, 'rb') text = f.readline() f.close() #text=text.encode('utf-8').strip() #print(text) #text=text.rstrip() if len(text) > 0: if text[len(text) - 1] == 10: text = text[:-1] if text == b"#gpvdm": itm.file_name = fl itm.icon = "dat_file" if (file_name.endswith(".inp") == True) and self.show_inp_files == True: itm.file_name = fl itm.icon = "text-x-generic" if (file_name.endswith(".omat") == True): itm.file_name = fl itm.icon = "omat" if file_name.endswith(".pdf") == True: itm.file_name = fl itm.icon = "pdf" if file_name.endswith(".jpg") == True: itm.file_name = fl itm.icon = "image-x-generic" if os.path.basename(file_name) == "sim_info.dat": itm.file_name = fl itm.icon = "info" if file_name.endswith( "default.gpvdm") == False and file_name.endswith( ".gpvdm"): lines = [] lines = inp_load_file("info.inp", archive=file_name) if lines != False: itm.file_name = fl itm.display_name = inp_get_token_value_from_list( lines, "#info_name") + " (" + fl + ")" icon_name = inp_get_token_value_from_list( lines, "#info_icon") itm.icon = icon_name itm.hidden = str2bool( inp_get_token_value_from_list( lines, "#info_hidden")) a = zip_lsdir(file_name, sub_dir="fs/") #,zf=None,sub_dir=None if len(a) != 0: for fname in a: lines = ret = read_lines_from_archive( file_name, "fs/" + fname) if lines != False: web_link = inp_get_token_value_from_list( lines, "#web_link") name = inp_get_token_value_from_list( lines, "#name") sub_itm = file_store() sub_itm.icon = "internet-web-browser" sub_itm.display_name = name sub_itm.file_name = web_link sub_itm.hidden = False self.file_list.append(sub_itm) if itm.display_name == "": itm.display_name = itm.file_name self.file_list.append(itm) for i in range(0, len(self.file_list)): if self.file_list[i].file_name == "p3htpcbm.gpvdm": self.file_list.insert(0, self.file_list.pop(i)) break self.paint()
def scan_ml_build_vector(sim_dir): out = open(os.path.join(sim_dir, "vectors.dat"), 'wb') for archive_name in os.listdir(sim_dir): if archive_name.startswith( "archive") == True and archive_name.endswith(".zip") == True: progress_window = progress_class() progress_window.show() progress_window.start() archive_path = os.path.join(sim_dir, archive_name) zf = zipfile.ZipFile(archive_path, 'r') dirs = zip_lsdir(archive_path, zf=zf, sub_dir="/") items = len(dirs) print(items, archive_path, dirs) for i in range(0, len(dirs)): tmp_dir = "/dev/shm/gpvdm" if os.path.isdir(tmp_dir) == True: shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) extract_dir_from_archive(tmp_dir, "", dirs[i], zf=zf) full_name = tmp_dir written = False #print(dirs[i]) while (1): v = "#ml_id\n" v = v + dirs[i] + "\n" v = v + "#ml_input_jv_dark\n" ret = get_vectors(full_name, "0.0", "measure_jv.dat", dolog=True) if ret == False: print("ml_input_jv_dark") break v = v + ret + "\n" v = v + "#ml_input_jv_light\n" ret = get_vectors(full_name, "1.0", "measure_jv.dat", div=1e2) if ret == False: print("ml_input_jv_ligh") break v = v + ret + "\n" v = v + "#ml_input_tpc_neg\n" ret = get_vectors(full_name, "TPC", "measure_tpc.dat", fabs=True, dolog=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_tpc\n" ret = get_vectors(full_name, "TPC_0", "measure_tpc.dat", fabs=True, dolog=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_tpc_neg_norm\n" ret = get_vectors(full_name, "TPC", "measure_tpc.dat", fabs=True, dolog=True, do_norm=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_tpc_norm\n" ret = get_vectors(full_name, "TPC_0", "measure_tpc.dat", fabs=True, dolog=True, do_norm=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_tpc_ideal\n" ret = get_vectors(full_name, "TPC_ideal", "measure_tpc.dat", fabs=True, dolog=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_tpc_ideal_norm\n" ret = get_vectors(full_name, "TPC_ideal", "measure_tpc.dat", fabs=True, dolog=True, do_norm=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_tpv\n" ret = get_vectors(full_name, "TPV", "measure_tpv.dat", fabs=True) if ret == False: break v = v + ret + "\n" v = v + "#ml_input_celiv\n" ret = get_vectors(full_name, "CELIV", "measure_celiv.dat", fabs=True) if ret == False: break v = v + ret + "\n" v = v + get_vectors_binary(full_name, "1.0") for min_max in ["min", "max", "avg"]: a = scan_ml_build_token_vectors( os.path.join(full_name, "dos0.inp"), "#Etrape", "#Etraph", [40e-3, 50e-3, 60e-3, 70e-3, 80e-3, 90e-3, 100e-3], min_max=min_max) v = v + a a = scan_ml_build_token_vectors( os.path.join(full_name, "dos0.inp"), "#mueffe", "#mueffh", [1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3], min_max=min_max) v = v + a a = scan_ml_build_token_vectors( os.path.join(full_name, "dos0.inp"), "#Ntraph", "#Ntrape", [1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27], min_max=min_max) v = v + a a = scan_ml_build_token_vectors( os.path.join(full_name, "parasitic.inp"), "#Rshunt", "#Rshunt", [1e2, 1e3, 1e4, 1e5, 1e6, 1e7], min_max="avg") v = v + a #a=scan_ml_build_token_abs(os.path.join(full_name,"parasitic.inp"),"#Rshunt","#Rshunt",min_max="avg") #v=v+a a = scan_ml_build_token_vectors( os.path.join(full_name, "parasitic.inp"), "#Rcontact", "#Rcontact", [5, 10, 15, 20, 25, 30, 35, 40], min_max="avg") v = v + a a = scan_ml_build_token_vectors( os.path.join(full_name, "1.0", "sim_info.dat"), "#jv_pmax_tau", "#jv_pmax_tau", [1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7], min_max="avg") v = v + a a = scan_ml_build_token_vectors( os.path.join(full_name, "1.0", "sim_info.dat"), "#jv_pmax_mue", "#jv_pmax_mue", [1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3], min_max="avg") v = v + a out.write(str.encode(v)) written = True break if written == False: print("Error", dirs[i]) progress_window.set_fraction(float(i) / float(len(dirs))) progress_window.set_text(dirs[i]) #if server_break()==True: # break process_events() #return progress_window.stop()