def copy_simulation(base_dir,cur_dir): global copy_materials gpvdm_clone(cur_dir,src_archive=os.path.join(base_dir, "sim.gpvdm"),dest="file") #print(">>>>>>>>>>>>>>>>>>>>>>>materials>>>>>>>>",copy_materials) if copy_materials==True: clone_materials(cur_dir)
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 callback_next(self): help_window().help_set_help([ "document-save-as.png", _("<big><b>Now save the simulation</b></big><br>Now select where you would like to save the simulation directory." ) ]) if len(self.viewer.selectedItems()) > 0: password = inp_get_token_value("info.inp", "#info_password", archive=self.viewer.file_path) if password != "": pw_dlg = dlg_get_text(_("password:"******"", "document-new") if password != pw_dlg.ret: return file_path = save_as_gpvdm(self) #print(file_path,get_exe_path()) if file_path != None: if file_path.startswith(get_exe_path()) == True: error_dlg( self, _("It's not a good idea to save the simulation in the gpvdm installation directory." )) return if os.path.isdir(file_path) == True: error_dlg( self, _("That directory already exists. Pick another name or delete the old one." )) return if not os.path.exists(file_path): os.makedirs(file_path) self.ret_path = file_path os.chdir(self.ret_path) bugs_clear() bugs_add_action(os.path.basename(self.viewer.file_path)) gpvdm_clone(os.getcwd(), copy_dirs=True) import_archive(self.viewer.file_path, os.path.join(os.getcwd(), "sim.gpvdm"), False) self.close() else: error_dlg(self, _("Please select a device before clicking next"))
def update_simulaton_to_new_ver(file_name): pre, ext = os.path.splitext(file_name) back_file = pre + ".bak" if os.path.isfile(back_file)==False: os.rename(file_name, back_file) dest_dir = os.path.dirname(file_name) pre, ext = os.path.splitext(file_name) dest_archive = pre + ".gpvdm" gpvdm_clone(dest_dir,False) merge_archives(back_file,dest_archive,False) else: print("Can't merge bak file already exists") return True
def tree_gen_random_files(sim_path, flat_simulation_list, program_list, base_dir): length = 0 for i in range(0, len(program_list)): if program_list[i][3] == "random_file_name": length = int(program_list[i][2]) progress_window = progress_class() progress_window.show() progress_window.start() process_events() 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")) if tree_apply_constant(cur_dir, program_list) == False: return False if tree_apply_python_script(cur_dir, program_list) == False: return False tree_apply_mirror(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 update_simulaton_to_new_ver(file_name): pre, ext = os.path.splitext(file_name) back_file = pre + ".bak" if os.path.isfile(back_file) == False: archive_compress(file_name) os.rename(file_name, back_file) dest_dir = os.path.dirname(file_name) pre, ext = os.path.splitext(file_name) dest_archive = pre + ".gpvdm" gpvdm_clone(dest_dir, copy_dirs=False) merge_archives(back_file, dest_archive, False) else: print("Can't merge bak file already exists") return True
def callback_next(self): help_window().help_set_help(["save.png",_("<big><b>Now save the simulation</b></big><br>Now select where you would like to save the simulation directory.")]) if len(self.window.listwidget.selectedItems())>0: file_path=save_as_gpvdm(self.window) if file_path!=None: selection=self.window.listwidget.selectedItems()[0].text() selection_file=selection[selection.find("(")+1:selection.find(")")] if not os.path.exists(file_path): os.makedirs(file_path) self.ret_path=file_path os.chdir(self.ret_path) gpvdm_clone(os.getcwd(),True) import_archive(os.path.join(get_device_lib_path(),selection_file),os.path.join(os.getcwd(),"sim.gpvdm"),False) self.window.close() else: error_dlg(self.window,_("Please select a device before clicking next"))
def callback_next(self): help_window().help_set_help([ "document-save-as.png", _("<big><b>Now save the simulation</b></big><br>Now select where you would like to save the simulation directory." ) ]) if len(self.viewer.selectedItems()) > 0: password = inp_get_token_value("info.inp", "#info_password", archive=self.viewer.file_path) if password != "": pw_dlg = dlg_get_text(_("password:"******"", "gnome-dialog-password") if password != pw_dlg.ret: error_dlg(self, _("Wrong password")) return file_path = save_as_gpvdm(self) #print(file_path,get_exe_path()) if file_path != None: if file_path.startswith(get_exe_path()) == True: error_dlg( self, _("It's not a good idea to save the simulation in the gpvdm installation directory. Try saving it somewhere else, such as your desktop or home directory." )) return if os.path.isdir(file_path) == True: error_dlg( self, _("That directory already exists. Pick another name or delete the old one." )) return if not os.path.exists(file_path): os.makedirs(file_path) self.ret_path = file_path os.chdir(self.ret_path) bugs_clear() bugs_add_action(os.path.basename(self.viewer.file_path)) gpvdm_clone(os.getcwd(), copy_dirs=True) import_archive(self.viewer.file_path, os.path.join(os.getcwd(), "sim.gpvdm"), False) disk_speed = disk_test(file_path) print("disk_speed=", file_path, disk_speed) inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_optics_verbose", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_print_newtonerror", "false") if disk_speed < 15000: inp_update_token_value(os.path.join(file_path, "dump.inp"), "#newton_dump", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_energy_slice_switch", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_write_converge", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_first_guess", "false") if disk_speed < 10000: inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_workbook", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_file_access_log", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_write_out_band_structure", "false") inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_1d_slices", "false") if disk_speed < 1000: inp_update_token_value(os.path.join(file_path, "dump.inp"), "#dump_log_level", "screen") self.close() else: error_dlg(self, _("Please select a device before clicking next"))
def command_args(argc, argv): if test_arg_for_sim_file() != False: return if argc >= 2: if args.version: print(version()) sys.exit(0) elif args.ver: print(ver()) sys.exit(0) elif args.syncver: ver_sync_ver() sys.exit(0) elif args.importscandirs: import_scan_dirs(os.getcwd(), args.importscandirs[0]) exit(0) elif args.replace: device_lib_replace(args.replace[0], dir_name=args.replace[1]) exit(0) elif args.delete: device_lib_delete(args.delete[0], dir_name=args.delete[1]) exit(0) elif args.clean: clean_sim_dir() sys.exit(0) elif args.export: export_as(args.export[0]) sys.exit(0) elif args.makeman: make_man() sys.exit(0) elif args.cleanscandirs: clean_scan_dirs(os.getcwd()) sys.exit(0) elif args.importfile: import_archive(args.importfile[0], os.path.join(os.getcwd(), "sim.gpvdm"), False) sys.exit(0) elif args.dumptab: export_as(args.dumptab[0]) sys.exit(0) elif args.patch: import_archive(args.patch[0], args.patch[1], True) sys.exit(0) elif args.patchfile: patch_file(args.patchfile[0], args.patchfile[1], args.patchfile[2]) sys.exit(0) elif args.clone: gpvdm_clone(os.getcwd(), copy_dirs=True) sys.exit(0) elif args.matcompress: archive_materials(os.path.join(os.getcwd(), "materials")) sys.exit(0) elif args.clonesrc: gpvdm_copy_src(clone - src[0]) sys.exit(0) elif args.editvalue: inp_update_token_value(args.editvalue[0], args.editvalue[1], args.editvalue[2]) sys.exit(0) elif args.load: set_sim_path(os.path.dirname(args.load[0])) #print("a") elif args.encrypt: inp_encrypt(args.encrypt[0]) sys.exit(0) elif args.extract: archive_decompress("sim.gpvdm") sys.exit(0) elif args.scanplot: plot_token = dat_file() oplot_file = args.scan - plot[0] if plot_load_info(plot_token, oplot_file) == True: print("file0=", plot_token.file0, "<") plot_files, plot_labels, save_file = scan_gen_plot_data( plot_token, os.path.dirname(oplot_file)) print("written data to", save_file) else: print("Problem loading oplot file") sys.exit(0) if args.unpack: archive_unpack(args.unpack[0]) sys.exit() if args.runscan: set_gui(False) scan_dir_path = args.runscan[0] #program file exe_command = get_exe_command() program_list = tree_load_program(scan_dir_path) watch_dir = os.path.join(os.getcwd(), scan_dir_path) commands = [] #server_find_simulations_to_run(commands,scan_dir_path) commands = tree_load_flat_list(scan_dir_path) print(commands) myserver = base_server() myserver.base_server_init(watch_dir) for i in range(0, len(commands)): myserver.base_server_add_job(commands[i], "") print("Adding job" + commands[i]) myserver.print_jobs() myserver.simple_run() #simple_run(exe_command) sys.exit(0) if args.scanarchive: set_gui(False) scan_archive(args.scanarchive[0]) sys.exit(0) if args.buildscan: set_gui(False) scan_items_clear() scan_items_populate_from_known_tokens() scan_items_populate_from_files() scan_dir_path = args.buildscan[0] #program file base_dir = args.buildscan[1] #base dir build_scan(scan_dir_path, base_dir) sys.exit(0) if args.scanbuildvectors: set_gui(False) scan_ml_build_vector(args.scanbuildvectors[0]) sys.exit(0) if args.buildnestedscan: set_gui(False) scan_items_clear() scan_items_populate_from_known_tokens() scan_items_populate_from_files() scan_dir_path = os.path.abspath( args.buildnestedscan[0]) #program file sim_to_nest = os.path.abspath( args.buildnestedscan[1]) #program file scan_build_nested_simulation( scan_dir_path, os.path.join(os.getcwd(), sim_to_nest)) sys.exit(0)
def command_args(argc, argv): if test_arg_for_sim_file() != False: return if argc >= 2: if args.version: print(version()) sys.exit(0) elif args.ver: print(ver()) sys.exit(0) elif args.syncver: ver_sync_ver() sys.exit(0) elif args.importscandirs: import_scan_dirs(os.getcwd(), args.importscandirs[0]) exit(0) elif args.replace: device_lib_replace(args.replace[0], dir_name=args.replace[1]) exit(0) elif args.clean: clean_sim_dir() sys.exit(0) elif args.export: export_as(args.export[0]) sys.exit(0) elif args.makeman: make_man() sys.exit(0) elif args.cleanscandirs: scan = scans_io(os.getcwd()) scan.clean_all() sys.exit(0) elif args.importfile: import_archive(args.importfile[0], os.path.join(os.getcwd(), "sim.gpvdm"), False) sys.exit(0) elif args.dumptab: export_as(args.dumptab[0]) sys.exit(0) elif args.patch: import_archive(args.patch[0], args.patch[1], True) sys.exit(0) elif args.patchfile: patch_file(args.patchfile[0], args.patchfile[1], args.patchfile[2]) sys.exit(0) elif args.clone: gpvdm_clone(os.getcwd(), copy_dirs=True) sys.exit(0) elif args.matcompress: archive_materials(os.path.join(os.getcwd(), "materials")) sys.exit(0) elif args.clonesrc: gpvdm_copy_src(clone - src[0]) sys.exit(0) elif args.editvalue: inp_update_token_value(args.editvalue[0], args.editvalue[1], args.editvalue[2]) sys.exit(0) elif args.load: set_sim_path(os.path.dirname(args.load[0])) #print("a") elif args.encrypt: inp_encrypt(args.encrypt[0]) sys.exit(0) elif args.unpack: archive_decompress(os.path.join(os.getcwd(), "sim.gpvdm"), remove_gpvdm_file=False) sys.exit(0) elif args.pack: archive_compress(os.path.join(os.getcwd(), "sim.gpvdm")) sys.exit(0) elif args.scanplot: plot_token = dat_file() oplot_file = args.scan - plot[0] if plot_load_info(plot_token, oplot_file) == True: print("file0=", plot_token.file0, "<") plot_files, plot_labels, save_file = scan_gen_plot_data( plot_token, os.path.dirname(oplot_file)) print("written data to", save_file) else: print("Problem loading oplot file") sys.exit(0)
def command_args(argc,argv): if argc>=2: if argv[1]=="--help": print(_("Usage: gpvdm [option] src_file dest_file")) print("") print(_("Options:")) print(_("\t--version\t\tdisplays the current version")) print(_("\t--help\t\t\tdisplays the help")) print(_("\t--export\t\texport a simulation to a gz file")) print(_("\t--import\t\timport a simulation from a .gpvdm file")) print(_("\t--patch\t\t\tpatch an .gpvdm file with an older .gpvdm file")) print(_("\t\t\t\tusage --import abc.gpvdm ./path/to/output/ ")) print(_("\t--clone\t\t\tgenerate a clean simulation in the current directory")) print(_("\t--clean\t\t\tcleans the current simulation directory deleting .dat files but not scan dirs")) print(_("\t--dump-tab\t\tdumps simulation parameters as jpg")) print(_("\t\t\t\tusage --dump-tab output_path ")) print(_("\t--import-scandirs\tOnly imports the scan directories")) print(_("\t--clean-scandirs\tDeletes the content of all scan dirs")) print(_("\t--scan-plot\t\truns an oplot file")) print(_("\t\t\t\tusage --scan-plot /path/to/oplot/file.oplot ")) print(_("\t--run-scan\t\truns a scan")) print(_("\t\t\t\tusage --run-scan /path/containing/base/files/ /path/to/scan/dir/ ")) print(_("\t--sync-ver\t\truns a scan")) print(_("\t--edit-value\t\tedits a value in a .gpvdm archive")) print(_("\t\t\t\tusage --edit-value /path/to/sim.gpvdm #token_to_change new_value ")) print(_("\t\t\t\tchanges the version of input file")) print(_("\t--replace\t\treplaces file in device lib")) if enable_cluster()==True: print(_("\t--server\t\tRun as server node for cluster")) print(_("\t--server\t\tRun as client node for cluster")) print("\t\t\t") print("") print(_("Additional information about gpvdm is available at http://www.gpvdm.com.")) print("") print(_("Report bugs to: [email protected]")) sys.exit(0) if check_params(argv,"--version",0)==True: print(version()) sys.exit(0) if check_params(argv,"--ver",0)==True: print(ver()) sys.exit(0) if check_params(argv,"--import-scandirs",1)==True: import_scan_dirs(os.getcwd(),argv[2]) exit(0) if check_params(argv,"--replace",1)==True: device_lib_replace(argv[2]) exit(0) if check_params(argv,"--export",1)==True: export_as(argv[2]) sys.exit(0) if check_params(argv,"--dump-tab",1)==True: export_as(argv[2]) sys.exit(0) if check_params(argv,"--import",1)==True: import_archive(argv[2],os.path.join(os.getcwd(),"sim.gpvdm"),False) sys.exit(0) if check_params(argv,"--patch",2)==True: import_archive(argv[2],argv[3],True) sys.exit(0) if check_params(argv,"--clone",0)==True: gpvdm_clone(os.getcwd(),True) sys.exit(0) if check_params(argv,"--clone-src",1)==True: gpvdm_copy_src(argv[2]) sys.exit(0) if check_params(argv,"--edit-value",3)==True: inp_update(argv[2], argv[3], argv[4]) sys.exit(0) #if check_params(argv,"--file_info",0)==True: # data=plot_data() # data.dump_file() # sys.exit(0) if check_params(argv,"--clean",0)==True: clean_sim_dir() sys.exit(0) if check_params(argv,"--clean-scandirs",0)==True: clean_scan_dirs(os.getcwd()) sys.exit(0) if check_params(argv,"--make-man",1)==True: make_man() sys.exit(0) if check_params(argv,"--sync-ver",0)==True: ver_sync_ver() sys.exit(0) if check_params(argv,"--run-scan",2)==True: scan_dir_path=argv[3] #program file program_list=[] base_dir=argv[2] #base dir exe_command = get_exe_command() tree_load_program(program_list,scan_dir_path) watch_dir=os.path.join(os.getcwd(),scan_dir_path) #print(program_list,pwd,scan_dir_path) #sys.exit(0) #print(pwd,scan_dir_path) #print(os.getcwd(),os.path.join(scan_dir_path)) #tree_gen(program_list,os.getcwd(),os.path.join(os.getcwd(),"suns")) flat_list=[] tree_gen(flat_list,program_list,base_dir,scan_dir_path) commands=[] server_find_simulations_to_run(commands,scan_dir_path) myserver=server() myserver.init(watch_dir) myserver.clear_cache() for i in range(0, len(commands)): myserver.add_job(commands[i],"") print("Adding job"+commands[i]) myserver.simple_run(exe_command) sys.exit(0) if check_params(argv,"--scan-plot",1)==True: plot_token=plot_state() oplot_file=argv[2] if plot_load_info(plot_token,oplot_file)==True: print("file0=",plot_token.file0,"<") plot_files, plot_labels, save_file = scan_gen_plot_data(plot_token,os.path.dirname(oplot_file)) print("written data to",save_file) else: print("Problem loading oplot file") sys.exit(0)
def copy_simulation(base_dir,cur_dir): gpvdm_clone(cur_dir,src_archive=os.path.join(base_dir, "sim.gpvdm"),dest="file")