Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup, allow run on cpu #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,23 @@ def forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom
attend_mask = atom_degree_list.clone()
attend_mask[attend_mask != mol_length-1] = 1
attend_mask[attend_mask == mol_length-1] = 0
attend_mask = attend_mask.type(torch.cuda.FloatTensor).unsqueeze(-1)
attend_mask = self._cast_float(attend_mask).unsqueeze(-1)

softmax_mask = atom_degree_list.clone()
softmax_mask[softmax_mask != mol_length-1] = 0
softmax_mask[softmax_mask == mol_length-1] = -9e8 # make the softmax value extremly small
softmax_mask = softmax_mask.type(torch.cuda.FloatTensor).unsqueeze(-1)
softmax_mask = self._cast_float(softmax_mask).unsqueeze(-1)

batch_size, mol_length, max_neighbor_num, fingerprint_dim = neighbor_feature.shape
atom_feature_expand = atom_feature.unsqueeze(-2).expand(batch_size, mol_length, max_neighbor_num, fingerprint_dim)
feature_align = torch.cat([atom_feature_expand, neighbor_feature],dim=-1)

align_score = F.leaky_relu(self.align[0](self.dropout(feature_align)))
# print(attention_weight)
align_score = align_score + softmax_mask
attention_weight = F.softmax(align_score,-2)
# print(attention_weight)
attention_weight = attention_weight * attend_mask
# print(attention_weight)
neighbor_feature_transform = self.attend[0](self.dropout(neighbor_feature))
# print(features_neighbor_transform.shape)
context = torch.sum(torch.mul(attention_weight,neighbor_feature_transform),-2)
# print(context.shape)
context = F.elu(context)
context_reshape = context.view(batch_size*mol_length, fingerprint_dim)
atom_feature_reshape = atom_feature.view(batch_size*mol_length, fingerprint_dim)
Expand All @@ -89,16 +84,11 @@ def forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom
feature_align = torch.cat([atom_feature_expand, neighbor_feature],dim=-1)

align_score = F.leaky_relu(self.align[d+1](self.dropout(feature_align)))
# print(attention_weight)
align_score = align_score + softmax_mask
attention_weight = F.softmax(align_score,-2)
# print(attention_weight)
attention_weight = attention_weight * attend_mask
# print(attention_weight)
neighbor_feature_transform = self.attend[d+1](self.dropout(neighbor_feature))
# print(features_neighbor_transform.shape)
context = torch.sum(torch.mul(attention_weight,neighbor_feature_transform),-2)
# print(context.shape)
context = F.elu(context)
context_reshape = context.view(batch_size*mol_length, fingerprint_dim)
# atom_feature_reshape = atom_feature.view(batch_size*mol_length, fingerprint_dim)
Expand All @@ -116,7 +106,7 @@ def forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom
mol_softmax_mask = atom_mask.clone()
mol_softmax_mask[mol_softmax_mask == 0] = -9e8
mol_softmax_mask[mol_softmax_mask == 1] = 0
mol_softmax_mask = mol_softmax_mask.type(torch.cuda.FloatTensor)
mol_softmax_mask = self._cast_float(mol_softmax_mask)

for t in range(self.T):

Expand All @@ -126,18 +116,17 @@ def forward(self, atom_list, bond_list, atom_degree_list, bond_degree_list, atom
mol_align_score = mol_align_score + mol_softmax_mask
mol_attention_weight = F.softmax(mol_align_score,-2)
mol_attention_weight = mol_attention_weight * atom_mask
# print(mol_attention_weight.shape,mol_attention_weight)
activated_features_transform = self.mol_attend(self.dropout(activated_features))
# aggregate embeddings of atoms in a molecule
mol_context = torch.sum(torch.mul(mol_attention_weight,activated_features_transform),-2)
# print(mol_context.shape,mol_context)
mol_context = F.elu(mol_context)
mol_feature = self.mol_GRUCell(mol_context, mol_feature)
# print(mol_feature.shape,mol_feature)

# do nonlinearity
activated_features_mol = F.relu(mol_feature)

mol_prediction = self.output(self.dropout(mol_feature))

return atom_feature, mol_prediction
return atom_feature, mol_prediction

def _cast_float(self, x):
return x.type(torch.cuda.FloatTensor if x.is_cuda else torch.FloatTensor)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
torch==1.0.1.post2
rdkit==2019.03.1
numpy==1.16.2
matplotlib==3.0.3
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import find_packages, setup


setup(
name='AttentiveFP',
version='0.0.1',
author='Erik Xiong',
description='Molecular representation using graph attention mechanism',
url='https://github.com/suleymanov/AttentiveFP',
license='MIT',
packages=find_packages(),
keywords=['chemistry', 'deep learning', 'graph attention']
)