-
Notifications
You must be signed in to change notification settings - Fork 2
/
apply_pdbfixer.py
47 lines (39 loc) · 1.55 KB
/
apply_pdbfixer.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
44
45
46
47
from pdbfixer import PDBFixer
from openmm.app.pdbfile import PDBFile
from openmm import app
import openmm.app.data
import openmm.app.data.charmm36
from sys import stdout
import parmed as pmd
import numpy as np
import time
import os
def fix_pdb(pdb_id, fixed_pdb_out_path, pH=7):
print(pdb_id, fixed_pdb_out_path)
if len(pdb_id) != 4:
print("Creating PDBFixer...")
fixer = PDBFixer(pdb_id)
print("Finding missing residues...")
fixer.findMissingResidues()
chains = list(fixer.topology.chains())
keys = fixer.missingResidues.keys()
for key in list(keys):
chain = chains[key[0]]
if key[1] == 0 or key[1] == len(list(chain.residues())):
del fixer.missingResidues[key]
print("Finding nonstandard residues...")
fixer.findNonstandardResidues()
print("Replacing nonstandard residues...")
fixer.replaceNonstandardResidues()
print("Removing heterogens...")
# fixer.removeHeterogens(keepWater=False)
print("Finding missing atoms...")
fixer.findMissingAtoms()
print("Adding missing atoms...")
fixer.addMissingAtoms()
print("Adding missing hydrogens...")
fixer.addMissingHydrogens(pH)
print("Writing PDB file...")
fixed_pdb_out_path = os.path.join(fixed_pdb_out_path, "%s_fixed_pH_%s.pdb" % (os.path.basename(pdb_id).split('.')[0], pH))
PDBFile.writeFile(fixer.topology, fixer.positions, open(fixed_pdb_out_path, "w"), keepIds=True)
return fixed_pdb_out_path