Python脚本:PDB文件中原子和残基重新编号

Command:

python renumber_pdb.py -i protein.pdb -a -r > output.pdb

renumber_pdb.py

# Python 3 script to atoms and residues in a PDB file.

#

# run

# ./renumber.py -h

# for help

#

class Pdb(object):

""" Object that allows operations with protein files in PDB format. """

def __init__(self, file_cont = [], pdb_code = ""):

self.cont = []

self.atom = []

self.hetatm = []

self.fileloc = ""

if isinstance(file_cont, list):

self.cont = file_cont[:]

elif isinstance(file_cont, str):

try:

with open(file_cont, 'r') as pdb_file:

self.cont = [row.strip() for row in pdb_file.read().split('\n') if row.strip()]

except FileNotFoundError as err:

print(err)

if self.cont:

self.atom = [row for row in self.cont if row.startswith('ATOM')]

self.hetatm = [row for row in self.cont if row.startswith('HETATM')]

self.conect = [row for row in self.cont if row.startswith('CONECT')]

def renumber_atoms(self, start=1):

""" Renumbers atoms in a PDB file. """

out = list()

count = start

for row in self.cont:

if len(row) > 5:

if row.startswith(('ATOM', 'HETATM', 'TER', 'ANISOU')):

num = str(count)

while len(num) < 5:

num = ' ' + num

row = '%s%s%s' %(row[:6], num, row[11:])

count += 1

out.append(row)

return out

def renumber_residues(self, start=1, reset=False):

""" Renumbers residues in a PDB file. """

out = list()

count = start - 1

cur_res = ''

for row in self.cont:

if len(row) > 25:

if row.startswith(('ATOM', 'HETATM', 'TER', 'ANISOU')):

next_res = row[22:27].strip() # account for letters in res., e.g., '1A'

if next_res != cur_res:

count += 1

cur_res = next_res

num = str(count)

while len(num) < 3:

num = ' ' + num

new_row = '%s%s' %(row[:23], num)

while len(new_row) < 29:

new_row += ' '

xcoord = row[30:38].strip()

while len(xcoord) < 9:

xcoord = ' ' + xcoord

row = '%s%s%s' %(new_row, xcoord, row[38:])

if row.startswith('TER') and reset:

count = start - 1

out.append(row)

return out

if __name__ == '__main__':

import argparse

parser = argparse.ArgumentParser(

description='Renumber residues in a pdb file',

formatter_class=argparse.RawTextHelpFormatter

)

parser.add_argument('-i', '--input', help='Input PDB file')

parser.add_argument('-s', '--start', help='Number of the first residue in the renumbered file (default = 1)')

parser.add_argument('-a', '--atoms' ,action='store_true', help='Renumbers atoms')

parser.add_argument('-r', '--residues', action='store_true', help='Renumbers residues')

parser.add_argument('-c', '--chainreset', action='store_true', help='Resets the residue renumbering after encountering a new chain.')

parser.add_argument('-v', '--version', action='version', version='v. 1.0')

args = parser.parse_args()

if not args.input:

print('{0}\nPlease provide an input file.\n{0}'.format(50* '-'))

parser.print_help()

quit()

if not args.start:

start = 1

else:

start = int(args.start)

if not args.atoms and not args.residues:

print('{0}\nPlease provide at least the --atoms or --residues flag.\n{0}'.format(50* '-'))

parser.print_help()

quit()

pdb1 = Pdb(args.input)

if args.atoms:

pdb1.cont = pdb1.renumber_atoms(start=start)

if args.residues:

pdb1.cont = pdb1.renumber_residues(start=start, reset=args.chainreset)

for line in pdb1.cont:

print(line)

效果:

参考:

https://github.com/AspirinCode/protein-science/tree/master/scripts-and-tools/renumber_pdb

python重新编号功能_Python:PDB文件中原子和残基重新编号相关推荐

  1. Python:PDB文件中原子和残基重新编号

    Python脚本:PDB文件中原子和残基重新编号 Command: python renumber_pdb.py -i protein.pdb -a -r > output.pdb renumb ...

  2. python解释器的功能_python的解释器是什么?

    python解释器是解释python脚本执行的程序.编写python代码保存后,我们会得到一个以.py为扩展名的文本文件.要运行此文件,就需要python解释器去执行.py文件. python解释器种 ...

  3. python查看模块功能_Python模块Os系统功能

    Os模块简介系统功能 python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关. OS模块使用实例 执行dos命令 Python os.sys ...

  4. python实现什么功能_Python 实现WC功能

    项目要求 基本要求 -c 统计文件字符数 (实现) -w 统计文件词数 (实现) -l 统计文件行数(实现) 扩展功能 -s 递归处理目录下符合条件得文件(实现) -a 返回文件代码行 / 空行 / ...

  5. python实现登录功能_python实现用户登录功能模块

    python实现登录功能模块#!/usr/bin/env python while True: user = raw_input('Please input username:') if user = ...

  6. [转载] python字典查询功能_Python中的字典功能

    参考链接: Python中的字典dictionary方法 (cmp(), len(), items()-) python字典查询功能 Let's check out some important fu ...

  7. python实现计算器功能_python实现计算器功能

    本文实例为大家分享了python计算器的具体代码,供大家参考,具体内容如下 主要用到的工具是Python中的Tkinter库 比较简单 直接上图形界面和代码 引用Tkinter库 from tkint ...

  8. PDB文件中有些残基有多个构像,怎么用pymol图形化界面操作,一个残基只保留一个构像

    在PyMOL图形化界面中处理PDB文件的多构像残基,只保留一个构像可以通过以下步骤实现: 打开PDB文件: 启动PyMOL图形化界面. 在菜单栏中选择 "File" -> & ...

  9. python重新编号功能_python – 重新编号蛋白质结构文件中的残基(pdb)

    我也经常遇到这个问题.在放弃旧的perl脚本后,我已经为此尝试了一些 python.此解决方案假设您已安装Biopython,ProDy( http://www.csb.pitt.edu/ProDy/ ...

最新文章

  1. 后端接口都测试什么?要怎么测?
  2. 机器学习数据预处理之缺失值:插值法填充+多项式插值
  3. 批处理-文件比较生成
  4. 及cp含义_新媒体运营炒CP,既好用,又好玩(第327回)
  5. cmake中添加引用动态链接_C# 添加、编辑、删除PPT中的超链接
  6. “sudo: apt-get:找不到命令”的解决方法
  7. ViewPager VS ViewFilpper
  8. Android8.0 HIDL绑定式和直通式区别
  9. linux将分区从目录上卸载,Linux CentOS 硬盘分区、格式化、挂载与卸载
  10. MAX422与422转USB及485以及232接线方法
  11. wps中论文标题编号的设置
  12. 双击事件(dblclick)时,不触发单击事件(click)
  13. 外显子名词解释_生物信息学常用名词解释(一)
  14. EXCEL高级玩法之非常酷炫的动态数据分析报表
  15. ubuntu 14.04.1 smbd环境搭建
  16. 计算机毕业生怎么参加清华暑校,上完清华暑校后,怎么才能进清华?
  17. LGB、XGB、CBT参数
  18. Quartz相关配置
  19. 如何用计算机名查看共享打印机,如何查找网络共享打印机名称
  20. 孔子为何砸掉子路给工人送饭的锅?

热门文章

  1. OSChina 周一乱弹 —— 终于可以尝尝冷水泡面了
  2. P2026 求一次函数解析式【题解】
  3. EXECUTE IMMEDIATE和Using的用法
  4. 一种自适应的红色章印去除算法
  5. IO-Link工业总线型汽车撑杆装配线RFID写卡器CK-FR05-IO计算示例
  6. 【Pytorch-从一团乱麻到入门】:4、模型效果评估指标:ROC-AUC、PR-AUC及可能遇到的问题(1)
  7. 六种难以启齿的真实离职原因,应该这样说
  8. 高中计算机八字标语,八字高考口号霸气押韵
  9. 解决pycharm调试断点无效跳过断点运行问题
  10. MySQL load data 快速导入大批量数据