我正在使用Biopython对pdb文件执行各种操作。随后,我想向Biopython生成的Biopython结构对象中添加一些新原子。有没有一种好的/推荐的方法可以在Python中做到这一点。看来Biopython仅提供了写出pdb文件中现有元素的选项,而不提供创建新元素的选项。
CHEN123NBA 回答:将杂原子添加到pdb文件
您可以查看我正在开发的Python软件包 Biotite (https://www.biotite-python.org/)。 在以下示例代码中,下载,读取PDB结构,然后添加原子:
import biotite.database.rcsb as rcsb
import biotite.structure as struc
import biotite.structure.io as strucio
# Download lysozyme structure for example
file_name = rcsb.fetch("1aki","pdb",target_path=".")
# Read the file into Biotite's structure object (atom array)
atom_array = strucio.load_structure(file_name)
# Add an HETATM
atom = struc.Atom(
coord = [1.0,2.0,3.0],chain_id = "A",# The residue ID is the last ID in the file +1
res_id = atom_array.res_id[-1] + 1,res_name = "ABC",hetero = True,atom_name = "CA",element = "C"
)
atom_array += struc.array([atom])
# Save edited structure
strucio.save_structure("1aki_edited.pdb",atom_array)
1aki_edited.pdb
的最后几行:
...
HETATM 1075 O HOH A 203 12.580 21.214 5.006 1.00 0.000 O
HETATM 1076 O HOH A 204 19.687 23.750 -4.851 1.00 0.000 O
HETATM 1077 O HOH A 205 27.098 35.956 -12.358 1.00 0.000 O
HETATM 1078 O HOH A 206 37.255 9.634 10.002 1.00 0.000 O
HETATM 1079 O HOH A 207 43.755 23.843 8.038 1.00 0.000 O
HETATM 1080 CA ABC A 208 1.000 2.000 3.000 1.00 0.000 C
,
我已经使用RDKit成功地添加和编辑了PDB文件中的原子。下面我展示了一个小例子,说明如何向PDB文件中添加碳原子并创建新的.pdb文件
from rdkit import Chem
from rdkit.Chem import rdGeometry
prot = Chem.MolFromPDBFile("./3etr.pdb") #Read in the .pdb-file
protconf = prot.GetConformer() #create a conformer of the molecule
#create an editable mol-object
mw = Chem.RWMol(mol)
#create an editable conformer. This dictates the atoms coordinates and other attributes
mw_conf = mw.GetConformer()
#add a carbon atom to the editable mol. Returns the index of the new atom,which is the same as prot.GetNumAtoms() + 1
c_idx = mw.AddAtom(Chem.Atom(6))
#cartesian coordinates of the new atom. I think the Point3D object is not strictly necessary. but can be easier to handle in RDKit
coord = rdGeometry.Point3D(1.0,3.0)
#set the new coordinates
mw_conf.SetAtomPosition(c_idx,coord)
#save the edited PDB-file
pdb_out = Chem.MolToPDBFile(mw_conf,"_out.pdb")