def contactm(distancem,threshold=None): if threshold == None: # Colormap pylab.matshow(np.transpose(distancem)) pylab.colorbar() pylab.savefig(protein_name + '.png') else: # Thresholded map contact_map = distancem > 15 pylab.autumn() pylab.imshow(np.transpose(contact_map)) pylab.savefig(protein_name + '_thr.png')
def contactm(distancem, threshold=None): if threshold == None: # Colormap pylab.matshow(np.transpose(distancem)) pylab.colorbar() pylab.savefig(protein_name + '.png') else: # Thresholded map contact_map = distancem > 15 pylab.autumn() pylab.imshow(np.transpose(contact_map)) pylab.savefig(protein_name + '_thr.png')
fh = pdbl.retrieve_pdb_file( '1CON') #downloads the pdb file of 2CD0 protein structure = parser.get_structure( '1CON', fh ) #extrae la inform estruct de la proteina descargada. 2cd0 es trivial. residues = structure.get_residues() #mirar si separa chains. counter = 0 mylist2 = list() i = 0 #for model in structure: for chain in structure[0]: for residue in chain: j = 0 mylist = list() for residue2 in chain: try: mylist.append(residue['CA'] - residue2['CA']) except: mylist.append(10000) j += 1 #print j mylist2.append(mylist) i += 1 #print i distancem = np.asarray(mylist2) contact_map = distancem > 15 pylab.autumn() pylab.imshow(np.transpose(contact_map)) pylab.show()
def _lss_corr(obs, interactive=True, maxcr=False, figno=20, rawxy=None, target='target', chatter=0): '''determine the LSS correction for the readout streak source ''' import os import numpy as np try: from astropy.io import fits except: import pyfits as fits from pylab import figure,imshow,ginput,axvspan,\ axhspan,plot,autumn,title,clf file = obs['infile'] ext = obs['extension'] cols = obs['streak_col_SN_CR_ERR'] kol = [] countrates = [] circle = [ np.sin(np.arange(0, 2 * np.pi, 0.05)), np.cos(np.arange(0, 2 * np.pi, 0.05)) ] for k in cols: kol.append(k[1]) # S/N countrates.append(k[2]) kol = np.array(kol) if len(kol) == 0: print "zero array kol in _lss_corr ???!!!!" print "LSS correction cannot be determined." return 1.0, (0, 0), (1100.5, 1100.5) k_sn_max = np.where(np.max(kol) == kol) # maximum s/n column print "k S/N max=", k_sn_max[0][0] kol = [] for k in cols: kol.append(k[0]) # column number relative to bottom rh corner subimage if len(kol) == 0: print "LSS correction cannot be determined." return 1.0, (0, 0), (1100.5, 1100.5) im = fits.getdata(file, ext=ext) hdr = fits.getheader(file, ext=ext) #binx = hdr['binx'] mn = im.mean() sig = im.std() # plot figure(figno) clf() autumn() imshow(im, vmin=mn - 0.2 * sig, vmax=mn + 2 * sig) if rawxy != None: rawx, rawy = rawxy R = hdr['windowdx'] / 15. plot(R * circle[0] + rawx - hdr['windowy0'], R * circle[1] + rawy - hdr['windowx0'], '-', color='m', alpha=0.7, lw=2) title(u"PUT CURSOR on your OBJECT", fontsize=16) if not maxcr: count = 0 for k in kol: axvspan(k - 6, k + 6, 0.01, 0.99, facecolor='k', alpha=0.3 - 0.02 * count) count += 1 else: k = k_sn_max[0][0] axvspan(k - 10, k + 10, 0.01, 0.99, facecolor='k', alpha=0.2) happy = False skip = False count = 0 while not happy: print "put the cursor on the location of your source" count += 1 coord = ginput(timeout=0) print "selected:", coord if len(coord[0]) == 2: print "window corner:", hdr['windowx0'], hdr['windowy0'] xloc = coord[0][0] + hdr['windowx0'] yloc = coord[0][1] + hdr['windowy0'] print "on detector (full raw image) should be :", xloc, yloc #plot(coord[0][0],coord[0][1],'+',markersize=14,color='k',lw=2) #can't see it axhspan(coord[0][1] - 6, coord[0][1] + 6, 0, 1, facecolor='k', alpha=0.3) if rawxy != None: rawx, rawy = rawxy R = hdr['windowdx'] / 15. plot(R * circle[0] + rawx - hdr['windowx0'], R * circle[1] + rawy - hdr['windowy0'], '-', color='k', alpha=0.7, lw=1) #plot(rawx-hdr['windowx0'],rawy-hdr['windowy0'],'o',markersize=25,color='w',alpha=0.3) ans = raw_input("happy (yes,skip,no): ") if len(ans) > 0: if ans.upper()[0] == 'Y': happy = True if ans.upper()[0] == 'S': return 0.0, coord[0], (yloc + 104, xloc + 78) else: print "no position found" if count > 10: print "Too many tries: aborting" happy = True im = '' try: lss = 1.0 band = obs['band'] caldb = os.getenv('CALDB') command = "quzcif swift uvota - "+band.upper()+\ " SKYFLAT "+\ obs['dateobs'].split('T')[0]+" "+\ obs['dateobs'].split('T')[1]+" - > lssfile.1234.tmp" print command os.system(command) f = open('lssfile.1234.tmp') lssfile = f.readline() f.close() f = fits.getdata(lssfile.split()[0], ext=int(lssfile.split()[1])) lss = f[yloc, xloc] print "lss correction = ", lss, " coords=", coord[0], (yloc + 104, xloc + 78) return lss, coord[0], (yloc + 104, xloc + 78) except: print "LSS correction cannot be determined." return 1.0, (0, 0), (1100.5, 1100.5)
pdb_filename = "1XI4.pdb" def calc_residue_dist(residue_one, residue_two) : """Returns the C-alpha distance between two residues""" diff_vector = residue_one["CA"].coord - residue_two["CA"].coord return numpy.sqrt(numpy.sum(diff_vector * diff_vector)) def calc_dist_matrix(chain_one, chain_two) : """Returns a matrix of C-alpha distances between two chains""" answer = numpy.zeros((len(chain_one), len(chain_two)), numpy.float) for row, residue_one in enumerate(chain_one) : for col, residue_two in enumerate(chain_two) : answer[row, col] = calc_residue_dist(residue_one, residue_two) return answer structure = Bio.PDB.PDBParser().get_structure(pdb_code, pdb_filename) model = structure[0] dist_matrix = calc_dist_matrix(model["D"], model["D"]) contact_map = dist_matrix < 20.0 # print "Minimum distance", numpy.min(dist_matrix) # print "Maximum distance", numpy.max(dist_matrix) import pylab pylab.autumn() pylab.imshow(numpy.transpose(contact_map)) pylab.show()
def _lss_corr(obs,interactive=True,maxcr=False,figno=20, rawxy=None, target='target', chatter=0): '''determine the LSS correction for the readout streak source ''' import os import numpy as np try: from astropy.io import fits except: import pyfits as fits from pylab import figure,imshow,ginput,axvspan,\ axhspan,plot,autumn,title,clf file = obs['infile'] ext = obs['extension'] cols = obs['streak_col_SN_CR_ERR'] kol = [] countrates=[] circle=[np.sin(np.arange(0,2*np.pi,0.05)),np.cos(np.arange(0,2*np.pi,0.05))] for k in cols: kol.append(k[1]) # S/N countrates.append(k[2]) kol = np.array(kol) if len(kol) == 0: print("zero array kol in _lss_corr ???!!!!") print("LSS correction cannot be determined.") return 1.0, (0,0), (1100.5,1100.5) k_sn_max = np.where(np.max(kol) == kol) # maximum s/n column print("k S/N max=",k_sn_max[0][0]) kol = [] for k in cols: kol.append(k[0]) # column number relative to bottom rh corner subimage if len(kol) == 0: print("LSS correction cannot be determined.") return 1.0, (0,0), (1100.5,1100.5) im=fits.getdata(file, ext=ext) hdr=fits.getheader(file, ext=ext) #binx = hdr['binx'] mn = im.mean() sig = im.std() # plot figure(figno) clf() autumn() imshow(im,vmin=mn-0.2*sig,vmax=mn+2*sig) if rawxy != None: rawx,rawy = rawxy R = hdr['windowdx']/15. plot(R*circle[0]+rawx-hdr['windowy0'],R*circle[1]+rawy-hdr['windowx0'], '-',color='m',alpha=0.7,lw=2) title(u"PUT CURSOR on your OBJECT",fontsize=16) if not maxcr: count = 0 for k in kol: axvspan(k-6,k+6,0.01,0.99, facecolor='k',alpha=0.3-0.02*count) count += 1 else: k = k_sn_max[0][0] axvspan(k-10,k+10,0.01,0.99, facecolor='k',alpha=0.2) happy = False skip = False count = 0 while not happy : print("put the cursor on the location of your source") count += 1 coord = ginput(timeout=0) print("selected:",coord) if len(coord[0]) == 2: print("window corner:", hdr['windowx0'],hdr['windowy0']) xloc = coord[0][0]+hdr['windowx0'] yloc = coord[0][1]+hdr['windowy0'] print("on detector (full raw image) should be :",xloc,yloc) #plot(coord[0][0],coord[0][1],'+',markersize=14,color='k',lw=2) #can't see it axhspan(coord[0][1]-6,coord[0][1]+6,0,1,facecolor='k',alpha=0.3) if rawxy != None: rawx,rawy = rawxy R = hdr['windowdx']/15. plot(R*circle[0]+rawx-hdr['windowx0'],R*circle[1]+rawy-hdr['windowy0'], '-',color='k',alpha=0.7,lw=1) #plot(rawx-hdr['windowx0'],rawy-hdr['windowy0'],'o',markersize=25,color='w',alpha=0.3) ans = raw_input("happy (yes,skip,no): ") if len(ans) > 0: if ans.upper()[0] == 'Y': happy = True if ans.upper()[0] == 'S': return 0.0, coord[0], (yloc+104,xloc+78) else: print("no position found") if count > 10: print("Too many tries: aborting" ) happy = True im = '' try: lss = 1.0 band = obs['band'] caldb = os.getenv('CALDB') command = "quzcif swift uvota - "+band.upper()+\ " SKYFLAT "+\ obs['dateobs'].split('T')[0]+" "+\ obs['dateobs'].split('T')[1]+" - > lssfile.1234.tmp" print(command) os.system(command) f = open('lssfile.1234.tmp') lssfile = f.readline() f.close() f = fits.getdata(lssfile.split()[0],ext=int(lssfile.split()[1])) lss = f[ yloc,xloc] print("lss correction = ",lss," coords=",coord[0], (yloc+104,xloc+78)) return lss, coord[0], (yloc+104,xloc+78) except: print("LSS correction cannot be determined.") return 1.0, (0,0), (1100.5,1100.5)