Example #1
0
        ## for every plane, find mid-oxygen sites
        for pl in planes:

            ## if something did not work upstream, then short-circuit
            if broken: break

            ## get the mobile-ion sites for this plane
            site_pts = cu.get_mobile_ion_sites(atoms, pl, cell)
            num_sites = len(site_pts)

            ## find the graph distances to Mg defects above & below the plane

            ## get all the mid-oxygen sites in this plane
            mid_oxs, edges, midpts = cu.get_mid_oxygen_sites_freud(site_pts,
                                                                   cell,
                                                                   viz=False)

            ## create a proper networkx graph from site-edge list for this plane
            site_graph = nx.from_edgelist(edges)
            path_lengths = cu.path_lengths(site_graph)

            ## find the defect closest to each mobile-ion site in this plane
            ## max distance serves to downselect the defects in the closest block
            e0, e1, d0, d1 = cu.get_nearest_points(site_pts,
                                                   defect_pts,
                                                   cell,
                                                   num_nn=6)
            e0 = np.array(e0)[np.array(d0) < dz]
            e1 = np.array(e1)[np.array(d1) < dz]
                                           viz=False)
        num_sites = len(site_pts)
        print(
            f'Identified {num_sites} mobile-ion sites in plane {input_plane_name}'
        )

        ## auto-get BR sites - this just yields a list of false for beta-doubleprime
        site_types = cu.auto_get_BR_sites(all_atoms,
                                          cell,
                                          site_pts,
                                          atoms_are_frac=frac)
        BR_sites = [i for i in range(len(site_types)) if site_types[i] == 'BR']

        # compose network of mobile-ion sites, calculate paths. Both beta and beta"
        # This can create and save a figure when viz=True. Pass cell if fractional was false
        _, edges, _ = cu.get_mid_oxygen_sites_freud(
            site_pts, cell if not frac else np.eye(3), viz=True)
        nxg = nx.from_edgelist(edges)
        path_lengths = cu.path_lengths(nxg)

        ## DEFECTS
        # find the interstitial defects in this plane: make an array and set z=0
        # the sites will be found below with the same query that counts hops
        try:
            oi_defects = ointers.query(f'z == {plane}')
            oi_defect_pts = oi_defects[['x', 'y', 'z']].values
            # oi_defect_pts[:,-1] = 0

            oi_adjacent_sites, _ = cu.get_defect_adjacent_sites(
                cell, site_pts, oi_defect_pts)
            print(f'sites next to O_i in plane {input_plane_name}: ',
                  oi_adjacent_sites)
## find all conduction planes in the input file
planes = cu.get_conduction_planes(atoms, metal)

## initialize data structures
new_atoms = atoms.copy(deep=True)
all_interstitial_indices = list()
all_paths_to_oi = list() ## plotting only

## for every plane, find mid-oxygen sites
for pl in planes:

    ## get the mobile-ion sites for this plane
    mobile_sites = cu.get_mobile_ion_sites(atoms, pl, cell)
    ## get all the mid-oxygen sites in this plane
    mid_oxs, edges, midpts = cu.get_mid_oxygen_sites_freud(mobile_sites, cell, viz=True)
    plt.gca().set(aspect=1, title=f'z={pl:.3f} $\AA$', ylim=np.array([-0.59,0.59])*cell[1,1],
                  xlim=np.array([-0.55,0.55])*cell[0,0])
    plt.gcf().tight_layout()

    ## Pick mid-oxygen sites quasi-randomly, independent of coordinates
    if packed: 
        picked, fresh, past = cu.generate_mid_oxygens_packed(mid_oxs, num_ois_per_plane, exclude)
    else:
        picked, fresh, past = cu.generate_mid_oxygens(mid_oxs, num_ois_per_plane, exclude)
    print(f'{len(picked)} picked, {len(past)} excluded, {len(fresh)} sites remain')

    ## Plot the mid-oxygen sites where interstitials are going
    xs = []; ys = []
    for mo in mid_oxs:
        for p4 in picked:
Example #4
0
all_ois = inters.copy(deep=True)

Lx, Ly, Lz = np.diag(cell) if not frac else np.ones(3)  ## box size for freud.

## find the conduction planes
planes = cu.get_conduction_planes(atoms, metal)

## hard-coded names for planes. Will be different for beta-doubleprime
plane_names = ['{:03d}'.format(x) for x in ((planes/Lz+0.5) * 100).astype(int)]

## iterate through planes
for pl, pname in zip(planes, plane_names):
    
    ## get and plot the mobile-ion sites for this plane
    mobile_sites = cu.get_mobile_ion_sites(atoms, pl, cell)
    _, edges, _ = cu.get_mid_oxygen_sites_freud(mobile_sites, cell, viz=False)
    
    ## try auto-getting BR sites
    site_types = cu.auto_get_BR_sites(atoms, cell, mobile_sites,atoms_are_frac=frac)
    BR_sites = [i for i in range(len(site_types)) if site_types[i] == 'BR']
    
    fig, ax = plt.subplots()
    box = freud.box.Box(Lx=Lx, Ly=Ly, is2D = True)
    site_vor = freud.locality.Voronoi(box)
    mobile_sites[:,-1] = 0
    site_vor.compute((box, mobile_sites))
    
    cu.draw_voronoi(box, mobile_sites, [site_vor.polytopes[i] for i in BR_sites],cell_numbers=BR_sites)
    plt.gca().set(aspect = 1 if not frac else cell[1,1]/cell[0,0], title=f'z={pname}')
    plt.gcf().tight_layout()
    
Example #5
0
## read the input .CONFIG file & add symmetry elements
phase, intro_line, cell, atoms = cu.read_poly(prod_file, fractional=False)
# atoms = cu.add_symmetry_beta(atoms, cell, mobile=metal, frac=False)

## find all conduction planes in the input file
planes = cu.get_conduction_planes(atoms, metal)

## generate networks and path lengths for every plane, only once 
mid_ox_dict = dict()
path_length_dict = dict()
mobile_site_dict = dict()

for pl in planes : 
    these_mobile_sites = cu.get_mobile_ion_sites(atoms, pl, cell)
    these_mid_oxs, these_edges, _ = cu.get_mid_oxygen_sites_freud(these_mobile_sites, cell, viz=False)
    path_length_dict[pl] = cu.path_lengths(nx.from_edgelist(these_edges))
    mid_ox_dict[pl] = these_mid_oxs
    mobile_site_dict[pl] = these_mobile_sites
    print(f'Made networks in plane z={pl:.4f}, total {(dt.now()-start).total_seconds():4.1f} sec.')
    
dict_of_excludes = dict()
print(f'Setup took {(dt.now()-start).total_seconds():4.1f} sec.')

# =============================================================================
# %% Generate a bunch of random structures and count their sites
# =============================================================================

start = dt.now()

for exclude in [1,4] :