PDBParser和MMCIFParser
PDBParser 解析器
使用p=PDBParser(参数)
来构建一个PDB解释器. 接收以下参数 (常用QUIET=True
) :
PERMISSIVE
- Evaluated as a Boolean. If false, exceptions in constructing the SMCRA data structure are fatal. If true (DEFAULT),the exceptions are caught, but some residues or atoms will be missing.get_header
- unused argument kept for historical compatibilty.structure_builder
- an optional user implemented StructureBuilder class.QUIET
- Evaluated as a Boolean. If true, warnings issued in constructing the SMCRA data will be suppressed. If false (DEFAULT), they will be shown. These warnings might be indicative of problems in the PDB file!
>>> from Bio.PDB.PDBParser import PDBParser
>>> p = PDBParser()
>>> s = p.get_structure('1d3z','1D3Z.pdb')
复制代码
解释器对象有以下方法和属性:
.get_structure(id,file)
: 读取结构, 返回Structure
对象. 可以用文件名或句柄.get_header()/.get_trailer()
: 获取PDB文件的文件头和文件尾. 文件头是一个字典. 文件尾是一个列表. 文件头和文件尾要在结构解释后才有信息..PERMISSIVE
,.QUIET
,.structure_builder
同PDBParser的参数..header
与.trailer
: 文件头和文件尾信息. 同相应get方法..line_counter
: 行数.
读取后获得的Structure对象有多项属性. 其中header
属性同PDBParser
获得. id
属性也是解析时指定.
Bio.PDB.parse_pdb_header(file)
也可以用来读取文件头. 包括head, deposition_date, release_date, structure_method, resolution, structure_reference, journal_reference, author and compound.
读取mmCIF文件
类似PDBParser, 参数支持structure_builder
与QUIET
. 解释器支持get_structure
方法, 有line_counter
属性. 要获取类似文件头信息, 要用MMCIF2Dict
方法. 获取的也是一个字典.
>>> from Bio.PDB.MMCIFParser import MMCIFParser
>>> parser = MMCIFParser()
>>> structure = parser.get_structure('1fat', '1fat.cif')
### 要解释mmCIF的额外信息, 需要MMCIF2Dict
>>> from Bio.PDB.MMCIF2Dict import MMCIF2Dict
>>> mmcif_dict = MMCIF2Dict('1fat.cif')
复制代码
PDBIO类对象保存文件
该类主要用于输出PDB文件. from Bio.PDB import PDBIO
来加载后, 直接构建一个io对象. 用set_structure
来指定结构后, 再用save
方法来保存.
如果想保存部分结构而非全部结构, 可以用Select
类来实现. Select支持四种方法来进行选择: accept_model(model)
, accept_chain(chain)
, accept_residue(residue)
, accept_atom(atom)
. 默认情况下, 每种方法的返回值都为1(即被保存), 可以继承该类自行构建子类来构建自己的选择器, 从而实现强大的功能. 当经常需要选择性保存时, 这种做法比较方便.
>>> from Bio.PDB import PDBIO
### 简单的读写
>>> io = PDBIO()
>>> io.set_structure(s)
>>> io.save('out.pdb')
#### 构建一个选择器来选择GLY.
>>> class GlySele