Skip to content

Instantly share code, notes, and snippets.

View marta-sd's full-sized avatar

Marta Stepniewska-Dziubinska marta-sd

View GitHub Profile
@marta-sd
marta-sd / backward_hook.py
Created November 19, 2022 12:57
Example of using backward hooks
import torch
from torch import nn
class Net(nn.Module):
def __init__(self):
super().__init__()
self.l1 = nn.Sequential(nn.Linear(8, 64), nn.ReLU(), nn.Linear(64, 2))
self.l2 = nn.Sequential(nn.Linear(64, 64), nn.ReLU(), nn.Linear(64, 2))
self.relu = nn.ReLU()
def forward(self, x, y):
# before running this script clone Pafnucy's repository and create the environment:
# $ git clone https://gitlab.com/cheminfIBB/pafnucy
# $ cd pafnucy
# $ conda env create -f environment_gpu.yml
import numpy as np
import h5py
import tensorflow as tf
@marta-sd
marta-sd / prepare.py
Created November 29, 2018 08:08
Prepare antibody data for Pafnucy
import numpy as np
import pandas as pd
import h5py
import pybel
from tfbio.data import Featurizer
import os
@marta-sd
marta-sd / decaf_merge.py
Created January 17, 2018 18:04
Merge multiple molecules in DeCAF
from rdkit.Chem import MolFromSmiles
from decaf.toolkits.rd import phar_from_mol
from decaf.utils import similarity, combine_pharmacophores, draw, filter_nodes
from scipy.cluster.hierarchy import average as avg_clustering
from scipy.spatial.distance import squareform
smiles = [
'c1cc(cc(c1)N)c2cc(cc(c2O)c3[nH]c4ccc(cc4n3)C(=N)N)Cl',
'c1cc(cc(c1)N(=O)=O)c2cc(cc(c2O)c3cc4cc(ccc4[nH]3)C(=N)N)C(CC(=O)O)C(=O)O',
@marta-sd
marta-sd / siamese.py
Created December 14, 2017 11:16
Load pretrained model as legs of siamese netwrok
import tensorflow as tf
# 1. Create and save a network
# c = a*b
g = tf.Graph()
with g.as_default():
a = tf.placeholder(tf.float32, name='a')
b = tf.Variable(initial_value=tf.truncated_normal((1,)), name='b')
c = tf.multiply(a, b, name='c')
@marta-sd
marta-sd / generators.py
Created November 29, 2017 08:18
Data generators
from random import shuffle
def example_generator(*lists, random_order=True):
"""Create infinite generator of examples.
example_generator([3, 6, 8], [0, 0, 1]) -> (6,0), (3,0), (8,1), (3,0)...
"""
assert len(lists) > 0, 'no lists provided'
@marta-sd
marta-sd / tf_merge.py
Last active February 10, 2022 10:08
Merge two models in TensorFlow
import tensorflow as tf
# 1. Create and save two graphs
# c = a*b
g1 = tf.Graph()
with g1.as_default():
a = tf.placeholder(tf.float32, name='a')
b = tf.Variable(initial_value=tf.truncated_normal((1,)), name='b')