用pytho写的分割pdb文件一个脚本

2021-11-02 14:40:26 浏览数 (2)

代码语言:javascript复制
import glob
def file_list():
    files=[]
    for file in glob.glob("*.pdb"):
        files.append(file)
    files=sorted(files,key=lambda x: int(x[:-4]))
    return files
def split_pdb(pdb_file,files_list,label1,label2):
    f_pdb=open(pdb_file,"r")
    lines=f_pdb.readlines()
    i=0;
    for line in lines:
        if i==12:
            break
        f_store=open(files_list[i],"a ")
        if label1 in line.strip():
            i =1
            f_store.write(line)
            print "I am here"
            f_store.close()
            continue
        elif line.strip()==label2:
            continue
        else:
            f_store.write(line)
if __name__=="__main__":
    file_lists=file_list()
    split_pdb("hex6-dna.pdb1",file_lists,"TER","ENDMDL")
pdb

0 人点赞