import argparse import sys import numpy as np from scipy.spatial.ckdtree import cKDTree HH_BOND_LENGTH = 0.74 def get_coordinates(filename: str) -> np.ndarray: coordinates = [] with open(filename) as f: for line in f: if line.startswith('ATOM'): coordinates.append([line[30:38], line[38:46], line[46:54]]) return np.array(coordinates) def get_minimum_distance(coordinates: np.ndarray) -> float: distances, _ = cKDTree(coordinates).query(coordinates, 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: coordinates = get_coordinates(args.file) except IOError: print(f'{args.file} cannot be opened') sys.exit(1) min_distance = get_minimum_distance(coordinates) print(f'{args.file}: {min_distance:5.3f}: ', end='') if min_distance > HH_BOND_LENGTH: print('Valid') else: print('Invalid') if __name__ == '__main__': main()