def shut(self): """ shut down the device. :return: """ command = self.base_command + "idevicediagnostics shutdown" run_command(command,self.output)
def reboot(self): """ reboot the device. :return: """ command = self.base_command + "idevicediagnostics restart" run_command(command,self.output)
def get_app_list(self): """ get the customer's app installed in device :return: """ command = self.base_command + "ideviceinstaller -l" run_command(command,self.output)
def sleep(self): """ set device in sleep mode. :return: """ command =self.base_command + "idevicediagnostics sleep" run_command(command,self.output)
def screen_shot(self): """ screenshot device to the pc desktop. :return: """ image_path = join(get_desktop_path(),get_time()) + ".tiff" command = self.base_command + "idevicescreenshot " + image_path run_command(command,self.output)
def uninstall(self): """ uninstall. :return: """ self.output.AppendText("choose: " + self.uninstall_bundle + "\n") command = self.base_command + "ideviceinstaller -u " + self.uninstall_bundle run_command(command,self.output)
def aniso_check(self): point_cmd = "pointless -xdsin noSelect.HKL hklout noSelect_point.mtz" try: run_command("Scale&Merge", self.subadm, self.user, point_cmd, 'pointless.log') except Exception: point_cmd1 = "pointless -xdsin noSelect.HKL hklout noSelect_point.mtz > pointless.log" sub.call(point_cmd1, shell=True) time.sleep(2) if os.path.isfile(os.path.join(self.subadm, "noSelect_point.mtz")): fh = open("onlymerge.inp", 'w') fh.write("ONLYMERGE\n") try: from iotbx import reflection_file_reader mtzfile = reflection_file_reader.any_reflection_file( "noSelect_point.mtz") mtz_content = mtzfile.file_content() col_labels = mtz_content.column_labels() if "BATCH" in col_labels: n_batches = mtz_content.n_batches() fh.write("run 1 batch %d to %d\n" % (1, n_batches)) else: pass except (ImportError, RuntimeError) as err: logger.info('iotbx-import-error:{}'.format(err)) fh.write("run 1 batch %d to %d\n" % (1, 50)) fh.close() aim_cmd = "aimless hklin noSelect_point.mtz hklout noSelect_aim.mtz < onlymerge.inp" try: run_command("Scale&Merge", self.subadm, self.user, aim_cmd, 'aimless.log') except (OSError, TypeError, Exception) as e: aim_cmd1 = aim_cmd + '| tee aimless.log' sub.call(aim_cmd1, shell=True) self.status = True self.scale_results['status'] = self.status else: err = "Could be pointless did not run\n" logger.info('aimless-error:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return try: fh = open("aimless.log", 'r') _all = fh.readlines() fh.close() self.status = True self.scale_results['status'] = self.status except OSError, IOError: err = "aimless.log file doesn't exist" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return
def Isa_select(self, ISa_th): # method to perform ISa based selection of 'good' HKL files for next round of XSCALEing if os.path.isfile("XSCALE.LP"): fh = open("XSCALE.LP", 'r') all_lines = fh.readlines() fh.close() try: start = all_lines.index( ' a b ISa ISa0 INPUT DATA SET\n') end = all_lines.index( ' (ASSUMING A PROTEIN WITH 50% SOLVENT)\n') # select the table with ISa values from the file.. Isa_list = all_lines[start + 1:end - 3] self.status = True except (ValueError, IndexError) as err: error = "check if XSCALE ran properly or XSCALE.INP screwed up \n" logger.info('Error: {}'.format(error)) self.scale_results['info'].append(error) self.status = False self.scale_results['status'] = self.status return try: for lines in Isa_list: line = lines.split() try: if float(line[2]) > float(ISa_th): self.selected_files.append(line[4]) except IndexError: pass self.selected_files = self.sort_xtal(self.selected_files) self.create_inp(self.selected_files, reso=self.res_cut) msg = "%d xtals selected by ISa-cut out of %d xtals\n" % (len( self.selected_files), len(self.hklpaths)) self.scale_results['xtals_after_isa'] = len( self.selected_files) logger.info('MSG:{}'.format(msg)) try: run_command("Scale&Merge", self.subadm, self.user, self.xscale_cmd, 'merge.log') except Exception: sub.call(self.xscale_cmd, shell=True) self.status = True except Exception as e: logger.info('Error:{}'.format(e)) self.status = False self.scale_results['status'] = self.status self.scale_results['info'].append(e) else: err = "XSCALE.LP file does not exist" logger.info('IOError: {}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return
def install(self): """ install ipa to device. :return: """ if self.ipa_path: # 判断ipa_path 是否为空 self.output.AppendText(self.ipa_path + "\n") if os.path.exists(self.ipa_path): # 判断输入的ipa文件是否存在 command = self.base_command + "ideviceinstaller -i " + self.ipa_path run_command(command,self.output) else: self.output.AppendText(u"\n文件不存在,请重新输入或者选择\n") else: self.output.AppendText(u"Error:ipa 文件不能为空,请选择或者输入ipa_path \n")
def pointless(fname, refname, dirname=None, user=None): success = False input_cmd = """pointless XDSIN %s -HKLREF %s << EOF\nTESTFIRSTFILE\nsetting symmtery-based\nEOF""" % ( fname, refname) try: fh = open("index_check", 'w') fh.write("#!/bin/bash\n\n") fh.write(input_cmd) fh.close() chmod_cmd = "chmod +x index_check" ind_cmd = "./index_check > pointless.log" try: run_command('Scale&Merge', dirname, user, chmod_cmd, 'merge.log') run_command('Scale&Merge', dirname, user, ind_cmd, 'merge.log') except (OSError, TypeError, Exception) as e: sub.call(chmod_cmd, shell=True) sub.call(ind_cmd, shell=True) success = True except Exception as err: logger.info('Error: {}'.format(err)) success = False return success
def isocluster(self, xscalefile): if os.path.isfile(xscalefile): comd = "xscale_isocluster -dim 3 -dmax %s %s" % (self.res_cut, xscalefile) msg = "iso-clustering based on Correlation\n" logger.info('MSG:{}'.format(msg)) try: run_command("Scale&Merge", self.subadm, self.user, comd, 'isocluster.log') except Exception: comd1 = "xscale_isocluster %s > isocluster.log" % xscalefile sub.call(comd1, shell=True) self.status = True self.scale_results['status'] = self.status else: self.status = False self.scale_results['status'] = self.status return if os.path.isfile(os.path.join(self.subadm, "isocluster.log")): fkey = "best number of clusters" fh = open("isocluster.log", "r") _all = fh.readlines() fh.close() for lines in _all: if "Error" in lines: self.status = False self.scale_results['status'] = self.status return self.scale_results elif fkey in lines: line = lines.split(':') val = line[-1].strip('\n') self.scale_results["clusters"] = val.strip(' ') self.status = True self.scale_results['status'] = self.status else: pass if self.status == True and os.path.isfile( os.path.join(self.subadm, "XSCALE.1.INP")): shutil.copyfile("XSCALE.1.INP", "XSCALE.INP") msg = "xscale-ing over 1st cluster only..\n" logger.info('MSG:{}'.format(msg)) try: run_command("Scale&Merge", self.subadm, self.user, self.xscale_cmd, 'merge.log') except Exception: sub.call(self.xscale_cmd, shell=True) try: state, stats = parse_xscale_output("XSCALE.LP") logger.info('stat_dict:{}'.format(stats)) shutil.copyfile("XSCALE.INP", "cluster1.INP") shutil.copyfile("XSCALE.LP", "cluster1.LP") shutil.copyfile("XSCALE.HKL", "cluster1.HKL") self.scale_results['iso-cluster'] = stats self.status = True self.scale_results['status'] = self.status except OSError: err = "xscaling after iso-clustering may not work\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return return
def xscale_for_sx(self): self.find_HKLs() if self.status == False: logger.info('Error: no hkls found\n') self.scale_results['status'] = False return try: self.outdir_make() os.chdir(self.subadm) except OSError: err = "adm folder either not there or not accessible\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return try: if len(self.hklpaths) < 1000: self.indexing_() else: MSG = "Too many hkls, so skipping indexing check" logger.info('MSG:{}'.format(MSG)) pass # state, self.reference = ref_choice(self.hklpaths, fom='rmeas') # state_rmeas, rmeas_sorted_hkls = rmeas_sorter(self.hklpaths) # if state == False and self.reference == None: # self.status = False; self.scale_results['status'] = self.status; # logging.info('Error: bfactor-based reference choice did not work') # elif state_rmeas == False and len(rmeas_sorted_hkls) == 0: # self.status = False; self.scale_results['status'] = False # logging.info('Error: Rmeas based ranking did not work') # # elif state == True and self.reference != None and len(rmeas_sorted_hkls) > 0: # logging.info('lowest-Bfactor file: %s' %self.reference) # ref_for_cell_sg = ASCII(self.reference) # self.scale_results['space_group'] = space_group[ref_for_cell_sg.spg][0] # self.scale_results['unit-cell'] = ref_for_cell_sg.unit_cell # self.friedel = ref_for_cell_sg.anom # self.hklpaths = rmeas_sorted_hkls # self.create_file_links() # self.create_inp(self.filelinks, refs=self.reference, reso=self.res_cut) # else: self.create_file_links() self.create_inp(self.filelinks, refs=self.reference, reso=self.res_cut) msg = "Running 1st round of xscale-ing with Rmeas based ranking\n" logger.info('MSG:{}'.format(msg)) try: run_command("Scale&Merge", self.subadm, self.user, self.xscale_cmd, 'merge.log') except Exception: sub.call(self.xscale_cmd, shell=True) try: state, stats = parse_xscale_output("XSCALE.LP") if state == False: self.status = False self.scale_results['status'] = self.status return logger.info('stat_dict:{}'.format(stats)) self.scale_results['no_selection'] = stats shutil.copyfile("XSCALE.INP", "noSelect.INP") shutil.copyfile("XSCALE.LP", "noSelect.LP") shutil.copyfile("XSCALE.HKL", "noSelect.HKL") self.status = True self.scale_results['status'] = self.status except OSError: err = "xscaling may not have run\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return msg = "running xscale after ISa selection\n" logger.info('MSG:{}'.format(msg)) self.Isa_select(self.isa_cut) try: if self.status == False: self.scale_results['status'] = self.status return state, stats = parse_xscale_output("XSCALE.LP") logger.info('stat_dict:{}'.format(stats)) self.scale_results['ISa_selection'] = stats shutil.copyfile("XSCALE.INP", "ISa_Select.INP") shutil.copyfile("XSCALE.LP", "ISa_Select.LP") shutil.copyfile("XSCALE.HKL", "ISa_Select.HKL") self.status = True self.scale_results['status'] = self.status except OSError: err = "xscaling after ISa selection may not work\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return celler = Cell(self.selected_files) if len(celler.hkllist) > 200: celler.cell_analysis() self.scale_results['cell_array'] = celler.cell_ar.tolist() self.scale_results['histogram'] = celler.dict_for_histogram() else: celler.clustering() self.scale_results[ 'cell_array'] = celler.cell_ar_best_cluster.tolist() self.scale_results['dendro_labels'] = celler.data_points if celler.status == False: self.status = False return mode_cells = { 'a': celler.a_mode, 'b': celler.b_mode, 'c': celler.c_mode, 'al': celler.al_mode, 'be': celler.be_mode, 'ga': celler.ga_mode } self.scale_results['unit-cell'] = mode_cells #convert dendro dictionary for easy plottable dictionary in adp tracker try: self.scale_results['cell_dendrogram'] = dendro2highcharts( celler.dendo) # self.scale_results['hclust_matrix'] = celler.hclust_matrix self.scale_results['cell_n_clusters'] = celler.n_clusters_cell except Exception as e: logger.info('skipping-dendro-cell:{}'.format(e)) #self.scale_results['cell_array_clean'] = [celler.a_ohne, celler.b_ohne, celler.c_ohne, celler.al_ohne, celler.be_ohne, celler.ga_ohne] try: #self.create_inp(self.sort_xtal(celler.cell_select), **mode_cells) self.create_inp(celler.cell_select, reso=self.res_cut, **mode_cells) msg = "xscaling after cell-analysis and rejecting outliers\n" logger.info('MSG:{}'.format(msg)) try: run_command("Scale&Merge", self.subadm, self.user, self.xscale_cmd, 'merge.log') except (OSError, TypeError, Exception) as e: sub.call(self.xscale_cmd, shell=True) msg = "%d xtals got selected after cell analysis out of %d xtals" % ( len(celler.cell_select), len(self.hklpaths)) logger.info('MSG:{}'.format(msg)) self.status = True self.scale_results['xtals_after_cell'] = len( celler.cell_select) self.scale_results['status'] = self.status except Exception as e: logger.info('Error:{}'.format(e)) self.scale_results['info'].append(e) self.status = False self.scale_results['status'] = self.status return try: state, stats = parse_xscale_output("XSCALE.LP") if state == False: self.status = False self.scale_results['status'] = self.status return logger.info('stat_dict:{}'.format(stats)) self.scale_results['cell_selection'] = stats shutil.copyfile("XSCALE.INP", "Cell_Select.INP") shutil.copyfile("XSCALE.LP", "Cell_Select.LP") shutil.copyfile("XSCALE.HKL", "Cell_Select.HKL") self.status = True self.scale_results['status'] = self.status except OSError: err = "xscaling after Cell selection may not work\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return CC = corc.CC_estimator('ISa_Select.HKL') logger.info('ASCII loaded') CC.cc_select('ISa_Select.LP', fom='pcc') try: self.scale_results['cc_dendrogram'] = dendro2highcharts( CC.cc_dendo) self.scale_results['cc_n_clusters'] = CC.n_clusters_cc self.hkl_cc_sorted = CC.cc_cluster_list msg = "pair-correlation sorting over Isa_select: %d hkls" % len( self.hkl_cc_sorted) logger.info('MSG:{}'.format(msg)) self.create_inp(self.hkl_cc_sorted, reso=self.res_cut, **mode_cells) except Exception as err: logger.info('cc-dendro-empty:{}'.format(err)) try: run_command("Scale&Merge", self.subadm, self.user, self.xscale_cmd, 'merge.log') except (OSError, TypeError, Exception) as e: sub.call(self.xscale_cmd, shell=True) self.status = True self.scale_results['xtals_after_pCC'] = len(self.hkl_cc_sorted) self.scale_results['status'] = self.status try: state, stats = parse_xscale_output("XSCALE.LP") if state == False: self.status = False self.scale_results['status'] = self.status return logger.info('stat_dict:{}'.format(stats)) self.scale_results['pCC_selection'] = stats shutil.copyfile("XSCALE.INP", "pCC_Select.INP") shutil.copyfile("XSCALE.LP", "pCC_Select.LP") shutil.copyfile("XSCALE.HKL", "pCC_Select.HKL") self.status = True self.scale_results['status'] = self.status except OSError: err = "xscaling after pair-correlation selection may not work\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return except Exception as e: logger.info('Error: {}'.format(e)) self.scale_results['info'].append(e) self.status = False self.scale_results['status'] = self.status return return
def xscale_for_sad(self): self.find_HKLs() if self.status is False: logger.info('Error: no hkls found\n') self.scale_results['status'] = self.status return try: self.outdir_make() os.chdir(self.subadm) except OSError: err = "adm folder either not there or not accessible\n" logger.info('OSError:{}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status if len(self.hklpaths) > 0: if len(self.hklpaths) < 1000: self.indexing_() else: logger.info('Too many hkls, so skipping the indexing check') pass self.create_file_links() state, self.reference = ref_choice(self.hklpaths, fom='bfac') if state == False and self.reference == None: self.status = False self.scale_results['status'] = self.status logging.info( 'Error: bfactor-based reference choice did not work') elif state == True and self.reference != None: logging.info('lowest-Bfactor file: %s' % self.reference) ref_for_cell_sg = ASCII(self.reference) self.scale_results['space_group'] = space_group[ ref_for_cell_sg.spg][0] self.scale_results['unit-cell'] = ref_for_cell_sg.unit_cell self.friedel = ref_for_cell_sg.anom self.create_inp(self.filelinks, refs=self.reference, reso=self.res_cut) else: self.create_inp(self.filelinks) msg = "xscale-ing of native SAD data\n" logger.info('MSG:{}'.format(msg)) try: run_command("Scale&Merge", self.subadm, self.user, self.xscale_cmd, 'merge.log') except Exception: sub.call(self.xscale_cmd, shell=True) try: state, stats = parse_xscale_output("XSCALE.LP") if state is False: self.status = False self.scale_results['status'] = self.status return else: logger.info('stat_dict:{}'.format(stats)) self.scale_results['nSAD_xscale_stats'] = stats shutil.copyfile('XSCALE.HKL', 'nSAD.HKL') shutil.copyfile('XSCALE.LP', 'nSAD.LP') self.status = True except Exception as err: logger.info('Error: {}'.format(err)) self.scale_results['info'].append(err) self.status = False self.scale_results['status'] = self.status return
xdsconv_cmd = 'xdsconv > /dev/null' f2mtz_cmd = 'f2mtz HKLOUT %s < F2MTZ.INP > /dev/null' % ( self.rootname + '_' + form + '.mtz') fh = open('XDSCONV.INP', 'w') fh.write("OUTPUT_FILE=temp.hkl %s\n" % (form)) fh.write("INPUT_FILE=%s\n" % (linkname)) fh.write("FRIEDEL'S_LAW=%s\n" % (self.anom)) fh.write("INCLUDE_RESOLUTION_RANGE=50 %s\n" % (res)) fh.write("GENERATE_FRACTION_OF_TEST_REFLECTIONS= 0.05\n") fh.close() logger.info("running xdsconv") try: run_command("Scale&Merge", dirname, user, xdsconv_cmd, 'xdsconv.log') except Exception: sub.call(xdsconv_cmd, shell=True) time.sleep(2) if os.path.isfile('F2MTZ.INP'): try: run_command("Scale&Merge", dirname, user, f2mtz_cmd, 'xdsconv.log') except Exception: sub.call(f2mtz_cmd, shell=True) time.sleep(2) os.remove('temp.hkl') else: logger.info('f2mtz_error:{}'.format('xdsconv did not run\n')) return