def file2Convert(fileName, style, header=False, newFile=None): ''' notes: fileName : the name of a eos file in the same directory as the script style : see 'convert' function for possible options header : Set to True if there is a header, else keep as False newFile : if None, the original file will be overwritten with the EoS if a string, a new file with a name equal to the string will be created and filled with the EoS if True, a list of the strings corrosponding to the EoS will be returned. ''' lines = iop.flat_file_intable(fileName, header=header, entete=True) if (header): modLines = convertFunc(lines[0][1:], convert=style, round_Value=4) modLines.insert(0, lines[0][0]) else: modLines = convertFunc(lines[0], convert=style, round_Value=4) lines[0] = modLines newLines = px.table_trans(lines) outLines = map(lambda x: strl.array_to_str(x, spc=' ', endline=True), newLines) if (newFile == None): iop.flat_file_write(fileName, outLines) elif (isinstance(newFile, str)): iop.flat_file_write(newFile, outLines) else: return outLines return True
def cdce_min(cdce): cd, ce = cdce iop.flat_file_write("check_Eos.don",["Run..."],par=True,ptype='a+') iop.flat_file_write("check_Eos.don",["cd : "+str(cd),"ce : "+str(ce)],par=True,ptype='a+') input_lines = iop.flat_file_grab("sample_input.txt",scrub = True) parline_Dict, numline_Dict = vmd.mat_parline_parse(input_lines) parline_Dict = vmd.mat_parline_dict(auto_Load = parline_Dict, cde = [cd,ce]) parlines, numlines = vmd.mat_parline_dict_to_lines(parline_Dict,numline_Dict) iop.flat_file_replace("sample_input.txt",numlines,parlines) run_matter = "./xtest" subp.call(run_matter,shell=True) input_Eos = iop.flat_file_intable("matched_Eos.don") test_Eos = iop.flat_file_intable("test.txt") input_ea = input_Eos[1] test_ea = test_Eos[1] iop.flat_file_write("check_Eos.don",[str(ea) for ea in test_ea],par=True,ptype='a+') outval = eos_match(input_ea,test_ea) return outval
import subprocess import re from pmod import ioparse as iop from pmod import vmed as vf # not a standard pmod file; must be added for compatability with all vmed scripts cmd = "f90 $F90FLAGS -o xl -s -w cpot.f eff3nfn3lo1.f $LINK_FNL" subprocess.call(cmd, shell=True) # Comment out if already compiled subprocess.call("./xl", shell=True) # Comment out if already excecuted flines = iop.flat_file_grab('pot.d') val_table_12, val_table_13 = vf.gen_table_12_13(flines) iop.flat_file_write('fig_12_vals.txt', val_table_12, par=True) iop.flat_file_write('fig_13_vals.txt', val_table_13, par=True)
output_lines.append("\n") output_lines.append(" Basic Part Tot Final e V\n") output_lines.append("\n") for i in range(n): # Generate new input new_lines = list(lines_list) for j in ngroup[i]: val = j + '\n' new_lines.append(val) new_lines.append(demark) # Write the new output and run the program iop.flat_file_write(in_path, new_lines) subp.call('./xtest', shell=True) # iop.flat_file_grab('test1.txt', scrub=True) values = vf.partial_eos(file_name='test1.txt') for j in range(len(values)): values[j] = strl.str_to_list(values[j], filtre=True) try: v1 = values[-1][-1] v2 = values[-2][-1] v3 = values[-3][-1] v5 = values[-5][-1] v8 = values[-8][-1]
def tabulate_vmed_all(jv_list, group_by_vindex=True, momenta=None, print_lines=True, momenta_units='invfm', pot_units='invmev2', round_value=None, digits=3, espace=3, pyver='2.6'): ''' Inputs: jv_list : 'jv' formatted list group_by_vindex : (True) If True, output table automatically arranged by vmed number (lowest to highest) momenta : (None), if momenta is an array of integers, these momenta values used in jsl search print_lines : (True), If true, outlines are printed to a file, either way the list of strings is returned momenta_units : ('invfm'), options are 'invfm' or 'mev' corrosponding to Inverse Fermi and MeV^2 respectively pot_units : ('fm'), options are 'fm' or 'invmev2' corrosponding to Fermi and MeV respectively ''' #Initialize internal command-line print("") cml = cmd.PathParse('linux') if (cml == False): return False # Get contents of vincp (contains the eff. potentials in question) Must run 'vmed_all.py' first! if ('vincp' not in cml.varPath_Folders): print("Error: no instance of 'vincp' in current (path) directory") return False vincp_path = cml.joinNode(cml.varPath, 'vincp') vincp_content = cml.contentPath( vincp_path, objType='file', ) # group by v# in order, set 'group_by_vindex = False' to ignore this command if (group_by_vindex): vincp_content = map( lambda x: (vmed_index_finder.findall(x.split('.')[0])[0], x), vincp_content) vincp_content.sort(key=lambda x: int(x[0])) # Set momenta values if (momenta == None): plist = strl.array_nth_index(vf.pf_vals_20, 5) elif (isinstance(momenta, (list, tuple))): plist = momenta else: print("Error: input variable, 'momenta', not recognized") return False jsl_list = [] for jv in jv_list: j = str(jv[0]) t = str(jv[1]) for p in plist: jsl_list.append(vf.jsl_entry(j, p, p, t)) outlines = [] if (isinstance(momenta_units, str)): if (momenta_units.lower() == 'invfm'): plist = map(lambda x: str(round(float(x) / vf.hc, 2)), plist) pstring = '' for entry in plist: pstring = pstring + mops.space_format(entry, 12, adjust='right') pline = mops.space_format('p', 14, adjust='right') heading = pline + pstring + '\n' outlines.append(heading) outlines.append('\n') for entry in vincp_content: vval = entry[0] filename = entry[1] filepath = cml.joinNode(vincp_path, filename) filetext = iop.flat_file_grab(filepath) matching_values = vf.grab_jsl(filetext, jsl_list, round_form=1) if (isinstance(matching_values, (list, tuple)) and isinstance(pot_units, str)): if (pot_units.lower() == 'invmev2'): pass else: if (not isinstance(round_value, int)): matching_values = map(lambda x: str(float(x) * vf.vmhc), matching_values) else: if (round_value > 2): matching_values = map( lambda x: str( round(float(x) * vf.vmhc, round_value)), matching_values) matching_values = mops.sci_space_format(matching_values, digi=digits, spacing=espace, pyver=pyver) outline = strl.array_to_str(matching_values, spc=' ') out_heading = 'vmed ' + str(vval) out_heading = mops.space_format(out_heading, 9, adjust='right') outline = out_heading + " " + outline + '\n' outlines.append(outline) elif (matching_values == False or matching_values == None): print(' ' + "Error: parsing partial wave value failed\n") continue else: print(' ' + "Error: unknown error when parsing partial wave\n") continue if (print_lines): iop.flat_file_write('table_vincp', outlines) return outlines
else: cmv.cmd('rmdir vincp') cmv.cmd('mkdir vincp') exist = True for i, entry in enumerate(ngroup): # Add new V-vals generator new_lines = list(lines_list) for ventry in entry: print(ventry[0]) for vm in ventry: val = vm + '\n' new_lines.append(val) new_lines.append(demark) iop.flat_file_write(in_path, new_lines) subp.call("./xl", shell=True) success, value = cmv.cmd('mv pot.d pot' + str(numgroup[i]) + '.txt') if (success == False): print(spc + "Error: failure to rename 'pot' file for the " + strl.print_ordinal(i) + " run") success, value = cmv.cmd('mv ' + 'pot' + str(numgroup[i]) + '.txt' + ' vincp') if (success == False): print(spc + "Error: failure to move 'pot' file into 'vincp' for the " + strl.print_ordinal(i) + " run") tend = time.time() print('')
cmv.cmd('mkdir vincp') exist = False else: cmv.cmd('rmdir vincp') cmv.cmd('mkdir vincp') exist = True for i in range(len(ngroup)): # Add new V-vals generator new_lines = list(lines_list) for j in ngroup[i]: val = j + '\n' new_lines.append(val) new_lines.append(demark) iop.flat_file_write(in_path, new_lines) subp.call("./xl", shell=True) flines = iop.flat_file_grab('pot.d') table_12, table_13 = vf.gen_table_12_13(flines) twelve_name = f12n + str(numgroup[i]) + '.txt' thirteen_name = f13n + str(numgroup[i]) + '.txt' iop.flat_file_write(twelve_name, table_12, par=True) iop.flat_file_write(thirteen_name, table_13, par=True) cmv.cmd('mv ' + twelve_name + ';' + thirteen_name + ' vincp') plist = [0.1, 0.5, 1.0, 1.3]
def tabulate_pot_data(self, pot_data, equiv_momenta=True, header_line=False, errorCheck=None, **kwargs): kwargs = self.__update_funcNameHeader__("tabulate_pot_data", **kwargs) def get_new_file_name(file_name): if (not isinstance(file_name, str)): return False new_file_list = file_name.split('.') if (len(new_file_list) != 2): return False new_file_list[0] = new_file_list[0] + "_pwaves" new_file_line = new_file_list[0] + '.' + new_file_list[1] return new_file_line if (errorCheck == None): errorCheck = self.errorCheck if (errorCheck): if (self.__not_arr_print__(pot_data, **kwargs)): return False header_list = [] file_list = [] for file_data in pot_data: momenta = [] file_name, data_dict = file_data file_list.append(file_name) new_file_name = get_new_file_name(file_name) if (new_file_name == False): self.__err_print__( "could not generate a new file name for '" + str(file_name) + "'", **kwargs) continue data_list = [] for wave in sorted(list(data_dict)): wave_data = data_dict[wave] if (header_line): header_list.append(file_name + "_" + str(wave)) if (equiv_momenta): if (len(momenta) == 0): momenta = map(lambda lam: lam[0], wave_data) data_list.append(momenta) data_column = map(lambda lam: lam[1], wave_data) data_list.append(data_column) else: data_list.append(map(lambda lam: lam[0], wave_data)) data_list.append(map(lambda lam: lam[1], wave_data)) data_list_trans = px.table_trans(data_list, **kwargs) data_lines = px.matrix_to_str_array(data_list_trans, endline=True, **kwargs) if (self.__not_strarr_print__(data_lines, varID='data_lines', **kwargs)): continue if (header_line): header_line_str = strl.array_to_str(header_list, **kwargs) data_lines = [header_line_str] + data_lines iop.flat_file_write(new_file_name, data_lines, **kwargs) return True