def setChainID( m ): """ set chainID for Hex pdb files """ if options['id']: id = T.toList( options['id'] ) cMap = m.chainMap() for chain in range( m.lenChains() ): idx = N0.nonzero( cMap == chain ) for i in idx: m.atoms['chain_id'][i] = id[chain]
def setChainID(m): """ set chainID for Hex pdb files """ if options['id']: id = T.toList(options['id']) cMap = m.chainMap() for chain in range(m.lenChains()): idx = N0.nonzero(cMap == chain) for i in idx: m.atoms['chain_id'][i] = id[chain]
def __setChainID( self, m, ids ): """ set chaiID for Hex pdb files @param m: model @type m: PDBModel @param ids: chain id, len(ids) == m.lenChains @type ids: [str] @return: m is changed directly @rtype: PDBModel """ if ids: ids = t.toList( ids ) cMap = m.chainMap() for chain in range( m.lenChains() ): idx = N.nonzero( cMap == chain ) for i in idx: m.atoms['chain_id'][i] = ids[chain]
def rmsdLimitedClustering( tc, options, min_cluster=5, max_cluster=30, rmsLimit=1.0 ): """ Cluster iteratively until the average of all clusters meet the rmsd cutoff criteria. """ allowedAtoms = T.toList( options.get('a',[]) ) if allowedAtoms: mask = tc.traj.ref.mask( lambda a: a['name'] in allowedAtoms ) else: mask = selectedAtoms( tc.traj.ref ) n_cluster = tc.calcClusterNumber( min_clst=min_cluster, max_clst=max_cluster, rmsLimit=1.0 ) options['n'] = n_cluster cluster( tc, options )
def rmsdLimitedClustering( tc, options, min_cluster=5, max_cluster=30, rmsLimit=1.0 ): """ Cluster iteratively until the average of all clusters meet the rmsd cutoff criteria. """ allowedAtoms = T.toList( options.get('a',[]) ) if allowedAtoms: mask = tc.traj.ref.mask( lambda a: a['name'] in allowedAtoms ) else: mask = selectedAtoms( tc.traj.ref ) n_cluster = tc.calcClusterNumber( min_clst=min_cluster, max_clst=max_cluster, rmsLimit=1.0 ) options['n'] = n_cluster cluster( tc, options )
T.dump(d, T.absfile(f)) ########## ## MAIN ## default = {'o': '', 'p': 'surf dens'} if len(sys.argv) < 2: _use(default) options = T.cmdDict(default) if options.has_key('i'): inLst = T.toList(options['i']) inLst = [T.absfile(f) for f in inLst] else: inLst = [] sourceIn = T.absfile(options['s']) sourceOut = None if options.has_key('so'): sourceOut = T.absfile(options['so']) prefix = options['o'] print 'Preparing source ' + str(os.path.basename(sourceIn))\ + ' -> ' + str(sourceOut)
if importas == module: importas = '' else: importas = ' as ' + importas return l.replace( 'from '+module+' import *', 'import '+module+importas) options = t.cmdDict( {'m':'Numeric', 'as':'N', 'e':['Complex'] } ) module = options['m'] importas = options.get('as', module ) srcfiles = t.toList( options.get('i', None) ) exclude = t.toList( options['e'] ) try: exec('import '+module) for fname in srcfiles: fname = t.absfile( fname ) shutil.copy( fname, fname + '_' ) methods = re_lst( module, exclude ) fold = open( fname + '_' )
if len (sys.argv) < 2: _use( default ) options = T.cmdDict( default ) ## where to run the calculation base_folder = T.absfile( options['r'] )+'/' ## template gly-xxx-gly template = os.path.abspath( options['i'] ) ## label the result dictionaty files label = '_' + options['l'] ## mask to used to delete glycines mask = [ int(i) for i in T.toList( options['mask'] )] ## create random prptides from template #randomPeptides( template, base_folder ) ## collect average surfaces MS, AS, MS_sd, AS_sd = randomSurfaces( base_folder, label, mask ) ## save dictionary with all 20 amino acids T.dump( MS, base_folder + 'MS%s.dic'%label) T.dump( AS, base_folder + 'AS%s.dic'%label ) T.dump( MS_sd, base_folder + 'MS_sd%s.dic'%label ) T.dump( AS_sd, base_folder + 'AS_sd%s.dic'%label )
########## ## MAIN ## options = tools.cmdDict() if not 'i' in options: print """Re-create LocalPath in PDBModel or Complex from the original file name (and the current environment variables). relocalize.py -i |file1 file2 ..| """ sys.exit(0) files = tools.toList( options['i'] ) repl = [] if 'r' in options: relacements = tools.toList( options['r'] ) repl = [ r.split( ':' ) for r in relacements ] for f in files: try: print "Re-localizing ", f f = tools.absfile( f ) o = tools.load( f ) result = 0 if o.__class__ in [ PCRModel, PDBModel ]: result = localizeModel( o, repl, f )
m.update( updateMissing=1 ) T.dump( d, T.absfile( f ) ) ########## ## MAIN ## default = {'o':'', 'p':'surf dens'} if len (sys.argv) < 2: _use( default ) options = T.cmdDict( default ) if options.has_key('i'): inLst = T.toList( options['i'] ) inLst = [ T.absfile( f ) for f in inLst ] else: inLst = [] sourceIn = T.absfile( options['s'] ) sourceOut = None if options.has_key('so'): sourceOut = T.absfile( options['so'] ) prefix = options['o'] print 'Preparing source ' + str(os.path.basename(sourceIn))\ + ' -> ' + str(sourceOut)
Default options: """ for key, value in o.items(): print "\t-", key, "\t", value sys.exit(0) if __name__ == '__main__': options = T.cmdDict({'o': [os.getcwd()]}) if '?' in options or 'help' in options: _use(options) folders = T.toList(options['o']) if not os.path.exists(folders[0] + '/templates'): print 'Current directory is not a valid modeling folder.' _use(options) T.flushPrint("Creating folders and links...\n") for f in folders: sv = VS(outFolder=f) sv.go(f) T.flushPrint("done\n")
if __name__ == '__main__': if len(sys.argv) < 2: _use() # options = test() options = T.cmdDict( defOptions() ) ##### COMPLEX LIST #### options['if'] = int( options['if'] ) options['if_bb'] = int( options['if_bb'] ) ## Load complex dictionary c_lst = T.load( options['i'] ) pkeys = T.toList( options['v'] ) keys = [ 'soln', 'rms', 'rms_if', 'rms_if_bb' ] + pkeys ## get complex data data = [ transpose(c_lst.valuesOf('soln')) ] for key in keys[1:]: data += [ transpose(c_lst.valuesOf(key)) ] for i in range( len(data) ): if sum( [ j==None for j in data[i] ] ) > 0: print '\n################################' print 'Info data for %s == None for at least one complex'%keys[i] print 'Plotting will fail for this key.' print '################################\n' else:
############## ## MAIN ############## if __name__ == '__main__': options = T.cmdDict( {'o':'complexes_pooled.cl', 'mo':'changed_models', 'ldic':'pcr_lig/models.dic', 'rdic':'pcr_rec/models.dic'} ) if len( sys.argv ) < 2: syntax() fs = [ T.absfile( f ) for f in T.toList( options['i'] ) ] result = ComplexList() rec_dic = T.load( T.absfile( options['rdic'] ) ) lig_dic = T.load( T.absfile( options['ldic'] ) ) for f in fs: T.flushPrint('Loading %s ...' % f ) cl = T.load( f ) cl = reduceComplexList( cl ) result += cl
for k in [ 'debug', 'verbose', 'cast', 'split', 'shuffle', 'shift', 'heavy', 'solvent', 'protein' ]: if k in options: options[k] = 1 else: options[k] = 0 for k in ['chains', 'ex1', 'ex2', 'ex']: if k in options: options[k] = t.toIntList(options[k]) if 'atoms' in options: options['atoms'] = t.toList(options['atoms']) if 'ex1' in options and 'ex2' in options: options['ex'] = (options['ex1'], options['ex2']) else: options['ex'] = options.get('ex', options.get('ex1', None)) if 'log' in options: options['log'] = LogFile(options['log']) f_in = options['i'] del options['i'] a = AmberEntropist(f_in, **options) a.run()
if start or end or (step != 1): t = t.takeFrames(range(start, e, step)) return t ############ ### MAIN ### use() o = T.cmdDict({'o': 'traj_ensemble.dat'}) out = T.absfile(o['o']) inLst = T.toList(o['i']) start = int(o.get('s', '0')) end = o.get('e', None) if end: end = int(end) step = int(o.get('step', 1)) ref = o.get('ref', None) if ref: ref = PDBModel(T.absfile(ref)) if 'prot' in o: ref = ref.compress(ref.maskProtein()) result_xyz = [] result_frameNames = [] result_ref = None
if __name__ == '__main__': if len(sys.argv) < 2: _use() # options = test() options = T.cmdDict(defOptions()) ##### COMPLEX LIST #### options['if'] = int(options['if']) options['if_bb'] = int(options['if_bb']) ## Load complex dictionary c_lst = T.load(options['i']) pkeys = T.toList(options['v']) keys = ['soln', 'rms', 'rms_if', 'rms_if_bb'] + pkeys ## get complex data data = [transpose(c_lst.valuesOf('soln'))] for key in keys[1:]: data += [transpose(c_lst.valuesOf(key))] for i in range(len(data)): if sum([j == None for j in data[i]]) > 0: print '\n################################' print 'Info data for %s == None for at least one complex' % keys[i] print 'Plotting will fail for this key.' print '################################\n' else:
if start or end or (step != 1): t = t.takeFrames( range( start, e, step ) ) return t ############ ### MAIN ### use() o = T.cmdDict( {'o':'traj_ensemble.dat'} ) out = T.absfile( o['o'] ) inLst = T.toList( o['i'] ) start = int( o.get('s','0') ) end = o.get( 'e', None ) if end: end = int( end ) step = int( o.get('step',1) ) ref = o.get('ref',None) if ref: ref = PDBModel( T.absfile( ref ) ) if 'prot' in o: ref = ref.compress( ref.maskProtein() ) result_xyz = [] result_frameNames = []
def cluster( tc, options ): n_cluster = int( options['n'] ) allowedAtoms = T.toList( options.get('a',[]) ) if allowedAtoms: mask = tc.traj.ref.mask( lambda a: a['name'] in allowedAtoms ) else: mask = selectedAtoms( tc.traj.ref ) saveIn = T.absfile( options['o'] ) + '/' conv = float( options['conv'] ) tc.cluster( n_cluster, aMask=mask, converged=conv ) ## collect center frame index for each cluster frames = [ members[0] for members in tc.memberFrames() ] result = tc.traj.takeFrames( frames ) ## trajectory of cluster centers model_dic = {} dic_index = 1 if options.has_key('ref'): ## use user-provided reference structure if os.path.isfile( T.absfile(options['ref']) ): print '\nUsing user specified reference pdb' m = PDBModel( options['ref'] ) m.remove( m.maskH2O() ) ## use reference in trajectory else: print '\nUsing reference in trajectory' m = tc.traj.ref m = dumpModel( m, options, saveIn+m.getPdbCode()+'_ref.model') ## add ref as first model in dictionary model_dic[dic_index] = m dic_index += 1 ## save the individual models and add them to the model dictionary for i in range(0, result.lenFrames() ): m = result.getPDBModel(i) m = dumpModel(m, options, saveIn + T.stripFilename(result.frameNames[i]) +'.model' ) model_dic[dic_index] = m dic_index += 1 ## save model dictionary fdic = options['dic'] or m.getPdbCode() + '_models.dic' T.dump( model_dic, T.absfile( fdic ) ) ## REDUNDANT CODE AS MULTIDOCK NOW WRITES THE HEX PDB FILES ## ## ## save all models in the dictionary as HEX pdb files ## for k in model_dic.keys(): ## m = model_dic[k] ## ## remove hydrogens and sort atoms in standard order ## m.remove( m.maskH() ) ## m = molUtils.sortAtomsOfModel(m) ## setChainID( m ) ## ## save single hex pdbs ## if options['hex']: ## fhex = options['hex'] + '_%03d' %(k) ## else: ## fhex = m.getPdbCode() + '_%03d_hex.pdb'%(k) ## hexTools.createHexPdb_single( m, T.absfile( fhex ) ) # fhex = options['hex'] or m.getPdbCode() + '_hex.pdb' # hexTools.createHexPdb( model_dic, T.absfile( fhex ) ) return result
_use() options = t.cmdDict( defaultOptions() ) ## ## current keys used for scoring ## scoreKeys = ['eProsa', 'ePairScore', 'foldX', 'cons_ent', 'cons_max'] ## load docking solutions t.flushPrint( "\nLoading complex list %s ... " % t.absfile( options['i'] ) ) complex_lst = t.load( options['i'] ) t.flushPrint( "done\n" ) ## validate and expand list of keys to be calculated force = [] if options.has_key('f'): raw_force = t.toList( options['f'] ) ## check that the key is valid validKeys = ['fnac_4.5', 'fnac_10', 'fnrc_4.5', 'fnarc_9', 'fnarc_10', 'c_ratom_9', 'c_ratom_10', 'eProsa', 'ePairScore', 'foldX', 'cons_ent', 'cons_max', 'cons_abs', 'rms_if', 'rms_if_bb'] for key in raw_force: if key in validKeys: force += [ key ] else: matching = [ v for v in validKeys if key == v[:len(key)] ] if matching: force += matching
if len (sys.argv) < 2: _use( default ) options = T.cmdDict( default ) ## where to run the calculation base_folder = T.absfile( options['r'] )+'/' ## template gly-xxx-gly template = os.path.abspath( options['i'] ) ## label the result dictionaty files label = '_' + options['l'] ## mask to used to delete glycines mask = [ int(i) for i in T.toList( options['mask'] )] ## create random prptides from template #randomPeptides( template, base_folder ) ## collect average surfaces MS, AS, MS_sd, AS_sd = randomSurfaces( base_folder, label, mask ) ## save dictionary with all 20 amino acids T.dump( MS, base_folder + 'MS%s.dic'%label) T.dump( AS, base_folder + 'AS%s.dic'%label ) T.dump( MS_sd, base_folder + 'MS_sd%s.dic'%label ) T.dump( AS_sd, base_folder + 'AS_sd%s.dic'%label )
if k in options: options[k] = int( options[k] ) for k in ['debug', 'verbose', 'cast', 'split', 'shuffle', 'shift', 'heavy', 'solvent', 'protein']: if k in options: options[k] = 1 else: options[k] = 0 for k in ['chains','ex1', 'ex2', 'ex']: if k in options: options[k] = t.toIntList( options[k] ) if 'atoms' in options: options['atoms'] = t.toList( options['atoms'] ) if 'ex1' in options and 'ex2' in options: options['ex'] = ( options['ex1'], options['ex2'] ) else: options['ex'] = options.get( 'ex', options.get('ex1', None) ) if 'log' in options: options['log'] = LogFile( options['log'] ) f_in = options['i'] del options['i'] a = AmberEntropist( f_in, **options ) a.run()
## MAIN ############## if __name__ == '__main__': options = T.cmdDict({ 'o': 'complexes_pooled.cl', 'mo': 'changed_models', 'ldic': 'pcr_lig/models.dic', 'rdic': 'pcr_rec/models.dic' }) if len(sys.argv) < 2: syntax() fs = [T.absfile(f) for f in T.toList(options['i'])] result = ComplexList() rec_dic = T.load(T.absfile(options['rdic'])) lig_dic = T.load(T.absfile(options['ldic'])) for f in fs: T.flushPrint('Loading %s ...' % f) cl = T.load(f) cl = reduceComplexList(cl) result += cl
return 1 ########## ## MAIN ## options = tools.cmdDict() if not 'i' in options: print """Re-create LocalPath in PDBModel or Complex from the original file name (and the current environment variables). relocalize.py -i |file1 file2 ..| """ sys.exit(0) files = tools.toList(options['i']) repl = [] if 'r' in options: relacements = tools.toList(options['r']) repl = [r.split(':') for r in relacements] for f in files: try: print "Re-localizing ", f f = tools.absfile(f) o = tools.load(f) result = 0 if o.__class__ in [PCRModel, PDBModel]: result = localizeModel(o, repl, f)
def cluster(tc, options): n_cluster = int(options['n']) allowedAtoms = T.toList(options.get('a', [])) if allowedAtoms: mask = tc.traj.ref.mask(lambda a: a['name'] in allowedAtoms) else: mask = selectedAtoms(tc.traj.ref) saveIn = T.absfile(options['o']) + '/' conv = float(options['conv']) tc.cluster(n_cluster, aMask=mask, converged=conv) ## collect center frame index for each cluster frames = [members[0] for members in tc.memberFrames()] result = tc.traj.takeFrames(frames) ## trajectory of cluster centers model_dic = {} dic_index = 1 if options.has_key('ref'): ## use user-provided reference structure if os.path.isfile(T.absfile(options['ref'])): print '\nUsing user specified reference pdb' m = PDBModel(options['ref']) m.remove(m.maskH2O()) ## use reference in trajectory else: print '\nUsing reference in trajectory' m = tc.traj.ref m = dumpModel(m, options, saveIn + m.getPdbCode() + '_ref.model') ## add ref as first model in dictionary model_dic[dic_index] = m dic_index += 1 ## save the individual models and add them to the model dictionary for i in range(0, result.lenFrames()): m = result.getPDBModel(i) m = dumpModel( m, options, saveIn + T.stripFilename(result.frameNames[i]) + '.model') model_dic[dic_index] = m dic_index += 1 ## save model dictionary fdic = options['dic'] or m.getPdbCode() + '_models.dic' T.dump(model_dic, T.absfile(fdic)) ## REDUNDANT CODE AS MULTIDOCK NOW WRITES THE HEX PDB FILES ## ## ## save all models in the dictionary as HEX pdb files ## for k in model_dic.keys(): ## m = model_dic[k] ## ## remove hydrogens and sort atoms in standard order ## m.remove( m.maskH() ) ## m = molUtils.sortAtomsOfModel(m) ## setChainID( m ) ## ## save single hex pdbs ## if options['hex']: ## fhex = options['hex'] + '_%03d' %(k) ## else: ## fhex = m.getPdbCode() + '_%03d_hex.pdb'%(k) ## hexTools.createHexPdb_single( m, T.absfile( fhex ) ) # fhex = options['hex'] or m.getPdbCode() + '_hex.pdb' # hexTools.createHexPdb( model_dic, T.absfile( fhex ) ) return result
if importas == module: importas = '' else: importas = ' as ' + importas return l.replace('from ' + module + ' import *', 'import ' + module + importas) options = t.cmdDict({'m': 'Numeric', 'as': 'N', 'e': ['Complex']}) module = options['m'] importas = options.get('as', module) srcfiles = t.toList(options.get('i', None)) exclude = t.toList(options['e']) try: exec('import ' + module) for fname in srcfiles: fname = t.absfile(fname) shutil.copy(fname, fname + '_') methods = re_lst(module, exclude) fold = open(fname + '_') fnew = open(fname, 'w')
_use() options = t.cmdDict(defaultOptions()) ## ## current keys used for scoring ## scoreKeys = ['eProsa', 'ePairScore', 'foldX', 'cons_ent', 'cons_max'] ## load docking solutions t.flushPrint("\nLoading complex list %s ... " % t.absfile(options['i'])) complex_lst = t.load(options['i']) t.flushPrint("done\n") ## validate and expand list of keys to be calculated force = [] if options.has_key('f'): raw_force = t.toList(options['f']) ## check that the key is valid validKeys = [ 'fnac_4.5', 'fnac_10', 'fnrc_4.5', 'fnarc_9', 'fnarc_10', 'c_ratom_9', 'c_ratom_10', 'eProsa', 'ePairScore', 'foldX', 'cons_ent', 'cons_max', 'cons_abs', 'rms_if', 'rms_if_bb' ] for key in raw_force: if key in validKeys: force += [key] else: matching = [v for v in validKeys if key == v[:len(key)]] if matching: force += matching
sort = options.has_key('s') outFolder = None if options.has_key('o'): outFolder = T.absfile( options['o'] ) ## get all PDBs and models directly from a directory (avoids shell limits) if 'd' in options: d = T.absfile( options['d'] ) files = os.listdir( d ) files = [ x for x in l if x[-4:].upper() == '.PDB' or \ x[-6:] == '.MODEL' or x[-7:].upper() == '.PDB.GZ' ] files = [ os.path.join( d, f ) for f in files ] else: ## extract file names files = T.toList( options['i'] ) ## add needed amount of hosts add_hosts = options.has_key('a') skipWat = options.has_key('wat') fileDic = {} for f in files: fileDic[T.absfile( f )] = '' print "Initialize Job queue.." master = StructMaster(fileDic, chunk , hosts.cpus_all[ : hostNumber ] , outFolder, skipWat=skipWat, amber=amber, sort=sort, show_output=windows, add_hosts=add_hosts )
if '?' in options or 'help' in options: _use( options ) if not os.path.exists(f + VS.F_RESULT_FOLDER) and not options.has_key('d'): print 'Current directory is not a valid modeling project folder.' _use( options ) ## Try to add project folders ## look for default cross-validation projects d = [] if os.path.exists( f + VS.F_RESULT_FOLDER ): d = [ f ] if options.has_key('d'): folders = T.toList(options['d']) else: folders = d T.flushPrint("Starting job...\n") for f in folders: a = A(outFolder=f) a.go() T.flushPrint("Done.\n") ## show result in PyMol if options.has_key('s'): p=Pymoler()
sort = options.has_key('s') outFolder = None if options.has_key('o'): outFolder = T.absfile(options['o']) ## get all PDBs and models directly from a directory (avoids shell limits) if 'd' in options: d = T.absfile(options['d']) files = os.listdir(d) files = [ x for x in l if x[-4:].upper() == '.PDB' or \ x[-6:] == '.MODEL' or x[-7:].upper() == '.PDB.GZ' ] files = [os.path.join(d, f) for f in files] else: ## extract file names files = T.toList(options['i']) ## add needed amount of hosts add_hosts = options.has_key('a') skipWat = options.has_key('wat') fileDic = {} for f in files: fileDic[T.absfile(f)] = '' print "Initialize Job queue.." master = StructMaster(fileDic, chunk, hosts.cpus_all[:hostNumber],