Commit 0b5a2a23 authored by Harrison Green's avatar Harrison Green
Browse files

gpu grid generation + rotation/translation

parent 6f845986
This diff is collapsed.
%% Cell type:code id: tags:
``` python
import grid_gpu2
import grid_gpu
import grid
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
import numpy as np
```
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
import os
import mol
```
%% Cell type:code id: tags:
``` python
mols = []
targets = [x for x in os.listdir('../data/mol/') if x[0] != '.']
for t in targets:
mols += mol.Mol.readfile(os.path.join('../data/mol/', t))
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
# atom types to consider
ATOM_TYPES = [
6, 7, 8, 9, 15, 16, 17, 35, 53
]
# mapping
# atomic number -> van der waals radius
VDW_RADIUS = {
6: 1.9,
7: 1.8,
8: 1.7,
9: 1.5,
15: 2.1,
16: 2.0,
17: 1.8,
35: 2.0,
53: 2.2
}
```
%% Cell type:code id: tags:
``` python
g2 = grid_gpu2.generate_grid_gpu(mols[0].atoms, ATOM_TYPES, VDW_RADIUS, mols[0].center(), 24, 0.5)
```
%% Cell type:code id: tags:
``` python
g0 = grid.generate_grid_cpu(mols[0].atoms, ATOM_TYPES, VDW_RADIUS, mols[0].center(), 24, 0.5)
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
np.max(np.abs(g0 - g2))
```
%% Output
0.029399282656419112
%% Cell type:code id: tags:
``` python
N = 10
i = 1
import time
```
%% Cell type:code id: tags:
``` python
a = time.time()
for i in range(N):
g = grid.generate_grid_cpu(mols[i].atoms, ATOM_TYPES, VDW_RADIUS, mols[i].center(), 24, 0.5)
b = time.time()
print('regular: %f' % (b - a))
```
%% Output
regular: 7.404712
%% Cell type:code id: tags:
``` python
a = time.time()
for i in range(N):
g1 = grid_gpu.generate_grid_gpu(mols[i].atoms, ATOM_TYPES, VDW_RADIUS, mols[i].center(), 24, 0.5)
b = time.time()
print('grid1: %f' % (b - a))
```
%% Output
grid1: 1.281223
%% Cell type:code id: tags:
``` python
a = time.time()
for i in range(N):
g2 = grid_gpu2.generate_grid_gpu(mols[i].atoms, ATOM_TYPES, VDW_RADIUS, mols[i].center(), 24, 0.5, rotation_vec=r)
b = time.time()
print('grid2: %f' % (b - a))
```
%% Output
grid2: 0.096580
%% Cell type:code id: tags:
``` python
r = rotation.rand_rot()
```
%% Cell type:code id: tags:
``` python
r
```
%% Output
(-0.68303215610766033,
0.01629461689893489,
0.6376531433702638,
0.35580897674603368)
%% Cell type:code id: tags:
``` python
np.save('grid_out_rot.npy', g2)
```
%% Cell type:code id: tags:
``` python
!ls
```
%% Output
Converter.ipynb grid_gpu.pyc model.py __pycache__ trainer.py
grid_gpu2.py grid_out.npy model.pyc Testing.ipynb trainer.pyc
grid_gpu2.pyc grid.py mol.py test.py Untitled.ipynb
grid_gpu.py grid.pyc mol.pyc todo.md
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
from keras.layers import Input, Dense
from keras.models import Model
```