Example #1
0
 def func(self):
     self.sstruc_refined = []
     self.elements = []
     self.phi = []
     self.psi = []
     self.pdb_id = self.sstruc_records[0].pdb_id
     self.pdb_file = self._pdb_file(self.pdb_id)
     self.npdb = numpdb.NumPdb(self.pdb_file)
     for r in self.sstruc_records:
         try:
             C3_O = self.npdb.copy(chain=r.chain2,
                                   resno=r.resno2 - 2,
                                   atomname="O")
             C2_O = self.npdb.copy(chain=r.chain2,
                                   resno=r.resno2 - 1,
                                   atomname="O")
             Cd_N = self.npdb.copy(chain=r.chain2,
                                   resno=r.resno2 + 2,
                                   atomname="N")
             Cdd_N = self.npdb.copy(chain=r.chain2,
                                    resno=r.resno2 + 3,
                                    atomname="N")
             Cddd_N = self.npdb.copy(chain=r.chain2,
                                     resno=r.resno2 + 4,
                                     atomname="N")
             if numpdb.numdist( C2_O, Cdd_N ) <= 3.9 or \
                     numpdb.numdist( C3_O, Cd_N ) <= 3.9:
                 self.sstruc_refined.append(r)
         except Exception as e:
             print e
     if self.sstruc_refined:
         self._make_provi()
         # self._make_phi_psi()
         self._make_element()
Example #2
0
 def prep(self):
     files = []
     #get all files from dir
     if len(self.pdb_files) == 1:
         v = ".*[pdb]$"
         for m, pdbfile in dir_walker(self.pdb_files[0], v):
             files.append(pdbfile)
     else:
         files = self.pdb_files
     if self.mapfile:
         fp2 = open(self.map_file, "w")
     self.new_files = []
     #generating a new pdb with only ATOM and if wanted selected chains
     for index, fi in enumerate(files):  #self.pdb_files):
         name = utils.path.stem(fi) + utils.path.ext(fi)
         if self.mapfile:
             fp2.write(fi.split("/")[-1] + " " + name + "\n")
         npdb = numpdb.NumPdb(fi)
         new_pdb = os.path.join(self.output_dir, name)
         if self.chain != "all" and self.chain[index] != "*":
             new = npdb.copy(**{
                 "record": "ATOM  ",
                 "chain": self.chain[index]
             })
         else:
             new = npdb.copy(**{"record": "ATOM  "})
         new.write(new_pdb)
         self.new_files.append(new_pdb)
     if self.mapfile:
         fp2.close()
Example #3
0
 def func( self ):
     npdb = numpdb.NumPdb( self.pdb_file, {
         "phi_psi": False,
         "sstruc": True,
         "backbone_only": False,
         "protein_only": False,
         "detect_incomplete": False,
         "configuration": False,
         "info": False
     })
     for i, numa in enumerate( npdb.iter_sstruc() ):
         print numa["chain"][0], numa["resno"].min(), numa["resno"].max()
         print numa.sequence()
         values_dic ={}
         values_dic[1]=numa['resno'][0]
         values_dic[2]=numa['resno'][-1]
         values_dic[3]=numa.sequence()
         values_dic[4]=numa['chain'][0]
         if not os.path.exists(self.pieces_dir):
             os.makedirs(self.pieces_dir)
         file_name=os.path.join(self.pieces_dir,  "%s_%s_%i-%i.%s" % (self.pdb_file[-8:-4],numa['chain'][0],numa['resno'][0],numa['resno'][-1],'pdb'))
         file_namej=os.path.join(self.pieces_dir, "%s_%s_%i-%i.%s" % (self.pdb_file[-8:-4],numa['chain'][0],numa['resno'][0],numa['resno'][-1],'json'))
         numa.write(file_name)
         with open(file_namej, "w" ) as fp:
             json.dump( values_dic,fp, indent=4 )
Example #4
0
    def _post_exec(self):
        if self.count:
            return
        phi = DefaultOrderedDict(list)
        psi = DefaultOrderedDict(list)

        if self.compare_pdb and self.compare_sele:
            s = self.compare_sele
            b = Bunch(chain1=s["chain"],
                      resno1=s["resno"][0],
                      chain2=s["chain"],
                      resno2=s["resno"][1],
                      pdb_id="COMP",
                      no=0)
            n = numpdb.NumPdb(self.compare_pdb)
            self.elements = [(b, n)]

        it = itertools.groupby(self.records, operator.attrgetter('pdb_id'))
        sf = SstrucFinderRefine([list(r) for pdb_id, r in it],
                                pdb_archive=self.pdb_archive,
                                window=self.window,
                                parallel="data")
        self.elements += sf.elements

        # rama_plot(
        #     zip( phi.values(), psi.values() ),
        #     titles = map( str, window )
        # )
        self._superpose_elements()
        self._msa_elements()
Example #5
0
    def func( self ):
        npdb = numpdb.NumPdb( self.pdb_file, {
            "phi_psi": False,
            "sstruc": False,
            "backbone_only": False,
            "protein_only": False,
            "detect_incomplete": True,
            "configuration": False,
            "info": False
        })
        sele = npdb.sele()

        if self.center:
            npdb['xyz'] -= npdb['xyz'].mean( axis=0 )

        if self.shift:
            shift = np.array( self.shift[0:3] )
            npdb['xyz'] += shift

        if self.box:
            corner1 = np.array( self.box[0:3] )
            corner2 = corner1 + np.array( self.box[3:6] )
            sele &= (
                ( npdb['xyz'] > corner1 ) &
                ( npdb['xyz'] < corner2 )
            ).all( axis=1 )

        if self.remove_h:
            sele &= ( npdb['element'] != ' H' )

        npdb.write( self.edited_pdb_file, sele=sele )
Example #6
0
def make_all_rotameres(pdbfile, chain1, resno1,zfill, outpath):
    rotamere_dict={}
    npdb = numpdb.NumPdb( pdbfile)
    sele={"resno": resno1, "chain": chain1}
    resname1=npdb.get('resname', **sele)[0]
    if resname1 != 'GLY':
        #backbone = ( ' N  ',' C  ', ' CA ',' O  ' )

        sele={ "resno": resno1, "chain": chain1, "resname": resname1 }
        no = get_rotno( sele["resname"] )
        test =npdb.sele(chain=chain1,resno=resno1)
        #test =npdb.sele(chain=self.chain,resno=[ self.res1, self.res2], invert=True)
        for i in range(0, no):
            npdb_rot = numpdb.NumPdb( pdbfile)
            rotamere = make_rotamere( npdb_rot, sele, i )
            rotamere.copy(sele=test).write("%s%s_%s_%s.%s" % (outpath,resname1,resno1, str(i+1).zfill(zfill) ,'pdb'))
        return rotamere_dict, test
Example #7
0
 def func( self ):
     self.info = numpdb.NumPdb( self.pdb_file, features={
         "phi_psi": False,
         "info": True,
         "backbone_only": True
     })._info
     with open( self.info_file, "w" ) as fp:
         json.dump( self.info, fp, indent=4 )
Example #8
0
 def func(self):
     npdb = numpdb.NumPdb(self.pdb_file)
     self.sele["atomname"] = "CA"
     numa = npdb.copy(**self.sele)
     sstruc_order = []
     for k, g in itertools.groupby(numa['sstruc']):
         n = len(list(g))
         sstruc_order.append((k, n))
         print k, n
Example #9
0
    def func( self ):
        npdb1 = numpdb.NumPdb( self.pdb_file1 )
        npdb2 = numpdb.NumPdb( self.pdb_file2 )

        sele1 = map( numpdb.numsele, self.sele1.split() )
        sele2 = map( numpdb.numsele, self.sele2.split() )

        sp, msg = numpdb.superpose(
            npdb1, npdb2, sele1, sele2,
            subset=self.subset, inplace=True,
            rmsd_cutoff=self.rmsd_cutoff, max_cycles=100,
            align=self.align
        )
        npdb1.write( self.superposed_file )

        _sele1 = np.zeros( npdb1.length, bool )
        _sele2 = np.zeros( npdb2.length, bool )

        for s in sele1:
            _sele1 |= npdb1.sele( **s )
        for s in sele2:
            _sele2 |= npdb2.sele( **s )

        s1 = npdb1.copy( **{ "sele": _sele1 } )
        s2 = npdb2.copy( **{ "sele": _sele2 } )

        # s1 = npdb1.copy( **self.sele1 )
        # s2 = npdb2.copy( **self.sele2 )

        i1 = s1.iter_resno()
        i2 = s2.iter_resno()

        # for n1, n2 in itertools.izip( i1, i2 ):
        #     for i in xrange( len(n1) ):
        #         a1 = n1[i]
        #         idx = n2['atomname'] == a1['atomname']
        #         a2 = n2[ idx ][0]
        #         d = mag( n1['xyz'][i] - n2['xyz'][ idx ][0] )
        #         n1['bfac'][i] = d
        s1.write( self.superposed2_file )

        with open( self.info_file, "w" ) as fp:
            fp.write( "\n".join( msg ) )
Example #10
0
 def func( self ):
     npdb = numpdb.NumPdb( self.pdb_file, {
         "phi_psi": False,
         "sstruc": False,
         "backbone_only": False,
         "protein_only": False,
         "detect_incomplete": False,
         "configuration": False,
         "info": False
     })
     test =npdb.sele(chain=self.chain,resno=[ self.res1, self.res2], invert=True)
     
     npdb.write( self.noloop_pdb_file,sele=test )
Example #11
0
def numpdb_test( pdb_file ):
    with Timer("read/parse pdb plain"):
        numpdb.NumPdb( pdb_file, features={
            "phi_psi": False,
            "sstruc": False,
            "backbone_only": True,
            "detect_incomplete": False
        })
    with Timer("read/parse pdb incomplete"):
        numpdb.NumPdb( pdb_file, features={
            "phi_psi": False, "sstruc": False,
            "backbone_only": False, "detect_incomplete": False
        } )
    with Timer("read/parse pdb phi/psi"):
        numpdb.NumPdb( pdb_file, features={"sstruc": False} )
    with Timer("read/parse pdb"):
        npdb = numpdb.NumPdb( pdb_file )
    # with Timer("resno iter2"):
    #     for numa_list in npdb.iter_resno2( 6, chain="A", resno=[1,22] ):
    #         print [ numa["resno"][0] for numa in numa_list ]
    # with Timer("dist"):
    #     print npdb.dist( {"chain":"A"}, {"chain":"B"} )
    with Timer("access phi/psi"):
        print np.nansum( npdb['phi'] ), np.nansum( npdb['psi'] )
    with Timer("access phi/psi, altloc"):
        print np.nansum( npdb.get('phi', altloc=[" ", "A"] ) )
    with Timer("sstruc iter"):
        for numa in npdb.iter_sstruc():
            pass
    with Timer("sequence"):
        print npdb.sequence(chain="A", resno=[1, 100])

    npdb = numpdb.NumPdb( pdb_file, features={
        "phi_psi": False,
        "sstruc": False,
        "backbone_only": False,
        "detect_incomplete": False
    })
    with Timer("plain resno iter"):
        for numa in npdb._iter_resno():
            pass
    with Timer("write pdb"):
        npdb.write( "test.pdb" )

    npdb = numpdb.NumPdb( pdb_file, features={
        "phi_psi": False,
        "sstruc": False,
        "backbone_only": False,
        "detect_incomplete": True
    })
    with Timer("resno iter new"):
        for numa in npdb.iter_resno():
            pass
Example #12
0
def make_nrhole_pdb(pdb_input, holes, nh_file, mean_file, pymol_file,
                    obj_list):
    npdb = numpdb.NumPdb(pdb_input)
    if len(npdb.get('atomno', record="HETATM")) > 0:
        sele2 = {'record': 'HETATM'}
    else:
        sele2 = {'record': 'ATOM  '}
    last_hetatm = int(npdb.get('atomno', **sele2)[-1])
    last_hetresno = int(npdb.get('resno', **sele2)[-1])

    preline = ""
    mean_dct = {}
    neighbours = {}
    mean_lst = []
    writing = False
    middle = []
    pre = []
    post = []
    for hno, holeneighbours in enumerate(holes["ses"]):
        if holeneighbours != [] and hno != 0:
            chain = ''
            xyz_list = []
            atom_list = []
            for atomno in holeneighbours:
                try:
                    resno = int(npdb.get('resno', atomno=atomno)[0])
                    chain = npdb.get('chain', atomno=atomno)[0]
                    xyz = npdb.get('xyz', atomno=atomno, chain=chain)[0]
                    xyz_list.append(xyz)
                    atom_list.append([atomno, resno, chain])
                except:
                    break
            neighbours[hno] = atom_list
            xyz2 = xyz_list
            coords = np.mean(xyz_list, axis=0)
            xyz_list_dist = []
            for co in xyz2:
                xyz_list_dist.append(np.sqrt(np.sum((coords - co)**2)))
            mean_num = np.mean(xyz_list_dist, axis=0)
            std_num = np.std(xyz_list_dist)
            natom = {
                "record": "HETATM",
                "atomno": last_hetatm + hno,
                "atomname": " CA ",
                "resname": "NEH",
                "chain": chain,
                "resno": resno,
                "x": coords[0],
                "y": coords[1],
                "z": coords[2],
                "bfac": std_num,
                "element": " C"
            }
            new_line = numpdb.pdb_line(natom),
            middle.append(numpdb.pdb_line(natom))
            mean_dct[last_hetatm + hno] = mean_num
            mean_lst.append(str(atomno) + '_' + str(resno) + '_' + chain)
    with open(pdb_input, 'r') as fp:
        for line in fp:
            if writing == True:
                post.append(line)
            else:
                if str(last_hetatm) in line[0:13]:
                    writing = True
                pre.append(line)
            preline = line[0:6]
    newline = "".join(pre + middle + post)
    with open(nh_file, 'w') as fi:
        fi.write(newline)

    with open(mean_file, "w") as fp:
        json.dump(mean_dct, fp)
    return mean_dct, neighbours, obj_list, last_hetresno, mean_lst
Example #13
0
 def __init__(self, pdb_file, pdb_id=None):
     self.npdb = numpdb.NumPdb(pdb_file, features={"phi_psi": False})
     self.pdb_id = pdb_id or utils.path.stem(pdb_file)