要模仿PDB文件的正确间隙,可以使用以下代码示例:
def mimic_pdb_file(file_name):
pdb_lines = []
with open(file_name, 'r') as pdb_file:
for line in pdb_file:
# Check for ATOM or HETATM records
if line.startswith('ATOM') or line.startswith('HETATM'):
# Extract the atom coordinates and add correct spacing
atom_name = line[12:16].strip()
residue_name = line[17:20].strip()
chain_id = line[21]
residue_number = line[22:26].strip()
x_coord = line[30:38].strip()
y_coord = line[38:46].strip()
z_coord = line[46:54].strip()
occupancy = line[54:60].strip()
temperature_factor = line[60:66].strip()
element_symbol = line[76:78].strip()
# Reformat the line with correct spacing
new_line = f'ATOM {atom_name:<4}{residue_name:>3} {chain_id} {residue_number:>4} {x_coord:>8}{y_coord:>8}{z_coord:>8}{occupancy:>6}{temperature_factor:>6} {element_symbol:>2}'
pdb_lines.append(new_line)
else:
# Preserve other lines as they are
pdb_lines.append(line)
# Write the new PDB file
with open('new_pdb_file.pdb', 'w') as new_pdb_file:
new_pdb_file.write('\n'.join(pdb_lines))
# Example usage
mimic_pdb_file('original_pdb_file.pdb')
这段代码会读取原始PDB文件,并将ATOM和HETATM记录的行重新格式化,以确保正确的间隙。其他行将保持不变。最后,将新的PDB行写入一个新的PDB文件中(命名为new_pdb_file.pdb
)。
请注意,代码中的file_name
参数应该是原始PDB文件的文件名,你需要将其替换为实际的文件名。
下一篇:包括正确的内含标题