コード例 #1
0
ファイル: pdbidx1.py プロジェクト: raywangyr/scripts
def pdbidx1( pdbname ):
    with open( pdbname, "r" ) as f:
        outlines = pdb_util.pdb_idx1( pdbname )
        outfn = pdb_util.get_uniq_outpdbname( pdbname, "_idx1")
        buf = open( outfn, "w" )
        buf.write( outlines )
        buf.close()
コード例 #2
0
ファイル: slice_pdbs.py プロジェクト: raywangyr/scripts
def slice_pdb( arguments ):
    pdb, resnum_to_slice_dict, save_hetatm = arguments
    pdbline_dict = pdb_util.create_xyzDict_bychain( pdb, save_hetatm )[1]

    outfn_lines = ""
    for chain in pdb_util.chnids:
        if chain in pdbline_dict.keys():
            resnums = pdb_util.get_resnums_from_resnum_dict( resnum_to_slice_dict, pdbline_dict, chain )
            if not resnums: continue
            for resnum in resnums:
                try:
                    outfn_lines += pdbline_dict[ chain ][ resnum ]
                except KeyError:
                    if resnum <= max(pdbline_dict[chain]):
                        print "WARNING:", resnum, "is not present in the pdb"
                        continue
                    else:
                        print "NOT"
                        return False
            outfn_lines += "TER\n" # end of a chain
    outfn_lines += "END\n"

    assert outfn_lines, "nothing is going to be sliced, check your chain definition while selecting residues"

    outfn = pdb_util.get_uniq_outpdbname( pdb, "_sliced")
    buf = open( outfn, "w" )
    buf.write( outfn_lines )
    buf.close()
コード例 #3
0
ファイル: trim_pdbs.py プロジェクト: raywangyr/scripts
def trim_pdb( arguments ):
    pdb, resnum_to_trim_dict, save_hetatm = arguments
    pdbline_dict = pdb_util.create_xyzDict_bychain( pdb, save_hetatm )[1]

    trim_res_list = []
    for chain in sorted( pdbline_dict.keys() ):
        resnums = pdb_util.get_resnums_from_resnum_dict( resnum_to_trim_dict, pdbline_dict, chain )
        if not resnums: continue
        for resnum in resnums:
            try:
                del pdbline_dict[ chain ][ resnum ]
                trim_res_list.append( str(resnum)+chain )
            except KeyError:
                if resnum <= max(pdbline_dict[chain]):
                    print "WARNING:", resnum, "not in pdb"
                    continue
                else:
                    stderr.write("ERROR: residue %s not present in the file\n" %(str(resnum)+chain))
                    return False


    outfn_lines = "REMARK trim residues: %s\n" % (" ".join( trim_res_list ))
    #for chain in sorted(pdbline_dict.keys()):
    for chain in pdb_util.chnids:
        if chain in (pdbline_dict.keys()):
            for rsn in sorted(pdbline_dict[ chain ].keys()):
                outfn_lines += pdbline_dict[ chain ][ rsn ]
            outfn_lines += "TER\n"
    outfn_lines += "END\n"


    outfn = pdb_util.get_uniq_outpdbname(pdb, "_trim")
    '''
    pdb = basename(pdb)
    tag = "_trim"
    outfn = pdb[:-4] + tag

    while exists( outfn+".pdb" ):
        outfn += tag
        print outfn

    outfn = outfn+".pdb"
    '''

    buf = open( outfn, "w" )
    buf.write( outfn_lines )
    buf.close()