def parse_seq_ginv (seq) : tmp_seq = parse_seq(seq) t_begin = tmp_seq[0] t_end = tmp_seq[-1] ngrid = len(tmp_seq) - 1 hh = (1/t_end - 1/t_begin) / ngrid inv_grid = np.arange(1/t_begin, 1/t_end+0.5*hh, hh) inv_grid = 1./inv_grid return inv_grid
def test_protect_eps(self): array1 = parse_seq(lambda_seq, protect_eps=1e-6) array2 = np.asarray([0.000001, 0.01, 0.02, 0.03, 0.04, 0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.19, 0.23, 0.27, 0.31, 0.35, 0.415, 0.48, 0.545, 0.61, 0.675, 0.74, 0.805, 0.87, 0.935, 0.999999]) assert_almost_equal(array1, array2, decimal=10)
def test_normal(self): array1 = parse_seq(lambda_seq) array2 = np.asarray([0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.19, 0.23, 0.27, 0.31, 0.35, 0.415, 0.48, 0.545, 0.61, 0.675, 0.74, 0.805, 0.87, 0.935, 1.0]) assert_almost_equal(array1, array2, decimal=10)
def test_no_posi_args(self): with self.assertRaises(TypeError): parse_seq(lambda_seq, 1e-6)
def _make_tasks(iter_name, jdata, step, if_meam=False, meam_model=None): if step == 'soft_on': all_lambda = parse_seq(jdata['lambda_soft_on']) elif step == 'deep_on': all_lambda = parse_seq(jdata['lambda_deep_on']) elif step == 'soft_off': all_lambda = parse_seq(jdata['lambda_soft_off']) else: raise RuntimeError('unknow step') equi_conf = jdata['equi_conf'] equi_conf = os.path.abspath(equi_conf) # mass_map = jdata['mass_map'] mass_map = get_first_matched_key_from_dict(jdata, ['mass_map', 'model_mass_map']) model = jdata.get('model', None) if model: model = os.path.abspath(model) soft_param = jdata['soft_param'] nsteps = jdata['nsteps'] # timestep = jdata['timestep'] timestep = get_first_matched_key_from_dict(jdata, ['timestep', 'dt']) # thermo_freq = jdata['thermo_freq'] thermo_freq = get_first_matched_key_from_dict(jdata, ['thermo_freq', 'stat_freq']) copies = None if 'copies' in jdata: copies = jdata['copies'] temp = jdata['temp'] sparam = jdata.get('soft_param', {}) if sparam: if 'sigma_oo' in sparam: sparam['sigma_0_0'] = sparam['sigma_oo'] sparam['sigma_0_1'] = sparam['sigma_oh'] sparam['sigma_1_1'] = sparam['sigma_hh'] # element_num=sparam.get('element_num', 1) element_num = len(mass_map) sigma_key_index = filter(lambda t: t[0] <= t[1], ((i, j) for i in range(element_num) for j in range(element_num))) sigma_key_name_list = [ 'sigma_' + str(t[0]) + '_' + str(t[1]) for t in sigma_key_index ] for sigma_key_name in sigma_key_name_list: assert sparam.get( sigma_key_name, None ), 'there must be key-value for {sigma_key_name} in soft_param'.format( sigma_key_name=sigma_key_name) job_abs_dir = create_path(iter_name) if meam_model: relative_link_file(os.path.abspath(meam_model['library']), job_abs_dir) relative_link_file(os.path.abspath(meam_model['potential']), job_abs_dir) # os.symlink(os.path.join('..', 'conf.lmp'), 'conf.lmp') # os.symlink(os.path.join('..', 'graph.pb'), 'graph.pb') cwd = os.getcwd() os.chdir(iter_name) os.symlink(os.path.join('..', 'in.json'), 'in.json') os.symlink(os.path.join('..', 'conf.lmp'), 'conf.lmp') os.symlink(os.path.join('..', 'graph.pb'), 'graph.pb') os.chdir(cwd) # print(9898, meam_model) for idx, ii in enumerate(all_lambda): work_path = os.path.join(iter_name, 'task.%06d' % idx) create_path(work_path) os.chdir(work_path) os.symlink(os.path.join('..', 'conf.lmp'), 'conf.lmp') os.symlink(os.path.join('..', 'graph.pb'), 'graph.pb') if meam_model: meam_library_basename = os.path.basename(meam_model['library']) meam_potential_basename = os.path.basename(meam_model['potential']) os.symlink(os.path.join('..', meam_library_basename), meam_library_basename) os.symlink(os.path.join('..', meam_potential_basename), meam_potential_basename) lmp_str \ = _gen_lammps_input_ideal(step, 'conf.lmp', mass_map, ii, soft_param, 'graph.pb', nsteps, timestep, 'nvt', temp, thermo_freq = thermo_freq, copies = copies, if_meam = if_meam, meam_model=meam_model) with open('in.lammps', 'w') as fp: fp.write(lmp_str) with open('lambda.out', 'w') as fp: fp.write(str(ii)) os.chdir(cwd)
def make_tasks(iter_name, jdata, if_meam=None): ti_settings = jdata.copy() if if_meam is None: if_meam = jdata.get('if_meam', None) equi_conf = jdata['equi_conf'] equi_conf = os.path.abspath(equi_conf) copies = None if 'copies' in jdata : copies = jdata['copies'] model = jdata['model'] meam_model = jdata.get('meam_model', None) # model = os.path.abspath(model) # mass_map = jdata['mass_map'] mass_map = get_first_matched_key_from_dict(jdata, ['model_mass_map', 'mass_map']) nsteps = jdata['nsteps'] # timestep = jdata['timestep'] timestep = get_first_matched_key_from_dict(jdata, ['timestep', 'dt']) # thermo_freq = jdata['thermo_freq'] thermo_freq = get_first_matched_key_from_dict(jdata, ['thermo_freq', 'stat_freq']) # thermos = jdata['thermos'] ens = jdata['ens'] path = jdata['path'] if 'nvt' in ens : if path == 't' : temp_seq = get_first_matched_key_from_dict(jdata, ['temp_seq', 'temps']) temp_list = parse_seq(temp_seq) tau_t = jdata['tau_t'] ntasks = len(temp_list) else : raise RuntimeError('supported path of nvt ens is \'t\'') elif 'npt' in ens : if path == 't' : temp_seq = get_first_matched_key_from_dict(jdata, ['temp_seq', 'temps']) temp_list = parse_seq(temp_seq) pres = get_first_matched_key_from_dict(jdata, ['pres', 'press']) ntasks = len(temp_list) elif path == 't-ginv' : temp_seq = get_first_matched_key_from_dict(jdata, ['temp_seq', 'temps']) temp_list = parse_seq_ginv(temp_seq) pres = get_first_matched_key_from_dict(jdata, ['pres', 'press']) ntasks = len(temp_list) elif path == 'p' : temp = get_first_matched_key_from_dict(jdata, ['temp', 'temps']) pres_seq = get_first_matched_key_from_dict(jdata, ['pres_seq', 'press']) pres_list = parse_seq(pres_seq) ntasks = len(pres_list) else : raise RuntimeError('supported path of npt ens are \'t\' or \'p\'') tau_t = jdata['tau_t'] tau_p = jdata['tau_p'] else : raise RuntimeError('invalid ens') job_abs_dir = create_path(iter_name) # dct1 = link_file_in_dict( # dct=jdata, # key_list=["equi_conf", "model"], # target_dir=job_abs_dir # ) # ti_settings.update(dct1) # meam_model = jdata.get('meam_model', None) # dct2 = link_file_in_dict( # dct=meam_model, # key_list=["library", "potential"], # target_dir=job_abs_dir # ) # if meam_model: # ti_settings['meam_model'].update(dct2) # link_file_dict = {} # link_file_dict.update(dct1) # link_file_dict.update(dct2) # copied_conf = os.path.join(os.path.abspath(iter_name), 'conf.lmp') # shutil.copyfile(equi_conf, copied_conf) # jdata['equi_conf'] = 'conf.lmp' # linked_model = os.path.join(os.path.abspath(iter_name), 'graph.pb') # shutil.copyfile(model, linked_model) # jdata['model'] = 'graph.pb' # cwd = os.getcwd() # os.chdir(iter_name) relative_link_file(equi_conf, job_abs_dir) if model: relative_link_file(model, job_abs_dir) if if_meam: relative_link_file(meam_model['library'], job_abs_dir) relative_link_file(meam_model['potential'], job_abs_dir) with open(os.path.join(job_abs_dir, 'ti_settings.json'), 'w') as fp: json.dump(ti_settings, fp, indent=4) with open(os.path.join(job_abs_dir, 'ti_settings.json'),'w') as f: json.dump(ti_settings, f, indent=4) for ii in range(ntasks) : task_dir = os.path.join(job_abs_dir, 'task.%06d' % ii) task_abs_dir = create_path(task_dir) # os.chdir(work_path) relative_link_file(equi_conf, task_abs_dir) if model: relative_link_file(model, task_abs_dir) if if_meam: relative_link_file(meam_model['library'], task_abs_dir) relative_link_file(meam_model['potential'], task_abs_dir) # for file in list(link_file_dict.values()): # file_path = os.path.join(job_abs_dir, file) # relative_link_file(file_path, task_abs_dir) # os.symlink() # os.symlink(os.path.relpath(copied_conf), 'conf.lmp') # os.symlink(os.path.relpath(linked_model), 'graph.pb') if 'nvt' in ens and path == 't' : lmp_str \ = _gen_lammps_input(os.path.basename(equi_conf), mass_map, model, nsteps, timestep, ens, temp_list[ii], pres=pres, tau_t = tau_t, thermo_freq = thermo_freq, copies = copies, if_meam=if_meam, meam_model=meam_model ) thermo_out = temp_list[ii] # with open('thermo.out', 'w') as fp : # fp.write('%f' % temps[ii]) elif 'npt' in ens and (path == 't' or path == 't-ginv'): lmp_str \ = _gen_lammps_input(os.path.basename(equi_conf), mass_map, model, nsteps, timestep, ens, temp_list[ii], pres, tau_t = tau_t, tau_p = tau_p, thermo_freq = thermo_freq, copies = copies, if_meam=if_meam, meam_model=meam_model ) thermo_out = temp_list[ii] # with open('thermo.out', 'w') as fp : # fp.write('%f' % (temps[ii])) elif 'npt' in ens and path == 'p' : lmp_str \ = _gen_lammps_input(os.path.basename(equi_conf), mass_map, model, nsteps, timestep, ens, temp, pres_list[ii], tau_t = tau_t, tau_p = tau_p, thermo_freq = thermo_freq, copies = copies, if_meam=if_meam, meam_model=meam_model ) thermo_out = pres_list[ii] else: raise RuntimeError('invalid ens or path setting' ) with open(os.path.join(task_abs_dir, 'thermo.out'), 'w') as fp: fp.write('%f' % (thermo_out)) with open(os.path.join(task_abs_dir, 'in.lammps'), 'w') as fp: fp.write(lmp_str)
def _make_tasks(iter_name, jdata, step) : if step == 'angle_on' : all_lambda = parse_seq(jdata['lambda_angle_on']) protect_eps = jdata['protect_eps'] if all_lambda[0] == 0 : all_lambda[0] += protect_eps elif step == 'deep_on' : all_lambda = parse_seq(jdata['lambda_deep_on']) protect_eps = jdata['protect_eps'] if all_lambda[0] == 0 : all_lambda[0] += protect_eps elif step == 'bond_angle_off' : all_lambda = parse_seq(jdata['lambda_bond_angle_off']) protect_eps = jdata['protect_eps'] if all_lambda[-1] == 1 : all_lambda[-1] -= protect_eps equi_conf = jdata['equi_conf'] equi_conf = os.path.abspath(equi_conf) model = jdata['model'] model = os.path.abspath(model) # mass_map = jdata['mass_map'] mass_map = get_first_matched_key_from_dict(jdata, ['mass_map', 'model_mass_map']) nsteps = jdata['nsteps'] # dt = jdata['dt'] # timestep = jdata['timestep'] timestep = get_first_matched_key_from_dict(jdata, ['timestep', 'dt']) bparam = jdata['bond_param'] sparam = jdata['soft_param'] # stat_freq = jdata['stat_freq'] # thermo_freq = jdata['thermo_freq'] thermo_freq = get_first_matched_key_from_dict(jdata, ['thermo_freq', 'stat_freq']) ens = jdata['ens'] temp = jdata['temp'] pres = jdata['pres'] tau_t = jdata['tau_t'] tau_p = jdata['tau_p'] copies = None if 'copies' in jdata : copies = jdata['copies'] create_path(iter_name) cwd = os.getcwd() os.chdir(iter_name) os.symlink(os.path.join('..', 'in.json'), 'in.json') os.symlink(os.path.join('..', 'conf.lmp'), 'orig.lmp') os.symlink(os.path.join('..', 'graph.pb'), 'graph.pb') with open('orig.lmp', 'r') as f: lines = water.add_bonds(f.read().split('\n')) with open('conf.lmp', 'w') as c: c.write('\n'.join(lines)) os.chdir(cwd) for idx in range(len(all_lambda)) : work_path = os.path.join(iter_name, 'task.%06d' % idx) create_path(work_path) os.chdir(work_path) os.symlink(os.path.join('..', 'conf.lmp'), 'conf.lmp') os.symlink(os.path.join('..', 'graph.pb'), 'graph.pb') lmp_str \ = _gen_lammps_input(step, 'conf.lmp', mass_map, all_lambda[idx], 'graph.pb', bparam, sparam, nsteps, timestep, ens, temp, pres, tau_t = tau_t, tau_p = tau_p, prt_freq = thermo_freq, copies = copies) with open('in.lammps', 'w') as fp : fp.write(lmp_str) with open('lambda.out', 'w') as fp : fp.write(str(all_lambda[idx])) os.chdir(cwd)