#!/usr/bin/env python
from __future__ import division
from Bio import PDB
import argparse
import sys

parser = argparse.ArgumentParser()
parser.add_argument("-c", type=float, default=4.5, help="Interaction cutoff (Angstrom)")
args, unk = parser.parse_known_args()

CUTOFF = args.c
PDB_IN = unk[0]

p = PDB.PDBParser(QUIET=True)
structure = p.get_structure('whatever', PDB_IN)
for resi in structure.get_residues():
    if resi.id[0] == 'W':
        for atom in resi:
            if atom.id == 'O':
                sys.stdout.write('> %s\n' % (atom.get_parent().id[1]))
                for model in structure:
                    for chain in model:
                        for residue in chain:
                            if any([(atom-a <= CUTOFF) for a in residue]):
                                sys.stdout.write('%s\t%s\t%s\n' % (chain.id, residue.id[1], residue.get_resname()))
