コード例 #1
0
def make_repro(vasp_path, path_to_work):
    if not os.path.exists(vasp_path):
        raise RuntimeError("please do VASP calcualtions first")
    vasp_task = glob.glob(os.path.join(vasp_path, 'task.[0-9]*[0-9]'))
    assert len(vasp_task) > 0, "Please do VASP calcualtions first"
    vasp_task.sort()
    task_num = 0
    task_list = []
    for ii in vasp_task:
        # get vasp energy
        outcar = os.path.join(ii, 'OUTCAR')
        energies = vasp.get_energies(outcar)
        # get xdat
        xdatcar = os.path.join(ii, 'XDATCAR')
        os.chdir(path_to_work)
        if os.path.exists('XDATCAR'):
            os.remove('XDATCAR')
        os.symlink(os.path.relpath(xdatcar), 'XDATCAR')
        xdat_lines = open('XDATCAR', 'r').read().split('\n')
        natoms = vasp.poscar_natoms('XDATCAR')
        xdat_secsize = natoms + 8
        xdat_nframes = len(xdat_lines) // xdat_secsize
        if xdat_nframes > len(energies):
            warnings.warn(
                'nframes %d in xdatcar is larger than energy %d, use the last %d frames'
                % (xdat_nframes, len(energies), len(energies)))
            xdat_nlines = -1 * len(energies) * xdat_secsize  # 06/12 revised
            xdat_lines = xdat_lines[xdat_nlines:]
        xdat_nframes = len(xdat_lines) // xdat_secsize
        print(xdat_nframes, len(energies))

        # loop over frames
        for jj in range(xdat_nframes):
            output_task = os.path.join(path_to_work, 'task.%06d' % task_num)
            task_num += 1
            task_list.append(output_task)
            os.makedirs(output_task, exist_ok=True)
            os.chdir(output_task)
            # clear dir
            for kk in [
                    'INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR', 'conf.lmp',
                    'in.lammps'
            ]:
                if os.path.exists(kk):
                    os.remove(kk)
            # make conf
            with open('POSCAR', 'w') as fp:
                fp.write('\n'.join(xdat_lines[jj * xdat_secsize:(jj + 1) *
                                              xdat_secsize]))

    return task_list
コード例 #2
0
ファイル: EOS.py プロジェクト: kevinwenminion/atest-refact
 def make_confs(self, path_to_work, path_to_equi, refine=False):
     path_to_work = os.path.abspath(path_to_work)
     path_to_equi = os.path.abspath(path_to_equi)
     cwd = os.getcwd()
     task_list = []
     if refine:
         task_list = make_refine(
             self.parameter['init_from_suffix'],
             self.parameter['output_suffix'], path_to_work,
             (self.vol_end - self.vol_start) / self.vol_step)
         os.chdir(cwd)
     if self.reprod:
         if 'vasp_path' not in self.parameter:
             raise RuntimeError(
                 "please provide the vasp_path for reproduction")
         vasp_path = os.path.abspath(self.parameter['vasp_path'])
         task_list = reproduce.make_repro(vasp_path, path_to_work)
         os.chdir(cwd)
     else:
         equi_contcar = os.path.join(path_to_equi, 'CONTCAR')
         if not os.path.exists(equi_contcar):
             raise RuntimeError("please do relaxation first")
         vol_to_poscar = vasp.poscar_vol(equi_contcar) / vasp.poscar_natoms(
             equi_contcar)
         for vol in np.arange(self.vol_start, self.vol_end, self.vol_step):
             task_num = (vol - self.vol_start) / self.vol_step
             output_task = os.path.join(path_to_work,
                                        'task.%06d' % task_num)
             os.makedirs(output_task, exist_ok=True)
             os.chdir(output_task)
             for ii in [
                     'INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR', 'conf.lmp',
                     'in.lammps'
             ]:
                 if os.path.exists(ii):
                     os.remove(ii)
             task_list.append(output_task)
             os.symlink(os.path.relpath(equi_contcar), 'POSCAR.orig')
             scale = (vol / vol_to_poscar)**(1. / 3.)
             self.parameter['scale2equi'] = scale  # 06/14
             vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale)
         os.chdir(cwd)
     return task_list
コード例 #3
0
def make_deepmd_lammps (jdata, conf_dir) :
    deepmd_model_dir = jdata['deepmd_model_dir']
    deepmd_type_map = jdata['deepmd_type_map']
    ntypes = len(deepmd_type_map)    
    deepmd_model_dir = os.path.abspath(deepmd_model_dir)
    deepmd_models = glob.glob(os.path.join(deepmd_model_dir, '*pb'))
    deepmd_models_name = [os.path.basename(ii) for ii in deepmd_models]
    vol_start = jdata['vol_start']
    vol_end = jdata['vol_end']
    vol_step = jdata['vol_step']

    # # get equi props
    # equi_path = re.sub('confs', global_equi_name, conf_path)
    # equi_path = os.path.join(equi_path, 'lmp')
    # equi_log = os.path.join(equi_path, 'log.lammps')
    # if not os.path.isfile(equi_log) :
    #     raise RuntimeError("the system should be equilibriated first")
    # natoms, epa, vpa = lammps.get_nev(equi_log)
    # task path
    task_path = re.sub('confs', global_task_name, conf_dir)
    task_path = os.path.abspath(task_path)
    os.makedirs(task_path, exist_ok = True)
    cwd = os.getcwd()
    conf_path = os.path.abspath(conf_dir)
    from_poscar = os.path.join(conf_path, 'POSCAR')
    to_poscar = os.path.join(task_path, 'POSCAR')
    if os.path.exists(to_poscar) :
        assert(filecmp.cmp(from_poscar, to_poscar))
    else :
        os.chdir(task_path)
        os.symlink(os.path.relpath(from_poscar), 'POSCAR')
        os.chdir(cwd)
    volume = vasp.poscar_vol(to_poscar)
    natoms = vasp.poscar_natoms(to_poscar)
    vpa = volume / natoms
    # structrure
    ss = Structure.from_file(to_poscar)
    # lmp path
    lmp_path = os.path.join(task_path, 'deepmd')
    os.makedirs(lmp_path, exist_ok = True)
    # # lmp conf
    # conf_file = os.path.join(lmp_path, 'conf.lmp')
    # lammps.cvt_lammps_conf(to_poscar, conf_file)
    # ptypes = vasp.get_poscar_types(to_poscar)
    # lammps.apply_type_map(conf_file, deepmd_type_map, ptypes)
    os.chdir(lmp_path)
    for ii in deepmd_models_name :
        if os.path.exists(ii) :
            os.remove(ii)
    for (ii,jj) in zip(deepmd_models, deepmd_models_name) :
            os.symlink(os.path.relpath(ii), jj)
    share_models = glob.glob(os.path.join(lmp_path, '*pb'))

    for vol in np.arange(vol_start, vol_end, vol_step) :
        vol_path = os.path.join(lmp_path, 'vol-%.2f' % vol)        
        print('# generate %s' % (vol_path))
        os.makedirs(vol_path, exist_ok = True)
        os.chdir(vol_path)
        #print(vol_path)
        for ii in ['conf.lmp', 'conf.lmp'] + deepmd_models_name :
            if os.path.exists(ii) :
                os.remove(ii)                
        # # link conf
        # os.symlink(os.path.relpath(conf_file), 'conf.lmp')
        # make conf
        scale_ss = ss.copy()
        scale_ss.scale_lattice(vol * natoms)
        scale_ss.to('POSCAR', 'POSCAR')
        lammps.cvt_lammps_conf('POSCAR', 'conf.lmp')
        ptypes = vasp.get_poscar_types('POSCAR')
        lammps.apply_type_map('conf.lmp', deepmd_type_map, ptypes)
        # link models
        for (ii,jj) in zip(share_models, deepmd_models_name) :
            os.symlink(os.path.relpath(ii), jj)
        # make lammps input
        scale = (vol / vpa) ** (1./3.)
        fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale,lammps.inter_deepmd, deepmd_models_name)
        with open(os.path.join(vol_path, 'lammps.in'), 'w') as fp :
            fp.write(fc)
        os.chdir(cwd)
コード例 #4
0
def make_meam_lammps_fixv (jdata, conf_dir) :
    meam_potfile_dir = jdata['meam_potfile_dir']
    meam_potfile_dir = os.path.abspath(meam_potfile_dir)
    meam_potfile = jdata['meam_potfile']
    meam_potfile = [os.path.join(meam_potfile_dir,ii) for ii in meam_potfile]
    meam_potfile_name = jdata['meam_potfile']
    type_map = jdata['meam_type_map']
    ntypes = len(type_map)
    meam_param = {'meam_potfile' :      jdata['meam_potfile'],
                  'meam_type':          jdata['meam_param_type']}

    vol_start = jdata['vol_start']
    vol_end = jdata['vol_end']
    vol_step = jdata['vol_step']

    # get equi props
    equi_path = re.sub('confs', global_equi_name, conf_dir)
    task_path = re.sub('confs', global_task_name, conf_dir)
    equi_path = os.path.join(equi_path, 'meam')
    task_path = os.path.join(task_path, 'meam')
    equi_path = os.path.abspath(equi_path)
    task_path = os.path.abspath(task_path)
    equi_log = os.path.join(equi_path, 'log.lammps')
    equi_dump = os.path.join(equi_path, 'dump.relax')
    os.makedirs(task_path, exist_ok = True)
    task_poscar = os.path.join(task_path, 'POSCAR')
    lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map)

    cwd = os.getcwd()
    volume = vasp.poscar_vol(task_poscar)
    natoms = vasp.poscar_natoms(task_poscar)
    vpa = volume / natoms
    # structrure
    ss = Structure.from_file(task_poscar)
    # make lammps.in
    fc = lammps.make_lammps_equi('conf.lmp', 
                                 ntypes, 
                                 lammps.inter_meam, 
                                 meam_param, 
                                 change_box = False)
    f_lammps_in = os.path.join(task_path, 'lammps.in')
    with open(f_lammps_in, 'w') as fp :
        fp.write(fc)
    # make vols
    for vol in np.arange(vol_start, vol_end, vol_step) :
        vol_path = os.path.join(task_path, 'vol-%.2f' % vol)        
        print('# generate %s' % (vol_path))
        os.makedirs(vol_path, exist_ok = True)
        os.chdir(vol_path)
        for ii in ['conf.lmp', 'conf.lmp', 'lammps.in'] + meam_potfile_name :
            if os.path.exists(ii) :
                os.remove(ii)                
        # make conf
        scale_ss = ss.copy()
        scale_ss.scale_lattice(vol * natoms)
        scale_ss.to('POSCAR', 'POSCAR')
        lammps.cvt_lammps_conf('POSCAR', 'conf.lmp')
        ptypes = vasp.get_poscar_types('POSCAR')
        lammps.apply_type_map('conf.lmp', type_map, ptypes)
        # link lammps.in
        os.symlink(os.path.relpath(f_lammps_in), 'lammps.in')
        # link models
        for (ii,jj) in zip(meam_potfile, meam_potfile_name) :
            os.symlink(os.path.relpath(ii), jj)
        # make lammps input
        os.chdir(cwd)
コード例 #5
0
def make_vasp(jdata, conf_dir) :
    fp_params = jdata['vasp_params']
    ecut = fp_params['ecut']
    ediff = fp_params['ediff']
    npar = fp_params['npar']
    kpar = fp_params['kpar']
    kspacing = fp_params['kspacing']
    kgamma = fp_params['kgamma']
    vol_start = jdata['vol_start']
    vol_end = jdata['vol_end']
    vol_step = jdata['vol_step']

    conf_path = os.path.abspath(conf_dir)
    task_path = re.sub('confs', global_task_name, conf_path)
    os.makedirs(task_path, exist_ok = True)
    cwd = os.getcwd()
    from_poscar = os.path.join(conf_path, 'POSCAR')
    to_poscar = os.path.join(task_path, 'POSCAR')
    if os.path.exists(to_poscar) :
        assert(filecmp.cmp(from_poscar, to_poscar))
    else :
        os.chdir(task_path)
        os.symlink(os.path.relpath(from_poscar), 'POSCAR')
        os.chdir(cwd)
    vol_to_poscar = vasp.poscar_vol(to_poscar) / vasp.poscar_natoms(to_poscar)
    # print(to_poscar, vol_to_poscar)
    is_alloy = \
               os.path.exists(
                   os.path.join(
                       os.path.join(conf_path, '..'),
                       'alloy'
                   )
               )    
    vasp_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing)
    os.makedirs(vasp_path, exist_ok = True)
    os.chdir(vasp_path)
    # gen incar
    if is_alloy :
        fc = vasp.make_vasp_relax_incar(ecut, ediff, True,  True, False, npar, kpar, kspacing, kgamma)
    else :
        fc = vasp.make_vasp_relax_incar(ecut, ediff, False, True, False, npar, kpar, kspacing, kgamma)
    with open('INCAR', 'w') as fp :
        fp.write(fc)
    # gen potcar
    with open(to_poscar,'r') as fp :
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list :
        assert(os.path.exists(potcar_map[ii]))
        potcar_list.append(potcar_map[ii])
    with open('POTCAR', 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    # loop over volumes
    for vol in np.arange(vol_start, vol_end, vol_step) :
        vol_path = os.path.join(vasp_path, 'vol-%.2f' % vol)        
        os.makedirs(vol_path, exist_ok = True)
        os.chdir(vol_path)
        print(vol_path)
        for ii in ['INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR'] :
            if os.path.exists(ii) :
                os.remove(ii)
        # link incar, potcar
        os.symlink(os.path.relpath(os.path.join(vasp_path, 'INCAR')), 'INCAR')
        os.symlink(os.path.relpath(os.path.join(vasp_path, 'POTCAR')), 'POTCAR')
        # gen poscar
        os.symlink(os.path.relpath(to_poscar), 'POSCAR.orig')
        scale = (vol / vol_to_poscar) ** (1./3.)
        # print(scale)
        vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale)
        # print(vol_path, vasp.poscar_vol('POSCAR') / vasp.poscar_natoms('POSCAR'))
        os.chdir(cwd)
コード例 #6
0
    def make_confs(self, path_to_work, path_to_equi, refine=False):
        path_to_work = os.path.abspath(path_to_work)
        if os.path.exists(path_to_work):
            dlog.warning('%s already exists' % path_to_work)
        else:
            os.makedirs(path_to_work)
        path_to_equi = os.path.abspath(path_to_equi)

        if 'start_confs_path' in self.parameter and os.path.exists(
                self.parameter['start_confs_path']):
            init_path_list = glob.glob(
                os.path.join(self.parameter['start_confs_path'], '*'))
            struct_init_name_list = []
            for ii in init_path_list:
                struct_init_name_list.append(ii.split('/')[-1])
            struct_output_name = path_to_work.split('/')[-2]
            assert struct_output_name in struct_init_name_list
            path_to_equi = os.path.abspath(
                os.path.join(self.parameter['start_confs_path'],
                             struct_output_name, 'relaxation', 'relax_task'))

        cwd = os.getcwd()
        task_list = []
        if self.reprod:
            print('eos reproduce starts')
            if 'init_data_path' not in self.parameter:
                raise RuntimeError(
                    "please provide the initial data path to reproduce")
            init_data_path = os.path.abspath(self.parameter['init_data_path'])
            task_list = make_repro(
                init_data_path, self.init_from_suffix, path_to_work,
                self.parameter.get('reprod_last_frame', True))
            os.chdir(cwd)

        else:
            if refine:
                print('eos refine starts')
                task_list = make_refine(self.parameter['init_from_suffix'],
                                        self.parameter['output_suffix'],
                                        path_to_work)
                os.chdir(cwd)

                init_from_path = re.sub(
                    self.parameter['output_suffix'][::-1],
                    self.parameter['init_from_suffix'][::-1],
                    path_to_work[::-1],
                    count=1)[::-1]
                task_list_basename = list(map(os.path.basename, task_list))

                for ii in task_list_basename:
                    init_from_task = os.path.join(init_from_path, ii)
                    output_task = os.path.join(path_to_work, ii)
                    os.chdir(output_task)
                    if os.path.isfile('eos.json'):
                        os.remove('eos.json')
                    if os.path.islink('eos.json'):
                        os.remove('eos.json')
                    os.symlink(
                        os.path.relpath(
                            os.path.join(init_from_task, 'eos.json')),
                        'eos.json')
                os.chdir(cwd)

            else:
                print('gen eos from ' + str(self.vol_start) + ' to ' +
                      str(self.vol_end) + ' by every ' + str(self.vol_step))
                equi_contcar = os.path.join(path_to_equi, 'CONTCAR')
                if not os.path.exists(equi_contcar):
                    raise RuntimeError("please do relaxation first")
                vol_to_poscar = vasp.poscar_vol(
                    equi_contcar) / vasp.poscar_natoms(equi_contcar)
                self.parameter['scale2equi'] = []

                task_num = 0
                while self.vol_start + self.vol_step * task_num < self.vol_end:
                    # for vol in np.arange(int(self.vol_start * 100), int(self.vol_end * 100), int(self.vol_step * 100)):
                    # vol = vol / 100.0
                    vol = self.vol_start + task_num * self.vol_step
                    #task_num = int((vol - self.vol_start) / self.vol_step)
                    output_task = os.path.join(path_to_work,
                                               'task.%06d' % task_num)
                    os.makedirs(output_task, exist_ok=True)
                    os.chdir(output_task)
                    for ii in [
                            'INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR',
                            'conf.lmp', 'in.lammps'
                    ]:
                        if os.path.exists(ii):
                            os.remove(ii)
                    task_list.append(output_task)
                    os.symlink(os.path.relpath(equi_contcar), 'POSCAR.orig')
                    # scale = (vol / vol_to_poscar) ** (1. / 3.)
                    scale = vol**(1. / 3.)
                    eos_params = {
                        'volume': vol * vol_to_poscar,
                        'scale': scale
                    }
                    dumpfn(eos_params, 'eos.json', indent=4)
                    self.parameter['scale2equi'].append(scale)  # 06/22
                    vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale)
                    task_num += 1
                os.chdir(cwd)
        return task_list
コード例 #7
0
def _make_reprod_traj(jdata, conf_dir, supercell, insert_ele, task_type):
    kspacing = jdata['vasp_params']['kspacing']
    fp_params = jdata['lammps_params']
    model_dir = fp_params['model_dir']
    type_map = fp_params['type_map']
    model_dir = os.path.abspath(model_dir)
    model_name = fp_params['model_name']
    if not model_name and task_type == 'deepmd':
        models = glob.glob(os.path.join(model_dir, '*pb'))
        model_name = [os.path.basename(ii) for ii in models]
        assert len(model_name) > 0, "No deepmd model in the model_dir"
    else:
        models = [os.path.join(model_dir, ii) for ii in model_name]

    model_param = {
        'model_name': fp_params['model_name'],
        'param_type': fp_params['model_param_type']
    }

    ntypes = len(type_map)

    conf_path = os.path.abspath(conf_dir)
    task_path = re.sub('confs', global_task_name, conf_path)
    vasp_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing)
    lmps_path = os.path.join(task_path, task_type + '-reprod-k%.2f' % kspacing)
    os.makedirs(lmps_path, exist_ok=True)
    copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
    struct_widecard = os.path.join(vasp_path,
                                   'struct-%s-%s-*' % (insert_ele, copy_str))
    vasp_struct = glob.glob(struct_widecard)
    vasp_struct.sort()
    cwd = os.getcwd()

    # make lammps.in
    if task_type == 'deepmd':
        fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_deepmd,
                                     model_name)
    elif task_type == 'meam':
        fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_meam,
                                     model_param)
    f_lammps_in = os.path.join(lmps_path, 'lammps.in')
    with open(f_lammps_in, 'w') as fp:
        fp.write(fc)

    for vs in vasp_struct:
        # get vasp energy
        outcar = os.path.join(vs, 'OUTCAR')
        energies = vasp.get_energies(outcar)
        # get xdat
        xdatcar = os.path.join(vs, 'XDATCAR')
        struct_basename = os.path.basename(vs)
        ls = os.path.join(lmps_path, struct_basename)
        print(ls)
        os.makedirs(ls, exist_ok=True)
        os.chdir(ls)
        if os.path.exists('XDATCAR'):
            os.remove('XDATCAR')
        os.symlink(os.path.relpath(xdatcar), 'XDATCAR')
        xdat_lines = open('XDATCAR', 'r').read().split('\n')
        natoms = vasp.poscar_natoms('XDATCAR')
        xdat_secsize = natoms + 8
        xdat_nframes = len(xdat_lines) // xdat_secsize
        if xdat_nframes > len(energies):
            warnings.warn(
                'nframes %d in xdat is larger than energy %d, use the last %d frames'
                % (xdat_nframes, len(energies), len(energies)))
            xdat_nlines = len(energies) * xdat_secsize
            xdat_lines = xdat_lines[xdat_nlines:]
        xdat_nframes = len(xdat_lines) // xdat_secsize
        print(xdat_nframes, len(energies))
        #link lammps.in and model
        for jj in ['lammps.in'] + model_name:
            if os.path.islink(jj):
                os.unlink(jj)
        os.symlink(os.path.relpath(f_lammps_in), 'lammps.in')
        if task_type == 'deepmd':
            for ii in model_name:
                if os.path.exists(ii):
                    os.remove(ii)
            for (ii, jj) in zip(models, model_name):
                os.symlink(os.path.relpath(ii), jj)
            share_models = glob.glob(os.path.join(ls, '*pb'))
        else:
            share_models = models

        # loop over frames
        for ii in range(xdat_nframes):
            frame_path = 'frame.%06d' % ii
            os.makedirs(frame_path, exist_ok=True)
            os.chdir(frame_path)
            # clear dir
            for jj in ['conf.lmp']:
                if os.path.isfile(jj):
                    os.remove(jj)
            for jj in ['lammps.in'] + model_name:
                if os.path.islink(jj):
                    os.unlink(jj)
            # link lammps in
            os.symlink(os.path.relpath('../lammps.in'), 'lammps.in')
            # make conf
            with open('POSCAR', 'w') as fp:
                fp.write('\n'.join(xdat_lines[ii * xdat_secsize:(ii + 1) *
                                              xdat_secsize]))
            lammps.cvt_lammps_conf('POSCAR', 'conf.lmp')
            ptypes = vasp.get_poscar_types('POSCAR')
            lammps.apply_type_map('conf.lmp', type_map, ptypes)
            # link models
            for (kk, ll) in zip(share_models, model_name):
                os.symlink(os.path.relpath(kk), ll)
            os.chdir(ls)
        os.chdir(cwd)
コード例 #8
0
def make_vasp(jdata, conf_dir) :
    vol_start = jdata['vol_start']
    vol_end = jdata['vol_end']
    vol_step = jdata['vol_step']
    eos_relax_cell_shape = jdata.get('eos_relax_cell_shape', True)
    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')

    if 'relax_incar' in jdata.keys():
        vasp_str='vasp-relax_incar'
    else:
        kspacing = jdata['vasp_params']['kspacing']
        vasp_str='vasp-k%.2f' % kspacing

    # get equi poscar
    equi_path = re.sub('confs', global_equi_name, conf_path)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_contcar = os.path.join(equi_path, 'CONTCAR')
    task_path = re.sub('confs', global_task_name, conf_path)
    task_path = os.path.join(task_path, vasp_str)
    os.makedirs(task_path, exist_ok = True)    
    # link poscar
    cwd = os.getcwd()
    from_poscar = os.path.join(equi_contcar)
    to_poscar = os.path.join(task_path, 'POSCAR')
    if os.path.exists(to_poscar) :
        assert(filecmp.cmp(from_poscar, to_poscar))
    else :
        os.chdir(task_path)
        os.symlink(os.path.relpath(from_poscar), 'POSCAR')
        os.chdir(cwd)
    vol_to_poscar = vasp.poscar_vol(to_poscar) / vasp.poscar_natoms(to_poscar)
    # print(to_poscar, vol_to_poscar)
    is_alloy = \
               os.path.exists(
                   os.path.join(
                       os.path.join(conf_path, '..'),
                       'alloy'
                   )
               )  
    # read potcar
    with open(to_poscar,'r') as fp :
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list :
        assert os.path.exists(os.path.abspath(potcar_map[ii])),"No POTCAR in the potcar_map of %s"%(ii)
        potcar_list.append(os.path.abspath(potcar_map[ii]))

    # gen incar
    if  'relax_incar' in jdata.keys():
        relax_incar_path = jdata['relax_incar']
        assert(os.path.exists(relax_incar_path))
        relax_incar_path = os.path.abspath(relax_incar_path)
        incar = incar_upper(Incar.from_file(relax_incar_path))
        if eos_relax_cell_shape:
            isif = 4
        else:
            isif = 2
        if incar.get('ISIF') != isif:
            dlog.info("%s:%s setting ISIF to %d" % (__file__, make_vasp.__name__, isif))
            incar['ISIF'] = isif
        fc = incar.get_string()
        kspacing = incar['KSPACING']
        kgamma = incar['KGAMMA']
    else :
        fp_params = jdata['vasp_params']
        ecut = fp_params['ecut']
        ediff = fp_params['ediff']
        npar = fp_params['npar']
        kpar = fp_params['kpar']
        kspacing = fp_params['kspacing']
        kgamma = fp_params['kgamma']
        fc = vasp.make_vasp_relax_incar(ecut, ediff, is_alloy,  True, False, npar, kpar, kspacing, kgamma)

    os.chdir(task_path)

    with open('INCAR', 'w') as fp :
        fp.write(fc)
    # gen potcar
    with open('POTCAR', 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    # loop over volumes
    for vol in np.arange(vol_start, vol_end, vol_step) :
        vol_path = os.path.join(task_path, 'vol-%.2f' % vol)        
        os.makedirs(vol_path, exist_ok = True)
        os.chdir(vol_path)
        for ii in ['INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR'] :
            if os.path.exists(ii) :
                os.remove(ii)
        # link incar, potcar
        os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR')
        os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR')
        # gen poscar
        os.symlink(os.path.relpath(to_poscar), 'POSCAR.orig')
        scale = (vol / vol_to_poscar) ** (1./3.)
        # print(scale)
        vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale)
        # print(vol_path, vasp.poscar_vol('POSCAR') / vasp.poscar_natoms('POSCAR'))
        # gen kpoints
        fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma)
        with open('KPOINTS', 'w') as fp: fp.write(fc)
        #copy cvasp
        if ('cvasp' in jdata) and (jdata['cvasp'] == True):
           shutil.copyfile(cvasp_file, os.path.join(vol_path,'cvasp.py'))
        os.chdir(cwd)
コード例 #9
0
def make_lammps_fixv (jdata, conf_dir,task_type) :
    fp_params = jdata['lammps_params']
    model_dir = fp_params['model_dir']
    type_map = fp_params['type_map'] 
    model_dir = os.path.abspath(model_dir)
    model_name =fp_params['model_name']
    deepmd_version = fp_params.get("deepmd_version", "0.12")
    if not model_name and task_type =='deepmd':
        models = glob.glob(os.path.join(model_dir, '*pb'))
        model_name = [os.path.basename(ii) for ii in models]
    else:
        models = [os.path.join(model_dir,ii) for ii in model_name]

    model_param = {'model_name' :      model_name,
                  'param_type':          fp_params['model_param_type'],
                  'deepmd_version' : deepmd_version}
    ntypes = len(type_map)


    vol_start = jdata['vol_start']
    vol_end = jdata['vol_end']
    vol_step = jdata['vol_step']

    # get equi props
    equi_path = re.sub('confs', global_equi_name, conf_dir)
    task_path = re.sub('confs', global_task_name, conf_dir)
    equi_path = os.path.join(equi_path, task_type)
    task_path = os.path.join(task_path, task_type)
    equi_path = os.path.abspath(equi_path)
    task_path = os.path.abspath(task_path)
    equi_dump = os.path.join(equi_path, 'dump.relax')
    os.makedirs(task_path, exist_ok = True)
    task_poscar = os.path.join(task_path, 'POSCAR')
    lammps.poscar_from_last_dump(equi_dump, task_poscar, type_map)

    cwd = os.getcwd()
    volume = vasp.poscar_vol(task_poscar)
    natoms = vasp.poscar_natoms(task_poscar)
    vpa = volume / natoms
    # structrure
    ss = Structure.from_file(task_poscar)
    # make lammps.in
    if task_type=='deepmd':
        fc = lammps.make_lammps_equi('conf.lmp', 
                                 ntypes, 
                                 lammps.inter_deepmd, 
                                 model_param, 
                                 change_box = False)
    elif task_type=='meam':
        fc = lammps.make_lammps_equi('conf.lmp', 
                                 ntypes, 
                                 lammps.inter_meam, 
                                 model_param, 
                                 change_box = False)
    f_lammps_in = os.path.join(task_path, 'lammps.in')
    with open(f_lammps_in, 'w') as fp :
        fp.write(fc)

    os.chdir(task_path)
    for ii in model_name :
        if os.path.exists(ii) :
            os.remove(ii)
    for (ii,jj) in zip(models, model_name) :
        os.symlink(os.path.relpath(ii), jj)
    share_models = [os.path.join(task_path,ii) for ii in model_name]

    # make vols
    for vol in np.arange(vol_start, vol_end, vol_step) :
        vol_path = os.path.join(task_path, 'vol-%.2f' % vol)        
        print('# generate %s' % (vol_path))
        os.makedirs(vol_path, exist_ok = True)
        os.chdir(vol_path)
        for ii in ['conf.lmp', 'conf.lmp', 'lammps.in'] + model_name :
            if os.path.exists(ii) :
                os.remove(ii)                
        # make conf
        scale_ss = ss.copy()
        scale_ss.scale_lattice(vol * natoms)
        scale_ss.to('POSCAR', 'POSCAR')
        lammps.cvt_lammps_conf('POSCAR', 'conf.lmp')
        ptypes = vasp.get_poscar_types('POSCAR')
        lammps.apply_type_map('conf.lmp', type_map, ptypes)
        # link lammps.in
        os.symlink(os.path.relpath(f_lammps_in), 'lammps.in')
        # link models
        for (ii,jj) in zip(share_models,model_name) :
            os.symlink(os.path.relpath(ii), jj)
        # make lammps input
        os.chdir(cwd)