src/proteingnn/data.py
def process_graph(self, pdb: AnyPath, pos_flag: bool = False, shared_pose: bool = False,
                      data_attr_dict: Optional[Dict[str, Callable]] = None) -> torchg.data.Data:
        """Process pdb structure in pyrosetta and return sample data as undirected graph.

        Args:
            pdb: path to pdb.
            pos_flag: include pos (xyz) in node (default: False).
            shared_pose: assume all pdbs are the same and reuse pose to speed up
            data_attr_dict: functions to annotate data (sample). Key must be attribute name.
                Value is any function with arguments (pose, pdb). For example,
                {'dummy': lambda x: 'dummy'} will get you data.dummy = 'dummy'
        """
        if shared_pose and (self._shared_pose is None or self._shared_atoms is None):
            raise ValueError('shared_pose is True but no self._shared_pose found. '
                             'User forgot to set_shared?')

        if shared_pose:
            pose = self._shared_pose
            atoms = self._shared_atoms
        else:
            pose, atoms = pdb2pose_atoms(pdb)
            atoms = self._filter_atoms(pose, atoms)

        atom_ids = sort_atom_ids(atoms)

        x = []  # size = (num_nodes, num_node_features)
        edge_index = []  # size = (2, num_edges)
        edge_attr = []  # size = (num_edges, num_edge_features)
        pos = []  # size = (num_nodes, num_dimensions)

        for i, atom_id1 in enumerate(atom_ids):
            x.append(self._node_feature(pose, atom_id1))
            if pos_flag:
                coord1 = pose.xyz(atom_id1)
                pos.append(coord1)

            for j, atom_id2 in enumerate(atom_ids[i + 1:], i + 1):
                is_edge, edge_feature = self._edge_feature(pose, atom_id1, atom_id2)
                if is_edge:
                    edge = [i, j]
                    edge_index.append(edge)
                    if edge_feature:
                        edge_attr.append(edge_feature)

                    edge = [j, i]
                    edge_index.append(edge)
                    if edge_feature:
                        edge_attr.append(edge_feature)

        x = torch.tensor(x)
        y = self.get_y(pdb)
        edge_index = torch.tensor(edge_index).T
        edge_attr = torch.tensor(edge_attr) if edge_attr else None
        pos = torch.tensor(pos) if pos else None

        if not edge_index.shape[0]:
            raise ValueError('No edge in node.')

        data = torchg.data.Data(x, edge_index, edge_attr, y, pos)
        data.pdb = Path(pdb).name

        if data_attr_dict is not None:
            for attr_name, attr_func in data_attr_dict.items():
                setattr(data, attr_name, attr_func(pose, pdb))

        assert data.is_undirected(), f'Data {pdb.stem} is directed and is not supported.'
        return data
Process pdb structure in pyrosetta and return sample data as undirected graph.

        Args:
            pdb: path to pdb.
            pos_flag: include pos (xyz) in node (default: False).
            shared_pose: assume all pdbs are the same and reuse pose to speed up
            data_attr_dict: functions to annotate data (sample). Key must be attribute name.
                Value is any function with arguments (pose, pdb). For example,
                {'dummy': lambda x: 'dummy'} will get you data.dummy = 'dummy'
        
Process pdb structure in pyrosetta and return sample data as undirected graph.
Process pdb structure in pyrosetta and return sample data as undirected graph .
def process_graph(self, pdb: AnyPath, pos_flag: bool = False, shared_pose: bool = False,
                      data_attr_dict: Optional[Dict[str, Callable]] = None) -> torchg.data.Data:
        if shared_pose and (self._shared_pose is None or self._shared_atoms is None):
            raise ValueError('shared_pose is True but no self._shared_pose found. '
                             'User forgot to set_shared?')
        if shared_pose:
            pose = self._shared_pose
            atoms = self._shared_atoms
        else:
            pose, atoms = pdb2pose_atoms(pdb)
            atoms = self._filter_atoms(pose, atoms)
        atom_ids = sort_atom_ids(atoms)
        x = []  
        edge_index = []  
        edge_attr = []  
        pos = []  
        for i, atom_id1 in enumerate(atom_ids):
            x.append(self._node_feature(pose, atom_id1))
            if pos_flag:
                coord1 = pose.xyz(atom_id1)
                pos.append(coord1)
            for j, atom_id2 in enumerate(atom_ids[i + 1:], i + 1):
                is_edge, edge_feature = self._edge_feature(pose, atom_id1, atom_id2)
                if is_edge:
                    edge = [i, j]
                    edge_index.append(edge)
                    if edge_feature:
                        edge_attr.append(edge_feature)
                    edge = [j, i]
                    edge_index.append(edge)
                    if edge_feature:
                        edge_attr.append(edge_feature)
        x = torch.tensor(x)
        y = self.get_y(pdb)
        edge_index = torch.tensor(edge_index).T
        edge_attr = torch.tensor(edge_attr) if edge_attr else None
        pos = torch.tensor(pos) if pos else None
        if not edge_index.shape[0]:
            raise ValueError('No edge in node.')
        data = torchg.data.Data(x, edge_index, edge_attr, y, pos)
        data.pdb = Path(pdb).name
        if data_attr_dict is not None:
            for attr_name, attr_func in data_attr_dict.items():
                setattr(data, attr_name, attr_func(pose, pdb))
        assert data.is_undirected(), f'Data {pdb.stem} is directed and is not supported.'
        return data
def process_graph ( self , pdb : AnyPath , pos_flag : bool = False , shared_pose : bool = False , data_attr_dict : Optional [ Dict [ str , Callable ] ] = None ) -> torchg . data . Data : if shared_pose and ( self . _shared_pose is None or self . _shared_atoms is None ) : raise ValueError ( 'shared_pose is True but no self._shared_pose found. ' 'User forgot to set_shared?' ) if shared_pose : pose = self . _shared_pose atoms = self . _shared_atoms else : pose , atoms = pdb2pose_atoms ( pdb ) atoms = self . _filter_atoms ( pose , atoms ) atom_ids = sort_atom_ids ( atoms ) x = [ ] edge_index = [ ] edge_attr = [ ] pos = [ ] for i , atom_id1 in enumerate ( atom_ids ) : x . append ( self . _node_feature ( pose , atom_id1 ) ) if pos_flag : coord1 = pose . xyz ( atom_id1 ) pos . append ( coord1 ) for j , atom_id2 in enumerate ( atom_ids [ i + 1 : ] , i + 1 ) : is_edge , edge_feature = self . _edge_feature ( pose , atom_id1 , atom_id2 ) if is_edge : edge = [ i , j ] edge_index . append ( edge ) if edge_feature : edge_attr . append ( edge_feature ) edge = [ j , i ] edge_index . append ( edge ) if edge_feature : edge_attr . append ( edge_feature ) x = torch . tensor ( x ) y = self . get_y ( pdb ) edge_index = torch . tensor ( edge_index ) . T edge_attr = torch . tensor ( edge_attr ) if edge_attr else None pos = torch . tensor ( pos ) if pos else None if not edge_index . shape [ 0 ] : raise ValueError ( 'No edge in node.' ) data = torchg . data . Data ( x , edge_index , edge_attr , y , pos ) data . pdb = Path ( pdb ) . name if data_attr_dict is not None : for attr_name , attr_func in data_attr_dict . items ( ) : setattr ( data , attr_name , attr_func ( pose , pdb ) ) assert data . is_undirected ( ) , f'Data {pdb.stem} is directed and is not supported.' return data
Process pdb structure in pyrosetta and return sample data as undirected graph.
Process pdb structure in pyrosetta and return sample data as undirected graph .
"""Process pdb structure in pyrosetta and return sample data as undirected graph.

        Args:
            pdb: path to pdb.
            pos_flag: include pos (xyz) in node (default: False).
            shared_pose: assume all pdbs are the same and reuse pose to speed up
            data_attr_dict: functions to annotate data (sample). Key must be attribute name.
                Value is any function with arguments (pose, pdb). For example,
                {'dummy': lambda x: 'dummy'} will get you data.dummy = 'dummy'
        """ # size = (num_nodes, num_node_features) # size = (2, num_edges) # size = (num_edges, num_edge_features) # size = (num_nodes, num_dimensions)
self
pdb
AnyPath
path to pdb.
path to pdb .
pos_flag
bool
include pos (xyz) in node (default: False).
include pos ( xyz ) in node ( default : False ) .
shared_pose
bool
assume all pdbs are the same and reuse pose to speed up
assume all pdbs are the same and reuse pose to speed up
data_attr_dict
Optional[Dict[str, Callable]]
functions to annotate data (sample). Key must be attribute name.
Value is any function with arguments (pose, pdb).
functions to annotate data ( sample ) . Key must be attribute name . Value is any function with arguments ( pose pdb ) .