在下面的代码中,我使用DSSP库解析了pdb和计算的二级结构。在解析和存储值之后,我重新编号了残差编号,但我没有修改_pdb
和_dssp
个实例。重新编号后,它还会重新编号以前指定的_dssp
值,就像您在我评论的输出中看到的那样。我认为这是参考操作的效果。我想在重新编号后避免_dssp
值的更改,因为我没有明确修改_dssp
。如何避免这种类型的操作?
class PDBModify:
_pdb = None
_dssp = None
def parse(self, pdbid, pdbfile):
pdbparser = PDBParser(PERMISSIVE=1)
structure = pdbparser.get_structure(pdbid, pdbfile)
self._pdb = structure[0]
self._dssp = DSSP(structure[0], pdbfile)
def delete_n_dump(self, rsds, map_rsds):
current = self._pdb
for chain in current:
for residue in list(chain):
if not residue.id[1] in rsds:
chain.detach_child(residue.id)
else:
residue.id = (' ', map_rsds[residue.id[1]], ' ')
write_pdb = PDBIO()
write_pdb.set_structure(current)
write_pdb.save("./3chy_md.pdb")
if __name__=="__main__":
map_rsds = {15:200, 20: 201, 25:202, 26:203, 30:204, 34:205, 35:206, 36:207}
rsds = [15, 20, 25, 26, 30, 34, 35, 36]
pdbmodify = PDBModify()
pdbmodify.parse('3chy', './3chy.pdb') # parsing pdb and computing ss
print "before "
for item in pdbmodify._dssp: # initial call
print item
pdbmodify.delete_n_dump(rsds, map_rsds) # renumber the residue id
print "after "
for item in pdbmodify._dssp: # second call
print item
输出:
before
(<Residue ALA het= resseq=2 icode= >, '-', 65, 0.6132075471698113, 360.0, 127.6)
...
(<Residue SER het= resseq=15 icode= >, 'H', 73, 0.5615384615384615, -60.0, -33.4)
...
after
(<Residue ALA het= resseq=2 icode= >, '-', 65, 0.6132075471698113, 360.0, 127.6)
...
(<Residue SER het= resseq=200 icode= >, 'H', 73, 0.5615384615384615, -60.0, -33.4) # residue number is changed here why?
...
答案 0 :(得分:1)
您使用structure[0]
和self._pdb
指向同一self._dssp
个对象
self._pdb = structure[0]
self._dssp = DSSP(structure[0], pdbfile)
如果要取消关联它们,可以使用copy.copy
或copy.deepcopy
(取决于structure[0]
是否是一个简单的对象,如列表,只需要浅层副本或复杂的,就像列表一样。)
例如:
import copy
self._pdb = copy.deepcopy(structure[0])
self._dssp = DSSP(structure[0], pdbfile)