Skip to content

Preprocessing with deepchem. Issue with positions #12

@KeremKurban

Description

@KeremKurban

I was runing train.py with recent installation of libraries. I think there is a mismatch of versions such that im getting

 File "../venv2023/lib/python3.8/site-packages/deepchem/feat/graph_data.py", line 151, in to_pyg_graph
    return Data(x=torch.from_numpy(self.node_features).float(),
TypeError: type object got multiple values for keyword argument 'pos'

I found a workaround by ignoring the positional information since f=featurizer._featurize(mol) later shows:

>>>f
GraphData(node_features=[75, 30], edge_index=[2, 162], edge_features=[162, 11], pos=[0])

The workaround is to write a custom function to convert into pyg_graph from f

    def _custom_to_pyg_graph(self,graph_data):
        from torch_geometric.data import Data
        return Data(x=torch.from_numpy(graph_data.node_features).float(),
                    edge_index=torch.from_numpy(graph_data.edge_index).long(),
                    edge_attr=torch.from_numpy(graph_data.edge_features).float())

    def process(self):
        self.data = pd.read_csv(self.raw_paths[0]).reset_index()
        featurizer = dc.feat.MolGraphConvFeaturizer(use_edges=True)
        for index, row in tqdm(self.data.iterrows(), total=self.data.shape[0]):
            # Featurize molecule
            mol = Chem.MolFromSmiles(row["smiles"])
            f = featurizer._featurize(mol)
            data = self._custom_to_pyg_graph(f)
            # data = f.to_pyg_graph()
            data.y = self._get_label(row["HIV_active"])
            data.smiles = row["smiles"]
            if self.test:
                torch.save(data, 
                    os.path.join(self.processed_dir, 
                                 f'data_test_{index}.pt'))
            else:
                torch.save(data, 
                    os.path.join(self.processed_dir, 
                                 f'data_{index}.pt'))

So far it is working in processing. But future versions with positions included needs to considered for general purpose solution.

Also, perhaps requirements didnt have some of the toolboxes like deepchem , providing a version for each tool or dockerizing the venv you have used could help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions