def setup_method(self): pos0 = np.array([[5, 10], [10, 15]]) pos1 = np.array([[20, 25], [30, 35]]) sublattice0 = am.Sublattice(pos0, np.zeros((40, 40))) sublattice1 = am.Sublattice(pos1, np.zeros((40, 40))) self.atom_lattice = am.Atom_Lattice( np.zeros((40, 40)), sublattice_list=[sublattice0, sublattice1]) self.x_pos = np.concatenate((pos0[:, 0], pos1[:, 0])) self.y_pos = np.concatenate((pos0[:, 1], pos1[:, 1]))
def test_scaling(self): sublattice = am.Sublattice([ [10, 10], ], np.ones((20, 20)), pixel_size=0.2) atom_lattice = am.Atom_Lattice(np.ones((100, 100)), sublattice_list=[sublattice]) signal = atom_lattice.signal assert signal.axes_manager.signal_axes[0].scale == 0.2 assert signal.axes_manager.signal_axes[1].scale == 0.2
def test_atom_lattice_all_parameters(self): name = 'test_atom_lattice' atom_lattice = am.Atom_Lattice(self.sublattice.image, name=name, sublattice_list=[ self.sublattice, ]) assert atom_lattice.name == name assert (atom_lattice.image == self.sublattice.image).all() assert atom_lattice.sublattice_list == [ self.sublattice, ]
def image_refine_via_intensity_loop(atom_lattice, change_sublattice, calibration_separation, calibration_area, percent_to_nn, mask_radius, element_list, image_sampling, iterations, delta_image_filter, image_size_x_nm, image_size_y_nm, image_size_z_nm, simulation_filename, filename, intensity_type, intensity_refine_name='intensity_refine_', folder_name='refinement_of_intensity'): for sub in atom_lattice.sublattice_list: if sub.name == 'sub1': sub1 = sub elif sub.name == 'sub2': sub2 = sub elif sub.name == 'sub3': sub3 = sub else: pass if len(atom_lattice.image) == 1: # image_pixel_x = len(atom_lattice.image.data[0, :]) # image_pixel_y = len(atom_lattice.image.data[:, 0]) # atom_lattice_data = atom_lattice.image.data atom_lattice_signal = atom_lattice.image elif len(atom_lattice.image) > 1: # image_pixel_x = len(atom_lattice.image[0, :]) # image_pixel_y = len(atom_lattice.image[:, 0]) # atom_lattice_data = atom_lattice.image atom_lattice_signal = atom_lattice.signal ''' Image Intensity Loop ''' if len(calibration_area) != 2: raise ValueError('calibration_area_simulation must be two points') df_inten_refine = pd.DataFrame(columns=element_list) real_sampling_exp_angs = image_sampling * 10 if str(real_sampling_exp_angs)[-1] == '5': real_sampling_sim_angs = real_sampling_exp_angs + 0.000005 else: pass for suffix in range(1, iterations): loading_suffix = '_' + str(suffix) saving_suffix = '_' + str(suffix + 1) if '.xyz' in simulation_filename: pass else: simulation_filename = simulation_filename + '.xyz' file_exists = os.path.isfile(simulation_filename) if file_exists: pass else: raise OSError('XYZ file not found, stopping refinement') file = pr.Metadata(filenameAtoms=simulation_filename, E0=60e3) file.integrationAngleMin = 0.085 file.integrationAngleMax = 0.186 file.interpolationFactorX = file.interpolationFactorY = 16 file.realspacePixelSizeX = file.realspacePixelSizeY = 0.0654 # file.probeStepX = file.cellDimX/atom_lattice_data.shape[1] # file.probeStepY = file.cellDimY/atom_lattice_data.shape[0] file.probeStepX = round(real_sampling_sim_angs, 6) file.probeStepY = round(real_sampling_sim_angs, 6) file.numFP = 1 file.probeSemiangle = 0.030 file.alphaBeamMax = 0.032 # in rads file.detectorAngleStep = 0.001 file.scanWindowXMin = file.scanWindowYMin = 0.0 file.scanWindowYMax = file.scanWindowXMax = 1.0 file.algorithm = "prism" file.numThreads = 2 file.save3DOutput = False file.filenameOutput = intensity_refine_name + loading_suffix + ".mrc" file.go() simulation = hs.load('prism_2Doutput_' + file.filenameOutput) simulation.axes_manager[0].name = 'extra_dimension' simulation = simulation.sum('extra_dimension') simulation.axes_manager[0].scale = image_sampling simulation.axes_manager[1].scale = image_sampling calibrate_intensity_distance_with_sublattice_roi( image=simulation, cropping_area=calibration_area, separation=calibration_separation, filename=intensity_refine_name + "Simulation" + loading_suffix, percent_to_nn=percent_to_nn, mask_radius=mask_radius, scalebar_true=True) # simulation.plot() # Filter the image with Gaussian noise to get better match with # experiment simulation_new = compare_two_image_and_create_filtered_image( image_to_filter=simulation, reference_image=atom_lattice_signal, delta_image_filter=delta_image_filter, cropping_area=calibration_area, separation=calibration_separation, percent_to_nn=percent_to_nn, mask_radius=mask_radius, refine=False, filename=filename) simulation = simulation_new simulation.save(intensity_refine_name + 'Filt_Simulation' + loading_suffix + '.hspy') simulation.plot() plt.title('Filt_Simulation' + loading_suffix, fontsize=20) plt.gca().axes.get_xaxis().set_visible(False) plt.gca().axes.get_yaxis().set_visible(False) plt.tight_layout() plt.savefig(fname=intensity_refine_name + 'Filt_Simulation' + loading_suffix + '.png', transparent=True, frameon=False, bbox_inches='tight', pad_inches=None, dpi=300, labels=False) plt.close() ''' Need to add the intensity type to the image_difference_intensity algorithm! ''' counter_before_refinement = count_atoms_in_sublattice_list( sublattice_list=atom_lattice.sublattice_list, filename=intensity_refine_name + 'Elements' + loading_suffix) if suffix == 1: df_inten_refine = df_inten_refine.append( counter_before_refinement, ignore_index=True).fillna(0) else: pass ''' Sub1 ''' image_difference_intensity(sublattice=sub1, simulation_image=simulation, element_list=element_list, percent_to_nn=percent_to_nn, mask_radius=mask_radius, change_sublattice=change_sublattice, filename=filename) # sub1_info_refined = print_sublattice_elements(sub1) ''' Sub2 ''' image_difference_intensity(sublattice=sub2, simulation_image=simulation, element_list=element_list, percent_to_nn=percent_to_nn, mask_radius=mask_radius, change_sublattice=change_sublattice, filename=filename) # sub2_info_refined = print_sublattice_elements(sub2) ''' Sub3 ''' image_difference_intensity(sublattice=sub3, simulation_image=simulation, element_list=element_list, percent_to_nn=percent_to_nn, mask_radius=mask_radius, change_sublattice=change_sublattice, filename=filename) # sub3_info_refined = print_sublattice_elements(sub3) counter_after_refinement = count_atoms_in_sublattice_list( sublattice_list=atom_lattice.sublattice_list, filename=intensity_refine_name + 'Elements' + saving_suffix) df_inten_refine = df_inten_refine.append(counter_after_refinement, ignore_index=True).fillna(0) compare_sublattices = compare_count_atoms_in_sublattice_list( counter_list=[counter_before_refinement, counter_after_refinement]) if compare_sublattices is True: print('Finished Refinement! No more changes.') break if suffix > 4: if df_inten_refine.diff(periods=2)[-4:].all(axis=1).all() is False: # if statement steps above: # .diff(periods=2) gets the difference between each row, # and the row two above it [-4:] slices this new difference # df to get the final four rows # .all(axis=1) checks if # all row elements are zero or NaN and returns False # .all() check if all four of these results are False # Basically checking that the intensity refinement is # repeating every second iteration print('Finished Refinement! Repeating every second iteration.') break ''' Remake XYZ file for further refinement''' # loading_suffix is now saving_suffix create_dataframe_for_xyz( sublattice_list=atom_lattice.sublattice_list, element_list=element_list, x_distance=image_size_x_nm * 10, y_distance=image_size_y_nm * 10, z_distance=image_size_z_nm * 10, filename=filename + saving_suffix, header_comment='Something Something Something Dark Side') # dataframe_intensity = create_dataframe_for_xyz( # sublattice_list=atom_lattice.sublattice_list, # element_list=element_list, # x_distance=image_size_x_nm*10, # y_distance=image_size_y_nm*10, # z_distance=image_size_z_nm*10, # filename=intensity_refine_name + image_name + saving_suffix, # header_comment='Something Something Something Dark Side') # when ready: example_df_cif = create_dataframe_for_cif( sublattice_list=atom_lattice.sublattice_list, element_list=element_list) write_cif_from_dataframe(dataframe=example_df_cif, filename=intensity_refine_name + filename + saving_suffix, chemical_name_common='MoSx-1Sex', cell_length_a=image_size_x_nm * 10, cell_length_b=image_size_y_nm * 10, cell_length_c=image_size_z_nm * 10) df_inten_refine.to_pickle(intensity_refine_name + 'df_inten_refine.pkl') df_inten_refine.to_csv(intensity_refine_name + 'df_inten_refine.csv', sep=',', index=False) # https://python-graph-gallery.com/124-spaghetti-plot/ # https://stackoverflow.com/questions/8931268/using-colormaps- # to-set-color-of-line-in-matplotlib plt.figure() palette = plt.get_cmap('tab20') # plt.style.use('seaborn-darkgrid') # multiple line plot color_num = 0 for df_column in df_inten_refine: # print(df_column) color_num += 1 plt.plot(df_inten_refine.index, df_inten_refine[df_column], marker='', color=palette(color_num), linewidth=1, alpha=0.9, label=df_column) plt.xlim(0, len(df_inten_refine.index) + 1) plt.legend(loc=5, ncol=1, fontsize=10, fancybox=True, frameon=True, framealpha=1) plt.title("Refinement of Atoms via Intensity \nAll Elements", loc='left', fontsize=16, fontweight=0) plt.xlabel("Refinement Iteration", fontsize=16, fontweight=0) plt.ylabel("Count of Element", fontsize=16, fontweight=0) plt.tight_layout() plt.savefig(fname=intensity_refine_name + 'inten_refine_all.png', transparent=True, frameon=False, bbox_inches='tight', pad_inches=None, dpi=300, labels=False) plt.close() atom_of_interest = 'Mo_1' # Highlight Plot text_position = (len(df_inten_refine.index) + 0.2) - 1 plt.figure() # plt.style.use('seaborn-darkgrid') # multiple line plot for df_column in df_inten_refine: plt.plot(df_inten_refine.index, df_inten_refine[df_column], marker='', color='grey', linewidth=1, alpha=0.4) plt.plot(df_inten_refine.index, df_inten_refine[atom_of_interest], marker='', color='orange', linewidth=4, alpha=0.7) plt.xlim(0, len(df_inten_refine.index) + 1) # Let's annotate the plot num = 0 for i in df_inten_refine.values[len(df_inten_refine.index) - 2][1:]: num += 1 name = list(df_inten_refine)[num] if name != atom_of_interest: plt.text(text_position, i, name, horizontalalignment='left', size='small', color='grey') plt.text(text_position, df_inten_refine.Mo_1.tail(1), 'Moly', horizontalalignment='left', size='medium', color='orange') plt.title("Refinement of Atoms via Intensity", loc='left', fontsize=16, fontweight=0) plt.xlabel("Refinement Iteration", fontsize=16, fontweight=0) plt.ylabel("Count of Element", fontsize=16, fontweight=0) plt.tight_layout() plt.savefig(fname=intensity_refine_name + 'inten_refine.png', transparent=True, frameon=False, bbox_inches='tight', pad_inches=None, dpi=300, labels=False) plt.close() ''' ATOM LATTICE with simulation refinement ''' atom_lattice_int_ref_name = 'Atom_Lattice_' + \ intensity_type + '_refined' + saving_suffix atom_lattice_int_ref = am.Atom_Lattice( image=atom_lattice_signal, name=atom_lattice_int_ref_name, sublattice_list=atom_lattice.sublattice_list) atom_lattice_int_ref.save(filename=intensity_refine_name + atom_lattice_int_ref_name + ".hdf5", overwrite=True) atom_lattice_int_ref.save(filename=atom_lattice_int_ref_name + "_intensity.hdf5", overwrite=True) atom_lattice_int_ref.get_sublattice_atom_list_on_image(markersize=2).plot() plt.title(atom_lattice_int_ref_name, fontsize=20) plt.gca().axes.get_xaxis().set_visible(False) plt.gca().axes.get_yaxis().set_visible(False) plt.tight_layout() plt.savefig(fname=intensity_refine_name + atom_lattice_int_ref_name + '.png', transparent=True, frameon=False, bbox_inches='tight', pad_inches=None, dpi=300, labels=False) plt.close() create_new_folder('./' + folder_name + '/') intensity_refine_filenames = glob('*' + intensity_refine_name + '*') for intensity_refine_file in intensity_refine_filenames: # print(position_refine_file, position_refine_name + '/' + # position_refine_file) os.rename(intensity_refine_file, folder_name + '/' + intensity_refine_file)
sublattice1.construct_zone_axes(atom_plane_tolerance=1) sublattice1.plot() # Find sublattice2 using sublattice1 atom_plane_dir = sublattice1.zones_axis_average_distances[3] atom_positions2 = sublattice1.find_missing_atoms_from_zone_vector( atom_plane_dir, vector_fraction=0.5) sublattice2 = am.Sublattice(atom_positions2, image, color='blue') sublattice2.find_nearest_neighbors() sublattice2.refine_atom_positions_using_2d_gaussian(percent_to_nn=0.25) sublattice2.construct_zone_axes(atom_plane_tolerance=1) sublattice2.plot() # Make and save the Atom Lattice atom_lattice = am.Atom_Lattice(image, name='PTO-SRO-cropped-region', sublattice_list=[sublattice1, sublattice2]) atom_lattice.save(filename="Atom_Lattice_crop_new.hdf5") atom_lattice.plot() # Set up parameters for calculate_atom_plane_curvature zone_vector_index = 0 atom_planes = (2, 6) # chooses the starting and ending atom planes vmin, vmax = 1, 2 cmap = 'bwr' # see matplotlib and colorcet for more colormaps title = 'Curvature Map' filename = None # Set to a string if you want to save the map # Set the extra initial fitting parameters p0 = [14, 10, 24, 173] kwargs = {'p0': p0, 'maxfev': 1000}
overwrite=True) s = dummy_data.get_two_sublattice_signal() A_positions = am.get_atom_positions(s, separation=15) sublattice_A = am.Sublattice(A_positions, image=s.data, color='r') sublattice_A.find_nearest_neighbors() sublattice_A.refine_atom_positions_using_center_of_mass() sublattice_A.refine_atom_positions_using_2d_gaussian() sublattice_A.construct_zone_axes() save_sub_A_image(sublattice_A) plot_planes_figure(sublattice_A) zone_axis_001 = sublattice_A.zones_axis_average_distances[1] B_positions = sublattice_A.find_missing_atoms_from_zone_vector(zone_axis_001) image_without_A = remove_atoms_from_image_using_2d_gaussian( sublattice_A.image, sublattice_A) plot_image_wo_A(image_without_A) sublattice_B = am.Sublattice(B_positions, image_without_A, color='blue') sublattice_B.construct_zone_axes() sublattice_B.refine_atom_positions_using_center_of_mass() sublattice_B.refine_atom_positions_using_2d_gaussian() atom_lattice = am.Atom_Lattice(image=s.data, name='test', sublattice_list=[sublattice_A, sublattice_B]) plot_atom_lattice(atom_lattice)
def test_no_image(self): atom_lattice = am.Atom_Lattice() with pytest.raises(ValueError): atom_lattice.signal
def test_simple(self): atom_lattice = am.Atom_Lattice(np.ones((100, 100))) signal = atom_lattice.signal assert_array_equal(atom_lattice.image, signal.data)
plt.gcf().savefig(os.path.join(my_path, 'sublattice_B2.png')) # Finding Oxygen zone_axis_002 = sublattice_B2.zones_axis_average_distances[0] O_positions = sublattice_B2.find_missing_atoms_from_zone_vector(zone_axis_002) image_without_AB = remove_atoms_from_image_using_2d_gaussian( sublattice_B2.image, sublattice_B2) sublattice_O = am.Sublattice(O_positions, image_without_AB, color='g') sublattice_O.construct_zone_axes() sublattice_O.refine_atom_positions_using_center_of_mass() sublattice_O.refine_atom_positions_using_2d_gaussian() s = sublattice_O.get_atom_list_on_image() s.plot() s._plot.signal_plot.ax.set_xlim(70, 130) s._plot.signal_plot.ax.set_ylim(50, 100) s._plot.signal_plot.figure.savefig( os.path.join(my_path, 'oxygen_positions.png')) atom_lattice = am.Atom_Lattice( image=s_ABF.data, name='ABO3', sublattice_list=[sublattice_A, sublattice_B, sublattice_O]) atom_lattice.plot() plt.gcf().savefig(os.path.join(my_path, 'ABO3.png')) s = atom_lattice.get_sublattice_atom_list_on_image(image=s_ADF.data) s.plot() s._plot.signal_plot.figure.savefig(os.path.join(my_path, 'ABO3-ADF.png'))
def test_atom_lattice_wrong_input(self): with pytest.raises(ValueError): am.Atom_Lattice(self.sublattice.image, [ self.sublattice, ])
def test_get_sublattice_atom_list_on_image(self): atom_lattice = am.Atom_Lattice() atom_lattice.image = self.sublattice.image atom_lattice.sublattice_list.append(self.sublattice) atom_lattice.get_sublattice_atom_list_on_image()
def test_create_atom_lattice_object(self): atom_lattice = am.Atom_Lattice() atom_lattice.sublattice_list.append(self.sublattice)
def test_create_empty_atom_lattice_object(self): am.Atom_Lattice()
peaks_p = am.select_atoms_with_gui(s, peaks, verts) sublattice_p = am.Sublattice(peaks_p, s) s_p = sublattice_p.get_atom_list_on_image() s_p.plot() s_p._plot.signal_plot.figure.savefig(os.path.join(my_path, 'precipitate_sublattice.png')) ###### peaks_m = am.select_atoms_with_gui(s, peaks, verts, invert_selection=True) sublattice_m = am.Sublattice(peaks_m, s, color='blue') s_m = sublattice_m.get_atom_list_on_image() s_m.plot() s_m._plot.signal_plot.figure.savefig(os.path.join(my_path, 'matrix_sublattice.png')) ###### atom_lattice = am.Atom_Lattice(s, sublattice_list=[sublattice_p, sublattice_m]) s_a = atom_lattice.get_sublattice_atom_list_on_image() s_a.plot() s_a._plot.signal_plot.figure.savefig(os.path.join(my_path, 'atom_lattice.png')) ###### i_points, i_record, p_record = atom_lattice.integrate_column_intensity() i_record.plot() i_record._plot.signal_plot.figure.savefig(os.path.join(my_path, 'atom_lattice_integrate.png')) i_record_crop = i_record.isig[30:-30, 30:-30] i_record_crop.plot() i_record_crop._plot.signal_plot.figure.savefig(os.path.join(my_path, 'atom_lattice_integrate_crop.png')) ###### sublattice_p.construct_zone_axes()
overwrite=True) s = am.dummy_data.get_fantasite() A_positions = am.get_atom_positions(s, separation=12, pca=True) sublattice_A = am.Sublattice(A_positions, image=s.data, color='r', name='A') sublattice_A.find_nearest_neighbors() sublattice_A.refine_atom_positions_using_center_of_mass() sublattice_A.refine_atom_positions_using_2d_gaussian() sublattice_A.construct_zone_axes() direction_001 = sublattice_A.zones_axis_average_distances[1] B_positions = sublattice_A.find_missing_atoms_from_zone_vector(direction_001) image_without_A = remove_atoms_from_image_using_2d_gaussian( sublattice_A.image, sublattice_A) sublattice_B = am.Sublattice(B_positions, image_without_A, color='blue', name='B') sublattice_B.construct_zone_axes() sublattice_B.refine_atom_positions_using_center_of_mass() sublattice_B.refine_atom_positions_using_2d_gaussian() atom_lattice = am.Atom_Lattice(image=s.data, name='fantasite', sublattice_list=[sublattice_A, sublattice_B]) atom_lattice.save(os.path.join(my_path, "fantasite.hdf5"), overwrite=True) plot_fantasite(s) plot_atom_lattice(atom_lattice)
def image_refine_via_position_loop(image, sublattice_list, filename, xyz_filename, add_sublattice, pixel_threshold, num_peaks, image_size_x_nm, image_size_y_nm, image_size_z_nm, calibration_area, calibration_separation, element_list, element_list_new_sub, middle_intensity_list, limit_intensity_list, delta_image_filter=0.5, intensity_type='max', scalar_method='mode', remove_background_method=None, background_sublattice=None, num_points=3, percent_to_nn=0.4, mask_radius=None, iterations=10, max_sigma=10, E0=60e3, integrationAngleMin=0.085, integrationAngleMax=0.186, interpolationFactor=16, realspacePixelSize=0.0654, numFP=1, probeSemiangle=0.030, alphaBeamMax=0.032, scanWindowMin=0.0, scanWindowMax=1.0, algorithm="prism", numThreads=2): ''' Image Position Loop ''' df_position_refine = pd.DataFrame(columns=element_list) new_subs = [] create_dataframe_for_xyz(sublattice_list=sublattice_list, element_list=element_list, x_distance=image_size_x_nm * 10, y_distance=image_size_y_nm * 10, z_distance=image_size_z_nm * 10, filename=xyz_filename + '01', header_comment=filename) for suffix in range(1, iterations): loading_suffix = '_' + str(suffix).zfill(2) saving_suffix = '_' + str(suffix + 1).zfill(2) simulation_filename = xyz_filename + loading_suffix + '.XYZ' simulation = simulate_and_calibrate_with_prismatic( reference_image=image, xyz_filename=simulation_filename, calibration_area=calibration_area, calibration_separation=calibration_separation, filename=filename, percent_to_nn=percent_to_nn, mask_radius=mask_radius, E0=E0, integrationAngleMin=integrationAngleMin, integrationAngleMax=integrationAngleMax, interpolationFactor=interpolationFactor, realspacePixelSize=realspacePixelSize, numFP=numFP, probeSemiangle=probeSemiangle, alphaBeamMax=alphaBeamMax, scanWindowMin=scanWindowMin, scanWindowMax=scanWindowMax, algorithm=algorithm, numThreads=numThreads) # Filter the image with Gaussian noise to get better match with # experiment simulation_new = compare_two_image_and_create_filtered_image( image_to_filter=simulation, reference_image=image, filename=filename + loading_suffix, delta_image_filter=delta_image_filter, cropping_area=calibration_area, separation=calibration_separation, percent_to_nn=percent_to_nn, mask_radius=mask_radius, max_sigma=max_sigma, refine=False) simulation = simulation_new simulation.save('filt_sim_' + filename + loading_suffix + '.hspy') # simulation.plot() # plt.title('Filtered_Simulation' + filename + # loading_suffix, fontsize=20) # plt.gca().axes.get_xaxis().set_visible(False) # plt.gca().axes.get_yaxis().set_visible(False) # plt.tight_layout() # plt.savefig(fname='filt_sim_' + filename + loading_suffix + '.png', # transparent=True, frameon=False, bbox_inches='tight', # pad_inches=None, dpi=300, labels=False) # plt.close() counter_before_refinement = count_atoms_in_sublattice_list( sublattice_list=sublattice_list, filename=None) if suffix == 1: df_position_refine = df_position_refine.append( counter_before_refinement, ignore_index=True).fillna(0) else: pass sub_new = image_difference_position(sublattice_list=sublattice_list, simulation_image=simulation, pixel_threshold=pixel_threshold, filename=None, mask_radius=mask_radius, num_peaks=num_peaks, add_sublattice=add_sublattice, sublattice_name='sub_new' + loading_suffix) if isinstance(sub_new, sublattice_list[0]): new_subs.append(sub_new) sublattice_list += [new_subs[-1]] sub_new.get_atom_list_on_image(markersize=2).plot() plt.title(sub_new.name, fontsize=20) plt.gca().axes.get_xaxis().set_visible(False) plt.gca().axes.get_yaxis().set_visible(False) plt.tight_layout() plt.savefig(fname=sub_new.name + filename + '.png', transparent=True, frameon=False, bbox_inches='tight', pad_inches=None, dpi=300, labels=False) plt.close() sort_sublattice_intensities( sublattice=sub_new, intensity_type=intensity_type, middle_intensity_list=middle_intensity_list, limit_intensity_list=limit_intensity_list, element_list=element_list_new_sub, scalar_method=scalar_method, remove_background_method=remove_background_method, background_sublattice=background_sublattice, num_points=num_points, percent_to_nn=percent_to_nn, mask_radius=mask_radius) ''' need to make mask_radius for this too, for the new sublattice ''' assign_z_height(sublattice=sub_new, lattice_type='chalcogen', material='mos2_one_layer') # sub_new_info = print_sublattice_elements(sub_new) elif sub_new is None: print('All new sublattices have been added!') break counter_after_refinement = count_atoms_in_sublattice_list( sublattice_list=sublattice_list, filename=None) df_position_refine = df_position_refine.append( counter_after_refinement, ignore_index=True).fillna(0) ''' Remake XYZ file for further refinement''' # loading_suffix is now saving_suffix create_dataframe_for_xyz(sublattice_list=sublattice_list, element_list=element_list, x_distance=image_size_x_nm * 10, y_distance=image_size_y_nm * 10, z_distance=image_size_z_nm * 10, filename=xyz_filename + filename + saving_suffix, header_comment=filename) df_position_refine.to_csv(filename + '.csv', sep=',', index=False) '''Save Atom Lattice Object''' atom_lattice = am.Atom_Lattice(image=image.data, name='All Sublattices ' + filename, sublattice_list=sublattice_list) atom_lattice.save(filename="Atom_Lattice_" + filename + ".hdf5", overwrite=True) folder_name = filename + "_pos_ref_data" create_new_folder('./' + folder_name + '/') position_refine_filenames = glob('*' + filename + '*') for position_refine_file in position_refine_filenames: os.rename(position_refine_file, folder_name + '/' + position_refine_file)
sub2 = am.Sublattice(atom_position_list=atom_positions2, image=image, color='blue') sub2.find_nearest_neighbors() # sub2.plot() sub2.refine_atom_positions_using_2d_gaussian(percent_to_nn=0.4) # sub2.refine_atom_positions_using_center_of_mass(percent_to_nn=0.2) np.save('atom_positions2_refined.npy', [sub2.x_position, sub2.y_position]) ''' Create and save the Atom Lattice Object - This contains our two sublattices. ''' atom_lattice = am.Atom_Lattice(image=image.data, name='PTO-type structure', sublattice_list=[sub1, sub2]) atom_lattice.save(filename="Atom_Lattice.hdf5", overwrite=True) atom_lattice.plot() ''' Now we need to get the (x, y) and (u, v) data for the polarisation vectors. This requires the relevant sublattice's original "ideal" positions and refined "actual" positions. We can use Atomap or the Temul toolkit to do this easily with the save information from above. ''' # Atomap method (if this doesn't work, try the Temul method below)
######## Model Creation Example - simulated Cu NP ######## s = tml.example_data.load_example_Cu_nanoparticle() s.plot() atom_positions = am.get_atom_positions(s, separation=10, pca=True) # atom_positions = am.add_atoms_with_gui(image=s, atom_list=atom_positions) # np.save("Au_NP_atom_positions", atom_positions) # atom_positions = np.load("Au_NP_atom_positions.npy") sublattice = am.Sublattice(atom_position_list=atom_positions, image=s) sublattice.refine_atom_positions_using_center_of_mass() sublattice.plot() atom_lattice = am.Atom_Lattice(image=s, name="Cu_NP_sim", sublattice_list=[sublattice]) atom_lattice.save(filename="Cu_NP_sim_Atom_Lattice.hdf5", overwrite=True) sublattice.image /= sublattice.image.max() element_list = tml.auto_generate_sublattice_element_list( material_type='single_element_column', elements='Cu', max_number_atoms_z=7) middle_list, limit_list = tml.find_middle_and_edge_intensities( sublattice, element_list=element_list, standard_element=element_list[-1], scaling_exponent=1.5) elements_in_sublattice = tml.sort_sublattice_intensities(