def find_blank(hklin): try: # first dump to temp. file with tempfile.NamedTemporaryFile(suffix=".hkl", dir=os.environ["CCP4_SCR"], delete=False) as fh: hklout = fh.name p = Pointless() p.set_hklin(hklin) _ = p.sum_mtz(hklout) if os.path.getsize(hklout) == 0: Debug.write("Pointless failed:") Debug.write("".join(p.get_all_output())) raise RuntimeError("Pointless failed: no output file written") isig = {} with open(hklout, "r") as fh: for record in fh: lst = record.split() if not lst: continue batch = int(lst[3]) i, sig = float(lst[4]), float(lst[5]) if not sig: continue if not batch in isig: isig[batch] = [] isig[batch].append(i / sig) finally: os.remove(hklout) # look at the mean and sd blank = [] good = [] for batch in sorted(isig): m, s = meansd(isig[batch]) if m < 1: blank.append(batch) else: good.append(batch) return blank, good
def find_blank(hklin): # first dump to temp. file hklout = tempfile.mktemp('.hkl', '', os.environ['CCP4_SCR']) p = Pointless() p.set_hklin(hklin) cell = p.sum_mtz(hklout) if not os.path.isfile(hklout): Debug.write('Pointless failed:') Debug.write(''.join(p.get_all_output())) raise RuntimeError('Pointless failed: %s does not exist' %hklout) isig = { } for record in open(hklout, 'r'): lst = record.split() if not lst: continue batch = int(lst[3]) i, sig = float(lst[4]), float(lst[5]) if not sig: continue if not batch in isig: isig[batch] = [] isig[batch].append(i / sig) # look at the mean and sd blank = [] good = [] for batch in sorted(isig): m, s = meansd(isig[batch]) if m < 1: blank.append(batch) else: good.append(batch) # finally delete temp file os.remove(hklout) return blank, good
def find_blank(hklin): # first dump to temp. file hklout = tempfile.mktemp('.hkl', '', os.environ['CCP4_SCR']) p = Pointless() p.set_hklin(hklin) cell = p.sum_mtz(hklout) if not os.path.isfile(hklout): Debug.write('Pointless failed:') Debug.write(''.join(p.get_all_output())) raise RuntimeError('Pointless failed: %s does not exist' %hklout) isig = { } for record in open(hklout, 'r'): lst = record.split() if not lst: continue batch = int(lst[3]) i, sig = float(lst[4]), float(lst[5]) if not sig: continue if not batch in isig: isig[batch] = [] isig[batch].append(i / sig) # look at the mean and sd blank = [] good = [] for batch in sorted(isig): m, s = meansd(isig[batch]) if m < 1: blank.append(batch) else: good.append(batch) # finally delete temp file os.remove(hklout) return blank, good