import sys # for argv!!! c = [] # Open file f = open( sys.argv[1] ) ## Read atoms from file for l in f: if l[:4] == "ATOM": atom = [float(l[30:38]),float(l[38:46]), float(l[46:54])] c.append(atom) else: #Go to next line continue n = len(c) m = 1000 # Some high value for i in range(n): for j in range(n): if i==j: continue d1 = ((c[i][0]-c[j][0])*(c[i][0]-c[j][0])) d2 = ((c[i][1]-c[j][1])*(c[i][1]-c[j][1])) d3 = ((c[i][2]-c[j][2])*(c[i][2]-c[j][2])) d = (d1+d2+d3) **0.5 if d < m: m=d if m > 0.74: print(f'{sys.argv[1]}: {m:5.3f}: Valid') #Print if molecule is valid else: print(f'{sys.argv[1]}: {m:5.3f}: Invalid') #Print if molecule is invalid #Close file f.close()