Ejemplo n.º 1
0
    def setup_neighbors(self, additional_conditions=None, valences=None):
        """
        Compute the list of neighbors for each distfactor/angfactor set of parameters from the voronoi list. The set of
        distfactor/angfactor parameters is a "square" of all combinations of distfactors with angfactors.
        :param distfactors: list of distfactors
        :param angfactors: list of angfactors
        :param only_anion_cation_bonds: Allows only neighbors that are cations (resp. anions) when the current site is
        an anion (resp. a cation).
        :param valences: Valences of all the sites in the structure, needed to check the anion-cation bond when
        only_anion_cation_bonds is set to True.
        :raise: ChemenvError if only_anion_cation_bonds is set to True and valences are not given.
        """
        if additional_conditions is None:
            additional_conditions = self.AC.ALL
        if (self.AC.ONLY_ACB in additional_conditions
                or self.AC.ONLY_ACB_AND_NO_E2SEB) and valences is None:
            raise ChemenvError(
                'VoronoiContainer', 'setup_neighbors',
                'Valences are not given while only_anion_cation_bonds are allowed. Cannot continue'
            )
        self.neighbors_lists = [None] * len(self.voronoi_list)
        self.additional_conditions = additional_conditions

        for ivoronoi, voronoi in enumerate(self.voronoi_list):
            if voronoi is None:
                continue
            self.neighbors_lists[ivoronoi] = []
            voronoi_ac = self._precompute_additional_conditions(
                ivoronoi, voronoi, valences)
            distance_conditions = self._precompute_distance_conditions(
                ivoronoi, voronoi)
            angle_conditions = self._precompute_angle_conditions(
                ivoronoi, voronoi)

            for idp, dp_dict in enumerate(
                    self.neighbors_weighted_distances[ivoronoi]):
                self.neighbors_lists[ivoronoi].append([])
                for iap, ap_dict in enumerate(
                        self.neighbors_weighted_angles[ivoronoi]):
                    self.neighbors_lists[ivoronoi][idp].append([])
                    for iac, ac in enumerate(self.additional_conditions):
                        nlist = [(ips, vals['index'], {
                            'weighted_distance':
                            vals['weighted_distance'],
                            'weighted_angle':
                            vals['weighted_angle'],
                            'distance':
                            vals['distance'],
                            'angle':
                            vals['angle']
                        }) for ips, (ps, vals) in enumerate(voronoi)
                                 if (distance_conditions[idp][ips]) and (
                                     angle_conditions[iap][ips]) and (
                                         voronoi_ac[ac][ips])]
                        self.neighbors_lists[ivoronoi][idp][iap].append(nlist)
Ejemplo n.º 2
0
 def materials_project_api_key(self):
     if self.materials_project_configuration is None:
         raise ChemenvError('ChemEnvConfig', 'materials_project_api_key',
                            'No api_key saved')
     return self.materials_project_configuration['api_key']
Ejemplo n.º 3
0
    def __init__(
        self,
        environments=None,
        links=None,
        environments_data=None,
        links_data=None,
        graph=None,
    ):
        """
        Constructor for the ConnectedComponent object.

        Args:
            environments: Environments in the connected component.
            links: Links between environments in the connected component.
            environments_data: Data of environment nodes.
            links_data: Data of links between environment nodes.
            graph: Graph of the connected component.

        Returns:
            ConnectedComponent: Instance of this class
        """
        self._periodicity_vectors = None
        self._primitive_reduced_connected_subgraph = None
        self._projected = False
        if graph is None:
            self._connected_subgraph = nx.MultiGraph()
            if environments_data is None:
                self._connected_subgraph.add_nodes_from(environments)
            else:
                for env in environments:
                    if env in environments_data:
                        self._connected_subgraph.add_node(env, **environments_data[env])
                    else:
                        self._connected_subgraph.add_node(env)
            for edge in links:
                env_node1 = edge[0]
                env_node2 = edge[1]
                if len(edge) == 2:
                    key = None
                else:
                    key = edge[2]
                if (not self._connected_subgraph.has_node(env_node1)) or (
                    not self._connected_subgraph.has_node(env_node2)
                ):
                    raise ChemenvError(
                        self.__class__,
                        "__init__",
                        "Trying to add edge with some unexisting node ...",
                    )
                if links_data is not None:
                    if (env_node1, env_node2, key) in links_data:
                        edge_data = links_data[(env_node1, env_node2, key)]
                    elif (env_node2, env_node1, key) in links_data:
                        edge_data = links_data[(env_node2, env_node1, key)]
                    elif (env_node1, env_node2) in links_data:
                        edge_data = links_data[(env_node1, env_node2)]
                    elif (env_node2, env_node1) in links_data:
                        edge_data = links_data[(env_node2, env_node1)]
                    else:
                        edge_data = None
                else:
                    edge_data = None
                if edge_data:
                    self._connected_subgraph.add_edge(env_node1, env_node2, key, **edge_data)
                else:
                    self._connected_subgraph.add_edge(env_node1, env_node2, key)
        else:
            # TODO: should check a few requirements here ?
            self._connected_subgraph = graph