Save as a python file (.py) and run from the command line:
Code: Select all
"""
Reads in a CKF and gets the reflections to be omitted from Section 2.
Runs from the command line with the file stem, and outputs filestem.omit as a text file.
"""
import sys
try:
_file_stem = sys.argv[1]
with open('{}.ckf'.format(_file_stem), 'r') as handle:
_ckf_full = handle.read()
except IndexError as e:
print("You haven't provided a file stem to run this script on.")
sys.exit()
except FileNotFoundError as e:
print("The file '{}.ckf' cannot be found. Check the spelling and remember to omit '.ckf', you only need to provide the filestem.".format(_file_stem))
sys.exit()
_section2 = _ckf_full.split("Section")[2].split('\n')[6:-8]
_results_indices = []
for line in _section2:
# test for Ratio < -100
if line[63:64] == '?':
_results_indices.append(line[5:17])
# test for RatioW <-10 or > 10
elif abs(float(line.split()[-1])) >= 10.0:
_results_indices.append(line[5:17])
if len(_results_indices) == 0:
print('No reflections found to OMIT!')
else:
_output_string = 'OMIT ' + "\nOMIT ".join(_results_indices)
with open('{}.omit'.format(_file_stem), 'w') as handle:
handle.write(_output_string)
print("OMITted reflections written to {}.omit".format(_file_stem))