def make_dry_pdb(self): envelope = self.msms0.envelope_msms.get_vert(filt=False) envelope = [(x['x'], x['y'], x['z']) for x in envelope] envelope_tree = scipy.spatial.KDTree(envelope) npdb_non = NumPdb(self.no_water_file, features=self.npdb_features) non_tree = scipy.spatial.KDTree(npdb_non['xyz']) pr2 = self.probe_radius * 2 pr3 = self.probe_radius * 3 wet_pdb = [(self.dowser.dowser_file, self.dowser_dry_pdb), (self.processed_pdb, self.original_dry_pdb)] for pdb_file, out_file in wet_pdb: npdb = NumPdb(pdb_file, features=self.npdb_features) sele_het = npdb.sele(record="HETATM") sele_not_wat = npdb.sele(resname="HOH", invert=True) hetero_tree = get_tree( npdb.get('xyz', sele=(sele_het & sele_not_wat))) sele = npdb.sele() i = 0 for numa in npdb.iter_resno(incomplete=True): flag = True if numa[0]['resname'] == 'HOH': # assume the first water atom is the oxygen dist_env = envelope_tree.query(numa['xyz'][0])[0] dist_het = hetero_tree.query(numa['xyz'][0])[0] dist_non = non_tree.query(numa['xyz'][0])[0] # TODO het cutoff only for dowser_file if dist_env < pr2 or dist_het < 3.9 or dist_non > pr3: flag = False for a in numa._atoms: sele[i] = flag i += 1 npdb.copy(sele=sele).write2(out_file)
def _pre_exec(self): if self.occupancy_one: occ_file = "occupancy_one.pdb" npdb = NumPdb(self.pdb_input) npdb['occupancy'] = 1.0 npdb.write(occ_file) self.pdb_input = self.outpath(occ_file)
def func (self): self.bestbuild() npdb=NumPdb( "bestrotamers.pdb" ) a=True z=2 #while a==True: clashes,a=find_all_clashes(npdb) gtree=get_tree(npdb['xyz']) print clashes for i in clashes: localresi=[] #hole CA atom vom ersten clashpartner r=npdb.sele(resno=i[0],atomname='CA') p=npdb.get('xyz',sele=r) #indices im 6 A umkreis um den clash l=gtree.query_ball_point(p,6) print l[0] #aus den indices eine liste mit residuname und nummer machen for x in l[0]: a=npdb.get('resname')[x] b=npdb.get('resno')[x] c=npdb.get('chain')[x] localresi.append([b,a,c]) localresi=sorted(localresi) localresi=list(localresi for localresi,_ in itertools.groupby(localresi)) #print localresi for index,i in enumerate (localresi): if i[1] not in ('ALA','GLY'): rotadir="%s_%s_%i" % (i[2],i[1],i[0]) ccsortpath=os.path.join(self.result_direc,rotadir) ccsort="%s/%s" % (ccsortpath,'ccsort.cpv') print ccsortpath break
def _get_ca (self,pdb_file,chain, residue): npdb=NumPdb( pdb_file ) sele1={"resno": self.residue, "chain": self.chain} resname1=npdb.get('resname', **sele1)[0] sele={"resno": residue, "chain": chain, "resname": resname1 ,"atomname":'CA'} cacoord=npdb.get('xyz',**sele) return cacoord
def func( self ): self.delete_backbone() npdb=NumPdb( self.pdb_file ) for i, numa in enumerate( npdb.iter_resno() ): sele={'resno':i+1} resname1=numa.get('resname') [0] resno1=numa.get('resno') [0] chain1=numa.get('chain') [0] dirg="%s_%s_%i" %(chain1,resname1,resno1) print resname1, resno1, chain1 if numa.get('resname') [0] not in ('ALA', 'GLY'): if resname1 in ('SER','CYS','PRO','ASP','THR','ASN','VAL','GLU','GLN'): SpiderSidechainCorrelation(self.map_file, self.pdb_file, self.pixelsize,self.resolution, resno1, chain1,output_dir=self.subdir(dirg)) else: SpiderSidechainCorrelation('deletebb.cpv', self.pdb_file, self.pixelsize,self.resolution, resno1, chain1,output_dir=self.subdir(dirg)) aaname="%s.%s" %(dirg,'pdb') print aaname aa=npdb.sele(resname=resname1,resno=resno1) dire="%s/%s" %(dirg,aaname) npdb.copy(sele=aa).write(dire) OriSidechainCorrel('deletebb.cpv',dire,self.pixelsize,self.resolution,resno1,chain1,output_dir=self.subdir(dirg)) else: aaname="%s.%s" %(dirg,'pdb') print aaname aa=npdb.sele(resname=resname1,resno=resno1) dire="%s/%s" %(dirg,aaname) if not os.path.exists(self.subdir(dirg)): os.makedirs(self.subdir(dirg)) npdb.copy(sele=aa).write(dire)
def get_npdb_dicts(self): mplanes = np.array(self.opm.get_planes()) dist = abs(point_plane_dist(mplanes[1][0], mplanes[0])) npdb_dict = {} npdb_tm_dict = {} npdb_sol_dict = {} for suffix, pdb_file in self.water_variants: npdb = NumPdb(pdb_file, features=self.npdb_features) npdb_dict[suffix] = npdb sele = npdb.sele() i = 0 # create transmembrane region selection for numa in npdb.iter_resno(incomplete=True): flag = True for c in numa._coords: d1 = abs(point_plane_dist(c, mplanes[0])) d2 = abs(point_plane_dist(c, mplanes[1])) if d1 < dist and d2 < dist: flag = False break for a in numa._atoms: sele[i] = flag i += 1 npdb_sol_dict[suffix] = npdb.copy(sele=sele) npdb.copy(sele=sele).write(self.outpath("sol_region.pdb")) np.logical_not(sele, sele) npdb_tm_dict[suffix] = npdb.copy(sele=sele) npdb.copy(sele=sele).write(self.outpath("tm_region.pdb")) return npdb_dict, npdb_tm_dict, npdb_sol_dict
def _post_exec(self): print('TEST 1') print(self.relpath(self.dowser_file)) if '++' in self.relpath(self.dowser_file): print('TEST !!!') print('Dowser++ not looked at!') return None self._make_provi_file(input_file=self.relpath(self.input_file), wat_file=self.relpath(self.wat_file), watall_file=self.relpath(self.watall_file), intsurf_file=self.relpath(self.intsurf_file)) # make sure all file exist for f in [self.wat_file, self.watall_file, self.intsurf_file]: with open(f, "a"): pass # write a pdb with all dowser waters but no others with open(self.dowser_file, "w") as fp: with open(self.pdb_file, "r") as fp_pdb: for line in fp_pdb: if (line[0:6] in ["ATOM ", "HETATM"] and line[17:20] != "HOH"): fp.write(line) with open(self.wat_file, "r") as fp_wat: for line in fp_wat: if line[0:6] in ["HETATM"]: fp.write(line) # rename HOH.OW atoms to HOH.O and # repair atom index npdb = NumPdb(self.dowser_file) for i, a in enumerate(npdb._atoms, start=1): if a["atomname"] == " OW " and a["resname"] == "HOH": a["atomname"] = " O " a["atomno"] = i npdb.write(self.dowser_file)
def _crop_pdb( self ): npdb = NumPdb( self.pdb_file ) npdb.write( self.cropped_pdb, chain=self.res1["chain"], resno=[ self.res1["resno"] + 1, self.res2["resno"] - 1 ], invert=True )
def _post_exec(self): npdb = NumPdb(self.pdb_file, features={ "sstruc": False, "phi_psi": False, "extra": [("dssp", "|S1", " ")] }) self.get_numpdb_sstruc(npdb)
def _pre_exec(self): self.pdb_assembly() # extract first model npdb = NumPdb(self.pdb_assembly.assembly_file, features={ "phi_psi": False, "info": False, }) npdb.write2(self.assembly_file)
def _pre_exec( self ): backbone = ( ' N ',' C ', ' CA ',' O ' ) npdb=NumPdb( self.pdb_file ) back=npdb.sele(atomname=backbone) npdb.copy(sele=back).write('nobb.pdb') self._make_script_file( map_name=self.relpath(self.map_file, no_ext=True) , pixelsize=self.pixelsize, pdb_file='nobb.pdb' )
def make_final_pdb(self): npdb_dow = NumPdb(self.dowser_dry_pdb, features=self.npdb_features) npdb_org = NumPdb(self.original_dry_pdb, features=self.npdb_features) dow_tree = get_tree(npdb_dow.get('xyz', resname="HOH")) sele = npdb_org.sele() i = 0 for numa in npdb_org.iter_resno(incomplete=True): flag = False if numa[0]['resname'] == 'HOH': dist = dow_tree.query(numa['xyz'][0])[0] if dist > 2.7: flag = True for a in numa._atoms: sele[i] = flag i += 1 coords_dow, atoms_dow = npdb_dow._select() coords_org, atoms_org = npdb_org._select(sele=sele) npdb_final = NumAtoms(np.hstack((atoms_dow, atoms_org)), np.vstack((coords_dow, coords_org))) npdb_final.write2(self.final_pdb)
def func(self): if self.check_only: return def do(name): if not self.tools: return True if self.tools[0] == "!": return name not in self.tools[1:] else: return name in self.tools if not self.analyze_only: if do("pdb_info"): self.pdb_info() if do("info"): self.make_info() if do("provi"): npdb = NumPdb(self.pdb_input, features=self.npdb_features) # npdb = NumPdb( self.final_pdb, features=self.npdb_features ) self._make_provi_file( pdb_id=self.pdb_id, pdb_title=self.pdb_info.get_info()["title"], pdb_file=self.relpath(self.pdb_input), # pdb_file=self.relpath( self.final_pdb ), # pdb_org_file=self.relpath( self.original_dry_pdb ), # mplane_file=self.relpath( self.opm.mplane_file ), ## hbx_file=self.relpath( self.hbexplore_fin.hbx_file ), vol_file=self.relpath(self.voronoia_ori.vol_file), # vol_file=self.relpath( self.voronoia_fin.vol_file ), ## msms_components=self.msms_vdw_fin.components_provi( ## color="lightgreen", translucent=0.5, ## relpath=self.relpath, max_atomno=len( npdb ) ## ), ) for suffix, pdb_file in self.water_variants: for prefix, tool, tool_kwargs in self.do_tool_list: name = "%s_%s" % (prefix, suffix) self.__dict__[name]() if do("stats"): self.make_stats() #if do( "stats2" ): # self.make_stats2() self.records = self.make_records() self.write()
def _pre_exec (self): npdb = NumPdb( self.pdb_file ) psf=1/self.pixelsize schrumpf=npdb['xyz']*psf #te= ma=np.amax(schrumpf, axis=0) mi=np.amin(schrumpf,axis=0) middle=[(mi[0]+ma[0])/2,(mi[1]+ma[1])/2,(mi[2]+ma[2])/2] abstand=round(((mi[0]-ma[0])**2+(mi[1]-ma[1])**2+(mi[2]-ma[2])**2)**0.5,0) print ma,mi,middle,abstand self._make_script_file( x1=middle[0], y1=middle[1], z1=middle[2], map_name=self.relpath(self.map_file, no_ext=True), abstand=abstand, ps=self.pixelsize, )
def _pre_exec( self ): npdb=NumPdb( self.pdb_file ) sele={"resno": self.residue, "chain": self.chain} resname1=npdb.get('resname', **sele)[0] num_rota=get_rotno(resname1) coords=self._get_ca(self.pdb_file,self.chain, self.residue) print "huh" ,coords [0] [0] x_ca= coords[0] [0] y_ca=coords [0][1] z_ca=coords [0] [2] self._make_script_file( x_ca= x_ca, y_ca=y_ca, z_ca=z_ca, map_name=self.relpath(self.map_file, no_ext=True) , pixelsize=self.pixelsize, resolution=self.resolution, pdb_file=self.relpath(self.pdb_file, no_ext=False) , )
def func (self): npdb=NumPdb( self.pdb_file ) clashes,a=find_all_clashes(npdb) gtree=get_tree(npdb['xyz']) lclashes=[] print clashes resi=range(self.residue_1,self.residue_2) print resi for i in clashes: print i[0], i[1] if (i[0] or i[1]) in resi: lclashes.append(i) else: continue for x in lclashes: print x as1=x[0] as2=x[1] resname100=npdb.get('resname',resno=as1)[0] resname101=npdb.get('resname',resno=as2)[0] # #print resname100, resname101, i if (resname100 and resname101) not in ('ALA','GLY'): chain100=npdb.get('chain',resno=as1)[0] chain101=npdb.get('chain',resno=as2)[0] #print resname101 resno1=get_rotno(resname100) resno2=get_rotno(resname101) if resno1 >= resno2 : # #print "anzahl rota" ,resno1,resno2 sele={'resno':as1} atom_no= npdb.index(**sele) # #erster clashpartner rotadir="%s_%s_%i" % (chain100,resname100,as1) ccsortpath=os.path.join(self.result_direc,rotadir) ccsort="%s/%s" % (ccsortpath,'ccsort.cpv') else: sele={'resno':as2} atom_no= npdb.index(**sele) rotadir="%s_%s_%i" % (chain101,resname101,as2) ccsortpath=os.path.join(self.result_direc,rotadir) ccsort="%s/%s" % (ccsortpath,'ccsort.cpv')
def get_npdb_dicts(self): npdb_dict = {} npdb_tm_dict = {} npdb_sol_dict = {} for suffix, pdb_file in self.water_variants: npdb = NumPdb(pdb_file, features=self.npdb_features) npdb_dict[suffix] = npdb sele = npdb.sele() i = 0 # create transmembrane region selection for numa in npdb.iter_resno(incomplete=True): flag = True for a in numa._atoms: sele[i] = flag i += 1 npdb_sol_dict[suffix] = npdb.copy(sele=sele) npdb.copy(sele=sele).write(self.outpath("sol_region.pdb")) np.logical_not(sele, sele) npdb_tm_dict[suffix] = npdb.copy(sele=sele) npdb.copy(sele=sele).write(self.outpath("tm_region.pdb")) return npdb_dict, npdb_tm_dict, npdb_sol_dict
def func(self): if self.check_only: return def do(name): if not self.tools: return True if self.tools[0] == "!": return name not in self.tools[1:] else: return name in self.tools if not self.analyze_only: if do("pdb_info"): self.pdb_info() if do("info"): self.make_info() if do("provi"): npdb = NumPdb(self.pdb_input, features=self.npdb_features) self._make_provi_file( pdb_id=self.pdb_id, pdb_title=self.pdb_info.get_info()["title"], pdb_file=self.relpath(self.pdb_input), vol_file=self.relpath(self.voronoia_ori.vol_file), ) for suffix, pdb_file in self.water_variants: for prefix, tool, tool_kwargs in self.do_tool_list: name = "%s_%s" % (prefix, suffix) self.__dict__[name]() if do("stats"): self.make_stats() self.records = self.make_records() self.write()
def _pre_exec( self ): npdb=NumPdb( self.pdb_file ) sele={"resno": self.residue, "chain": self.chain} resname1=npdb.get('resname', **sele)[0] num_rota=get_rotno(resname1) coords=self._get_ca(self.pdb_file,self.chain, self.residue) print "huh" ,coords [0] [0] x_ca= coords[0] [0] y_ca=coords [0][1] z_ca=coords [0] [2] self._make_script_file( resolution=self.resolution, pixelsize=self.pixelsize, map_name=self.relpath( self.map_file, no_ext=True ), x_ca=x_ca , y_ca=y_ca, z_ca=z_ca, cc_dir=self.relpath( self.sidechain_dir ) + os.sep, num_rota=num_rota, resname1=self.relpath (self.sidechain_dir)+ os.sep+resname1, residue=self.residue ) MakeAllRotameres(self.pdb_file, self.chain,self.residue,zfill=2,output_dir=self.sidechain_dir)
def make_processed_pdb(self): npdb = NumPdb(self.opm.processed_file, features=self.npdb_features) sele = npdb.sele() coords_dict = {} i = 0 tree = scipy.spatial.KDTree(npdb['xyz']) for numa in npdb._iter_resno(): for c in numa._coords: c = tuple(c) # remove atoms with identical coords if c in coords_dict: print npdb._atoms[i] sele[i] = False else: coords_dict[c] = True sele[i] = True # remove atoms with almost identical coords rslt = tree.query(c, k=10, distance_upper_bound=0.2) rslt[1].sort() if rslt[1][0] != i and rslt[0][1] != np.inf: print i, npdb._atoms[i] sele[i] = False i += 1 npdb.copy(sele=sele).write2(self.processed_pdb)
def func(self): if self.check_only: return def do(name): if not self.tools: return True if self.tools[0] == "!": return name not in self.tools[1:] else: return name in self.tools if not self.analyze_only: if do("opm_info"): self.opm_info() if do("opm"): self.opm() if do("proc"): self.make_processed_pdb() self.make_nowat_pdb() if do("dowser"): self.dowser() if (self.dowserplus2): self.dowserPlus2() if do("msms0"): self.msms0() if do("dry"): self.make_dry_pdb() if do("final"): self.make_final_pdb() if do("dssp"): self.dssp() if do("pdb_info"): self.pdb_info() if do("mpstruc_info"): self.mpstruc_download() self.mpstruc_info() if do("info"): self.make_info() if do("provi"): npdb = NumPdb(self.final_pdb, features=self.npdb_features) self._make_provi_file( pdb_id=self.pdb_id, pdb_title=self.pdb_info.get_info()["title"], pdb_file=self.relpath(self.final_pdb), pdb_org_file=self.relpath(self.original_dry_pdb), mplane_file=self.relpath(self.opm.mplane_file), hbx_file=self.relpath(self.hbexplore_fin.hbx_file), vol_file=self.relpath(self.voronoia_fin.vol_file), msms_components="" '''self.msms_vdw_fin.components_provi( color="lightgreen", translucent=0.5, relpath=self.relpath, max_atomno=len( npdb ) ),''') for suffix, pdb_file in self.water_variants: for prefix, tool, tool_kwargs in self.do_tool_list: name = "%s_%s" % (prefix, suffix) self.__dict__[name]() if do("stats"): self.make_stats() if do("stats2"): self.make_stats2() self.records = self.make_records() self.write()
def func( self ): tmdet_xml = tmdet( self.pdb_file ) if not tmdet_xml: tmdet_xml=" " with open( self.tmdet_file, "w" ) as fp: fp.write( tmdet_xml ) with open(self.tmdet_file, 'r') as fp: text = fp.read() if text != " ": O = [] N = [] s = text s = s.replace("\n", " ") result = re.findall('<CHAIN(.*?)TYPE="alpha"', s) if result: chain = re.findall('CHAINID="(.*?)"', result[0]) regiontext = re.findall('TYPE="alpha"(.*?)</CHAIN>',s) regions = re.findall('<REGION (.*?)type="H"/>', regiontext[0]) found = [] for reg in regions: regio = reg.split("REGION")[-1] pdb_beg = re.findall('pdb_beg="(.*?)"', regio) pdb_end = re.findall('pdb_end="(.*?)"', regio) found.append([ int(pdb_beg[0])-1, int(pdb_end[0])+1 ]) for index, elem in enumerate(found): N.append(elem[index%2]) O.append(elem[(index+1)%2]) npdb = NumPdb( self.pdb_file, features={ "phi_psi": False, "sstruc": False, "backbone_only": True }) sele = {"chain": chain[-1]} with open(self.ply_file, 'w') as fp2: fp2.write( "ply\n"+\ "format ascii 1.0\n"+\ "element vertex 8\n"+\ "property float x\n"+\ "property float y\n"+\ "property float z\n"+\ "property uchar red\n"+\ "property uchar green\n"+\ "property uchar blue\n"+\ "element face 4\n"+\ "property list uchar int vertex_indices\n"+\ "property uchar red\n"+\ "property uchar green\n"+\ "property uchar blue\n"+\ "end_header\n") for val in [N, O]: alln = [] if val == N: sele["atomname"] = "C" elif val == O: sele["atomname"] = "N" else: print 'error' for elem in val: sele["resno"] = elem coords = npdb.get( 'xyz', **sele ) if coords.size != 0: alln.append(coords[0].tolist()) point, normall = planeFit(np.array(alln).transpose()) distance = scipy.spatial.distance.cdist(alln, [point]) if val == N: normal = normall distances = distance d = -point.dot(normal) maxdist = max(distances)[0]+2 xx = np.array([point[0]+maxdist, point[0]+maxdist, point[0]-maxdist, point[0]-maxdist]) yy = np.array([point[1]+maxdist, point[1]-maxdist, point[1]+maxdist, point[1]-maxdist]) z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2] fp2.write( str( xx[0] )+" "+str( yy[0] )+" "+str( z[0] )+" 255\t0\t0\n") fp2.write( str( xx[1] )+" "+str( yy[1] )+" "+str( z[1] )+" 255\t0\t0\n") fp2.write( str( xx[2] )+" "+str( yy[2] )+" "+str( z[2] )+" 255\t0\t0\n") fp2.write( str( xx[3] )+" "+str( yy[3] )+" "+str( z[3] )+" 255\t0\t0\n") fp2.write("3 0 1 2 255\t0\t0\n") fp2.write("3 1 2 3 255\t0\t0\n") fp2.write("3 4 5 6 255\t0\t0\n") fp2.write("3 5 6 7 255\t0\t0\n")
def _get_coords( self, pdb_file, res1, res2 ): npdb = NumPdb( pdb_file ) return npdb.center( **res1 ), npdb.center( **res2 )