Ejemplo n.º 1
0
def refine_tasks(from_task, to_task, err) :
    jdata = json.load(open(os.path.join(from_task, 'in.json')))    
    equi_conf = get_task_file_abspath(from_task, jdata['equi_conf'])
    model = get_task_file_abspath(from_task, jdata['model'])

    create_path(to_task)
    copied_conf = os.path.join(os.path.abspath(to_task), 'conf.lmp')
    shutil.copyfile(equi_conf, copied_conf)
    jdata['equi_conf'] = 'conf.lmp'
    linked_model = os.path.join(os.path.abspath(to_task), 'graph.pb')
    shutil.copyfile(model, linked_model)
    jdata['model'] = 'graph.pb'
    jdata['orig_task'] = from_task
    jdata['refine_error'] = err

    cwd = os.getcwd()
    os.chdir(to_task)
    with open('in.json', 'w') as fp:
        json.dump(jdata, fp, indent=4)
    os.chdir(cwd)

    from_name = os.path.join(from_task, '00.angle_on')
    to_name = os.path.join(to_task, '00.angle_on')
    _refine_tasks(from_name, to_name, err, 'angle_on')
    from_name = os.path.join(from_task, '01.deep_on')
    to_name = os.path.join(to_task, '01.deep_on')
    _refine_tasks(from_name, to_name, err, 'deep_on')
    from_name = os.path.join(from_task, '02.bond_angle_off')
    to_name = os.path.join(to_task, '02.bond_angle_off')
    _refine_tasks(from_name, to_name, err, 'bond_angle_off')
Ejemplo n.º 2
0
def _setup_dpdt (task_path, jdata) :
    name_0 = jdata['phase_i']['name']
    name_1 = jdata['phase_ii']['name']
    conf_0 = os.path.join(task_path, '../', jdata['phase_i']['equi_conf'])
    conf_1 = os.path.join(task_path, '../', jdata['phase_ii']['equi_conf'])
    conf_0 = os.path.abspath(conf_0)
    conf_1 = os.path.abspath(conf_1)
    model = os.path.join(task_path, '../', jdata['model'])
    if model:
        model = os.path.abspath(model)

    task_abs_dir = create_path(task_path)
    conf_0_name = 'conf.%s.lmp' % '0'
    conf_1_name = 'conf.%s.lmp' % '1'
    # conf_0_name = 'conf.%s.lmp' % name_0
    # conf_1_name = 'conf.%s.lmp' % name_1
    copied_conf_0 = os.path.join(os.path.abspath(task_path), conf_0_name)
    copied_conf_1 = os.path.join(os.path.abspath(task_path), conf_1_name)
    shutil.copyfile(conf_0, copied_conf_0)
    shutil.copyfile(conf_1, copied_conf_1)
    if model:
        linked_model = os.path.join(os.path.abspath(task_path), 'graph.pb')
        shutil.copyfile(model, linked_model)

    with open(os.path.join(os.path.abspath(task_path), 'in.json'), 'w') as fp:
        json.dump(jdata, fp, indent=4)
Ejemplo n.º 3
0
def make_tasks(iter_name, jdata, if_meam=None):
    if not if_meam:
        if_meam = jdata['if_meam']
    equi_conf = os.path.abspath(jdata['equi_conf'])
    if jdata.get('model', None):
        model = os.path.abspath(jdata['model'])
    else:
        model = None
    meam_model = jdata.get('meam_model', None)

    create_path(iter_name)
    copied_conf = os.path.join(os.path.abspath(iter_name), 'conf.lmp')
    shutil.copyfile(equi_conf, copied_conf)
    # jdata['equi_conf'] = copied_conf
    if model:
        copied_model = os.path.join(os.path.abspath(iter_name), 'graph.pb')
        shutil.copyfile(model, copied_model)
    # jdata['model'] = copied_model

    cwd = os.getcwd()
    os.chdir(iter_name)
    with open('in.json', 'w') as fp:
        json.dump(jdata, fp, indent=4)
    os.chdir(cwd)
    subtask_name = os.path.join(iter_name, '00.soft_on')
    _make_tasks(subtask_name,
                jdata,
                'soft_on',
                if_meam=if_meam,
                meam_model=meam_model)
    subtask_name = os.path.join(iter_name, '01.deep_on')
    _make_tasks(subtask_name,
                jdata,
                'deep_on',
                if_meam=if_meam,
                meam_model=meam_model)
    subtask_name = os.path.join(iter_name, '02.soft_off')
    _make_tasks(subtask_name,
                jdata,
                'soft_off',
                if_meam=if_meam,
                meam_model=meam_model)
Ejemplo n.º 4
0
def make_tasks(iter_name, jdata) :
    equi_conf = os.path.abspath(jdata['equi_conf'])
    model = os.path.abspath(jdata['model'])

    create_path(iter_name)
    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)    
    with open('in.json', 'w') as fp:
        json.dump(jdata, fp, indent=4)
    os.chdir(cwd)
    subtask_name = os.path.join(iter_name, '00.angle_on')
    _make_tasks(subtask_name, jdata, 'angle_on')
    subtask_name = os.path.join(iter_name, '01.deep_on')
    _make_tasks(subtask_name, jdata, 'deep_on')
    subtask_name = os.path.join(iter_name, '02.bond_angle_off')
    _make_tasks(subtask_name, jdata, 'bond_angle_off')
Ejemplo n.º 5
0
def make_task(iter_name,
              jdata,
              ens=None,
              temp=None,
              pres=None,
              avg_posi=None,
              npt_conf=None,
              if_meam=None):
    equi_conf = jdata['equi_conf']
    equi_conf = os.path.abspath(equi_conf)
    if npt_conf is not None:
        npt_conf = os.path.abspath(npt_conf)
    model = jdata['model']
    meam_model = jdata.get('meam_model', None)
    model = os.path.abspath(model)
    model_mass_map = jdata['model_mass_map']
    nsteps = jdata['nsteps']
    dt = jdata['dt']
    stat_freq = jdata['stat_freq']
    dump_freq = jdata['dump_freq']
    tau_t = jdata['tau_t']
    tau_p = jdata['tau_p']

    if ens is None:
        ens = jdata['ens']
    elif 'ens' in jdata:
        print('ens = %s overrides the ens in json data' % ens)
    jdata['ens'] = ens
    if temp is None:
        temp = jdata['temp']
    elif 'temp' in jdata:
        print('T = %f overrides the temp in json data' % temp)
    jdata['temp'] = temp
    if 'npt' in ens:
        if pres == None:
            pres = jdata['pres']
        elif 'pres' in jdata:
            print('P = %f overrides the pres in json data' % pres)
        jdata['pres'] = pres
    if if_meam is None:
        if_meam = jdata.get('if_meam', False)

    create_path(iter_name)
    cwd = os.getcwd()
    os.chdir(iter_name)
    with open('in.json', 'w') as fp:
        json.dump(jdata, fp, indent=4)
    if npt_conf is None:
        os.symlink(os.path.realpath(equi_conf), 'conf.lmp')
    else:
        open('conf.lmp', 'w').write(npt_equi_conf(npt_conf))
    os.symlink(os.path.realpath(model), 'graph.pb')
    lmp_str \
            = _gen_lammps_input('conf.lmp',
                            model_mass_map,
                            'graph.pb',
                            nsteps,
                            dt,
                            ens,
                            temp,
                            pres,
                            tau_t = tau_t,
                            tau_p = tau_p,
                            prt_freq = stat_freq,
                            dump_freq = dump_freq,
                            dump_ave_posi = avg_posi,
                            if_meam = if_meam,
                            meam_model = meam_model)
    with open('in.lammps', 'w') as fp:
        fp.write(lmp_str)
    os.chdir(cwd)
Ejemplo n.º 6
0
def _make_tasks_onephase(temp, 
                         pres, 
                         task_path, 
                         jdata,
                         ens = 'npt',
                         conf_file = 'conf.lmp', 
                         graph_file = 'graph.pb',
                         if_meam=False,
                         meam_model=None):
    # assume that model and conf.lmp exist in the current dir
    assert os.path.isfile(conf_file), (conf_file, os.getcwd())
    # assert(os.path.isfile(graph_file))
    conf_file = os.path.abspath(conf_file)
    if graph_file:
        graph_abs_file = os.path.abspath(graph_file)
    
    mass_map = jdata['mass_map']
    # MD simulation protocol
    nsteps = jdata['nsteps']
    timestep = jdata['timestep']
    thermo_freq = jdata['thermo_freq']
    tau_t = jdata['tau_t']
    tau_p = jdata['tau_p']

    cwd = os.getcwd()
    if not os.path.isdir(task_path):
        create_path(task_path)

    os.chdir(task_path)
    if not os.path.exists('conf.lmp'):
        os.symlink(os.path.relpath(conf_file), 'conf.lmp')
    if graph_file:
        if not os.path.exists('graph.pb'):
            os.symlink(os.path.relpath(graph_abs_file), 'graph.pb')

    if if_meam:
        relative_link_file(meam_model['library_abs_path'], './')
        relative_link_file(meam_model['potential_abs_path'], './')
        # 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)
    
    # input for NPT MD
    lmp_str \
        = _gen_lammps_input('conf.lmp',
                               mass_map, 
                               graph_file,
                               nsteps, 
                               timestep,
                               ens,
                               temp,
                               pres,
                               tau_t = tau_t,
                               tau_p = tau_p,
                               thermo_freq = thermo_freq,
                               if_meam=if_meam,
                               meam_model=meam_model)
    with open('thermo.out', 'w') as fp :
        fp.write('%.16e %.16e' % (temp, pres))
    with open('in.lammps', 'w') as fp :
        fp.write(lmp_str)

    os.chdir(cwd)
Ejemplo n.º 7
0
def make_task(iter_name,
              jdata,
              ens=None,
              temp=None,
              pres=None,
              if_dump_avg_posi=None,
              npt_dir=None):
    # jfile_path = os.path.abspath(jfile)
    # with open(jfile, 'r') as f:
    #     jdata = json.load(f)

    equi_args = [
        Argument("equi_conf", str),
        Argument("mass_map", list, alias=['model_mass_map']),
        Argument("model", str),
        Argument("nsteps", int),
        Argument("timestep", float, alias=['dt']),
        Argument("ens", str),
        Argument("temp", int),
        Argument("pres", int),
        Argument("tau_t", float),
        Argument("tau_p", float),
        Argument("thermo_freq", int, alias=['stat_freq']),
        Argument("dump_freq", int),
        Argument("stat_skip", int),
        Argument("stat_bsize", int),
        Argument("if_dump_avg_posi", bool, optional=True, default=False),
        Argument("is_water",
                 bool,
                 optional=True,
                 default=False,
                 alias=['if_water']),
        Argument("if_meam", bool, optional=True, default=False),
        Argument("meam_model", list, optional=True, default=False),
    ]

    equi_format = Argument("equi", dict, equi_args)

    equi_kwargs_settings = create_dict_not_empty_key(
        ens=ens,
        temp=temp,
        pres=pres,
        if_dump_avg_posi=if_dump_avg_posi,
        npt_dir=npt_dir)

    equi_pre_settings = jdata.copy()
    equi_pre_settings.update(equi_kwargs_settings)

    equi_settings = equi_format.normalize_value(equi_pre_settings)

    task_abs_dir = create_path(iter_name)

    if npt_dir is not None:
        npt_avg_conf_lmp = npt_equi_conf(npt_dir)
        with open(os.path.join(task_abs_dir, 'npt_avg.lmp'), 'w') as f:
            f.write(npt_avg_conf_lmp)
        equi_settings['equi_conf'] = 'npt_avg.lmp'
    else:
        equi_conf = equi_settings['equi_conf']
        relative_link_file(equi_conf, task_abs_dir)
        equi_settings['equi_conf'] = os.path.basename(equi_conf)

    model = equi_settings['model']
    if model:
        relative_link_file(model, task_abs_dir)
        equi_settings['model'] = os.path.basename(model)

    if_meam = equi_settings.get('if_meam', None)
    meam_model = equi_settings.get('meam_model', None)
    if if_meam:
        relative_link_file(meam_model['library'], task_abs_dir)
        relative_link_file(meam_model['potential'], task_abs_dir)

    with open(os.path.join(task_abs_dir, 'jdata.json'), 'w') as f:
        json.dump(jdata, f, indent=4)
    with open(os.path.join(task_abs_dir, 'equi_kwargs_setting.json'),
              'w') as f:
        json.dump(equi_kwargs_settings, f, indent=4)
    with open(os.path.join(task_abs_dir, 'equi_settings.json'), 'w') as f:
        json.dump(equi_settings, f, indent=4)

    lmp_str = gen_equi_lammps_input(
        nsteps=equi_settings['nsteps'],
        thermo_freq=equi_settings['thermo_freq'],
        dump_freq=equi_settings['dump_freq'],
        mass_map=equi_settings['mass_map'],
        temp=equi_settings['temp'],
        tau_t=equi_settings['tau_t'],
        tau_p=equi_settings['tau_p'],
        equi_conf=equi_settings['equi_conf'],
        model=equi_settings['model'],
        timestep=equi_settings['timestep'],
        if_dump_avg_posi=equi_settings['if_dump_avg_posi'],
        ens=equi_settings['ens'],
        pres=equi_settings['pres'],
        if_meam=equi_settings['if_meam'],
        meam_model=equi_settings['meam_model'])

    with open(os.path.join(task_abs_dir, 'in.lammps'), 'w') as fp:
        fp.write(lmp_str)
    return equi_settings
Ejemplo n.º 8
0
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)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)