graphinvent/MolecularGraph.py
def truncate_graph(self) -> None:
        """
        Truncates a molecule by editing its molecular graph (`self.node_features`
        and `self.edge_features`) in place. By default deletes the last node.

        If the last atom is bound to multiple atoms on the graph (i.e. a ring
        atom), then only deletes the least "important" bond, as determined from
        the breadth-first ordering. This is so as to allow the APD to be broken
        up into multiple steps (add, connect, terminate).
        """
        last_atom_idx = self.n_nodes - 1

        if self.n_nodes == 1:
            # remove the last atom
            self.node_features[last_atom_idx, :] = 0
            self.n_nodes                        -= 1
        else:
            # determine how many bonds on the least important atom
            bond_idc = []
            for bond_type in range(self.constants.n_edge_features):
                bond_idc.extend(
                    list(
                        np.nonzero(self.edge_features[:, last_atom_idx, bond_type])[0]
                    )
                )

            degree = len(bond_idc)

            if degree == 1:
                # delete atom from node features
                self.node_features[last_atom_idx, :] = 0
                self.n_nodes -= 1
            else:  # if degree > 1
                # if the last atom is bound to multiple atoms, only delete the
                # least important bond, but leave the atom and remaining bonds
                bond_idc = bond_idc[-1]  # mark bond for deletion (below)

            # delete bond from row feature tensor (first row, then column)
            self.edge_features[bond_idc, last_atom_idx, :] = 0
            self.edge_features[last_atom_idx, bond_idc, :] = 0

        Truncates a molecule by editing its molecular graph (`self.node_features`
        and `self.edge_features`) in place. By default deletes the last node.

        If the last atom is bound to multiple atoms on the graph (i.e. a ring
        atom), then only deletes the least "important" bond, as determined from
        the breadth-first ordering. This is so as to allow the APD to be broken
        up into multiple steps (add, connect, terminate).
        
Truncates a molecule by editing its molecular graph (`self.node_features`
and `self.edge_features`) in place. By default deletes the last node.

If the last atom is bound to multiple atoms on the graph , then only deletes the least "important" bond, as determined from
the breadth-first ordering. This is so as to allow the APD to be broken
up into multiple steps (add, connect, terminate).
Truncates a molecule by editing its molecular graph ( ` self . node_features ` and ` self . edge_features ` ) in place . By default deletes the last node . If the last atom is bound to multiple atoms on the graph then only deletes the least " important " bond as determined from the breadth - first ordering . This is so as to allow the APD to be broken up into multiple steps ( add connect terminate ) .
def truncate_graph(self) -> None:
        last_atom_idx = self.n_nodes - 1
        if self.n_nodes == 1:
            self.node_features[last_atom_idx, :] = 0
            self.n_nodes                        -= 1
        else:
            bond_idc = []
            for bond_type in range(self.constants.n_edge_features):
                bond_idc.extend(
                    list(
                        np.nonzero(self.edge_features[:, last_atom_idx, bond_type])[0]
                    )
                )
            degree = len(bond_idc)
            if degree == 1:
                self.node_features[last_atom_idx, :] = 0
                self.n_nodes -= 1
            else:  
                bond_idc = bond_idc[-1]  
            self.edge_features[bond_idc, last_atom_idx, :] = 0
            self.edge_features[last_atom_idx, bond_idc, :] = 0
def truncate_graph ( self ) -> None : last_atom_idx = self . n_nodes - 1 if self . n_nodes == 1 : self . node_features [ last_atom_idx , : ] = 0 self . n_nodes -= 1 else : bond_idc = [ ] for bond_type in range ( self . constants . n_edge_features ) : bond_idc . extend ( list ( np . nonzero ( self . edge_features [ : , last_atom_idx , bond_type ] ) [ 0 ] ) ) degree = len ( bond_idc ) if degree == 1 : self . node_features [ last_atom_idx , : ] = 0 self . n_nodes -= 1 else : bond_idc = bond_idc [ - 1 ] self . edge_features [ bond_idc , last_atom_idx , : ] = 0 self . edge_features [ last_atom_idx , bond_idc , : ] = 0
Truncates a molecule by editing its molecular graph (`self.node_features`
and `self.edge_features`) in place.
Truncates a molecule by editing its molecular graph ( ` self . node_features ` and ` self . edge_features ` ) in place .
"""
        Truncates a molecule by editing its molecular graph (`self.node_features`
        and `self.edge_features`) in place. By default deletes the last node.

        If the last atom is bound to multiple atoms on the graph (i.e. a ring
        atom), then only deletes the least "important" bond, as determined from
        the breadth-first ordering. This is so as to allow the APD to be broken
        up into multiple steps (add, connect, terminate).
        """ # remove the last atom # determine how many bonds on the least important atom # delete atom from node features # if degree > 1 # if the last atom is bound to multiple atoms, only delete the # least important bond, but leave the atom and remaining bonds # mark bond for deletion (below) # delete bond from row feature tensor (first row, then column)
self