forked from h4gen/dtnn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize.py
More file actions
64 lines (52 loc) · 1.47 KB
/
Copy pathvisualize.py
File metadata and controls
64 lines (52 loc) · 1.47 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 16 16:14:52 2018
@author: hagen
"""
import argparse
import os
import numpy as np
import tensorflow as tf
from ase.db import connect
from ase.visualize import mlab
from ase.visualize import view
from ase.io import read
import copy
from dtnn.models import DTNN
model_dir='output/DTNN_64_64_3_20.0_split_1'
split_dir='output/split_1'
atom0 = read('conversion/5779.xyz')
r_vec = atom0.positions[1] - atom0.positions[16]
features = {
'numbers': tf.placeholder(tf.int64, shape=(None,)),
'positions': tf.placeholder(tf.float32, shape=(None, 3)),
'cell': np.eye(3).astype(np.float32),
'pbc': np.zeros((3,)).astype(np.int64)
}
model = DTNN(model_dir)
model_output = model.get_output(features, is_training=False)
y = model_output['y']
#%%
fac = np.linspace(0,2,10)
u = []
for a in range(100):
atom0.positions[16] += .01*r_vec
# print(atom0.positions)
u.append(predict(atom0))
#%%
def predict(X):
with tf.Session() as sess:
model.restore(sess)
feed_dict = {
features['numbers']:
np.array(X.numbers).astype(np.int64),
features['positions']:
np.array(X.positions).astype(np.float32)
}
U0_p = sess.run(y, feed_dict=feed_dict)
# g = tf.get_default_graph()
# with g.gradient_override_map({"Tile": "TileDense"}):
# ret = tf.gradients(y, features['positions'])
# print(ret)
return U0_p