def test_descriptor_one_side(self): jfile = 'water_se_a_type.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 1 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have(jdata['model']['descriptor'], 'rcut') sel = j_must_have(jdata['model']['descriptor'], 'sel') ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() numb_test = 1 # set parameters jdata['model']['descriptor']['neuron'] = [5, 5, 5] jdata['model']['descriptor']['axis_neuron'] = 2 jdata['model']['descriptor']['type_one_side'] = True typeebd_param = { 'neuron': [5, 5, 5], 'resnet_dt': False, 'seed': 1, } # init models typeebd = TypeEmbedNet(neuron=typeebd_param['neuron'], resnet_dt=typeebd_param['resnet_dt'], seed=typeebd_param['seed'], uniform_seed=True) jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed=True) # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']]) input_data = { 'coord': [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec': [test_data['natoms_vec']], 'default_mesh': [test_data['default_mesh']] } descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [ntypes + 2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') is_training = tf.placeholder(tf.bool) t_fparam = None type_embedding = typeebd.build(ntypes, suffix="_se_a_type_des_ebd_1side") dout \ = descrpt.build( t_coord, t_type, t_natoms, t_box, t_mesh, {'type_embedding' : type_embedding}, reuse = False, suffix = "_se_a_type_des_1side" ) feed_dict_test = { t_prop_c: test_data['prop_c'], t_energy: test_data['energy'][:numb_test], t_force: np.reshape(test_data['force'][:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]), t_box: test_data['box'][:numb_test, :], t_type: np.reshape(test_data['type'][:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], is_training: False } sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [model_dout] = sess.run([dout], feed_dict=feed_dict_test) model_dout = model_dout.reshape([-1]) ref_dout = [ 0.0009704469114440277, 0.0007136310372560243, 0.0007136310372560243, 0.000524968274824758, -0.0019790100690810016, -0.0014556100390424947, -0.001318691223889266, -0.0009698525512440269, 0.001937780602605409, 0.0014251755182315322, 0.0008158935519461114, 0.0005943870925895051, 0.0005943870925895051, 0.0004340263490412088, -0.0016539827195947239, -0.0012066241021841376, -0.0011042186455562336, -0.0008051343572505189, 0.0016229491738044255, 0.0011833923257801077, 0.0006020440527161554, 0.00047526899287409847, 0.00047526899287409847, 0.00037538142786805136, -0.0012811397377036637, -0.0010116898098710776, -0.0008465095301785942, -0.0006683577463042215, 0.0012459039620461505, 0.0009836962283627838, 0.00077088529431722, 0.0006105807630364827, 0.0006105807630364827, 0.00048361458700877996, -0.0016444700616024337, -0.001302510079662288, -0.0010856603485807576, -0.0008598975276238373, 0.00159730642327918, 0.001265146946434076, 0.0008495806081447204, 0.000671787466824433, 0.000671787466824433, 0.0005312928157964384, -0.0018105890543181475, -0.001431844407277983, -0.0011956722392735362, -0.000945544277375045, 0.0017590147511761475, 0.0013910348287283414, 0.0007393644735054756, 0.0005850536182149991, 0.0005850536182149991, 0.0004631887654949332, -0.0015760302086346792, -0.0012475134925387294, -0.001041074331192672, -0.0008239586048523492, 0.0015319673563669856, 0.0012124704278707746 ] places = 10 np.testing.assert_almost_equal(model_dout, ref_dout, places)
def test_descriptor_two_sides(self): jfile = 'water_se_a_type.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 2 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have(jdata['model']['descriptor'], 'rcut') sel = j_must_have(jdata['model']['descriptor'], 'sel') ntypes = len(sel) data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() numb_test = 1 # set parameters jdata['model']['descriptor']['neuron'] = [5, 5, 5] jdata['model']['descriptor']['axis_neuron'] = 2 typeebd_param = { 'neuron': [5, 5, 5], 'resnet_dt': False, 'seed': 1, } # init models typeebd = TypeEmbedNet(neuron=typeebd_param['neuron'], resnet_dt=typeebd_param['resnet_dt'], seed=typeebd_param['seed'], uniform_seed=True) jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed=True) # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']]) input_data = { 'coord': [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec': [test_data['natoms_vec']], 'default_mesh': [test_data['default_mesh']] } descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [ntypes + 2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') is_training = tf.placeholder(tf.bool) t_fparam = None type_embedding = typeebd.build(ntypes, suffix="_se_a_type_des_ebd_2sdies") dout \ = descrpt.build( t_coord, t_type, t_natoms, t_box, t_mesh, {'type_embedding' : type_embedding}, reuse = False, suffix = "_se_a_type_des_2sides" ) feed_dict_test = { t_prop_c: test_data['prop_c'], t_energy: test_data['energy'][:numb_test], t_force: np.reshape(test_data['force'][:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]), t_box: test_data['box'][:numb_test, :], t_type: np.reshape(test_data['type'][:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], is_training: False } sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [model_dout] = sess.run([dout], feed_dict=feed_dict_test) model_dout = model_dout.reshape([-1]) ref_dout = [ 0.0005722682145569174, -0.00020202686217742682, -0.00020202686217742682, 7.13250554992363e-05, -0.0014770058171250015, 0.000521468690207748, -0.001143865186937176, 0.0004038453384193948, 0.0005617335409639567, -0.00019831394075147532, 0.00048086740718842236, -0.0001693584775806112, -0.0001693584775806112, 5.966987137476082e-05, -0.0012342029581315136, 0.00043492340851472783, -0.0009566016612537016, 0.00033706767041080107, 0.00047065988464132244, -0.0001657950398095401, 0.0003647849239740657, -0.00013744939018250384, -0.00013744939018250384, 5.1825826955234744e-05, -0.00096004206555711, 0.00036185565262332876, -0.0007267433909643961, 0.0002738914365542745, 0.00038019365906978136, -0.00014322754331896057, 0.0004675256930823109, -0.00017634410399626168, -0.00017634410399626168, 6.652672908755666e-05, -0.0012328062885292486, 0.00046500213384094614, -0.0009328887521346069, 0.0003518668613172834, 0.0004877847509912577, -0.00018396318824508986, 0.0005154794374703516, -0.00019422534512034776, -0.00019422534512034776, 7.318151797939947e-05, -0.0013576642997136488, 0.0005115548790018505, -0.0010275333676074971, 0.00038716440070070385, 0.0005376426714609369, -0.00020257810468163985, 0.0004482204892297628, -0.00016887749501640607, -0.00016887749501640607, 6.364643102775375e-05, -0.001181345877677835, 0.0004452029242063362, -0.0008941636427724908, 0.0003369586197174627, 0.0004677878512312651, -0.00017625260641095753 ] places = 10 np.testing.assert_almost_equal(model_dout, ref_dout, places)
def test_model(self): jfile = 'water_se_a_type.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 1 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have (jdata['model']['descriptor'], 'rcut') data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt = None) test_data = data.get_test () numb_test = 1 jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed = True) jdata['model']['fitting_net']['descrpt'] = descrpt fitting = EnerFitting(**jdata['model']['fitting_net'], uniform_seed = True) typeebd_param = jdata['model']['type_embedding'] typeebd = TypeEmbedNet( neuron = typeebd_param['neuron'], resnet_dt = typeebd_param['resnet_dt'], seed = typeebd_param['seed'], uniform_seed = True) model = EnerModel(descrpt, fitting, typeebd) # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']]) input_data = {'coord' : [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec' : [test_data['natoms_vec']], 'default_mesh' : [test_data['default_mesh']] } model._compute_input_stat(input_data) model.descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [model.ntypes+2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') is_training = tf.placeholder(tf.bool) t_fparam = None inputs_dict = {} model_pred \ = model.build (t_coord, t_type, t_natoms, t_box, t_mesh, inputs_dict, suffix = "se_a_type", reuse = False) energy = model_pred['energy'] force = model_pred['force'] virial = model_pred['virial'] atom_ener = model_pred['atom_ener'] feed_dict_test = {t_prop_c: test_data['prop_c'], t_energy: test_data['energy'] [:numb_test], t_force: np.reshape(test_data['force'] [:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'] [:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'] [:numb_test, :], [-1]), t_box: test_data['box'] [:numb_test, :], t_type: np.reshape(test_data['type'] [:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], is_training: False} sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [e, f, v] = sess.run([energy, force, virial], feed_dict = feed_dict_test) # print(sess.run(model.type_embedding)) # np.savetxt('tmp.out', sess.run(descrpt.dout, feed_dict = feed_dict_test), fmt='%.10e') # # print(sess.run(model.atype_embed, feed_dict = feed_dict_test)) # print(sess.run(fitting.inputs, feed_dict = feed_dict_test)) # print(sess.run(fitting.outs, feed_dict = feed_dict_test)) # print(sess.run(fitting.atype_embed, feed_dict = feed_dict_test)) e = e.reshape([-1]) f = f.reshape([-1]) v = v.reshape([-1]) np.savetxt('e.out', e.reshape([1, -1]), delimiter=',') np.savetxt('f.out', f.reshape([1, -1]), delimiter=',') np.savetxt('v.out', v.reshape([1, -1]), delimiter=',') refe = [6.049065170680415804e+01] reff = [1.021832439441947293e-01,1.122650466359011306e-01,3.927874278714531091e-03,1.407089812207832635e-01,1.312473824343091400e-01,-1.228371057389851181e-02,-1.109672154547165501e-01,6.582735820731049070e-02,1.251568633647655391e-03,7.933758749748777428e-02,-1.831777072317984367e-01,-6.173090134630876760e-03,-2.703597126460742794e-01,4.817856571062521104e-02,1.491963457594796399e-02,5.909711543832503466e-02,-1.743406457563475287e-01,-1.642276779780762769e-03] refv = [-6.932736357193732823e-01,1.453756052949563837e-01,2.138263139115256783e-02,1.453756052949564392e-01,-3.880901656480436612e-01,-7.782259726407755700e-03,2.138263139115256437e-02,-7.782259726407749628e-03,-1.225285973678705374e-03] refe = np.reshape(refe, [-1]) reff = np.reshape(reff, [-1]) refv = np.reshape(refv, [-1]) places = 10 np.testing.assert_almost_equal(e, refe, places) np.testing.assert_almost_equal(f, reff, places) np.testing.assert_almost_equal(v, refv, places)
def test_model(self): jfile = 'water_se_a_fparam.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 1 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have(jdata['model']['descriptor'], 'rcut') data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() numb_test = 1 jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed=True) jdata['model']['fitting_net']['descrpt'] = descrpt fitting = EnerFitting(**jdata['model']['fitting_net'], uniform_seed=True) # descrpt = DescrptSeA(jdata['model']['descriptor']) # fitting = EnerFitting(jdata['model']['fitting_net'], descrpt) model = EnerModel(descrpt, fitting) # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']]) input_data = { 'coord': [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec': [test_data['natoms_vec']], 'default_mesh': [test_data['default_mesh']], 'fparam': [test_data['fparam']], } model._compute_input_stat(input_data) model.descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') t_fparam = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_fparam') is_training = tf.placeholder(tf.bool) input_dict = {} input_dict['fparam'] = t_fparam model_pred\ = model.build (t_coord, t_type, t_natoms, t_box, t_mesh, input_dict, suffix = "se_a_fparam", reuse = False) energy = model_pred['energy'] force = model_pred['force'] virial = model_pred['virial'] atom_ener = model_pred['atom_ener'] feed_dict_test = { t_prop_c: test_data['prop_c'], t_energy: test_data['energy'][:numb_test], t_force: np.reshape(test_data['force'][:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]), t_box: test_data['box'][:numb_test, :], t_type: np.reshape(test_data['type'][:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], t_fparam: np.reshape(test_data['fparam'][:numb_test, :], [-1]), is_training: False } sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [e, f, v] = sess.run([energy, force, virial], feed_dict=feed_dict_test) e = e.reshape([-1]) f = f.reshape([-1]) v = v.reshape([-1]) refe = [61.35473702079649] reff = [ 7.789591210641927388e-02, 9.411176646369459609e-02, 3.785806413688173194e-03, 1.430830954178063386e-01, 1.146964190520970150e-01, -1.320340288927138173e-02, -7.308720494747594776e-02, 6.508269338140809657e-02, 5.398739145542804643e-04, 5.863268336973800898e-02, -1.603409523950408699e-01, -5.083084610994957619e-03, -2.551569799443983988e-01, 3.087934885732580501e-02, 1.508590526622844222e-02, 4.863249399791078065e-02, -1.444292753594846324e-01, -1.125098094204559241e-03 ] refv = [ -6.069498397488943819e-01, 1.101778888191114192e-01, 1.981907430646132409e-02, 1.101778888191114608e-01, -3.315612988100872793e-01, -5.999739184898976799e-03, 1.981907430646132756e-02, -5.999739184898974197e-03, -1.198656608172396325e-03 ] refe = np.reshape(refe, [-1]) reff = np.reshape(reff, [-1]) refv = np.reshape(refv, [-1]) places = 10 np.testing.assert_almost_equal(e, refe, places) np.testing.assert_almost_equal(f, reff, places) np.testing.assert_almost_equal(v, refv, places)
def test_model(self): jfile = 'water_se_a_srtab.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 1 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have (jdata['model']['descriptor'], 'rcut') data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt = None) test_data = data.get_test () numb_test = 1 jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeA(**jdata['model']['descriptor'], uniform_seed = True) jdata['model']['fitting_net']['descrpt'] = descrpt fitting = EnerFitting(**jdata['model']['fitting_net'], uniform_seed = True) # descrpt = DescrptSeA(jdata['model']['descriptor']) # fitting = EnerFitting(jdata['model']['fitting_net'], descrpt) model = EnerModel( descrpt, fitting, None, jdata['model'].get('type_map'), jdata['model'].get('data_stat_nbatch'), jdata['model'].get('data_stat_protect'), jdata['model'].get('use_srtab'), jdata['model'].get('smin_alpha'), jdata['model'].get('sw_rmin'), jdata['model'].get('sw_rmax') ) # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']]) input_data = {'coord' : [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec' : [test_data['natoms_vec']], 'default_mesh' : [test_data['default_mesh']] } model._compute_input_stat(input_data) model.descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [model.ntypes+2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') is_training = tf.placeholder(tf.bool) t_fparam = None model_pred\ = model.build (t_coord, t_type, t_natoms, t_box, t_mesh, t_fparam, suffix = "se_a_srtab", reuse = False) energy = model_pred['energy'] force = model_pred['force'] virial = model_pred['virial'] atom_ener = model_pred['atom_ener'] feed_dict_test = {t_prop_c: test_data['prop_c'], t_energy: test_data['energy'] [:numb_test], t_force: np.reshape(test_data['force'] [:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'] [:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'] [:numb_test, :], [-1]), t_box: test_data['box'] [:numb_test, :], t_type: np.reshape(test_data['type'] [:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], is_training: False} sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [e, f, v] = sess.run([energy, force, virial], feed_dict = feed_dict_test) e = e.reshape([-1]) f = f.reshape([-1]) v = v.reshape([-1]) refe = [1.141610882066236599e+02] reff = [-1.493121233165248043e+02,-1.831419491743885715e+02,-8.439542992300344437e+00,-1.811987095947552859e+02,-1.476380826187439084e+02,1.264271856742560018e+01,1.544377958934875323e+02,-7.816520233903435866e+00,1.287925245463442225e+00,-4.000393268449002449e+00,1.910748885843098890e+02,7.134789955349889468e+00,1.826908441979261113e+02,3.677156386479059513e+00,-1.122312112141401741e+01,-2.617413911684622008e+00,1.438445070562470391e+02,-1.402769654524568033e+00] refv = [3.585047655925112622e+02,-7.569252978336677984e+00,-1.068382043878426124e+01,-7.569252978336677096e+00,3.618439481685132932e+02,5.448668500896081568e+00,-1.068382043878426302e+01,5.448668500896082456e+00,1.050393462151727686e+00] refe = np.reshape(refe, [-1]) reff = np.reshape(reff, [-1]) refv = np.reshape(refv, [-1]) places = 10 np.testing.assert_almost_equal(e, refe, places) np.testing.assert_almost_equal(f, reff, places) np.testing.assert_almost_equal(v, refv, places)
def test_model(self): jfile = 'water_se_t.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 1 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have(jdata['model']['descriptor'], 'rcut') data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() numb_test = 1 jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeT(**jdata['model']['descriptor'], uniform_seed=True) jdata['model']['fitting_net']['descrpt'] = descrpt fitting = EnerFitting(**jdata['model']['fitting_net'], uniform_seed=True) model = EnerModel(descrpt, fitting) input_data = { 'coord': [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec': [test_data['natoms_vec']], 'default_mesh': [test_data['default_mesh']] } model._compute_input_stat(input_data) model.descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') is_training = tf.placeholder(tf.bool) t_fparam = None model_pred\ = model.build (t_coord, t_type, t_natoms, t_box, t_mesh, t_fparam, suffix = "se_t", reuse = False) energy = model_pred['energy'] force = model_pred['force'] virial = model_pred['virial'] atom_ener = model_pred['atom_ener'] feed_dict_test = { t_prop_c: test_data['prop_c'], t_energy: test_data['energy'][:numb_test], t_force: np.reshape(test_data['force'][:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]), t_box: test_data['box'][:numb_test, :], t_type: np.reshape(test_data['type'][:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], is_training: False } sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [e, f, v] = sess.run([energy, force, virial], feed_dict=feed_dict_test) e = e.reshape([-1]) f = f.reshape([-1]) v = v.reshape([-1]) np.savetxt('e.out', e.reshape([1, -1])) np.savetxt('f.out', f.reshape([1, -1]), delimiter=',') np.savetxt('v.out', v.reshape([1, -1]), delimiter=',') refe = [4.8436558582194039e+01] reff = [ 5.2896335066946598e+00, 5.5778402259211131e+00, 2.6839994229557251e-01, 5.3528786387686784e+00, 5.2477755362164968e+00, -4.0486366542657343e-01, -5.1297084055340498e+00, 3.4607112287117253e-01, -5.1800783428369482e-02, 1.5557068351407846e-01, -5.9071343228741506e+00, -2.2012359669589748e-01, -5.9156735320857488e+00, 8.8397615509389127e-02, 3.6701215949753935e-01, 2.4729910864238122e-01, -5.3529501776440211e+00, 4.1375943757728552e-02 ] refv = [ -1.3159448660141607e+01, 4.6952048725161544e-01, 3.5482003698976106e-01, 4.6952048725161577e-01, -1.2178990983673918e+01, -1.6867277410496895e-01, 3.5482003698976106e-01, -1.6867277410496900e-01, -3.3986741457321945e-02 ] refe = np.reshape(refe, [-1]) reff = np.reshape(reff, [-1]) refv = np.reshape(refv, [-1]) places = 6 np.testing.assert_almost_equal(e, refe, places) np.testing.assert_almost_equal(f, reff, places) np.testing.assert_almost_equal(v, refv, places)
def test_model(self): jfile = 'water_se_r.json' jdata = j_loader(jfile) systems = j_must_have(jdata, 'systems') set_pfx = j_must_have(jdata, 'set_prefix') batch_size = j_must_have(jdata, 'batch_size') test_size = j_must_have(jdata, 'numb_test') batch_size = 1 test_size = 1 stop_batch = j_must_have(jdata, 'stop_batch') rcut = j_must_have(jdata['model']['descriptor'], 'rcut') data = DataSystem(systems, set_pfx, batch_size, test_size, rcut, run_opt=None) test_data = data.get_test() numb_test = 1 jdata['model']['descriptor'].pop('type', None) descrpt = DescrptSeR(**jdata['model']['descriptor'], uniform_seed=True) jdata['model']['fitting_net']['descrpt'] = descrpt fitting = EnerFitting(**jdata['model']['fitting_net'], uniform_seed=True) # fitting = EnerFitting(jdata['model']['fitting_net'], descrpt) model = EnerModel(descrpt, fitting) # model._compute_dstats([test_data['coord']], [test_data['box']], [test_data['type']], [test_data['natoms_vec']], [test_data['default_mesh']]) input_data = { 'coord': [test_data['coord']], 'box': [test_data['box']], 'type': [test_data['type']], 'natoms_vec': [test_data['natoms_vec']], 'default_mesh': [test_data['default_mesh']] } model._compute_input_stat(input_data) model.descrpt.bias_atom_e = data.compute_energy_shift() t_prop_c = tf.placeholder(tf.float32, [5], name='t_prop_c') t_energy = tf.placeholder(GLOBAL_ENER_FLOAT_PRECISION, [None], name='t_energy') t_force = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_force') t_virial = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_virial') t_atom_ener = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='t_atom_ener') t_coord = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None], name='i_coord') t_type = tf.placeholder(tf.int32, [None], name='i_type') t_natoms = tf.placeholder(tf.int32, [model.ntypes + 2], name='i_natoms') t_box = tf.placeholder(GLOBAL_TF_FLOAT_PRECISION, [None, 9], name='i_box') t_mesh = tf.placeholder(tf.int32, [None], name='i_mesh') is_training = tf.placeholder(tf.bool) t_fparam = None model_pred\ = model.build (t_coord, t_type, t_natoms, t_box, t_mesh, t_fparam, suffix = "se_r", reuse = False) energy = model_pred['energy'] force = model_pred['force'] virial = model_pred['virial'] atom_ener = model_pred['atom_ener'] feed_dict_test = { t_prop_c: test_data['prop_c'], t_energy: test_data['energy'][:numb_test], t_force: np.reshape(test_data['force'][:numb_test, :], [-1]), t_virial: np.reshape(test_data['virial'][:numb_test, :], [-1]), t_atom_ener: np.reshape(test_data['atom_ener'][:numb_test, :], [-1]), t_coord: np.reshape(test_data['coord'][:numb_test, :], [-1]), t_box: test_data['box'][:numb_test, :], t_type: np.reshape(test_data['type'][:numb_test, :], [-1]), t_natoms: test_data['natoms_vec'], t_mesh: test_data['default_mesh'], is_training: False } sess = self.test_session().__enter__() sess.run(tf.global_variables_initializer()) [e, f, v] = sess.run([energy, force, virial], feed_dict=feed_dict_test) e = e.reshape([-1]) f = f.reshape([-1]) v = v.reshape([-1]) refe = [6.152085988309423925e+01] reff = [ -1.714443151616400110e-04, -1.315836609370952051e-04, -5.584120460897444674e-06, -7.197863450669731334e-05, -1.384609799994930676e-04, 8.856091902774708468e-06, 1.120578238869146797e-04, -7.428703645877488470e-05, 9.370560731488587317e-07, -1.048347129617610465e-04, 1.977876923815685781e-04, 7.522050342771599598e-06, 2.361772659657814205e-04, -5.774651813388292487e-05, -1.233143271630744828e-05, 2.257277740226381951e-08, 2.042905031476775584e-04, 6.003548585097267914e-07 ] refv = [ 1.035180911513190792e-03, -1.118982949050497126e-04, -2.383287813436022850e-05, -1.118982949050497126e-04, 4.362023915782403281e-04, 8.119543218224559240e-06, -2.383287813436022850e-05, 8.119543218224559240e-06, 1.201142938802945237e-06 ] refe = np.reshape(refe, [-1]) reff = np.reshape(reff, [-1]) refv = np.reshape(refv, [-1]) places = 6 for ii in range(e.size): self.assertAlmostEqual(e[ii], refe[ii], places=places) for ii in range(f.size): self.assertAlmostEqual(f[ii], reff[ii], places=places) for ii in range(v.size): self.assertAlmostEqual(v[ii], refv[ii], places=places)