From f30ec5fe651158c81a123e256af581badc3c8f02 Mon Sep 17 00:00:00 2001 From: suleymanov Date: Sat, 14 Sep 2019 17:58:48 +0300 Subject: [PATCH 1/2] reorganize, add setup.py, requirements --- .../AttentiveFP => AttentiveFP}/AttentiveLayers.py | 0 .../AttentiveLayers_viz.py | 0 {code/AttentiveFP => AttentiveFP}/Featurizer.py | 0 .../Featurizer_aromaticity_rm.py | 0 {code/AttentiveFP => AttentiveFP}/__init__.py | 0 {code/AttentiveFP => AttentiveFP}/getFeatures.py | 0 .../getFeatures_aromaticity_rm.py | 0 .../1_POC_test_Malaria_Bioactivity.ipynb | 0 .../1_POC_test_Photovoltaic_efficiency.ipynb | 0 {code => notebooks}/1_POC_test_Solubility.ipynb | 0 {code => notebooks}/2_Bioactivity_BACE.ipynb | 0 {code => notebooks}/2_Bioactivity_HIV.ipynb | 0 {code => notebooks}/2_Bioactivity_MUV.ipynb | 0 .../2_Physical_Chemistry_ESOL.ipynb | 0 .../2_Physical_Chemistry_FreeSolv.ipynb | 0 .../2_Physical_Chemistry_Lipop.ipynb | 0 .../2_Physiology_or_Toxicity_BBBP.ipynb | 0 .../2_Physiology_or_Toxicity_ClinTox.ipynb | 0 .../2_Physiology_or_Toxicity_SIDER.ipynb | 0 .../2_Physiology_or_Toxicity_Tox21.ipynb | 0 .../2_Physiology_or_Toxicity_ToxCast.ipynb | 0 {code => notebooks}/3_qm9.ipynb | 0 ...ure_visualization_of_Learning_aromaticity.ipynb | 0 ...g_hidden_environment_and_water_solubility.ipynb | 0 {code => notebooks}/LICENSE | 0 {code => notebooks}/fpscores.pkl.gz | Bin .../hyper_parameter_search_Solubility.py | 0 {code => notebooks}/run | 0 {code => notebooks}/sascorer.py | 0 {code => notebooks}/saved_models/placeholder | 0 requirements.txt | 4 ++++ setup.py | 13 +++++++++++++ 32 files changed, 17 insertions(+) rename {code/AttentiveFP => AttentiveFP}/AttentiveLayers.py (100%) rename {code/AttentiveFP => AttentiveFP}/AttentiveLayers_viz.py (100%) rename {code/AttentiveFP => AttentiveFP}/Featurizer.py (100%) rename {code/AttentiveFP => AttentiveFP}/Featurizer_aromaticity_rm.py (100%) rename {code/AttentiveFP => AttentiveFP}/__init__.py (100%) rename {code/AttentiveFP => AttentiveFP}/getFeatures.py (100%) rename {code/AttentiveFP => AttentiveFP}/getFeatures_aromaticity_rm.py (100%) rename {code => notebooks}/1_POC_test_Malaria_Bioactivity.ipynb (100%) rename {code => notebooks}/1_POC_test_Photovoltaic_efficiency.ipynb (100%) rename {code => notebooks}/1_POC_test_Solubility.ipynb (100%) rename {code => notebooks}/2_Bioactivity_BACE.ipynb (100%) rename {code => notebooks}/2_Bioactivity_HIV.ipynb (100%) rename {code => notebooks}/2_Bioactivity_MUV.ipynb (100%) rename {code => notebooks}/2_Physical_Chemistry_ESOL.ipynb (100%) rename {code => notebooks}/2_Physical_Chemistry_FreeSolv.ipynb (100%) rename {code => notebooks}/2_Physical_Chemistry_Lipop.ipynb (100%) rename {code => notebooks}/2_Physiology_or_Toxicity_BBBP.ipynb (100%) rename {code => notebooks}/2_Physiology_or_Toxicity_ClinTox.ipynb (100%) rename {code => notebooks}/2_Physiology_or_Toxicity_SIDER.ipynb (100%) rename {code => notebooks}/2_Physiology_or_Toxicity_Tox21.ipynb (100%) rename {code => notebooks}/2_Physiology_or_Toxicity_ToxCast.ipynb (100%) rename {code => notebooks}/3_qm9.ipynb (100%) rename {code => notebooks}/Feature_visualization_of_Learning_aromaticity.ipynb (100%) rename {code => notebooks}/Feature_visualization_of_Learning_hidden_environment_and_water_solubility.ipynb (100%) rename {code => notebooks}/LICENSE (100%) rename {code => notebooks}/fpscores.pkl.gz (100%) rename {code => notebooks}/hyper_parameter_search_Solubility.py (100%) rename {code => notebooks}/run (100%) rename {code => notebooks}/sascorer.py (100%) rename {code => notebooks}/saved_models/placeholder (100%) create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/code/AttentiveFP/AttentiveLayers.py b/AttentiveFP/AttentiveLayers.py similarity index 100% rename from code/AttentiveFP/AttentiveLayers.py rename to AttentiveFP/AttentiveLayers.py diff --git a/code/AttentiveFP/AttentiveLayers_viz.py b/AttentiveFP/AttentiveLayers_viz.py similarity index 100% rename from code/AttentiveFP/AttentiveLayers_viz.py rename to AttentiveFP/AttentiveLayers_viz.py diff --git a/code/AttentiveFP/Featurizer.py b/AttentiveFP/Featurizer.py similarity index 100% rename from code/AttentiveFP/Featurizer.py rename to AttentiveFP/Featurizer.py diff --git a/code/AttentiveFP/Featurizer_aromaticity_rm.py b/AttentiveFP/Featurizer_aromaticity_rm.py similarity index 100% rename from code/AttentiveFP/Featurizer_aromaticity_rm.py rename to AttentiveFP/Featurizer_aromaticity_rm.py diff --git a/code/AttentiveFP/__init__.py b/AttentiveFP/__init__.py similarity index 100% rename from code/AttentiveFP/__init__.py rename to AttentiveFP/__init__.py diff --git a/code/AttentiveFP/getFeatures.py b/AttentiveFP/getFeatures.py similarity index 100% rename from code/AttentiveFP/getFeatures.py rename to AttentiveFP/getFeatures.py diff --git a/code/AttentiveFP/getFeatures_aromaticity_rm.py b/AttentiveFP/getFeatures_aromaticity_rm.py similarity index 100% rename from code/AttentiveFP/getFeatures_aromaticity_rm.py rename to AttentiveFP/getFeatures_aromaticity_rm.py diff --git a/code/1_POC_test_Malaria_Bioactivity.ipynb b/notebooks/1_POC_test_Malaria_Bioactivity.ipynb similarity index 100% rename from code/1_POC_test_Malaria_Bioactivity.ipynb rename to notebooks/1_POC_test_Malaria_Bioactivity.ipynb diff --git a/code/1_POC_test_Photovoltaic_efficiency.ipynb b/notebooks/1_POC_test_Photovoltaic_efficiency.ipynb similarity index 100% rename from code/1_POC_test_Photovoltaic_efficiency.ipynb rename to notebooks/1_POC_test_Photovoltaic_efficiency.ipynb diff --git a/code/1_POC_test_Solubility.ipynb b/notebooks/1_POC_test_Solubility.ipynb similarity index 100% rename from code/1_POC_test_Solubility.ipynb rename to notebooks/1_POC_test_Solubility.ipynb diff --git a/code/2_Bioactivity_BACE.ipynb b/notebooks/2_Bioactivity_BACE.ipynb similarity index 100% rename from code/2_Bioactivity_BACE.ipynb rename to notebooks/2_Bioactivity_BACE.ipynb diff --git a/code/2_Bioactivity_HIV.ipynb b/notebooks/2_Bioactivity_HIV.ipynb similarity index 100% rename from code/2_Bioactivity_HIV.ipynb rename to notebooks/2_Bioactivity_HIV.ipynb diff --git a/code/2_Bioactivity_MUV.ipynb b/notebooks/2_Bioactivity_MUV.ipynb similarity index 100% rename from code/2_Bioactivity_MUV.ipynb rename to notebooks/2_Bioactivity_MUV.ipynb diff --git a/code/2_Physical_Chemistry_ESOL.ipynb b/notebooks/2_Physical_Chemistry_ESOL.ipynb similarity index 100% rename from code/2_Physical_Chemistry_ESOL.ipynb rename to notebooks/2_Physical_Chemistry_ESOL.ipynb diff --git a/code/2_Physical_Chemistry_FreeSolv.ipynb b/notebooks/2_Physical_Chemistry_FreeSolv.ipynb similarity index 100% rename from code/2_Physical_Chemistry_FreeSolv.ipynb rename to notebooks/2_Physical_Chemistry_FreeSolv.ipynb diff --git a/code/2_Physical_Chemistry_Lipop.ipynb b/notebooks/2_Physical_Chemistry_Lipop.ipynb similarity index 100% rename from code/2_Physical_Chemistry_Lipop.ipynb rename to notebooks/2_Physical_Chemistry_Lipop.ipynb diff --git a/code/2_Physiology_or_Toxicity_BBBP.ipynb b/notebooks/2_Physiology_or_Toxicity_BBBP.ipynb similarity index 100% rename from code/2_Physiology_or_Toxicity_BBBP.ipynb rename to notebooks/2_Physiology_or_Toxicity_BBBP.ipynb diff --git a/code/2_Physiology_or_Toxicity_ClinTox.ipynb b/notebooks/2_Physiology_or_Toxicity_ClinTox.ipynb similarity index 100% rename from code/2_Physiology_or_Toxicity_ClinTox.ipynb rename to notebooks/2_Physiology_or_Toxicity_ClinTox.ipynb diff --git a/code/2_Physiology_or_Toxicity_SIDER.ipynb b/notebooks/2_Physiology_or_Toxicity_SIDER.ipynb similarity index 100% rename from code/2_Physiology_or_Toxicity_SIDER.ipynb rename to notebooks/2_Physiology_or_Toxicity_SIDER.ipynb diff --git a/code/2_Physiology_or_Toxicity_Tox21.ipynb b/notebooks/2_Physiology_or_Toxicity_Tox21.ipynb similarity index 100% rename from code/2_Physiology_or_Toxicity_Tox21.ipynb rename to notebooks/2_Physiology_or_Toxicity_Tox21.ipynb diff --git a/code/2_Physiology_or_Toxicity_ToxCast.ipynb b/notebooks/2_Physiology_or_Toxicity_ToxCast.ipynb similarity index 100% rename from code/2_Physiology_or_Toxicity_ToxCast.ipynb rename to notebooks/2_Physiology_or_Toxicity_ToxCast.ipynb diff --git a/code/3_qm9.ipynb b/notebooks/3_qm9.ipynb similarity index 100% rename from code/3_qm9.ipynb rename to notebooks/3_qm9.ipynb diff --git a/code/Feature_visualization_of_Learning_aromaticity.ipynb b/notebooks/Feature_visualization_of_Learning_aromaticity.ipynb similarity index 100% rename from code/Feature_visualization_of_Learning_aromaticity.ipynb rename to notebooks/Feature_visualization_of_Learning_aromaticity.ipynb diff --git a/code/Feature_visualization_of_Learning_hidden_environment_and_water_solubility.ipynb b/notebooks/Feature_visualization_of_Learning_hidden_environment_and_water_solubility.ipynb similarity index 100% rename from code/Feature_visualization_of_Learning_hidden_environment_and_water_solubility.ipynb rename to notebooks/Feature_visualization_of_Learning_hidden_environment_and_water_solubility.ipynb diff --git a/code/LICENSE b/notebooks/LICENSE similarity index 100% rename from code/LICENSE rename to notebooks/LICENSE diff --git a/code/fpscores.pkl.gz b/notebooks/fpscores.pkl.gz similarity index 100% rename from code/fpscores.pkl.gz rename to notebooks/fpscores.pkl.gz diff --git a/code/hyper_parameter_search_Solubility.py b/notebooks/hyper_parameter_search_Solubility.py similarity index 100% rename from code/hyper_parameter_search_Solubility.py rename to notebooks/hyper_parameter_search_Solubility.py diff --git a/code/run b/notebooks/run similarity index 100% rename from code/run rename to notebooks/run diff --git a/code/sascorer.py b/notebooks/sascorer.py similarity index 100% rename from code/sascorer.py rename to notebooks/sascorer.py diff --git a/code/saved_models/placeholder b/notebooks/saved_models/placeholder similarity index 100% rename from code/saved_models/placeholder rename to notebooks/saved_models/placeholder diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e936798 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +torch==1.0.1.post2 +rdkit==2019.03.1 +numpy==1.16.2 +matplotlib==3.0.3 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1963323 --- /dev/null +++ b/setup.py @@ -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'] +) From 07255fa4b2de6da15a087a029c9d784e095502e9 Mon Sep 17 00:00:00 2001 From: Suleimanov Date: Fri, 4 Oct 2019 12:42:40 +0300 Subject: [PATCH 2/2] Cast tensors to Float depending on device type --- AttentiveFP/AttentiveLayers.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/AttentiveFP/AttentiveLayers.py b/AttentiveFP/AttentiveLayers.py index 7b2c8bc..e6522d4 100644 --- a/AttentiveFP/AttentiveLayers.py +++ b/AttentiveFP/AttentiveLayers.py @@ -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) @@ -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) @@ -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): @@ -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 \ No newline at end of file + return atom_feature, mol_prediction + + def _cast_float(self, x): + return x.type(torch.cuda.FloatTensor if x.is_cuda else torch.FloatTensor)