-
Notifications
You must be signed in to change notification settings - Fork 0
/
renum_atoms.py
43 lines (33 loc) · 1.32 KB
/
renum_atoms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# coding: UTF-8
# Copyright (C) 2011, Carlos Ríos V. <[email protected]>
# This code is part of the Biopython distribution and governed by its
# license. Please see the LICENSE file that should have been included
# as part of this package.
from Bio import PDB
def renum_atoms(structure, output, model_id=0, start=1):
"""
renum_atoms will renumber the atoms starting with start...
"""
model = structure[model_id]
atoms = list(model.get_atoms())
for a in atoms:
a.set_serial_number(start)
start += 1
w = PDB.PDBIO()
w.set_structure(structure)
w.save(output, conserve_atoms_number=True)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('pdb_in',
help='PDB file to be renumbered')
parser.add_argument('pdb_out',
help='PDB file where the renumbered atoms will be stored.')
parser.add_argument('--start', dest='start',
type=int, default=1, help='Starting number for renumber.')
parser.add_argument('--model', dest='model',
type=int, default=0, help='Model (id) where the renumber will be applied.')
opts = parser.parse_args()
structure = PDB.PDBParser().get_structure(opts.pdb_in, opts.pdb_in)
renum_atoms(structure, opts.pdb_out, opts.model, opts.start)