Skip to content

Commit

Permalink
update test code of generate function
Browse files Browse the repository at this point in the history
  • Loading branch information
hswoo369 committed Apr 5, 2021
1 parent 078550a commit 4758279
Show file tree
Hide file tree
Showing 35 changed files with 598,997 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test_code/generate/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* Setting
- Set save_to_pickle (True/False) in [input.yaml] file
- Set save_directory (default: data/) in [input.yaml] file
- command "python run.py"
* Output
If code runs correctly, show "COMPLET" message
If created data file has wrong value, show "ERROR" message
50 changes: 50 additions & 0 deletions test_code/generate/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
generate_features: true
preprocess: false
train_model: false
atom_types:
- Si
- O

symmetry_function:
params:
Si: params_Si
O: params_O
valid_rate: 0.1
remain_pickle: True
compress_outcar: False
save_to_pickle: False
save_directory: data

neural_network:
pca: true
pca_whiten: true
weight_initializer:
type: he normal
save_criteria: []
batch_size: 20
continue: false
double_precision: true
energy_coeff: 1.0
force_coeff: 0.1
full_batch: false
cache: false
learning_rate: 0.0001
loss_scale: 1.0
acti_func: tanh
method: Adam
nodes: 30-30
optimizer: {}
print_structure_rmse: true
regularization:
type: l2
params:
coeff: 1.0e-8
save_interval: 200
show_interval: 200
test: false
total_iteration: 50000
train: true
use_force: true
use_stress: true
intra_op_parallelism_threads: 20
inter_op_parallelism_threads: 2
70 changes: 70 additions & 0 deletions test_code/generate/params_O
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
2 1 0 6.0 0.003214 0.0 0.0
2 1 0 6.0 0.035711 0.0 0.0
2 1 0 6.0 0.071421 0.0 0.0
2 1 0 6.0 0.124987 0.0 0.0
2 1 0 6.0 0.214264 0.0 0.0
2 1 0 6.0 0.357106 0.0 0.0
2 1 0 6.0 0.714213 0.0 0.0
2 1 0 6.0 1.428426 0.0 0.0
2 2 0 6.0 0.003214 0.0 0.0
2 2 0 6.0 0.035711 0.0 0.0
2 2 0 6.0 0.071421 0.0 0.0
2 2 0 6.0 0.124987 0.0 0.0
2 2 0 6.0 0.214264 0.0 0.0
2 2 0 6.0 0.357106 0.0 0.0
2 2 0 6.0 0.714213 0.0 0.0
2 2 0 6.0 1.428426 0.0 0.0
4 1 1 6.0 0.000357 1.0 -1.0
4 1 1 6.0 0.028569 1.0 -1.0
4 1 1 6.0 0.089277 1.0 -1.0
4 1 1 6.0 0.000357 2.0 -1.0
4 1 1 6.0 0.028569 2.0 -1.0
4 1 1 6.0 0.089277 2.0 -1.0
4 1 1 6.0 0.000357 4.0 -1.0
4 1 1 6.0 0.028569 4.0 -1.0
4 1 1 6.0 0.089277 4.0 -1.0
4 1 1 6.0 0.000357 1.0 1.0
4 1 1 6.0 0.028569 1.0 1.0
4 1 1 6.0 0.089277 1.0 1.0
4 1 1 6.0 0.000357 2.0 1.0
4 1 1 6.0 0.028569 2.0 1.0
4 1 1 6.0 0.089277 2.0 1.0
4 1 1 6.0 0.000357 4.0 1.0
4 1 1 6.0 0.028569 4.0 1.0
4 1 1 6.0 0.089277 4.0 1.0
4 1 2 6.0 0.000357 1.0 -1.0
4 1 2 6.0 0.028569 1.0 -1.0
4 1 2 6.0 0.089277 1.0 -1.0
4 1 2 6.0 0.000357 2.0 -1.0
4 1 2 6.0 0.028569 2.0 -1.0
4 1 2 6.0 0.089277 2.0 -1.0
4 1 2 6.0 0.000357 4.0 -1.0
4 1 2 6.0 0.028569 4.0 -1.0
4 1 2 6.0 0.089277 4.0 -1.0
4 1 2 6.0 0.000357 1.0 1.0
4 1 2 6.0 0.028569 1.0 1.0
4 1 2 6.0 0.089277 1.0 1.0
4 1 2 6.0 0.000357 2.0 1.0
4 1 2 6.0 0.028569 2.0 1.0
4 1 2 6.0 0.089277 2.0 1.0
4 1 2 6.0 0.000357 4.0 1.0
4 1 2 6.0 0.028569 4.0 1.0
4 1 2 6.0 0.089277 4.0 1.0
4 2 2 6.0 0.000357 1.0 -1.0
4 2 2 6.0 0.028569 1.0 -1.0
4 2 2 6.0 0.089277 1.0 -1.0
4 2 2 6.0 0.000357 2.0 -1.0
4 2 2 6.0 0.028569 2.0 -1.0
4 2 2 6.0 0.089277 2.0 -1.0
4 2 2 6.0 0.000357 4.0 -1.0
4 2 2 6.0 0.028569 4.0 -1.0
4 2 2 6.0 0.089277 4.0 -1.0
4 2 2 6.0 0.000357 1.0 1.0
4 2 2 6.0 0.028569 1.0 1.0
4 2 2 6.0 0.089277 1.0 1.0
4 2 2 6.0 0.000357 2.0 1.0
4 2 2 6.0 0.028569 2.0 1.0
4 2 2 6.0 0.089277 2.0 1.0
4 2 2 6.0 0.000357 4.0 1.0
4 2 2 6.0 0.028569 4.0 1.0
4 2 2 6.0 0.089277 4.0 1.0
70 changes: 70 additions & 0 deletions test_code/generate/params_Si
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
2 1 0 6.0 0.003214 0.0 0.0
2 1 0 6.0 0.035711 0.0 0.0
2 1 0 6.0 0.071421 0.0 0.0
2 1 0 6.0 0.124987 0.0 0.0
2 1 0 6.0 0.214264 0.0 0.0
2 1 0 6.0 0.357106 0.0 0.0
2 1 0 6.0 0.714213 0.0 0.0
2 1 0 6.0 1.428426 0.0 0.0
2 2 0 6.0 0.003214 0.0 0.0
2 2 0 6.0 0.035711 0.0 0.0
2 2 0 6.0 0.071421 0.0 0.0
2 2 0 6.0 0.124987 0.0 0.0
2 2 0 6.0 0.214264 0.0 0.0
2 2 0 6.0 0.357106 0.0 0.0
2 2 0 6.0 0.714213 0.0 0.0
2 2 0 6.0 1.428426 0.0 0.0
4 1 1 6.0 0.000357 1.0 -1.0
4 1 1 6.0 0.028569 1.0 -1.0
4 1 1 6.0 0.089277 1.0 -1.0
4 1 1 6.0 0.000357 2.0 -1.0
4 1 1 6.0 0.028569 2.0 -1.0
4 1 1 6.0 0.089277 2.0 -1.0
4 1 1 6.0 0.000357 4.0 -1.0
4 1 1 6.0 0.028569 4.0 -1.0
4 1 1 6.0 0.089277 4.0 -1.0
4 1 1 6.0 0.000357 1.0 1.0
4 1 1 6.0 0.028569 1.0 1.0
4 1 1 6.0 0.089277 1.0 1.0
4 1 1 6.0 0.000357 2.0 1.0
4 1 1 6.0 0.028569 2.0 1.0
4 1 1 6.0 0.089277 2.0 1.0
4 1 1 6.0 0.000357 4.0 1.0
4 1 1 6.0 0.028569 4.0 1.0
4 1 1 6.0 0.089277 4.0 1.0
4 1 2 6.0 0.000357 1.0 -1.0
4 1 2 6.0 0.028569 1.0 -1.0
4 1 2 6.0 0.089277 1.0 -1.0
4 1 2 6.0 0.000357 2.0 -1.0
4 1 2 6.0 0.028569 2.0 -1.0
4 1 2 6.0 0.089277 2.0 -1.0
4 1 2 6.0 0.000357 4.0 -1.0
4 1 2 6.0 0.028569 4.0 -1.0
4 1 2 6.0 0.089277 4.0 -1.0
4 1 2 6.0 0.000357 1.0 1.0
4 1 2 6.0 0.028569 1.0 1.0
4 1 2 6.0 0.089277 1.0 1.0
4 1 2 6.0 0.000357 2.0 1.0
4 1 2 6.0 0.028569 2.0 1.0
4 1 2 6.0 0.089277 2.0 1.0
4 1 2 6.0 0.000357 4.0 1.0
4 1 2 6.0 0.028569 4.0 1.0
4 1 2 6.0 0.089277 4.0 1.0
4 2 2 6.0 0.000357 1.0 -1.0
4 2 2 6.0 0.028569 1.0 -1.0
4 2 2 6.0 0.089277 1.0 -1.0
4 2 2 6.0 0.000357 2.0 -1.0
4 2 2 6.0 0.028569 2.0 -1.0
4 2 2 6.0 0.089277 2.0 -1.0
4 2 2 6.0 0.000357 4.0 -1.0
4 2 2 6.0 0.028569 4.0 -1.0
4 2 2 6.0 0.089277 4.0 -1.0
4 2 2 6.0 0.000357 1.0 1.0
4 2 2 6.0 0.028569 1.0 1.0
4 2 2 6.0 0.089277 1.0 1.0
4 2 2 6.0 0.000357 2.0 1.0
4 2 2 6.0 0.028569 2.0 1.0
4 2 2 6.0 0.089277 2.0 1.0
4 2 2 6.0 0.000357 4.0 1.0
4 2 2 6.0 0.028569 4.0 1.0
4 2 2 6.0 0.089277 4.0 1.0
61 changes: 61 additions & 0 deletions test_code/generate/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sys
sys.path.append('../../')

from simple_nn_v2 import Simple_nn
from simple_nn_v2.features.symmetry_function import Symmetry_function

# 1. Make data files
model = Simple_nn('input.yaml', descriptor=Symmetry_function())
descriptor = Symmetry_function()
descriptor.parent = model
descriptor.set_inputs()

print("Making data files...")
descriptor.generate()
print("Done!")

# 2. Check if values are same as SIMPLE-NN ver.1
import pickle
import torch

f=open('../test_data/SiO2/data1.pickle', 'rb')
d1=pickle.load(f)
f.close()

DIR = descriptor.inputs['save_directory']
if descriptor.inputs['save_to_pickle'] == True:
f=open(DIR+'/data1.pickle', 'rb')
d2=pickle.load(f)
f.close()
else:
d2=torch.load(DIR+'/data1.pt')

err_key = 0

def comp(d1, d2):
if type(d1) == dict:
for key in d1.keys():
comp(d1[key], d2[key])
elif type(d1) == int or type(d1) == float or type(d1) == str:
if d1 != d2:
err_key = 1
else:
comp_list(d1, d2)

def comp_list(l1, l2):
try: # if l1 is list, numpy array type
len(l1)
for i in range(len(l1)):
comp_list(l1[i], l2[i])
except: # if l1 is single value
if l1 != l2:
err_key = 1

print("\nChecking data file values...")

comp(d1, d2)

if err_key == 0:
print("COMPLET: generate data Ok!")
else:
print("ERROR: Wrong value in data file")
1 change: 1 addition & 0 deletions test_code/generate/str_list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../test_data/SiO2/OUTCAR_comp :30:10
53 changes: 53 additions & 0 deletions test_code/generate/test_function/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
1. parsing_symf_params.py : test _parsing_symf_params()
*Setting
input.yaml : match [symmetry_function][params] files to [atom_types]
params_XX : prepare for all atom_types
*Output
- Check if all atom_types in symf_params_set keys
- Check if ['i', 'total', 'num', 'd'] keys are in all atom types
- Check if ['num'] value is matched with symmetry function numbers in params_XX
- If value in ['i'], ['d'] or ['total'] is not mathed with params_XX value, show mismatch index in screen
Else, "ok" sign in screen

2. get_structure_info.py : test _get_structure_info()
*Setting
set OUTCAR file path in "FILE" variable in [_get_structure_info.py] in line 22
*Ouput
- Check if "atom_num" is total atom number
- Check "type_num" has correct element types and atom number for each elements
- Check if atom_type_idx has correct values
- Check "type_atom_idx" has correct atom index
- Check lattice parameter
- Check Cartesian coordination in "cart" (first 5, last 5 coordination)
- Check Fractional coordination in "scale" (first 5, last 5 coordination)

3. init_result.py : test _init_result()
*Setting
set OUTCAR file path in "FILE" variable in [_init_result.py] in line 23
set example "structure_tags", "structure_weights", "idx" in line 31~33
*Output
- Chcek if 'x', 'dx', 'da', 'params' is empty dictionary
- Check if 'N' has correct element types and atom number for each elements
- Check if 'tot_num' has total atom number
- Check if 'struct_type', 'struct_weight' has correct tag, weight with correspond to idx
- Check if 'atom_idx' set correctly

4. init_sf_variables.py : test _init_sf_variables()
*Setting
set OUTCAR file path in "FILE" variable in [_init_sf_variables.py] in line 25
*Output
- Check if "jtem" atom number is correct
- Check if "jtem" atom idx is correct
- Check if 'x', 'dx', 'da' is initialze to 0

5. set_result.py : test _set_result()
*Setting
set OUTCAR file path in "FILE" variable in [_init_sf_variables.py] in line 33
*Output
- Check if 'N', 'tot_num', 'struct_type', 'struct_weight' is identical to test3 results
- Check if 'x', 'dx', 'da' has available values (didn't check if has identical values)
- Check if 'E', 'F', 'S' value extract correctly

6. datagenerator.py : test datagenerator() in util/
*Output

Loading

0 comments on commit 4758279

Please sign in to comment.