graphinvent/GraphGenerator.py
def _features_to_atom(node_idx : int, node_features : torch.Tensor) -> \
            rdkit.Chem.Atom:
            """
            Converts the node feature vector corresponding to the specified node
            into an atom object.

            Args:
            ----
                node_idx (int)               : Index denoting the specific node
                                               on the graph to convert.
                node_features (torch.Tensor) : Node features tensor for one graph.

            Returns:
            -------
                new_atom (rdkit.Atom) : Atom object corresponding to specified
                                        node features.
            """
            # get all the nonzero indices in the specified node feature vector
            nonzero_idc = torch.nonzero(node_features[node_idx])

            # determine atom symbol
            atom_idx = nonzero_idc[0]
            atom_type = constants.atom_types[atom_idx]

            # initialize atom
            new_atom = rdkit.Chem.Atom(atom_type)

            # determine formal charge
            fc_idx = nonzero_idc[1] - constants.n_atom_types
            formal_charge = constants.formal_charge[fc_idx]

            new_atom.SetFormalCharge(formal_charge)  # set property

            # determine number of implicit Hs (if used)
            if not constants.use_explicit_H and not constants.ignore_H:
                total_num_h_idx = (nonzero_idc[2] -
                                   constants.n_atom_types -
                                   constants.n_formal_charge)
                total_num_h = constants.imp_H[total_num_h_idx]

                new_atom.SetUnsignedProp("_TotalNumHs", total_num_h)  # set property
            elif constants.ignore_H:
                # Hs will be set with structure is "sanitized" (corrected) later
                # in `mol_to_graph()`
                pass

            # determine chirality (if used)
            if constants.use_chirality:
                cip_code_idx = (
                    nonzero_idc[-1]
                    - constants.n_atom_types
                    - constants.n_formal_charge
                    - (not constants.use_explicit_H and not
                       constants.ignore_H) * constants.n_imp_H
                )
                cip_code = constants.chirality[cip_code_idx]
                new_atom.SetProp("_CIPCode", cip_code)  # set property

            return new_atom

            Converts the node feature vector corresponding to the specified node
            into an atom object.

            Args:
            ----
                node_idx (int)               : Index denoting the specific node
                                               on the graph to convert.
                node_features (torch.Tensor) : Node features tensor for one graph.

            Returns:
            -------
                new_atom (rdkit.Atom) : Atom object corresponding to specified
                                        node features.
            
Converts the node feature vector corresponding to the specified node
into an atom object.
Converts the node feature vector corresponding to the specified node into an atom object .
def _features_to_atom(node_idx : int, node_features : torch.Tensor) -> \
            rdkit.Chem.Atom:
            nonzero_idc = torch.nonzero(node_features[node_idx])
            atom_idx = nonzero_idc[0]
            atom_type = constants.atom_types[atom_idx]
            new_atom = rdkit.Chem.Atom(atom_type)
            fc_idx = nonzero_idc[1] - constants.n_atom_types
            formal_charge = constants.formal_charge[fc_idx]
            new_atom.SetFormalCharge(formal_charge)  
            if not constants.use_explicit_H and not constants.ignore_H:
                total_num_h_idx = (nonzero_idc[2] -
                                   constants.n_atom_types -
                                   constants.n_formal_charge)
                total_num_h = constants.imp_H[total_num_h_idx]
                new_atom.SetUnsignedProp("_TotalNumHs", total_num_h)  
            elif constants.ignore_H:
                pass
            if constants.use_chirality:
                cip_code_idx = (
                    nonzero_idc[-1]
                    - constants.n_atom_types
                    - constants.n_formal_charge
                    - (not constants.use_explicit_H and not
                       constants.ignore_H) * constants.n_imp_H
                )
                cip_code = constants.chirality[cip_code_idx]
                new_atom.SetProp("_CIPCode", cip_code)  
            return new_atom
def _features_to_atom ( node_idx : int , node_features : torch . Tensor ) -> rdkit . Chem . Atom : nonzero_idc = torch . nonzero ( node_features [ node_idx ] ) atom_idx = nonzero_idc [ 0 ] atom_type = constants . atom_types [ atom_idx ] new_atom = rdkit . Chem . Atom ( atom_type ) fc_idx = nonzero_idc [ 1 ] - constants . n_atom_types formal_charge = constants . formal_charge [ fc_idx ] new_atom . SetFormalCharge ( formal_charge ) if not constants . use_explicit_H and not constants . ignore_H : total_num_h_idx = ( nonzero_idc [ 2 ] - constants . n_atom_types - constants . n_formal_charge ) total_num_h = constants . imp_H [ total_num_h_idx ] new_atom . SetUnsignedProp ( "_TotalNumHs" , total_num_h ) elif constants . ignore_H : pass if constants . use_chirality : cip_code_idx = ( nonzero_idc [ - 1 ] - constants . n_atom_types - constants . n_formal_charge - ( not constants . use_explicit_H and not constants . ignore_H ) * constants . n_imp_H ) cip_code = constants . chirality [ cip_code_idx ] new_atom . SetProp ( "_CIPCode" , cip_code ) return new_atom
Converts the node feature vector corresponding to the specified node
into an atom object.
Converts the node feature vector corresponding to the specified node into an atom object .
"""
            Converts the node feature vector corresponding to the specified node
            into an atom object.

            Args:
            ----
                node_idx (int)               : Index denoting the specific node
                                               on the graph to convert.
                node_features (torch.Tensor) : Node features tensor for one graph.

            Returns:
            -------
                new_atom (rdkit.Atom) : Atom object corresponding to specified
                                        node features.
            """ # get all the nonzero indices in the specified node feature vector # determine atom symbol # initialize atom # determine formal charge # set property # determine number of implicit Hs (if used) # set property # Hs will be set with structure is "sanitized" (corrected) later # in `mol_to_graph()` # determine chirality (if used) # set property
new_atom (rdkit.Atom) : Atom object corresponding to specified
node features.
new_atom ( rdkit . Atom ) : Atom object corresponding to specified node features .
node_idx
int
Index denoting the specific node
on the graph to convert.
Index denoting the specific node on the graph to convert .
node_features
torch.Tensor
Node features tensor for one graph.
Node features tensor for one graph .