Python:PDB文件中原子和残基重新编号
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 = startfor row in self.cont:if len(row) > 5:if row.startswith(('ATOM', 'HETATM', 'TER', 'ANISOU')):num = str(count)while len(num) < 5:num = ' ' + numrow = '%s%s%s' %(row[:6], num, row[11:])count += 1out.append(row)return outdef renumber_residues(self, start=1, reset=False):""" Renumbers residues in a PDB file. """out = list()count = start - 1cur_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 += 1cur_res = next_resnum = str(count)while len(num) < 3:num = ' ' + numnew_row = '%s%s' %(row[:23], num)while len(new_row) < 29:new_row += ' 'xcoord = row[30:38].strip()while len(xcoord) < 9:xcoord = ' ' + xcoordrow = '%s%s%s' %(new_row, xcoord, row[38:])if row.startswith('TER') and reset:count = start - 1out.append(row)return outif __name__ == '__main__':import argparseparser = 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 = 1else: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:PDB文件中原子和残基重新编号相关推荐
- python重新编号功能_Python:PDB文件中原子和残基重新编号
Python脚本:PDB文件中原子和残基重新编号 Command: python renumber_pdb.py -i protein.pdb -a -r > output.pdb renumb ...
- PDB文件中有些残基有多个构像,怎么用pymol图形化界面操作,一个残基只保留一个构像
在PyMOL图形化界面中处理PDB文件的多构像残基,只保留一个构像可以通过以下步骤实现: 打开PDB文件: 启动PyMOL图形化界面. 在菜单栏中选择 "File" -> & ...
- 在python平台上利用pymol来查找PDB文件中蛋白质的相互作用位点
这篇代码写的可能有点问题,大家如果有需要,去看另一篇吧.如果有啥不足,请批评指正. 在python平台上利用pymol来查找PDB文件中蛋白质的相互作用位点 关于蛋白质结合位点,查阅了很多篇文献,大多 ...
- Biopython+python 自动化分析蛋白质pdb文件,输出id,序列以及作用位点
项目包含两部分,自定义函数和主体 主体部分 import numpy as np from Bio.PDB import * from Bio import PDB import os import ...
- python pdb 安装_Python MMTK“没有与..pdb文件关联的程序,请安装合适的查看器”
我对编程和计算机世界还不熟悉.我想用MMTK研究生物分子模拟.在 我在Windows 7中运行,并且已经安装了此软件:python-2.5.4 numpy-1.6.2-win32-superpack- ...
- HTMD | 从PDB文件获取3D特征描述符
KDEEP是使用深度学习(CNN)进行亲和力预测的预测器. 关于这篇文章,我发现了一个新的名为HTMD(高通分子动力学)的python库. 我真的不擅长从头算或MD计算等计算领域. 因此,我无法评估该 ...
- python文件读取输出-Python 读写文件中数据
1 需求 在文件 h264.txt 中的数据如图1,读入该文件中的数据,然后将第1列的地址删除,然后将数据输出到h264_out.txt中: 图1 h264.txt 数据截图 图2 输出文件 h264 ...
- python写文件读文件-Python文件读写
在本章中将介绍Python 3中可用的所有基本文件读取I/O功能.有关更多功能,请参考标准Python文档. 打印到屏幕 产生输出的最简单方法是使用print语句,可以传递零个或多个由逗号分隔的表达式 ...
- matlab读取pdb文件,使用BioPython读取.pdb文件的整个目录
我最近的任务是在python中编写一个程序,找到距离.pdb(蛋白质数据库)蛋白质中每种金属2埃范围内的原子.这是我为它写的脚本. from Bio.PDB import * parser = PDB ...
最新文章
- Android Retrofit使用教程(三):Retrofit与RxJava初相逢
- 【Python算法】哈希存储、哈希表、散列表原理
- linux 内存管理 Transparent HugePages 透明大页 简介
- Nutanix 将社区版代码带入云中
- 阿里云:面向5G时代的物联网无线连接服务
- OpenCV学习笔记三-Mat数据结构
- spring-boot--整合thymeleaf模板
- 【资源下载】512页IBM沃森研究员Charu最新2018著作《神经网络与深度学习》(附下载链接)
- mysql数据库插入数据错误Error Code: 1118 - Row size too large ( 8126)
- 免费后台挂尔雅浏览器下载及使用教程
- 微波炉控制器的设计(EDA课程设计)
- 计算机学报发表论文格式,计算机学报论文格式(24页)-原创力文档
- CH340串口驱动的官网下载链接地址(包含各大操作系统平台)
- Halcon实战之车牌识别
- 问题——TortoiseGit Git clone 的时候密码写错
- 装机不求人,10 分钟完成电脑配置挑选
- 【解决方案】Microsoft Edge 浏览器 出现“无法访问该页面”问题
- Docker-核心篇(1)-CentOS7安装Docker社区版
- Win7系统网络连接图标显示红叉但可以正常上网怎么办
- Highcharts去掉右下角URL水印