def prepareposfiles(Input, base): bp_folder = '%spositions_bp/' % Input['systempath'] os.mkdir(bp_folder) filelist = bf.lookupfiles(path=Input['folder_snapshot_data'], filechr='Wigner') for file_ in filelist: filename = '%s%s' % (Input['folder_snapshot_data'], file_) f = open(filename, 'r') xml.ReadHeader(f) if base is True: positions = xml.ReadCoordinates(f, Input['BASEparticles']) else: positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() bp_positions = positions + 0.5 * Input['BOXsize'] savename = '%s%s.dat' % (bp_folder, file_.strip('.xml')) saveasdatfile(Input, bp_positions, savename, base)
def saveinputasdat(Input): filename = '%sInputConfiguration.xml' % (Input['systempath']) f = open(filename, 'r') xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() bp_positions = positions + 0.5 * Input['BOXsize'] savename = '%sInputConfiguration.dat' % (Input['systempath']) saveasdatfile(Input, bp_positions, savename)
def calculate_deviations(Input): """Calculates the deviations from the average particle site""" filelist = bf.lookupfiles(path=Input['folder_snapshot_data'], filechr='Wigner') i = 0 for filename in filelist: if int(filename.strip('Wigner').strip('.xml')) > 10000000: filepath = '%s%s' % (Input['folder_snapshot_data'], filename) f = open(filepath, 'r') xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() if i == 0: all_positions = np.reshape(positions, (1, len(positions), 3)) else: positions = unfold_boundary_crossings(Input, all_positions, positions, i) positions = np.reshape(positions, (1, len(positions), 3)) all_positions = np.append(all_positions, positions, axis=0) i += 1 average_positions = np.average(all_positions, axis=0) deviations = np.std(np.sqrt( np.sum(np.square(all_positions - average_positions), axis=2)), axis=0) filepath = '%sWigner.0099000000.xml' % (Input['folder_snapshot_data']) f = open(filepath, 'r') xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() positions = unfold_boundary_crossings(Input, all_positions, positions, i) snapdeviations = np.sqrt( np.sum(np.square(average_positions - positions), axis=1)) posanddev = np.zeros((Input['ALLparticles'], 8)) posanddev[:, :3] = average_positions posanddev[:, 3] = deviations / Input['a'] posanddev[:, 4:7] = positions posanddev[:, 7] = snapdeviations / Input['a'] head = '%-18s\t%-18s\t%-18s\t%-18s\t%-18s\t%-18s\t%-18s\t%-18s' % ( 'x[sigma]', 'y[sigma]', 'z[sigma]', 'lindemann', 'snapx[sigma]', 'snapy[sigma]', 'snapz[sigma]', 'snapdev[sigma]') savename = '%s%s.deviations' % (Input['folder_processed_data'], Input['system']) np.savetxt(savename, posanddev, fmt='%18.11e', header=head, delimiter='\t') return positions, deviations
def calculate_potential_slice(Input, resolution, experimental=False): filepath = '%sWigner.0099000000.xml' % (Input['folder_snapshot_data']) if experimental is True: filepath = '%sWigner.0000000025.xml' % (Input['folder_snapshot_data']) f = open(filepath, 'r') xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['BASEparticles']) f.close() coordinates, potential = potential_slice(Input, positions, resolution) print coordinates save_potential_field(Input, coordinates, potential)
def bondparameter_distance(Input): filename = '%s%saveragebp.txt' % (Input['folder_processed_data'], Input['system']) data = np.genfromtxt(filename, delimiter='\t') filename = '%s%s' % (Input['folder_snapshot_data'], 'Wigner.0099000000.xml') f = open(filename, 'r') xml.ReadHeader(f) if base is True: positions = xml.ReadCoordinates(f, Input['BASEparticles']) f.close()
def Scatterplot3D(Input, data, images=None, show=False): """Plots particles in a 3D frame.""" if type(data) == str: filename = '%s%s' % (Input['systempath'], data) f = open(filename) xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() else: positions = data # CHOOSING LIMITS MinLim = np.zeros([3]) MaxLim = np.zeros([3]) Differences = np.zeros([3]) diff = 0 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(positions[:, 0], positions[:, 1], positions[:, 2], s=10) if images is not None: ax.plot(images[:, 0], images[:, 1], images[:, 2], color='r') for i in range(3): MinLim[i] = min(images[:, i]) - 0.1 MaxLim[i] = max(images[:, i]) + 0.1 Differences[i] = MaxLim[i] - MinLim[i] if Differences[i] > diff: diff = Differences[i] ax.set_xlim(MinLim[0], MinLim[0] + diff) ax.set_ylim(MinLim[1], MinLim[1] + diff) ax.set_zlim(MinLim[2], MinLim[2] + diff) else: for i in range(3): MinLim[i] = min(positions[:, i]) - 0.1 MaxLim[i] = max(positions[:, i]) + 0.1 Differences[i] = MaxLim[i] - MinLim[i] if Differences[i] > diff: diff = Differences[i] ax.set_xlim(MinLim[0], MinLim[0] + diff) ax.set_ylim(MinLim[1], MinLim[1] + diff) ax.set_zlim(MinLim[2], MinLim[2] + diff) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.axis('equal') if show is True: plt.show()
def prepareforvoro(Input): voronoi_folder = '%spositions_voronoi/' % Input['systempath'] os.mkdir(voronoi_folder) filelist = bf.lookupfiles(path=Input['folder_snapshot_data'], filechr='Wigner') for file_ in filelist: filename = '%s%s' % (Input['folder_snapshot_data'], file_) f = open(filename, 'r') xml.ReadHeader(f) Positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() voronoiformat = np.concatenate( (np.reshape(np.arange(1, Input['ALLparticles'] + 1), (-1, 1)), Positions), axis=1) savename = '%s%s' % (voronoi_folder, file_.strip('.xml')) format_ = ['%6d', '%.18e', '%.18e', '%.18e'] np.savetxt(savename, voronoiformat, fmt=format_, delimiter='\t')
def distancetointerstitials(Input): """Calculates the distance to the nearest interstitial for every particle""" # Does take into account the boundaries filename = '%sWigner.0099000000.xml' % (Input['folder_snapshot_data']) f = open(filename, 'r') xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['ALLparticles']) f.close() count = 0 list_ = [-1.0, 0.0, 1.0] N_inter = np.ones( (Input['BASEparticles'], Input['INTERparticles'])) * np.arange( 1, Input['INTERparticles'] + 1) for x in list_: for y in list_: for z in list_: transpose = np.array([x, y, z]) * Input['BOXsize'] transpose_array = np.ones([Input['BASEparticles'], 3 ]) * transpose base_transpose = positions[:Input[ 'BASEparticles']] + transpose_array distance_sub = cdist(base_transpose, positions[Input['BASEparticles']:], 'euclidean') if count == 0: distance_collection = distance_sub selection_collection = N_inter else: distance_collection = np.hstack((distances, distance_sub)) selection_collection = np.hstack((selection, N_inter)) distances = np.reshape(np.min(distance_collection, axis=1), (-1, 1)) selection_index = np.nonzero( np.equal(distance_collection, distances)) selection = np.reshape(selection_collection[selection_index], (-1, 1)) count += 1 data = np.hstack((selection, distances)) savename = '%s%snearestinterstitial.dist' % ( Input['folder_processed_data'], Input['system']) np.savetxt(savename, data, delimiter='\t')
def Sxy_operator(Input, cylR, sigma): filename = '%sWigner.0000000030.xml' % (Input['folder_snapshot_data']) f = open(filename, 'r') xml.ReadHeader(f) data = xml.ReadCoordinates(f, Input['BASEparticles']) f.close() #### tmp is a random frame (x,y,z) #### Get rotation matrix: #rotMat,fullMat = rotation_matrix(0.25*np.pi, [0, 1, 0], point=None) #data = np.dot(data, rotMat) # This is where the magic happens grid, S = Sxy(data, cylR, sigma) x = np.reshape(grid[:, :, 0], (-1, 1)) y = np.reshape(grid[:, :, 1], (-1, 1)) sofq = np.reshape(S, (-1, 1)) output = np.concatenate((x, y, sofq), axis=1) savename = '%s%ssofqsnapshot.txt' % (Input['folder_processed_data'], Input['system']) np.savetxt(savename, output, delimiter='\t')
def calculate_variation(Input, resolution): """Calculates the variation in the activation Energy""" filelist = bf.lookupfiles(path=Input['folder_snapshot_data'], filechr='Wigner') filenumbers = np.zeros((len(filelist))) i = 0 for filename in filelist: filepath = '%s%s' % (Input['folder_snapshot_data'], filename) f = open(filepath, 'r') xml.ReadHeader(f) positions = xml.ReadCoordinates(f, Input['BASEparticles']) f.close() coordinates, potential = potential_slice(Input, positions, resolution) if i == 0: all_potential = potential.reshape( (1, len(potential), len(potential))) else: all_potential = np.append(all_potential, potential.reshape( (1, len(potential), len(potential))), axis=0) filenumber = int(filename.strip('Wigner.').strip('.xml')) filenumbers[i] = filenumber if i == 0: save_potential_field(Input, coordinates, potential, 'testje') i += 1 sorted_filenumbers = np.argsort(filenumbers, axis=0) sorted_potentials = all_potential[sorted_filenumbers] average_potential = np.average(sorted_potentials, axis=0) variance_potential = np.var(sorted_potentials, axis=0) coordx, coordy = np.nonzero(np.less(variance_potential, 100)) print len(coordx) if len(coordx) > 0: time = np.sort(sorted_filenumbers) * Input['dt'] * Input['BASEtau'] #eplt.plotsliceheatmap(Input, coordinates, potential, positions, resolution, plotpart=False) eplt.plot_energy_track( time, sorted_potentials[:, coordx[0], coordy[0]] - np.min(sorted_potentials[:, coordx[0], coordy[0]]))
def SingleHist(Input, Filename, Bin_Edges, normalizedshellvolume): """Calculating a single histogram and normalizing over G. Keyword arguments: Filename -- Filename of the xml positions file Bin_Edges -- The r values for the edges of the histogram bins normalizedshellvolume -- The shell volumes normalized to the complete volume Output: singlenormhist -- Histogram intesities produced from a single xml file Positions -- A list with the positions of all particles """ F = open(Filename, 'r') TimeStep, Dimensions, NParticles, Lx, Ly, Lz = xml.ReadHeader(F) Positions = xml.ReadCoordinates(F, Input['BASEparticles']) F.close() Sx, Sy, Sz = SetSmallBox(Input, Lx, Ly, Lz) RefParticles = IdentifySmallBoxParticles(Positions, Sx, Sy, Sz) Distances = IPDCalculation(Input, RefParticles, Positions) Hist, Dump = np.histogram(Distances, bins=Bin_Edges) singlenormhist = NormalizedIPD(Distances, Hist, normalizedshellvolume) return singlenormhist