def plot_angle(cut, traj, target_configuration=None, save_file=None, show=True, index=-1, **kwargs): fig = plt.figure() ax = fig.add_subplot(111) stru_l = {} # If the PDF document created with atomic config, use that as target if target_configuration is not None: stru_l['Target'] = target_configuration stru_l['Start'] = traj[0] stru_l['Finish'] = traj[index] for atoms in stru_l.values(): if len(set(atoms.get_tags())) == 1: tag_surface_atoms(atoms) symbols = set(stru_l['Start'].get_chemical_symbols()) tags = {'Core': (0, '+'), 'Surface': (1, '*')} for tag in tags.keys(): tagged_atoms = stru_l['Start'][ [atom.index for atom in stru_l['Start'] if atom.tag == tags[tag][0]]] if len(tagged_atoms) == 0: del tags[tag] if len(tags) == 1: tags = {'': (1, '*')} # need to change this bins = np.linspace(0, 180, 100) # Bin the data for n, key in enumerate(stru_l.keys()): for symbol in symbols: for tag in tags.keys(): a, b = np.histogram( get_angle_list(stru_l[key], cut, element=symbol, tag=tags[tag][0]), bins=bins) if False: pass # if np.alltrue(stru_l[key].pbc): # crystal # for y, x in zip(a, b[:-1]): # plt.axvline(x=x, ymax=y, color='grey', linestyle='--') else: total = np.sum(a) ax.plot(b[:-1], a, label='{0} {1} {2}, {3}'.format(key, symbol, tag, total), marker=tags[tag][1], color=colors[n]) ax.set_xlabel('Bond angle in Degrees') ax.set_xlim(0, 180) ax.set_ylabel('Angle Counts') ax.legend(loc='best', prop={'size': 12}) if save_file is not None: plt.savefig(save_file + '_angle.eps', bbox_inches='tight', transparent='True') plt.savefig(save_file + '_angle.png', bbox_inches='tight', transparent='True') if show is True: plt.show()
def plot_bonds(sim, cut, save_file=None, show=True, index=-1): atomic_config, = find_atomic_config_document(_id=sim.atoms.id) traj = atomic_config.file_payload stru_l = {} # If the PDF document created with atomic config, use that as target cl = sim.pes.calc_list for calc in cl: if calc.calculator == 'PDF': break # If we used a theoretical target structure, get it and name it # if calc.ase_config_id is not None: # target_atoms, = find_atomic_config_document(_id=calc.ase_config_id) # stru_l['Target'] = target_atoms.file_payload stru_l['Start'] = traj[0] stru_l['Finish'] = traj[index] for atoms in stru_l.values(): tag_surface_atoms(atoms, cut) symbols = set(stru_l['Start'].get_chemical_symbols()) tags = {'Core': (0, '+'), 'Surface': (1, '*')} for tag in tags.keys(): tagged_atoms = stru_l['Start'][[ atom.index for atom in stru_l['Start'] if atom.tag == tags[tag][0] ]] if len(tagged_atoms) == 0: del tags[tag] linestyles = ['-', '--', ':'] fig = plt.figure() ax = fig.add_subplot(111) for n, key in enumerate(stru_l.keys()): for k, symbol in enumerate(symbols): for tag in tags.keys(): bonds = get_bond_dist_list(stru_l[key], cut, element=symbol, tag=tags[tag][0]) a, b = np.histogram(bonds, bins=10) plt.plot(b[:-1], a, linestyles[k], label=key + ' ' + symbol + ' ' + tag, marker=tags[tag][1], color=colors[n]) ax.set_xlabel('Bond distance in angstrom') ax.set_ylabel('Bond Counts') plt.legend(loc='best', prop={'size': 12}) if save_file is not None: plt.savefig(save_file + '_angle.eps', bbox_inches='tight', transparent='True') plt.savefig(save_file + '_angle.png', bbox_inches='tight', transparent='True') if show is True: plt.show()
def plot_bonds(sim, cut, save_file=None, show=True, index=-1): atomic_config, = find_atomic_config_document(_id=sim.atoms.id) traj = atomic_config.file_payload stru_l = {} # If the PDF document created with atomic config, use that as target cl = sim.pes.calc_list for calc in cl: if calc.calculator == 'PDF': break # If we used a theoretical target structure, get it and name it # if calc.ase_config_id is not None: # target_atoms, = find_atomic_config_document(_id=calc.ase_config_id) # stru_l['Target'] = target_atoms.file_payload stru_l['Start'] = traj[0] stru_l['Finish'] = traj[index] for atoms in stru_l.values(): tag_surface_atoms(atoms, cut) symbols = set(stru_l['Start'].get_chemical_symbols()) tags = {'Core': (0, '+'), 'Surface': (1, '*')} for tag in tags.keys(): tagged_atoms = stru_l['Start'][ [atom.index for atom in stru_l['Start'] if atom.tag == tags[tag][0]]] if len(tagged_atoms) == 0: del tags[tag] linestyles = ['-', '--', ':'] fig = plt.figure() ax = fig.add_subplot(111) for n, key in enumerate(stru_l.keys()): for k, symbol in enumerate(symbols): for tag in tags.keys(): bonds = get_bond_dist_list( stru_l[key], cut, element=symbol, tag=tags[tag][0]) a, b = np.histogram(bonds, bins=10) plt.plot(b[:-1], a, linestyles[k], label=key + ' ' + symbol + ' ' + tag, marker=tags[tag][1], color=colors[n]) ax.set_xlabel('Bond distance in angstrom') ax.set_ylabel('Bond Counts') plt.legend(loc='best', prop={'size': 12}) if save_file is not None: plt.savefig(save_file + '_angle.eps', bbox_inches='tight', transparent='True') plt.savefig(save_file + '_angle.png', bbox_inches='tight', transparent='True') if show is True: plt.show()
def plot_average_coordination(cut, traj, target_configuration=None, save_file=None, show=True, index=-1, **kwargs): stru_l = {} # If the PDF document created with atomic config, use that as target if target_configuration is not None: stru_l['Target'] = target_configuration stru_l['Start'] = traj[0] stru_l['Equilibrium'] = traj[index] for atoms in stru_l.values(): tag_surface_atoms(atoms) symbols = set(stru_l.itervalues().next().get_chemical_symbols()) tags = {'Core': (0, '+'), 'Surface': (1, '*')} for tag in tags.keys(): tagged_atoms = stru_l.itervalues().next()[ [atom.index for atom in stru_l.itervalues().next() if atom.tag == tags[tag][0]]] if len(tagged_atoms) == 0: del tags[tag] if len(tags) == 1: tags = {'': (1, '*')} b_min = None b_max = None for key in stru_l.keys(): total_coordination = get_coord_list(stru_l[key], cut) l_min = min(total_coordination) l_max = max(total_coordination) if b_min is None or b_min > l_min: b_min = l_min if b_max is None or b_max < l_max: b_max = l_max if b_min == b_max: bins = np.asarray([b_min, b_max]) else: bins = np.arange(b_min, b_max + 2) width = 3. / 4 / len(stru_l) offset = .3 * 3 / len(stru_l) patterns = ('x', '\\', 'o', '.', '\\', '*') fig = plt.figure() ax = fig.add_subplot(111) for n, key in enumerate(stru_l.keys()): bottoms = np.zeros(bins.shape) j = 0 for symbol in symbols: for tag in tags.keys(): hatch = patterns[j] coord = get_coord_list(stru_l[key], cut, element=symbol, tag=tags[tag][0]) a, b = np.histogram(coord, bins=bins) total = np.sum(a) ax.bar(b[:-1] + n * offset, a, width, bottom=bottoms[:-1], color=colors[n], label='{0} {1} {2}, {3}'.format(key, symbol, tag, total), hatch=hatch) j += 1 bottoms[:-1] += a ax.set_xlabel('Coordination Number') ax.set_xticks(bins[:-1] + 1 / 2.) ax.set_xticklabels(bins[:-1]) ax.set_ylabel('Atomic Counts') ax2 = plt.twinx() ax2.set_ylim(ax.get_ylim()) ax.legend(loc='best', prop={'size': 12}) if save_file is not None: plt.savefig(save_file + '_coord.eps', bbox_inches='tight', transparent='True') plt.savefig(save_file + '_coord.png', bbox_inches='tight', transparent='True') if show is True: plt.show() return
def plot_average_coordination(cut, traj, target_configuration=None, save_file=None, show=True, index=-1, **kwargs): stru_l = {} # If the PDF document created with atomic config, use that as target if target_configuration is not None: stru_l['Target'] = target_configuration stru_l['Start'] = traj[0] stru_l['Equilibrium'] = traj[index] for atoms in stru_l.values(): tag_surface_atoms(atoms) symbols = set(stru_l.itervalues().next().get_chemical_symbols()) tags = {'Core': (0, '+'), 'Surface': (1, '*')} for tag in tags.keys(): tagged_atoms = stru_l.itervalues().next()[[ atom.index for atom in stru_l.itervalues().next() if atom.tag == tags[tag][0] ]] if len(tagged_atoms) == 0: del tags[tag] if len(tags) == 1: tags = {'': (1, '*')} b_min = None b_max = None for key in stru_l.keys(): total_coordination = get_coord_list(stru_l[key], cut) l_min = min(total_coordination) l_max = max(total_coordination) if b_min is None or b_min > l_min: b_min = l_min if b_max is None or b_max < l_max: b_max = l_max if b_min == b_max: bins = np.asarray([b_min, b_max]) else: bins = np.arange(b_min, b_max + 2) width = 3. / 4 / len(stru_l) offset = .3 * 3 / len(stru_l) patterns = ('x', '\\', 'o', '.', '\\', '*') fig = plt.figure() ax = fig.add_subplot(111) for n, key in enumerate(stru_l.keys()): bottoms = np.zeros(bins.shape) j = 0 for symbol in symbols: for tag in tags.keys(): hatch = patterns[j] coord = get_coord_list(stru_l[key], cut, element=symbol, tag=tags[tag][0]) a, b = np.histogram(coord, bins=bins) total = np.sum(a) ax.bar(b[:-1] + n * offset, a, width, bottom=bottoms[:-1], color=colors[n], label='{0} {1} {2}, {3}'.format(key, symbol, tag, total), hatch=hatch) j += 1 bottoms[:-1] += a ax.set_xlabel('Coordination Number') ax.set_xticks(bins[:-1] + 1 / 2.) ax.set_xticklabels(bins[:-1]) ax.set_ylabel('Atomic Counts') ax2 = plt.twinx() ax2.set_ylim(ax.get_ylim()) ax.legend(loc='best', prop={'size': 12}) if save_file is not None: plt.savefig(save_file + '_coord.eps', bbox_inches='tight', transparent='True') plt.savefig(save_file + '_coord.png', bbox_inches='tight', transparent='True') if show is True: plt.show() return
def plot_angle(cut, traj, target_configuration=None, save_file=None, show=True, index=-1, **kwargs): fig = plt.figure() ax = fig.add_subplot(111) stru_l = {} # If the PDF document created with atomic config, use that as target if target_configuration is not None: stru_l['Target'] = target_configuration stru_l['Start'] = traj[0] stru_l['Finish'] = traj[index] for atoms in stru_l.values(): if len(set(atoms.get_tags())) == 1: tag_surface_atoms(atoms) symbols = set(stru_l['Start'].get_chemical_symbols()) tags = {'Core': (0, '+'), 'Surface': (1, '*')} for tag in tags.keys(): tagged_atoms = stru_l['Start'][[ atom.index for atom in stru_l['Start'] if atom.tag == tags[tag][0] ]] if len(tagged_atoms) == 0: del tags[tag] if len(tags) == 1: tags = {'': (1, '*')} # need to change this bins = np.linspace(0, 180, 100) # Bin the data for n, key in enumerate(stru_l.keys()): for symbol in symbols: for tag in tags.keys(): a, b = np.histogram(get_angle_list(stru_l[key], cut, element=symbol, tag=tags[tag][0]), bins=bins) if False: pass # if np.alltrue(stru_l[key].pbc): # crystal # for y, x in zip(a, b[:-1]): # plt.axvline(x=x, ymax=y, color='grey', linestyle='--') else: total = np.sum(a) ax.plot(b[:-1], a, label='{0} {1} {2}, {3}'.format( key, symbol, tag, total), marker=tags[tag][1], color=colors[n]) ax.set_xlabel('Bond angle in Degrees') ax.set_xlim(0, 180) ax.set_ylabel('Angle Counts') ax.legend(loc='best', prop={'size': 12}) if save_file is not None: plt.savefig(save_file + '_angle.eps', bbox_inches='tight', transparent='True') plt.savefig(save_file + '_angle.png', bbox_inches='tight', transparent='True') if show is True: plt.show()
from ase.cluster import * from ase.constraints import FixAtoms from pyiid.utils import tag_surface_atoms from ase.visualize import view from ase.atoms import Atoms # name = '1nm_Au_distorted_surface_oct' # name = '1nm_Au_distorted_surface_icos' name = '1nm_Au_distorted_surface_fcc' # parent_atoms = Atoms(Octahedron('Au', 4, 0)) parent_atoms = Atoms(FaceCenteredCubic('Au', [[1,0, 0], [1, 1, 0], [1, 1, 1]], (2, 4, 2))) # parent_atoms = Icosahedron('Au', 3) parent_atoms.set_tags(0) tag_surface_atoms(parent_atoms) # Prevent the core from moving c = FixAtoms([atom.index for atom in parent_atoms if atom.tag == 0]) parent_atoms.set_constraint(c) # move the surface target_atoms = dc(parent_atoms) target_atoms.rattle(.2) start_config = insert_atom_document(name + ' starting', parent_atoms) # start_config = next(find_atomic_config_document(name='2nm Au crystal')) target_config = insert_atom_document(name + ' Target', target_atoms) # Now load the G(r) data, this is not needed if it is already in the DB pdf = insert_pdf_data_document(name + ' Target', atomic_config=target_config,