Esempio n. 1
0
def build_atomgraph(bimetallic_result):
    """
    Returns an atomgraph object from the result of a bimetallic result query.

    :param bimetallic_result: the result of a bimetallic result query

    :return: an atomgraph object
    """
    bondlist = bimetallic_result.nanoparticle.bonds_list
    assert bondlist is not None
    return atomgraph.AtomGraph(bondlist,
                               kind0=bimetallic_result.metal1,
                               kind1=bimetallic_result.metal2)
Esempio n. 2
0
def cn_dist_plot(bimet_res: "dt.BimetallicResults",
                 pcty=False, show=False):
    """
    Creates CN distribution plot of bimetallic NP

    Args:
    - bimet_res (npdb.datatables.BimetallicResults): bimetallic result from
                                                     sql database

    KArgs:
    - pcty (bool): if True, y-axis is normalized to show percentage
                   of CN filled by each metal type
                   (Default: False)
    - show (bool): if True, plt.show() is called to show plot
                   (Default: False)

    Returns:
    - (plt.Figure), (plt.gca()): figure and axis object of plot
    """
    # create params from BiMetResult object (done to shorten names)
    m1 = bimet_res.metal1
    m2 = bimet_res.metal2
    shape = bimet_res.shape

    # create bonds list
    # try to load it from nanoparticle object
    if isinstance(bimet_res.nanoparticle.load_bonds_list(), np.ndarray):
        bonds = bimet_res.nanoparticle.bonds_list
    else:
        raise ValueError("Unable to load bonds list")

    # ordering array
    ordering = np.array([int(i) for i in bimet_res.ordering])

    # initialize atom graph
    ag = atomgraph.AtomGraph(bonds.copy(), m1, m2)

    cn_dist = ag.calc_cn_dist(ordering)

    # get metal colors
    m1_color = jmol_colors[chemical_symbols.index(m1)]
    m2_color = jmol_colors[chemical_symbols.index(m2)]

    # get x value for both plots
    x = range(1, len(cn_dist['cn_options']) + 1)

    fig, ax = plt.subplots()

    # plot params
    formula = bimet_res.build_chem_formula(True)
    ax.set_title(f'{formula} ({bimet_res.num_atoms}-atom {shape.title()})')
    ax.set_xlabel('CN')
    ax.set_xticks(x)
    ax.set_xticklabels(cn_dist['cn_options'])

    # normalize counts
    if pcty:
        cn_dist['m1_counts'] = cn_dist['m1_counts'] / cn_dist['tot_counts']
        cn_dist['m2_counts'] = cn_dist['m2_counts'] / cn_dist['tot_counts']
        ax.set_ylabel('Percentage of Atoms')
        ax.set_ylim(0, 1.2)
        ax.set_yticklabels(['{:,.0%}'.format(x)
                            for x in ax.get_yticks()[:-1]] + [''])

    else:
        ax.set_ylabel('Number of Atoms')
        ax.set_ylim(0, max(cn_dist['tot_counts']) * 1.1)

    ax.bar(x, cn_dist['m1_counts'], color=m1_color, edgecolor='k',
           label=m1)
    ax.bar(x, cn_dist['m2_counts'], bottom=cn_dist['m1_counts'],
           color=m2_color, edgecolor='k', label=m2)

    ax.legend()
    fig.tight_layout()
    if show:
        plt.show()
    return fig, ax
Esempio n. 3
0
    n = db_inter.get_shell2num(shape, s)

    # get half such that metal1 has the extra atom (if natoms is odd)
    n = (n + n % 2) // 2

    res = db_inter.get_bimet_result(metals, shape=shape, num_shells=s,
                                    n_metal1=n)

    # get ordering array
    ordering = np.array([int(i) for i in res.ordering])

    # load bonds list
    bonds = res.nanoparticle.load_bonds_list()

    # build atomgraph object
    ag = atomgraph.AtomGraph(bonds, 'Au', 'Cu')

    # get atom indices for each shell
    shells = db_inter.build_atoms_in_shell_dict(shape, s)

    # create a 'Test Atom' to ensure shells are being correctly counted
    test_atom = res.build_atoms_obj()

    # remove shells from dict not in study
    maxshell = max(shells.keys())
    dropcount = 0
    for drop in range(buffer):
        # pop inner and outer <buffer> layers
        for d in shells.pop(drop) + shells.pop(maxshell - drop):
            # set symbol of dropped atoms to Br
            test_atom[d].symbol = 'Br'
Esempio n. 4
0
import ase.lattice.cubic
import ase.neighborlist

from ce_expansion.atomgraph import adjacency, atomgraph
from ce_expansion.ga import ga

# Make a generic FCC cell
for cell_size in range(5, 10):
    pairs = [["Ag", "Au"], ["Ag", "Cu"], ["Au", "Cu"]]
    fcc_cell = ase.lattice.cubic.FaceCenteredCubic(
        symbol="Cu", size=[cell_size, cell_size, cell_size])
    bonds = adjacency.buildBondsList(fcc_cell)
    for pair in pairs:
        metal1 = pair[0]
        metal2 = pair[1]
        graph = atomgraph.AtomGraph(bonds.copy(), metal1, metal2)

        # Genetic Algorithm
        n_atoms = len(fcc_cell)
        known_comps = [None] * 101
        for composition in range(0, 101):
            percent = composition / 100
            n_metal1 = int(percent * n_atoms)
            if n_metal1 in known_comps:
                continue
            else:
                known_comps[composition] = n_metal1
            n_metal2 = n_atoms - n_metal1
            formula = "".join(map(str, [metal1, n_metal1, metal2, n_metal2]))
            if os.path.exists("cells/" + formula + ".cif"):
                continue
Esempio n. 5
0
# Calculating the bonding is fairly slow in ASE's libraries.
# Fortunately, every XYZ in the dataset has the same set of coordinates,
# so we can use the same atomgraph for every system.
print("Building atom graph...")
filename = "Ag0Au309.xyz"  # chosen completely arbitrarily
path = os.path.join(data, filename)
atoms = ase.io.read(path)
bondlist = adjacency.buildBondsList(atoms,
                                    radius_dictionary={
                                        ("Ag", "Ag"): 3,
                                        ("Ag", "Au"): 3,
                                        ("Au", "Au"): 3
                                    })
# Make the atomgraph; set "0" to Ag and set "1" to Au
graph = atomgraph.AtomGraph(bondlist, kind0="Ag", kind1="Au")

# Array to hold mixing parameters and energies
csv_data = [None] * 310

# Now we'll iterate over every xyz file in the directory
print("Calculating mixing parameters and cohesive energies...")
for i in range(0, 310):
    # Specify the path to the file and open it as an ASE_Atoms Object
    filename = "Ag" + str(i) + "Au" + str(309 - i) + ".xyz"
    print(filename[:-4])
    path = os.path.join(data, filename)
    atoms = ase.io.read(path)

    # Make a holder array for the chemical ordering
    ordering = np.zeros(309)