How to use the megnet.utils.general.expand_1st function in megnet

To help you get started, we’ve selected a few megnet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
# Get the inputs for each batch
        inputs = self._generate_inputs(batch_index)

        # Make the graph data
        inputs = self._combine_graph_data(*inputs)

        # Return the batch
        if self.targets is None:
            return inputs
        else:
            # get targets
            it = itemgetter(*batch_index)
            target_temp = itemgetter_list(self.targets, batch_index)
            target_temp = np.atleast_2d(target_temp)

            return inputs, expand_1st(target_temp)
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
# assemble bond indices
        index1 = []
        index2 = []
        offset_ind = 0
        for ind1, ind2 in zip(index1_temp, index2_temp):
            index1 += [i + offset_ind for i in ind1]
            index2 += [i + offset_ind for i in ind2]
            offset_ind += (max(ind1) + 1)

        # Compile the inputs in needed order
        inputs = [expand_1st(feature_list_temp),
                  expand_1st(connection_list_temp),
                  expand_1st(global_list_temp),
                  expand_1st(index1),
                  expand_1st(index2),
                  expand_1st(gnode),
                  expand_1st(gbond)]
        return inputs
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
def graph_to_input(self, graph: Dict) -> List[np.ndarray]:
        """
        Turns a graph into model input

        Args:
            (dict): Dictionary description of the graph
        Return:
            ([np.ndarray]): Inputs in the form needed by MEGNet
        """
        gnode = [0] * len(graph['atom'])
        gbond = [0] * len(graph['index1'])

        return [expand_1st(self.atom_converter.convert(graph['atom'])),
                expand_1st(self.bond_converter.convert(graph['bond'])),
                expand_1st(np.array(graph['state'])),
                expand_1st(np.array(graph['index1'])),
                expand_1st(np.array(graph['index2'])),
                expand_1st(np.array(gnode)),
                expand_1st(np.array(gbond))]
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
index1 = []
        index2 = []
        offset_ind = 0
        for ind1, ind2 in zip(index1_temp, index2_temp):
            index1 += [i + offset_ind for i in ind1]
            index2 += [i + offset_ind for i in ind2]
            offset_ind += (max(ind1) + 1)

        # Compile the inputs in needed order
        inputs = [expand_1st(feature_list_temp),
                  expand_1st(connection_list_temp),
                  expand_1st(global_list_temp),
                  expand_1st(index1),
                  expand_1st(index2),
                  expand_1st(gnode),
                  expand_1st(gbond)]
        return inputs
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
# assemble bond indices
        index1 = []
        index2 = []
        offset_ind = 0
        for ind1, ind2 in zip(index1_temp, index2_temp):
            index1 += [i + offset_ind for i in ind1]
            index2 += [i + offset_ind for i in ind2]
            offset_ind += (max(ind1) + 1)

        # Compile the inputs in needed order
        inputs = [expand_1st(feature_list_temp),
                  expand_1st(connection_list_temp),
                  expand_1st(global_list_temp),
                  expand_1st(index1),
                  expand_1st(index2),
                  expand_1st(gnode),
                  expand_1st(gbond)]
        return inputs
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
global_list_temp = self.process_state_feature(global_list_temp)

        # assemble bond indices
        index1 = []
        index2 = []
        offset_ind = 0
        for ind1, ind2 in zip(index1_temp, index2_temp):
            index1 += [i + offset_ind for i in ind1]
            index2 += [i + offset_ind for i in ind2]
            offset_ind += (max(ind1) + 1)

        # Compile the inputs in needed order
        inputs = [expand_1st(feature_list_temp),
                  expand_1st(connection_list_temp),
                  expand_1st(global_list_temp),
                  expand_1st(index1),
                  expand_1st(index2),
                  expand_1st(gnode),
                  expand_1st(gbond)]
        return inputs
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
def graph_to_input(self, graph: Dict) -> List[np.ndarray]:
        """
        Turns a graph into model input

        Args:
            (dict): Dictionary description of the graph
        Return:
            ([np.ndarray]): Inputs in the form needed by MEGNet
        """
        gnode = [0] * len(graph['atom'])
        gbond = [0] * len(graph['index1'])

        return [expand_1st(self.atom_converter.convert(graph['atom'])),
                expand_1st(self.bond_converter.convert(graph['bond'])),
                expand_1st(np.array(graph['state'])),
                expand_1st(np.array(graph['index1'])),
                expand_1st(np.array(graph['index2'])),
                expand_1st(np.array(gnode)),
                expand_1st(np.array(gbond))]
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
# assemble state feature together
        global_list_temp = np.concatenate(global_list_temp, axis=0)
        global_list_temp = self.process_state_feature(global_list_temp)

        # assemble bond indices
        index1 = []
        index2 = []
        offset_ind = 0
        for ind1, ind2 in zip(index1_temp, index2_temp):
            index1 += [i + offset_ind for i in ind1]
            index2 += [i + offset_ind for i in ind2]
            offset_ind += (max(ind1) + 1)

        # Compile the inputs in needed order
        inputs = [expand_1st(feature_list_temp),
                  expand_1st(connection_list_temp),
                  expand_1st(global_list_temp),
                  expand_1st(index1),
                  expand_1st(index2),
                  expand_1st(gnode),
                  expand_1st(gbond)]
        return inputs
github materialsvirtuallab / megnet / megnet / data / graph.py View on Github external
# assemble state feature together
        global_list_temp = np.concatenate(global_list_temp, axis=0)
        global_list_temp = self.process_state_feature(global_list_temp)

        # assemble bond indices
        index1 = []
        index2 = []
        offset_ind = 0
        for ind1, ind2 in zip(index1_temp, index2_temp):
            index1 += [i + offset_ind for i in ind1]
            index2 += [i + offset_ind for i in ind2]
            offset_ind += (max(ind1) + 1)

        # Compile the inputs in needed order
        inputs = [expand_1st(feature_list_temp),
                  expand_1st(connection_list_temp),
                  expand_1st(global_list_temp),
                  expand_1st(index1),
                  expand_1st(index2),
                  expand_1st(gnode),
                  expand_1st(gbond)]
        return inputs