import sys import argparse import numpy as np from scipy.spatial.ckdtree import cKDTree HH_BOND_LENGTH = 0.74 def get_coordinates(filename: str) -> np.ndarray: coords = [] with open(filename) as f: for line in f: if line.startswith('ATOM'): atom = [float(line[30:38]), float(line[38:46]), float(line[46:54])] coords.append(atom) return np.array(coords) def get_minimum_distance(coords: np.ndarray) -> float: tree = cKDTree(coords) distances, _ = tree.query(coords, k=2) return np.min(distances[:, 1]) def main(): parser = argparse.ArgumentParser() parser.add_argument('file', type=str, help='PDB file to process') args = parser.parse_args() try: coords = get_coordinates(args.file) except IOError: print(f'{args.file} cannot be opened') sys.exit(1) min_distance = get_minimum_distance(coords) print(f'{args.file}: {min_distance:5.3f}: ', end='') if min_distance > HH_BOND_LENGTH: print('Valid') else: print('Invalid') if __name__ == '__main__': main()