def test_dipole (args) : if args.rand_seed is not None : np.random.seed(args.rand_seed % (2**32)) dp = DeepDipole(args.model) data = DeepmdData(args.system, args.set_prefix, shuffle_test = args.shuffle_test) data.add('dipole', 3, atomic=True, must=True, high_prec=False, type_sel = dp.get_sel_type()) test_data = data.get_test () numb_test = args.numb_test natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = min(nframes, numb_test) coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] atype = test_data["type"][0] dipole = dp.eval(coord, box, atype) dipole = dipole.reshape([numb_test,-1]) l2f = (l2err (dipole - test_data["dipole"] [:numb_test])) print ("# number of test data : %d " % numb_test) print ("Dipole L2err : %e eV/A" % l2f) detail_file = args.detail_file if detail_file is not None : pe = np.concatenate((np.reshape(test_data["dipole"][:numb_test], [-1,3]), np.reshape(dipole, [-1,3])), axis = 1) np.savetxt(detail_file+".out", pe, header = 'data_x data_y data_z pred_x pred_y pred_z')
def test_wfc (args) : if args.rand_seed is not None : np.random.seed(args.rand_seed % (2**32)) dp = DeepWFC(args.model) data = DeepmdData(args.system, args.set_prefix, shuffle_test = args.shuffle_test) data.add('wfc', 12, atomic=True, must=True, high_prec=False, type_sel = dp.get_sel_type()) test_data = data.get_test () numb_test = args.numb_test natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = min(nframes, numb_test) coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] atype = test_data["type"][0] wfc = dp.eval(coord, box, atype) wfc = wfc.reshape([numb_test,-1]) l2f = (l2err (wfc - test_data["wfc"] [:numb_test])) print ("# number of test data : %d " % numb_test) print ("WFC L2err : %e eV/A" % l2f) detail_file = args.detail_file if detail_file is not None : pe = np.concatenate((np.reshape(test_data["wfc"][:numb_test], [-1,12]), np.reshape(wfc, [-1,12])), axis = 1) np.savetxt(detail_file+".out", pe, header = 'ref_wfc(12 dofs) predicted_wfc(12 dofs)')
def test_polar (args) : if args.rand_seed is not None : np.random.seed(args.rand_seed % (2**32)) dp = DeepPolar(args.model) data = DeepmdData(args.system, args.set_prefix, shuffle_test = args.shuffle_test) data.add('polarizability', 9, atomic=True, must=True, high_prec=False, type_sel = dp.get_sel_type()) test_data = data.get_test () numb_test = args.numb_test natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = min(nframes, numb_test) coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] atype = test_data["type"][0] polar = dp.eval(coord, box, atype) polar = polar.reshape([numb_test,-1]) l2f = (l2err (polar - test_data["polarizability"] [:numb_test])) print ("# number of test data : %d " % numb_test) print ("Polarizability L2err : %e eV/A" % l2f) detail_file = args.detail_file if detail_file is not None : pe = np.concatenate((np.reshape(test_data["polarizability"][:numb_test], [-1,9]), np.reshape(polar, [-1,9])), axis = 1) np.savetxt(detail_file+".out", pe, header = 'data_pxx data_pxy data_pxz data_pyx data_pyy data_pyz data_pzx data_pzy data_pzz pred_pxx pred_pxy pred_pxz pred_pyx pred_pyy pred_pyz pred_pzx pred_pzy pred_pzz')
def test_polar(dp, args, global_polar=False): if args.rand_seed is not None: np.random.seed(args.rand_seed % (2**32)) data = DeepmdData(args.system, args.set_prefix, shuffle_test=args.shuffle_test) if not global_polar: data.add('polarizability', 9, atomic=True, must=True, high_prec=False, type_sel=dp.get_sel_type()) else: data.add('polarizability', 9, atomic=False, must=True, high_prec=False, type_sel=dp.get_sel_type()) test_data = data.get_test() numb_test = args.numb_test natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = min(nframes, numb_test) coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] atype = test_data["type"][0] polar = dp.eval(coord, box, atype) sel_type = dp.get_sel_type() sel_natoms = 0 for ii in sel_type: sel_natoms += sum(atype == ii) polar = polar.reshape([numb_test, -1]) l2f = (l2err(polar - test_data["polarizability"][:numb_test])) l2fs = l2f / np.sqrt(sel_natoms) l2fa = l2f / sel_natoms print("# number of test data : %d " % numb_test) print("Polarizability L2err : %e eV/A" % l2f) if global_polar: print("Polarizability L2err/sqrtN : %e eV/A" % l2fs) print("Polarizability L2err/N : %e eV/A" % l2fa) detail_file = args.detail_file if detail_file is not None: pe = np.concatenate( (np.reshape(test_data["polarizability"][:numb_test], [-1, 9]), np.reshape(polar, [-1, 9])), axis=1) np.savetxt( detail_file + ".out", pe, header= 'data_pxx data_pxy data_pxz data_pyx data_pyy data_pyz data_pzx data_pzy data_pzz pred_pxx pred_pxy pred_pxz pred_pyx pred_pyy pred_pyz pred_pzx pred_pzy pred_pzz' ) return [l2f], [polar.size]
def test_ener(args): if args.rand_seed is not None: np.random.seed(args.rand_seed % (2**32)) dp = DeepPot(args.model) data = DeepmdData(args.system, args.set_prefix, shuffle_test=args.shuffle_test, type_map=dp.get_type_map()) data.add('energy', 1, atomic=False, must=False, high_prec=True) data.add('force', 3, atomic=True, must=False, high_prec=False) data.add('virial', 9, atomic=False, must=False, high_prec=False) if dp.get_dim_fparam() > 0: data.add('fparam', dp.get_dim_fparam(), atomic=False, must=True, high_prec=False) if dp.get_dim_aparam() > 0: data.add('aparam', dp.get_dim_aparam(), atomic=True, must=True, high_prec=False) test_data = data.get_test() natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = args.numb_test numb_test = min(nframes, numb_test) coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] atype = test_data["type"][0] if dp.get_dim_fparam() > 0: fparam = test_data["fparam"][:numb_test] else: fparam = None if dp.get_dim_aparam() > 0: aparam = test_data["aparam"][:numb_test] else: aparam = None energy, force, virial, ae, av = dp.eval(coord, box, atype, fparam=fparam, aparam=aparam, atomic=True) energy = energy.reshape([numb_test, 1]) force = force.reshape([numb_test, -1]) virial = virial.reshape([numb_test, 9]) ae = ae.reshape([numb_test, -1]) av = av.reshape([numb_test, -1]) l2e = (l2err(energy - test_data["energy"][:numb_test].reshape([-1, 1]))) l2f = (l2err(force - test_data["force"][:numb_test])) l2v = (l2err(virial - test_data["virial"][:numb_test])) l2ea = l2e / natoms l2va = l2v / natoms # print ("# energies: %s" % energy) print("# number of test data : %d " % numb_test) print("Energy L2err : %e eV" % l2e) print("Energy L2err/Natoms : %e eV" % l2ea) print("Force L2err : %e eV/A" % l2f) print("Virial L2err : %e eV" % l2v) print("Virial L2err/Natoms : %e eV" % l2va) detail_file = args.detail_file if detail_file is not None: pe = np.concatenate((np.reshape(test_data["energy"][:numb_test], [-1, 1]), np.reshape(energy, [-1, 1])), axis=1) np.savetxt(detail_file + ".e.out", pe, header='data_e pred_e') pf = np.concatenate((np.reshape(test_data["force"][:numb_test], [-1, 3]), np.reshape(force, [-1, 3])), axis=1) np.savetxt(detail_file + ".f.out", pf, header='data_fx data_fy data_fz pred_fx pred_fy pred_fz') pv = np.concatenate((np.reshape(test_data["virial"][:numb_test], [-1, 9]), np.reshape(virial, [-1, 9])), axis=1) np.savetxt( detail_file + ".v.out", pv, header= 'data_vxx data_vxy data_vxz data_vyx data_vyy data_vyz data_vzx data_vzy data_vzz pred_vxx pred_vxy pred_vxz pred_vyx pred_vyy pred_vyz pred_vzx pred_vzy pred_vzz' )
def test_get_test(self): dd = DeepmdData(self.data_name) data = dd.get_test() self._comp_np_mat2(np.sort(data['coord'], axis=0), np.sort(self.coord_tar, axis=0))
np.random.seed(args.rand_seed % (2**32)) <<<<<<< HEAD dp = DeepPot(args.model) ======= >>>>>>> 93aa90768089e265465f93fb3d9f99b494d56b09 data = DeepmdData(args.system, args.set_prefix, shuffle_test = args.shuffle_test, type_map = dp.get_type_map()) data.add('energy', 1, atomic=False, must=False, high_prec=True) data.add('force', 3, atomic=True, must=False, high_prec=False) data.add('virial', 9, atomic=False, must=False, high_prec=False) if dp.get_dim_fparam() > 0: data.add('fparam', dp.get_dim_fparam(), atomic=False, must=True, high_prec=False) if dp.get_dim_aparam() > 0: data.add('aparam', dp.get_dim_aparam(), atomic=True, must=True, high_prec=False) test_data = data.get_test () natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = args.numb_test numb_test = min(nframes, numb_test) <<<<<<< HEAD ======= >>>>>>> 93aa90768089e265465f93fb3d9f99b494d56b09 coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] if not data.pbc: box = None atype = test_data["type"][0] if dp.get_dim_fparam() > 0: fparam = test_data["fparam"][:numb_test]
def test_ener(dp, system, set_prefix='set', numb_test=100000, shuffle_test=False, rand_seed=None, detail_file='detail'): if rand_seed is not None: np.random.seed(rand_seed % (2**32)) data = DeepmdData(system, set_prefix, shuffle_test=shuffle_test, type_map=dp.get_type_map()) data.add('energy', 1, atomic=False, must=False, high_prec=True) data.add('force', 3, atomic=True, must=False, high_prec=False) data.add('virial', 9, atomic=False, must=False, high_prec=False) if dp.get_dim_fparam() > 0: data.add('fparam', dp.get_dim_fparam(), atomic=False, must=True, high_prec=False) if dp.get_dim_aparam() > 0: data.add('aparam', dp.get_dim_aparam(), atomic=True, must=True, high_prec=False) test_data = data.get_test() natoms = len(test_data["type"][0]) nframes = test_data["box"].shape[0] numb_test = min(nframes, numb_test) coord = test_data["coord"][:numb_test].reshape([numb_test, -1]) box = test_data["box"][:numb_test] atype = test_data["type"][0] if dp.get_dim_fparam() > 0: fparam = test_data["fparam"][:numb_test] else: fparam = None if dp.get_dim_aparam() > 0: aparam = test_data["aparam"][:numb_test] else: aparam = None energy, force, virial, ae, av = dp.eval(coord, box, atype, fparam=fparam, aparam=aparam, atomic=True) energy = energy.reshape([numb_test, 1]) force = force.reshape([numb_test, -1]) virial = virial.reshape([numb_test, 9]) ae = ae.reshape([numb_test, -1]) av = av.reshape([numb_test, -1]) l2e = (l2err(energy - test_data["energy"][:numb_test].reshape([-1, 1]))) l2f = (l2err(force - test_data["force"][:numb_test])) l2v = (l2err(virial - test_data["virial"][:numb_test])) l2ea = l2e / natoms l2va = l2v / natoms if detail_file is not None: pe = np.concatenate( (np.reshape(test_data["energy"][:numb_test] / natoms, [-1, 1]), np.reshape(energy / natoms, [-1, 1])), axis=1) np.savetxt(detail_file + ".e.out", pe, header='data_e pred_e') pf = np.concatenate((np.reshape(test_data["force"][:numb_test], [-1, 3]), np.reshape(force, [-1, 3])), axis=1) np.savetxt(detail_file + ".f.out", pf, header='data_fx data_fy data_fz pred_fx pred_fy pred_fz') pv = np.concatenate((np.reshape(test_data["virial"][:numb_test], [-1, 9]), np.reshape(virial, [-1, 9])), axis=1) np.savetxt( detail_file + ".v.out", pv, header= 'data_vxx data_vxy data_vxz data_vyx data_vyy data_vyz data_vzx data_vzy data_vzz pred_vxx pred_vxy pred_vxz pred_vyx pred_vyy pred_vyz pred_vzx pred_vzy pred_vzz' ) return numb_test, l2e, l2ea, l2f, l2v, l2va