""" protonate.py: Wrapper method for the reduce program: protonate (i.e., add hydrogens) a pdb using reduce and save to an output file. Pablo Gainza - LPDI STI EPFL 2019 Released under an Apache License 2.0 """ from subprocess import Popen, PIPE from IPython.core.debugger import set_trace import os def protonate(in_pdb_file, out_pdb_file): # protonate (i.e., add hydrogens) a pdb using reduce and save to an output file. # in_pdb_file: file to protonate. # out_pdb_file: output file where to save the protonated pdb file. # Remove protons first, in case the structure is already protonated args = ["reduce", "-Trim", in_pdb_file] p2 = Popen(args, stdout=PIPE, stderr=PIPE) stdout, stderr = p2.communicate() outfile = open(out_pdb_file, "w") outfile.write(stdout.decode('utf-8').rstrip()) outfile.close() # Now add them again. args = ["reduce", "-HIS", out_pdb_file] p2 = Popen(args, stdout=PIPE, stderr=PIPE) stdout, stderr = p2.communicate() outfile = open(out_pdb_file, "w") outfile.write(stdout.decode('utf-8')) outfile.close()