def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'a:b:h') except Exception, e: print "Error Options:[%s]"%e usage(sys.argv[0]) return -1
def main(): """ called when the file itself is executed""" (options, values) = getopt.getopt(sys.argv[1:], "-d") for option in options: #print value if option[0] == '-s': try: write_states('mongo') except ValueError: pass
def _value_after_option(self, option): """ 内部函数,用来获取跟在选项后面的值 """ """ try: # 获得选项位置 index = self.args.index(option) # 下一位置即为选项值 return self.args[index + 1] except (ValueError, IndexError): print('Parameter Error') exit() """ try: # 把选项和参数装入数组 optlist, args = getopt.getopt(self.args, 'C:c:d:o:') for i in range(len(optlist)): if option in optlist[i]: return optlist[i][1] break except getopt.GetoptError as err: print(err) exit()
def batch(self): """Automatic run of the tests""" self.pre_run() self.run() def usage(): print """ ./tester.py [-s|--simulate] <user> <conf1> <conf2>... if no file are given in input it loads the configuration files configs/test_\d\w.ini user is mandatory and will pick up the configuration from userconfs/*.ini """ sys.exit(0) if __name__ == '__main__': # TODO implementing a test cleaner opts, args = getopt.getopt(sys.argv[1:], 'cvshdl', ['verbose', 'simulate', 'help', 'clean', 'debug', 'list']) for o, a in opts: if o in ('-h', '--help'): usage() if o in ('-d', '--debug'): # Not functional programming logging.getLogger().setLevel(logging.DEBUG) if o in ('-v', '--verbose'): logging.getLogger().setLevel(logging.INFO) if o in ('-s', '--simulate'): SIMULATE = True if o in ('-l', '--list'):
def main(): global LISTEN_MODE global CONNECT_MODE global SCAN_MODE mode = CONNECT_MODE host = "localhost" family = FAMILIES["inet"] t = TYPES["tcp"] ports = range(0, 300 + 1) command = "" sslkey = None sslcert = None systemArgs = sys.argv[1:] # ignore program name optlist = [] args = [] try: optlist, args = getopt.getopt( systemArgs, "", [ "connect", "listen", "scan", "family=", "type=", "port=", "execute=", "sslkey=", "sslcert=", "help" ] ) except getopt.GetoptError: usage() if len(optlist) < 1 and len(args) < 1: usage() for option, value in optlist: if option == "--help": usage() elif option == "--connect": mode = CONNECT_MODE elif option == "--family": if value in FAMILIES: family = FAMILIES[value] else: raise new TypeError("Family not valid") elif option == "--type": if value in TYPES: t = TYPES[value] else: raise new TypeError("Type not valid") elif option == "--port": try: ports = makerange(value) except Exception, e: usage() elif option == "--listen": mode = LISTEN_MODE
#!/usr/bin/python #coding:utf-8 """ @author:derek @contract:[email protected] @file: getopt_test.py @time: 2020-09-28 15:21 """ from getopt import getopt import sys opts, args = getopt.getopt(sys.argv[1:], "ho:", ["help", "output="]) print(opts) print(args)
def multidock(argv): ''' 自动多进程处理多个PDB晶体并完成自动对接 提取对接结果数据并保存为CSV文件 Parameters ---------- pdb_list: 包含多个pdb晶体ID的列表 ''' ligand_file = '' try: opts, argvs = getopt.getopt(argv, '-hr:l:') except getopt.GetoptError: print( "usage: run py4schrodinger -r <receptors list file> -l <ligand file>\nUse run py4schrodinger.py -h for more information." ) sys.exit(2) for opt, arg in opts: if opt == '-h': print( 'usage: run py4schrodinger -r <receptors list file> [-l <ligand file>]' ) print(''' Options ---------- -r 包含所有需要对接的受体PDB ID的列表文件(.txt) -l 需要对接的外源配体文件(.pdb) *当没有-l参数传入时,脚本仅执行受体列表内的晶体获取、处理与内源配体对接,而不会将任何外源配体对接到列表中的受体 ''') sys.exit(1) elif opt == '-r': list_file = arg elif opt == '-l': ligand_file = arg try: listname = list_file.split('.')[0] with open(list_file, 'r') as f: pdbs = f.readlines() except FileNotFoundError: print('Error: 未找到列表文件!') sys.exit(2) pdb_list = [] for i in pdbs: j = i.strip().upper() pdb_list.append(j) print_title() print('\nProcessing Input List...\n') print('All Crystals to be Processed:', ''.join(str(x) + ' ' for x in pdb_list)) flag = input('\nContinue to Dock ? (Y/N)\n').strip().upper() if flag == 'Y': precision = input('请输入对接精度(HTVS|SP|XP):').strip().upper() print('\nNumber of Total CPU:', multiprocessing.cpu_count(), end='\n') cpus = int(input('请输入需要使用的CPU核心数量:')) pool1 = multiprocessing.Pool(cpus) pool2 = multiprocessing.Pool(cpus) dic = {} for pdb in pdb_list: if not os.path.exists(pdb + '.pdb'): # 下载PDB文件 getpdb.get_pdb(pdb) try: os.makedirs(pdb) except FileExistsError: pass dic[pdb] = get_ligname(pdb) # 如列表中有晶体存在多个配体 首先核对并确定唯一配体分子名 for pdb_code, ligand in dic.items(): # 采用进程池控制多线程运行 pool1.apply_async(autodock, ( pdb_code, ligand, precision, )) time.sleep(1.5) pool1.close() # 进程池关闭 不再提交新任务 pool1.join() # 阻塞进程 等待全部子进程结束 keys = dic.keys() for k in keys: #异常晶体跳过 if not os.path.exists('./%s/%s_glide_dock_%s.maegz' % (k, k, precision)): del dic[k] if ligand_file: for pdb_code in pdb_list: pool2.apply_async(dock_one_to_n, ( pdb_code, ligand_file, precision, )) time.sleep(1.5) pool2.close() pool2.join() prop = [ 'PDB', 'Ligand', 'Docking_Score', 'rmsd', 'precision', 'ligand_efficiency', 'XP_Hbond', 'rotatable_bonds', 'ecoul', 'evdw', 'emodel', 'energy', 'einternal', 'lipo', 'hbond', 'metal', 'rewards', 'erotb', 'esite' ] data = [] for pdb in pdb_list: pro_ligand = dic[pdb] prop_dic = extra_data( './%s/%s_glide_dock_%s.maegz' % (pdb, pdb, precision), precision, pro_ligand) data.append(prop_dic) if ligand_file: ligname = ligand_file.strip().split('.')[0] ex_dic = extra_data( './%s/%s_glide_dock_on_%s_%s.maegz' % (pdb, ligname, pdb, precision), precision, ligname) data.append(ex_dic) with open('%s_FINAL_RESULTS.csv' % listname, 'w', encoding='UTF-8', newline='') as f: writer = csv.DictWriter(f, fieldnames=prop) writer.writeheader() writer.writerows(data) print('\nAll Docking Jobs Done.\n') else: sys.exit(1)