def create_init_tasks(target_folder, param_file, output, fp_json, verbose = True) : target_folder = os.path.abspath(target_folder) output = os.path.abspath(output) tool_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'template') jdata = json.load(open(os.path.join(target_folder, param_file))) fp_jdata = json.load(open(fp_json)) # fp settings mass_map = jdata['mass_map'] type_map = jdata['type_map'] fp_style = fp_jdata['fp_style'] fp_pp_path = fp_jdata['fp_pp_path'] fp_pp_files = fp_jdata['fp_pp_files'] cwd_ = os.getcwd() os.chdir(target_folder) fp_pp_path = os.path.abspath(fp_pp_path) os.chdir(cwd_) # init data sys init_data_prefix = jdata['init_data_prefix'] init_data_sys = jdata['init_data_sys'] for idx,ii in enumerate(init_data_sys): sys = dpdata.LabeledSystem(os.path.join(init_data_prefix, ii), fmt = 'deepmd/npy', type_map = type_map) nframes = sys.get_nframes() sys_dir = os.path.join(output, 'init_system.%03d' % idx) os.makedirs(sys_dir, exist_ok = True) if verbose : print('# working on ' + sys_dir) with open(os.path.join(sys_dir,'record'), 'w') as fp: fp.write(os.path.join(init_data_prefix, ii) + '\n') for ff in range(nframes) : task_dir = os.path.join(sys_dir, 'task.%06d' % ff) os.makedirs(task_dir, exist_ok = True) sys.to_vasp_poscar(os.path.join(task_dir, 'POSCAR')) # make fp cwd_ = os.getcwd() os.chdir(task_dir) for pp in fp_pp_files : if os.path.lexists(pp) : os.remove(pp) os.symlink(os.path.relpath(os.path.join(output, pp)), pp) if fp_style == 'vasp': if os.path.lexists('INCAR') : os.remove('INCAR') os.symlink(os.path.relpath(os.path.join(output, 'INCAR')), 'INCAR') elif fp_style == 'pwscf': try: fp_params = fp_jdata['user_fp_params'] user_input = True except: fp_params = fp_jdata['fp_params'] user_input = False make_pwscf('.', fp_params, mass_map, fp_pp_files, fp_pp_files, user_input) os.chdir(cwd_)
def test_post_fp_vasp_0(self): with open(param_file, 'r') as fp: jdata = json.load(fp) jdata['use_ele_temp'] = 2 post_fp_vasp(0, jdata, rfailed=0.3) sys = dpdata.LabeledSystem('iter.000000/02.fp/data.000/', fmt='deepmd/raw') self.assertEqual(sys.get_nframes(), 2) if sys.data['coords'][0][1][0] < sys.data['coords'][1][1][0]: idx = [1, 0] else: idx = [0, 1] ref_coord = self.ref_coord[idx] ref_cell = self.ref_cell[idx] ref_e = self.ref_e[idx] ref_f = self.ref_f[idx] ref_v = self.ref_v[idx] ref_at = self.ref_at for ff in range(2): self.assertAlmostEqual(ref_e[ff], sys.data['energies'][ff]) for ii in range(2): self.assertEqual(ref_at[ff], sys.data['atom_types'][ff]) for ff in range(2): for ii in range(2): for dd in range(3): self.assertAlmostEqual(ref_coord[ff][ii][dd], sys.data['coords'][ff][ii][dd]) self.assertAlmostEqual(ref_f[ff][ii][dd], sys.data['forces'][ff][ii][dd]) for ff in range(2): for ii in range(3): for jj in range(3): self.assertAlmostEqual(ref_v[ff][ii][jj], sys.data['virials'][ff][ii][jj], places=5) self.assertAlmostEqual(ref_cell[ff][ii][jj], sys.data['cells'][ff][ii][jj]) self.assertTrue( os.path.isfile('iter.000000/02.fp/data.000/set.000/aparam.npy')) aparam = np.load('iter.000000/02.fp/data.000/set.000/aparam.npy') natoms = sys.get_natoms() self.assertEqual(natoms, 2) self.assertEqual(list(list(aparam)[0]), [0, 0]) self.assertEqual(list(list(aparam)[1]), [1, 1])
def test_post_fp_vasp_1(self): with open(param_file, 'r') as fp: jdata = json.load(fp) jdata['use_ele_temp'] = 1 post_fp_vasp(0, jdata, rfailed=0.3) sys = dpdata.LabeledSystem('iter.000000/02.fp/data.001/', fmt='deepmd/raw') self.assertEqual(sys.get_nframes(), 1) # if sys.data['coords'][0][1][0] < sys.data['coords'][1][1][0]: # idx = [0] # else : idx = [1] ref_coord = self.ref_coord[idx] ref_cell = self.ref_cell[idx] ref_e = self.ref_e[idx] ref_f = self.ref_f[idx] ref_v = self.ref_v[idx] ref_at = self.ref_at for ff in range(1): self.assertAlmostEqual(ref_e[ff], sys.data['energies'][ff]) for ii in range(2): self.assertEqual(ref_at[ff], sys.data['atom_types'][ff]) for ff in range(1): for ii in range(2): for dd in range(3): self.assertAlmostEqual(ref_coord[ff][ii][dd], sys.data['coords'][ff][ii][dd]) self.assertAlmostEqual(ref_f[ff][ii][dd], sys.data['forces'][ff][ii][dd]) for ff in range(1): for ii in range(3): for jj in range(3): self.assertAlmostEqual(ref_v[ff][ii][jj], sys.data['virials'][ff][ii][jj], places=5) self.assertAlmostEqual(ref_cell[ff][ii][jj], sys.data['cells'][ff][ii][jj]) fparam = np.load('iter.000000/02.fp/data.001/set.000/fparam.npy') self.assertEqual(fparam.shape[0], 1) self.assertEqual(list(fparam), [100000])
def test_coll(self): with open(param_file, 'r') as fp: jdata = json.load(fp) jdata['out_dir'] = self.odir coll_vasp_md(jdata) sys = dpdata.LabeledSystem(self.odir + '/02.md/sys-004/deepmd//', fmt='deepmd/raw') self.assertEqual(sys.get_nframes(), 2) if sys.data['coords'][0][1][0] < sys.data['coords'][1][1][0]: idx = [1, 0] else: idx = [0, 1] ref_coord = self.ref_coord[idx] ref_cell = self.ref_cell[idx] ref_e = self.ref_e[idx] ref_f = self.ref_f[idx] ref_v = self.ref_v[idx] ref_at = self.ref_at for ff in range(2): self.assertAlmostEqual(ref_e[ff], sys.data['energies'][ff]) for ii in range(2): self.assertEqual(ref_at[ff], sys.data['atom_types'][ff]) for ff in range(2): for ii in range(2): for dd in range(3): self.assertAlmostEqual(ref_coord[ff][ii][dd], sys.data['coords'][ff][ii][dd]) self.assertAlmostEqual(ref_f[ff][ii][dd], sys.data['forces'][ff][ii][dd]) for ff in range(2): for ii in range(3): for jj in range(3): self.assertAlmostEqual(ref_v[ff][ii][jj], sys.data['virials'][ff][ii][jj], places=5) self.assertAlmostEqual(ref_cell[ff][ii][jj], sys.data['cells'][ff][ii][jj])