def make_selected_output(components): """ Build SELECTED_OUTPUT data block """ headings = "-headings cb H O " for i in range(len(components)): headings += components[i] + "\t" selected_output = """ SELECTED_OUTPUT -reset false USER_PUNCH """ selected_output += headings + "\n" # # charge balance, H, and O # code = '10 w = TOT("water")\n' code += '20 PUNCH CHARGE_BALANCE, TOTMOLE("H"), TOTMOLE("O")\n' # # All other elements # lino = 30 for component in components: code += '%d PUNCH w*TOT(\"%s\")\n' % (lino, component) lino += 10 selected_output += code return selected_outputdef get_selected_output(phreeqc): """Return calculation result as dict. Header entries are the keys and the columns are the values as lists of numbers. """ output = phreeqc.get_selected_output_array() print output header = output[0] conc = {} for head in header: conc[head] = [] for row in output[1:]: for col, head in enumerate(header): conc[head].append(row[col]) return concdef simulate_with(string): phreeqc = phreeqc_mod.IPhreeqc() phreeqc.load_database(r"../../phreeqc/ror.dat") phreeqc.run_string(string) conc = get_selected_output(phreeqc) return {key: np.array(val) for (key, val) in conc.iteritems()}