#!/export/people/yongzhao/Python2.3_libgcc2.3/i86Linux2/bin//python2.3 import sys def usage(): print "\nUsage: pyDock setting-file [options]" print "OPTIONS:" print "-email name@domain" print "\tsend email to name@domain after job is done" print "-log file" print "\twrite all the output to 'file'" print def printHeader(): print "#############################################################" print "# #" print "# pyDock V0.9 #" print "# Yong Zhao #" print "# yongzhao@scripps.edu #" print "# #" print "# The Scripps Research Institute (TSRI) #" print "# Molecular Graphics Lab #" print "# La Jolla, CA 92037, USA #" print "# #" print "# Copyright: Yong Zhao and TSRI, 2004 #" print "# #" print "#############################################################" print "settings of the calculation:" for k in setting.keys(): print k, "=", setting[k] try: filename = sys.argv[1] except IndexError: usage() sys.exit(1) _email_to = None _log_filename = None for i in range(len(sys.argv)): #sys.argv[1:]: if sys.argv[i] == "-email": _email_to = sys.argv[i+1]; i+=1 elif sys.argv[i] == "-log": _log_filename = sys.argv[i+1]; i+=1 ## elif sys.argv[i] == "-t": ## args.remove("-l") ## do_timing = True if _log_filename is not None: import sys sys.stdout = file(_log_filename, 'wb') #filename='setting' # set default setting of docking setting={} setting['XML'] = '' setting['pop_size'] = 10 setting['p_replace'] = 0.9 setting['p_cross'] = 0.8 setting['gens'] = 2 setting['p_mutate'] = 'gene' setting['p_deviation'] = 1e-6, setting['rand_seed'] = 0 setting['rand_alg'] = 'CMRG' setting['calcIE'] = True setting['scorerVersion'] = 'C++' ### parse the configure file to setting{} try: input_file = file(filename, 'r') lines=input_file.readlines() for line in lines: if line[0] != '#' and line[0] != '\n': line = line.replace(' ', '') tmp = line.split('\n')[0].split('=') if tmp[1][0] !='\'': # number setting setting[tmp[0]] = eval(tmp[1]) else: # string setting strSetting = tmp[1].replace('\'', '') setting[tmp[0]] = strSetting except: print "Error in opening ",filename sys.exit(1) ### end of parsing # begin docking test from FlexTree.XMLParser import ReadXML reader = ReadXML() reader(setting['XML']) tree=reader.get() root=tree[0].root atmSet=root.children[0].getAtoms() for i in range(1,len(root.children) -1): atmSet += root.children[i].getAtoms() ligandSet = tree[0].root.children[-1].getAtoms() #from FlexTree.VisionInterface.FlexTreeNodes import FTtreeGaRepr from FlexTree.FTGA import FTtreeGaRepr printHeader() scorerVersion = setting['scorerVersion'] del setting['scorerVersion'] if scorerVersion == "C++": # C++ scorer from FlexTree.FTGA import AD305ScoreC scoreObject = AD305ScoreC(atmSet, ligandSet, setting['calcIE']) print "Using C++ scorer" elif scorerVersion == "Python": # Python scorer from FlexTree.FTGA import AD305Scoring scoreObject = AD305Scoring(atmSet, ligandSet, setting['calcIE']) print "Using Python scorer" elif scorerVersion == "IEC++": # Python scorer from FlexTree.FTGA import ADSinglePoint atmSet=root.getAtoms() #import pdb #pdb.run("atmSet=root.getAtoms()") #print "lala: ", len(atmSet) scoreObject = ADSinglePoint(atmSet) print "Using C++ scorer, calculate internal energy of receptor" elif scorerVersion == "Amber": # Python scorer from FlexTree.FTGA import AmberScoringIE atmSet=root.getAtoms() scoreObject = AmberScoringIE(atmSet) print "Using Amber scorer" else: print "Unknown scorer" raise print FlexTree = tree[0] gnm = FTtreeGaRepr(FlexTree, scoreObject) def postGeneration_cb(): best = galg.pop.best() ## print scoreObject.totalScoring, "scoreing take", scoreObject.totalTime,\ ## "seconds, avg = ",scoreObject.totalTime/scoreObject.totalScoring,\ ## "per score() call" print "Best Gene of current generation: " print best print "\n-----------------" import time from scipy import ga pop = ga.population.population(gnm) galg = ga.algorithm.galg(pop) settings = setting.copy() del settings['XML'] galg.settings.update(settings) print "Docking begins at:", time.ctime() print "-----------------" print galg.settings print "-----------------" from mglutil.util.callback import CallBackFunction cb = CallBackFunction(postGeneration_cb) galg.addCallback('postGeneration', cb) galg.evolve() print " *** evolution finished at ", time.ctime(), " ***" ###### end of GA ########## # clean up, if using shared memory (C++ scorer) if scorerVersion == "C++": #print "Releasing shared memory" scoreObject.freeSharedMem() # email user when job is done if _email_to: import os os.system("echo 'pyDock done' | mail -s 'Your pyDock job done' '%s'" %(_email_to))