Jach

  • Home

  • About

  • Tags

  • Categories

  • Archives

Graph Laplacian Operator

Posted on 2019-03-15 | Edited on 2019-03-16 | In math

Graph Laplacian Operator

Let \(L\) be the Laplacian operator

Let \(f(x,y)​\) be \[ L: f \Longrightarrow \frac{\partial^2 f}{\partial x^2}+\frac{\partial^2 f}{\partial y^2}\tag{0} \]

Then Laplace equation refers to \(Lf=0\), thus \[ \frac{\partial^2 f(x,y)}{\partial x^2}+\frac{\partial^2f(x,y)}{\partial y^2}=0 \tag{1} \] A function satisfies formula (1) is called Harmonic function. Then lets discretize this function.

Assume \(f\) is a real function on \(\mathbb{Z}\), let's define \(f'\) a function on \(\mathbb{Z}+\frac{1}{2}\), and \(f'(\frac{1}{2}+n)=f(n+1)-f(n)\), eg. \(f'(\frac{1}{2})=f(1)-f(0)\). Then the second-order differential becomes a function on \(\mathbb{Z}\), and \(f''(n)=f(n+1)+f(n-1)-2f(n)\).

Considering 2-D situation, define \(f\) a function on \(\mathbb{Z}^2\), and formula (1) becomes: \[ f(x+1,y)+f(x-1,y)+f(x,y+1)+f(x,y-1)-4f(x,y)=0 \tag{2} \] Formula (2) demonstrates the value of \(f\) on \((x,y)\) equals to average value of 4 points around \((x,y)\). Then we spread the conception to simple undirected graphs.

Define a simple undirected graph \(G=(V,E)​\), whose adjacency matrix is \(A​\) and degree matrix is \(D​\). The let \(L=D-A​\). Define \(f​\) a function on \(V​\), and the value of \(f(v)​\) on each node equals to the average value of nodes connected directly with this node, thus \[ \forall v\in V, f(v)=\frac{1}{\left|N(v)\right|}\sum_{u\in N(v)}f(u) \tag{3} \] among which \(N(v)=\{u\in V|uv \in E\}\)

We can consider \(f\) a vector on \(\mathbb{R}^n\), still written as \(f\). \[ V={v_1, v_2, \ldots,v_n} \\ \\ f = \begin{pmatrix} f(v_1)\\ f(v_2)\\ \vdots\\ f(v_n) \end{pmatrix} \tag{4} \] We can transform the condition a vector form: \[ (D-A)f=0 \Rightarrow Lf=0 \tag{5} \]

Scaffold network generator

Posted on 2019-03-15 | In python

Scaffold Network Generator

Repo

Github

Usage

1
2
3
git clone [email protected]:jach4/scaffold_network_generator.git sng
cd sng
python scaffolds_output.py --np=50 --file_input=data/datasets/input.smi --scaffolds_output=data/datasets/scaffolds.smi --file_output=data/datasets/scaffolds.bin

Read the entire scaffold message from a file

1
2
3
4
5
6
7
8
9
10
from data import *
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole

dic = DicSmScaffoldLs()
with open('data/datasets/scaffolds.bin','rb') as f:
dic.ParseFromString(f.read())

print(len(dic.smiles_scaffold))
1
402344

Get the 1990th scaffold

1
2
print(scaffold_smiles_idx(1990))
Chem.MolFromSmiles(scaffold_smiles_idx(1990))
1
c1n[nH]nc1-c1nnc(-c2cnns2)o1
png
png
1
dic.smiles_scaffold[scaffold_smiles_idx(1990)]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
dic_mol_atoms {
idx_mol: 111921
ls_atom {
idx_atom: 1
idx_atom: 2
idx_atom: 3
idx_atom: 10
idx_atom: 11
idx_atom: 12
idx_atom: 13
idx_atom: 14
idx_atom: 15
idx_atom: 16
idx_atom: 17
idx_atom: 18
idx_atom: 19
idx_atom: 20
idx_atom: 22
}
ls_nh {
idx_atom: 3
}
ls_np {
}
}

The 111,921th molecule containing the 6th scaffold

1
Chem.MolFromSmiles(smiles_from_line(111921))
png
png

Get the scaffold network of The 111,921th molecule

1
scaffold_list = get_mol_graph(smiles_from_line(111921)).ls_mol_from_sng_u()
1
Draw.MolsToGridImage(scaffold_list)
png
png

My 1st blog

Posted on 2019-03-13 | Edited on 2019-03-20 | In python
1
2
3
4
5
6
7
8
9
10
11
# to save a pytorch model
# adopted from https://github.com/CanisW
def save_model(model, version, state, epoch, log_file_obj):
t = time.strftime('%Y-%m-%d-%H:%M', time.localtime(time.time()))
torch.save(model.state_dict(), "./checkpoint/ForceFieldFeatNet{}_Epoch{}_{}_{}.pt".format(version, str(epoch), state, t))
log = 'Checkpoint Saved at ' + t + '.'
print(log)
log_file_obj.write(log + '\n')
log_file_obj.flush()
with open('training.log', 'a') as f:
save(model, version, 'checkpoint', epoch_l, f)
Jach

Jach

3 posts
2 categories
4 tags
GitHub E-Mail Weibo Twitter
© 2019 Jach
Powered by Hexo v3.8.0
|
Theme – NexT.Muse v7.0.1