Exemple #1
0
def hilighter(event):
    # if we did not hit a node, bail
    if not hasattr(event, 'nodes') or not event.nodes:
        return

    # pull out the graph,
    graph = event.artist.graph

    # clear any non-default color on nodes
    for node, attributes in graph.nodes.data():
        attributes.pop('color', None)

    for u, v, attributes in graph.edges.data():
        attributes.pop('width', None)

    for node in event.nodes:
        graph.nodes[node]['color'] = 'C1'
        #print(node)

        for edge_attribute in graph[node].values():
            edge_attribute['width'] = 3

    # update the screen
    event.artist.stale = True
    event.artist.figure.canvas.draw_idle()
    print(event.nodes)

    simulation_id = event.nodes[0]
    simulation = simulations[str(simulation_id)]
    pp(simulation)
    print("simulation id", simulation_id)
    atoms = atoms_dict_to_ase(simulation["atoms"])
    view(atoms)
Exemple #2
0
    def run_task(self, fw_spec):
        ase_atoms_lst = self["ase_atoms_lst"]
        workflow_id = fw_spec.get("workflow", {"_id": -1}).get("_id", -1)
        logging.debug(fw_spec)
        update_spec = fw_spec

        calc_ids = []
        for atoms_dict in ase_atoms_lst:
            atoms = atoms_dict_to_ase(atoms_dict)
            dct = atoms.info
            total_energy = dct.get(
                "E",
                dct.get(
                    "energy",
                    dct.get(
                        "total_energy",
                        dct.get("TotalEnergy", dct.get("totalenergy",
                                                       "UNKNOWN")))))
            if total_energy == "UNKNOWN":
                logging.warning(
                    "total energy of cluster not specified in structure file")
            nanocluster_atom_ids = list(range(len(atoms)))

            db = get_external_database(fw_spec["extdb_connect"])
            simulations = db['simulations']
            # request id counter
            simulation_id = _query_id_counter_and_increment('simulations', db)

            nanocluster = {
                "atom_ids": nanocluster_atom_ids,
                "reference_id": simulation_id
            }

            dct = {
                "_id": simulation_id,
                "atoms": atoms_dict,
                "source_id": -1,
                "workflow_id": workflow_id,
                "nanoclusters": [nanocluster],
                "adsorbates": [],
                "substrates": [],
                "operations": [],
                "inp": {},
                "output": {
                    "total_energy": total_energy
                },
            }
            # update external database
            simulations.insert_one(dct)
            calc_ids.append(simulation_id)

        # update temp workflow data
        update_spec["temp"]["calc_ids"] = calc_ids
        update_spec.pop("_category")
        update_spec.pop("name")
        return FWAction(update_spec=update_spec)
def onpick3(event):
    ind = event.ind
    print('onpick3 scatter:', ind)
    try:
        first_id = ind[0]
    except:
        return
    print("taking first point", first_id)
    simulation = initial_guess_simulations_list[first_id]
    pp(simulation)
    print("simulation id", simulation["_id"])
    atoms = atoms_dict_to_ase(simulation["atoms"])
    view(atoms)
def onpick3(event):
    ind = event.ind
    print('onpick3 scatter:', ind)
    try:
        first_id = ind[0]
    except:
        return
    #print(first_id)
    simulation_id = dft_ids[first_id]
    simulation = simulations[str(simulation_id)]
    pp(simulation)
    print("simulation id", simulation_id)
    atoms = atoms_dict_to_ase(simulation["atoms"])
    view(atoms)
Exemple #5
0
def gather_all_atom_types(calc_ids, simulations):
    """Helper function to determine all atom types in the dataset

    Args:
        calc_ids (list) : ids of the simulation collection
        simulations (list) : simulation documents

    Returns:
        list :  a sorted unique list of atomic numbers in the
                dataset
    """
    # going through nc atoms once to find atom types
    atomic_numbers = []
    for idx, calc_id in enumerate(calc_ids):
        atoms_dict = simulations[str(calc_id)]["atoms"]
        atoms = atoms_dict_to_ase(atoms_dict)
        atomic_numbers.extend(atoms.get_atomic_numbers())

    sorted_list_atomic_numbers = list(sorted(set(atomic_numbers)))

    all_atomtypes = sorted_list_atomic_numbers
    return all_atomtypes
    i = 0
    epoch = 0
    while i < MAX_VERTICAL:
        current_simulations = odict()
        print("# simulations on current level", len(children_ids))
        print(children_ids)
        for idx in children_ids:
            current_simulations[idx] = simulations[idx]

        current_structures = odict()
        for idx, simulation in current_simulations.items():
            step = simulation["operations"][0]
            #print("step:", step)

            atoms = atoms_dict_to_ase(simulation["atoms"])
            current_structures[idx] = atoms
            n_adsorbates = len(atoms[atoms.get_atomic_numbers() != 0]) - 55
            #print(n_adsorbates)


        # compare parent with current structures
        marked_structures = odict()
        if not is_root: # add safeguard for root and reprints

            for idx, atoms in current_structures.items():
                # mapping of parents to children
                parent_idx = current_simulations[idx]["source_id"]
                step = current_simulations[idx]["operations"][0]

                parent_atoms = parent_structures[str(parent_idx)]
        # shortened list of adsorption energies (possibly the workflow contains more than two different elements)
        y_property_shortened.append(property_dct[latest_simulation["_id"]])

    compositions = np.array(compositions)

    # summarized structures of nanoclusters fully covered with adsorbate #
    ######################################################################

    covered_structures = []
    nanoclusters = []

    # sort nanoclusters by element 1
    nel1_lst = []
    for nanocluster in ref_simulations_list:
        nano_atoms_dct = nanocluster["atoms"]
        nano_atoms = atoms_dict_to_ase(nano_atoms_dct)
        nel1 = (nano_atoms.get_atomic_numbers() == element1).sum()
        nel1_lst.append(nel1)
    sort_ids = np.argsort(np.array(nel1_lst))
    ref_simulations_list = np.array(ref_simulations_list)[sort_ids]

    #print("ref_simulations_list", ref_simulations_list)
    for nanocluster in ref_simulations_list:
        ref_id = nanocluster["_id"]
        nano_atoms_dct = nanocluster["atoms"]
        nano_atoms = atoms_dict_to_ase(nano_atoms_dct)
        covered_atoms = nano_atoms.copy()

        related_ids = reference_id_dct[ref_id]
        for related_id in related_ids:
            positions = positions_dct[related_id]