Skip to content

Commit

Permalink
fix mapping (issue deepchem#3057)
Browse files Browse the repository at this point in the history
  • Loading branch information
ARY2260 committed Sep 6, 2022
1 parent fed8ae5 commit 4b50728
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion deepchem/models/tests/test_mapper_dmpnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
has_torch = False

# Set up tests.
smiles_list = ["C", "CC", "CCC", "C1=CC=CC=C1"]
smiles_list = ["C", "CC", "CCC", "C1=CC=CC=C1", "[I-].[K+]"]
featurizer = DMPNNFeaturizer(use_original_atom_ranks=True,
features_generators=['morgan'])
graphs = featurizer.featurize(smiles_list)
Expand Down Expand Up @@ -97,3 +97,14 @@ def test_mapper_ring():
assert (
mapper.atom_to_incoming_bonds == benezene_atom_to_incoming_bonds).all()
assert (mapper.mapping == benezene_mapping).all()


@pytest.mark.torch
def test_mapper_disconnected_compounds():
"""
Test '[I-].[K+]' in _MapperDMPNN (disconnected compounds)
"""
mapper = _MapperDMPNN(graphs[0])
assert (mapper.bond_to_ini_atom == np.empty(0)).all()
assert (mapper.atom_to_incoming_bonds == np.asarray([[-1], [-1]])).all()
assert (mapper.mapping == np.asarray([[-1]])).all()
7 changes: 4 additions & 3 deletions deepchem/models/torch_models/dmpnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def __init__(self, graph: GraphData):
self.f_ini_atoms_bonds = np.zeros(
(1, self.num_atom_features + self.num_bond_features))

self.atom_to_incoming_bonds = np.asarray([[-1]], dtype=int)
self.atom_to_incoming_bonds = np.asarray([[-1]] * self.num_atoms,
dtype=int)
self.mapping = np.asarray([[-1]], dtype=int)

else:
Expand Down Expand Up @@ -435,14 +436,14 @@ class DMPNNModel(TorchModel):
.. note::
Current implementation of the DMPNNModel class only supports features of 1 molecule per batch.
The DMPNN model has 2 phases, message-passing phase and read-out phase.
- The goal of the message-passing phase is to generate 'hidden states of all the atoms in the molecule' using encoders.
- Next in read-out phase, the features are passed into feed-forward neural network to get the task-based prediction.
For additional information:
- `Mapper class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/dmpnn.py#L10-L92>`_
- `Encoder layer class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/layers.py#L1223-L1374>`_
- `Feed-Forward class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/layers.py#L689-L700>`_
Expand Down

0 comments on commit 4b50728

Please sign in to comment.