def conf2yap(conf_fname, yap_filename): print("Yap file : ", yap_filename) positions, radii, meta = clff.read_conf_file(conf_fname) positions[:, 0] -= float(meta['lx'])/2 positions[:, 1] -= float(meta['ly'])/2 positions[:, 2] -= float(meta['lz'])/2 if 'np_fixed' in meta: # for conf with fixed particles split_line = len(positions) - int(meta['np_fixed']) pos_mobile, pos_fixed = np.split(positions, [split_line]) rad_mobile, rad_fixed = np.split(radii, [split_line]) yap_out = pyp.layer_switch(3) yap_out = pyp.add_color_switch(yap_out, 3) yap_out = np.row_stack((yap_out, particles_yaparray(pos_mobile, rad_mobile))) yap_out = pyp.add_layer_switch(yap_out, 4) yap_out = pyp.add_color_switch(yap_out, 4) yap_out = np.row_stack((yap_out, particles_yaparray(pos_fixed, rad_fixed))) else: yap_out = pyp.layer_switch(3) yap_out = pyp.add_color_switch(yap_out, 3) yap_out = np.row_stack((yap_out, particles_yaparray(positions, radii))) pyp.savetxt(yap_filename, yap_out)
def conf2yap(conf_fname, yap_filename): print("Yap file : ", yap_filename) positions, radii, meta = clff.read_conf_file(conf_fname) positions[:, 0] -= float(meta['lx']) / 2 positions[:, 1] -= float(meta['ly']) / 2 positions[:, 2] -= float(meta['lz']) / 2 if 'np_fixed' in meta: # for conf with fixed particles split_line = len(positions) - int(meta['np_fixed']) pos_mobile, pos_fixed = np.split(positions, [split_line]) rad_mobile, rad_fixed = np.split(radii, [split_line]) yap_out = pyp.layer_switch(3) yap_out = pyp.add_color_switch(yap_out, 3) yap_out = np.row_stack( (yap_out, particles_yaparray(pos_mobile, rad_mobile))) yap_out = pyp.add_layer_switch(yap_out, 4) yap_out = pyp.add_color_switch(yap_out, 4) yap_out = np.row_stack( (yap_out, particles_yaparray(pos_fixed, rad_fixed))) else: yap_out = pyp.layer_switch(3) yap_out = pyp.add_color_switch(yap_out, 3) yap_out = np.row_stack((yap_out, particles_yaparray(positions, radii))) pyp.savetxt(yap_filename, yap_out)
def interactions_bonds_yaparray(int_snapshot, par_snapshot, icols, pcols, f_factor=None, f_chain_thresh=None, layer_contacts=1, layer_noncontacts=2, color_contacts=1, color_noncontacts=2): if f_chain_thresh is None: f_chain_thresh = 0 r1r2 = lfu.get_interaction_end_points(int_snapshot, par_snapshot, icols, pcols) f, r1r2 = filter_interactions_crossing_PBC(int_snapshot, r1r2) # display a line joining the center of interacting particles # with a thickness proportional to the normal force normal_forces = get_normal_force(f, icols) # convert the force to a thickness. case-by-case. if f_factor is None: f_factor = 0.5/np.max(np.abs(normal_forces)) normal_forces = f_factor*np.abs(normal_forces) avg_force = np.mean(np.abs(normal_forces)) large_forces = normal_forces > f_chain_thresh * avg_force contact_state = f[:, du.matching_uniq(icols, 'contact state')[1]] # contacts keep = np.logical_and(contact_state > 0, large_forces) yap_out = pyp.layer_switch(layer_contacts) yap_out = pyp.add_color_switch(yap_out, color_contacts) contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep]) yap_out = np.row_stack((yap_out, contact_bonds)) # non contacts keep = np.logical_and(contact_state == 0, large_forces) yap_out = pyp.add_layer_switch(yap_out, layer_noncontacts) yap_out = pyp.add_color_switch(yap_out, color_noncontacts) non_contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep]) yap_out = np.row_stack((yap_out, non_contact_bonds)) return yap_out, f_factor
def interactions_bonds_yaparray(int_snapshot, par_snapshot, icols, pcols, f_factor=None, f_chain_thresh=None, layer_contacts=1, layer_noncontacts=2, color_contacts=1, color_noncontacts=2): if f_chain_thresh is None: f_chain_thresh = 0 r1r2 = lfu.get_interaction_end_points(int_snapshot, par_snapshot, icols, pcols) f, r1r2 = filter_interactions_crossing_PBC(int_snapshot, r1r2) # display a line joining the center of interacting particles # with a thickness proportional to the normal force normal_forces = get_normal_force(f, icols) # convert the force to a thickness. case-by-case. if f_factor is None: f_factor = 0.5 / np.max(np.abs(normal_forces)) normal_forces = f_factor * np.abs(normal_forces) avg_force = np.mean(np.abs(normal_forces)) large_forces = normal_forces > f_chain_thresh * avg_force contact_state = f[:, du.matching_uniq(icols, 'contact state')[1]] # contacts keep = np.logical_and(contact_state > 0, large_forces) yap_out = pyp.layer_switch(layer_contacts) yap_out = pyp.add_color_switch(yap_out, color_contacts) contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep]) yap_out = np.row_stack((yap_out, contact_bonds)) # non contacts keep = np.logical_and(contact_state == 0, large_forces) yap_out = pyp.add_layer_switch(yap_out, layer_noncontacts) yap_out = pyp.add_color_switch(yap_out, color_noncontacts) non_contact_bonds = pyp.sticks_yaparray(r1r2[keep], normal_forces[keep]) yap_out = np.row_stack((yap_out, non_contact_bonds)) return yap_out, f_factor
def snaps2yap(pos_fname, yap_file, f_factor=None, f_chain_thresh=None): forces_fname = pos_fname.replace("par_", "int_") par_f = clff.snapshot_file(pos_fname) int_f = clff.snapshot_file(forces_fname) pcols = par_f.column_def() icols = int_f.column_def() is2d = float(par_f.meta_data()['Ly']) == 0 i = 0 for frame_par, frame_int in zip(par_f, int_f): yap_out, f_factor =\ interactions_bonds_yaparray(frame_int[1], frame_par[1], icols, pcols, f_factor=f_factor, f_chain_thresh=f_chain_thresh, layer_contacts=1, layer_noncontacts=2, color_contacts=4, color_noncontacts=5) # display a circle for every particle yap_out = pyp.add_layer_switch(yap_out, 3) yap_out = pyp.add_color_switch(yap_out, 3) if 'position (x, y, z)' in pcols: pos_slice = pcols['position (x, y, z)'] else: pos_slice = slice(pcols['position x'], pcols['position z']+1) pos = frame_par[1][:, pos_slice].astype(np.float) rad = frame_par[1][:, pcols['radius']].astype(np.float) if is2d: angle = frame_par[1][:, pcols['angle']].astype(np.float) particles, crosses = particles_yaparray(pos, rad, angles=angle) yap_out = np.row_stack((yap_out, particles)) yap_out = pyp.add_color_switch(yap_out, 1) yap_out = np.row_stack((yap_out, crosses)) else: yap_out = np.row_stack((yap_out, particles_yaparray(pos, rad))) # display bounding box yap_out = pyp.add_layer_switch(yap_out, 4) yap_out = pyp.add_color_switch(yap_out, 0) lx2 = float(par_f.meta_data()['Lx'])/2 ly2 = float(par_f.meta_data()['Ly'])/2 lz2 = float(par_f.meta_data()['Lz'])/2 if not is2d: yap_out = pyp.add_cmd(yap_out, 'l', cuboid(lx2, ly2, lz2)) else: yap_out = pyp.add_cmd(yap_out, 'l', rectangle(lx2, lz2)) # display strain yap_out = pyp.add_layer_switch(yap_out, 5) yap_out = pyp.add_color_switch(yap_out, 1) # *cu*rvilinear or *cu*mulated strain depending on LF_DEM version strain = du.matching_uniq(frame_par[0], ["cu".encode('utf8'), "strain".encode('utf8')]) yap_out = np.row_stack((yap_out, ['t', str(10.), str(0.), str(10.), 'strain='+str(strain), '', ''])) # output np.savetxt(yap_file, yap_out, fmt="%s "*7) yap_file.write("\n".encode('utf-8')) i += 1 out_str = "\r frame " + str(i) +\ " - " + yap_filename + \ " [force factor " + str(f_factor) + "]" try: print(out_str, end="", flush=True) except TypeError: # to work with Python 2.7.* importing print_function without flush print(out_str, end="") print("")
def snaps2yap(pos_fname, yap_file, f_factor=None, f_chain_thresh=None): forces_fname = pos_fname.replace("par_", "int_") positions, forces, strains, shear_rates, meta_pos, meta_int =\ read_data(pos_fname, forces_fname) pcols = lf.convert_columndef_to_indices(meta_pos['column def']) icols = lf.convert_columndef_to_indices(meta_int['column def']) nb_of_frames = len(strains) is2d = meta_pos['Ly'] == 0 i = 0 for f, p, strain, rate in zip(forces, positions, strains, shear_rates): yap_out, f_factor =\ interactions_bonds_yaparray(f, p, icols, pcols, f_factor=f_factor, f_chain_thresh=f_chain_thresh, layer_contacts=1, layer_noncontacts=2, color_contacts=4, color_noncontacts=5) # display a circle for every particle yap_out = pyp.add_layer_switch(yap_out, 3) yap_out = pyp.add_color_switch(yap_out, 3) if 'position (x, y, z)' in pcols: pos_slice = pcols['position (x, y, z)'] else: pos_slice = slice(pcols['position x'], pcols['position z']+1) pos = p[:, pos_slice].astype(np.float) rad = p[:, pcols['radius']].astype(np.float) if is2d: angle = p[:, pcols['angle']].astype(np.float) particles, crosses = particles_yaparray(pos, rad, angles=angle) yap_out = np.row_stack((yap_out, particles)) yap_out = pyp.add_color_switch(yap_out, 1) yap_out = np.row_stack((yap_out, crosses)) else: yap_out = np.row_stack((yap_out, particles_yaparray(pos, rad))) # display bounding box yap_out = pyp.add_layer_switch(yap_out, 4) yap_out = pyp.add_color_switch(yap_out, 0) lx2 = meta_pos['Lx']/2 ly2 = meta_pos['Ly']/2 lz2 = meta_pos['Lz']/2 if not is2d: yap_out = pyp.add_cmd(yap_out, 'l', cuboid(lx2, ly2, lz2)) else: yap_out = pyp.add_cmd(yap_out, 'l', rectangle(lx2, lz2)) # display strain yap_out = pyp.add_layer_switch(yap_out, 5) yap_out = pyp.add_color_switch(yap_out, 1) yap_out = np.row_stack((yap_out, ['t', str(10.), str(0.), str(10.), 'strain='+str(strain), '', ''])) # output np.savetxt(yap_file, yap_out, fmt="%s "*7) yap_file.write("\n".encode('utf-8')) i += 1 out_str = "\r frame " + str(i) + "/"+str(nb_of_frames) +\ " - " + yap_filename + \ " [force factor " + str(f_factor) + "]" try: print(out_str, end="", flush=True) except TypeError: # to work with Python 2.7.* importing print_function without flush print(out_str, end="") print("")
def snaps2yap(pos_fname, yap_file, f_factor=None, f_chain_thresh=None): forces_fname = pos_fname.replace("par_", "int_") par_f = clff.snapshot_file(pos_fname) int_f = clff.snapshot_file(forces_fname) pcols = par_f.column_def() icols = int_f.column_def() is2d = float(par_f.meta_data()['Ly']) == 0 i = 0 for frame_par, frame_int in zip(par_f, int_f): yap_out, f_factor =\ interactions_bonds_yaparray(frame_int[1], frame_par[1], icols, pcols, f_factor=f_factor, f_chain_thresh=f_chain_thresh, layer_contacts=1, layer_noncontacts=2, color_contacts=4, color_noncontacts=5) # display a circle for every particle yap_out = pyp.add_layer_switch(yap_out, 3) yap_out = pyp.add_color_switch(yap_out, 3) if 'position (x, y, z)' in pcols: pos_slice = pcols['position (x, y, z)'] else: pos_slice = slice(pcols['position x'], pcols['position z'] + 1) pos = frame_par[1][:, pos_slice].astype(np.float) rad = frame_par[1][:, pcols['radius']].astype(np.float) if is2d: angle = frame_par[1][:, pcols['angle']].astype(np.float) particles, crosses = particles_yaparray(pos, rad, angles=angle) yap_out = np.row_stack((yap_out, particles)) yap_out = pyp.add_color_switch(yap_out, 1) yap_out = np.row_stack((yap_out, crosses)) else: yap_out = np.row_stack((yap_out, particles_yaparray(pos, rad))) # display bounding box yap_out = pyp.add_layer_switch(yap_out, 4) yap_out = pyp.add_color_switch(yap_out, 0) lx2 = float(par_f.meta_data()['Lx']) / 2 ly2 = float(par_f.meta_data()['Ly']) / 2 lz2 = float(par_f.meta_data()['Lz']) / 2 if not is2d: yap_out = pyp.add_cmd(yap_out, 'l', cuboid(lx2, ly2, lz2)) else: yap_out = pyp.add_cmd(yap_out, 'l', rectangle(lx2, lz2)) # display strain yap_out = pyp.add_layer_switch(yap_out, 5) yap_out = pyp.add_color_switch(yap_out, 1) # *cu*rvilinear or *cu*mulated strain depending on LF_DEM version strain = du.matching_uniq( frame_par[0], ["cu".encode('utf8'), "strain".encode('utf8')]) yap_out = np.row_stack((yap_out, [ 't', str(10.), str(0.), str(10.), 'strain=' + str(strain), '', '' ])) # output np.savetxt(yap_file, yap_out, fmt="%s " * 7) yap_file.write("\n".encode('utf-8')) i += 1 out_str = "\r frame " + str(i) +\ " - " + yap_filename + \ " [force factor " + str(f_factor) + "]" try: print(out_str, end="", flush=True) except TypeError: # to work with Python 2.7.* importing print_function without flush print(out_str, end="") print("")