def plot_prediction_templates(n_templates=3, n_templates_plot=None): '''Plot the prediction together with the templates''' # Parse arguments n_templates = int(n_templates) if n_templates_plot is None: n_templates_plot = n_templates else: n_templates_plot = int(n_templates_plot) # Delete previous objects pymol.cmd.delete('all') # Get the prediction predfile = '../results/1yje_A-multiple_n_'+str(n_templates)+'.pdb' predid = '1yje_A-multiple_n_'+str(n_templates) pymol.cmd.load(predfile) pymol.cmd.color('red', predid) # Get the template codes # 1:n_templates_plot+1 because we want to exclude the target (which appears first on the list otherwise). templates = read_templates('../data/templates/most_relevant.dat')[1:n_templates_plot+1] print templates # Load structures for template in templates: id = template['id'].upper() chain = template['chain'] pymol.cmd.load(pdb_folder+id+'.pdb') pymol.cmd.align('('+id+' and chain '+chain+')', predid) pymol.cmd.hide(representation='line', selection='all') pymol.cmd.show(representation='cartoon', selection=predid) for template in templates: id = template['id'].upper() chain = template['chain'] pymol.cmd.show(representation='cartoon', selection='('+id+' and chain '+chain+')') pymol.cmd.center() pymol.cmd.bg_color('white')
def plot_prediction_templates(n_templates_plot=2): '''Plot the prediction together with the templates''' # Parse arguments n_templates_plot= int(n_templates_plot) # Delete previous objects pymol.cmd.delete('all') # Get the prediction predfile = '../results/1yje_A-multiple_n_'+str(n_templates)+'.pdb' predid = '1yje_A-multiple_n_'+str(n_templates) pymol.cmd.load(predfile) pymol.cmd.color('red', predid) # Get the template codes templates = read_templates('../data/templates/most_relevant.dat')[:n_templates_plot] # Load structures for template in templates: id = template['id'].upper() pymol.cmd.load(pdb_folder+id+'.pdb') pymol.cmd.align(id, predid) pymol.cmd.hide(representation='line', selection='all') pymol.cmd.show(representation='cartoon', selection=predid) for template in templates: id = template['id'].upper() chain = template['chain'] pymol.cmd.show(representation='cartoon', selection='('+id+' and chain '+chain+')') pymol.cmd.center() pymol.cmd.bg_color('white')
# work in the tmp folder if not os.path.isdir('data/tmp'): os.mkdir('data/tmp') os.chdir('data/tmp') try: #the environment object is needed to do pretty much everything env = environ() #.pdb files must be stored herein env.io.atom_files_directory = ['../templates/pdb/'] # align the unknown sequence with all templates seqname = (os.path.basename(seqfile).split('.')[0]) seqname = seqname[:-1]+seqname[-1].upper() templates = read_templates('../templates/most_relevant.dat')[:n_templates] n_templates = len(templates) # check whether the alignment exists already if not os.path.isfile(seqname+'-multiple_n_'+str(n_templates)+'.ali'): aln = alignment(env) for template in templates: id = template['id'] chain = template['chain'] tplname = get_tplname(template) mdl = model(env, file=id, model_segment=('FIRST:'+chain, 'LAST:'+chain)) aln.append_model(mdl, align_codes=tplname, atom_files=id+'.pdb') # add the unknown sequence to the alignment. aln.append(file=seqfile, align_codes=seqname)
author: Fabio Zanini date: 13/06/12 content: Download a PDB sequence from the database and save it into a file with the same name in the data/pdb folder ''' import urllib # From http://boscoh.com/protein/fetching-pdb-files-remotely-in-pure-python-code def fetch_pdb(id): url = 'http://www.rcsb.org/pdb/files/%s.pdb' % id return urllib.urlopen(url).read() def get_save_pdb(id): '''Get the PDB file and save it in the right folder''' pdbstring = fetch_pdb(id) with open('data/templates/pdb/'+id+'.pdb','w') as pdbfile: pdbfile.write(pdbstring) # Script if __name__ == '__main__': templatefilename = 'data/templates/most_relevant.dat' from read_templates import read_templates templates = read_templates(templatefilename) for template in templates: id = template['id'] print 'downloading', id, '...' get_save_pdb() print 'done'