Example #1
0
def cmpt_deepmd_lammps(jdata, conf_dir, supercell, task_name):
    equi_path = re.sub('confs', global_equi_name, conf_dir)
    equi_path = os.path.join(equi_path, task_name)
    equi_path = os.path.abspath(equi_path)
    equi_log = os.path.join(equi_path, 'log.lammps')
    task_path = re.sub('confs', global_task_name, conf_dir)
    task_path = os.path.join(task_path, task_name)
    task_path = os.path.abspath(task_path)
    print("# ", task_path)

    equi_natoms, equi_epa, equi_vpa = lammps.get_nev(equi_log)

    copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
    struct_path_widecard = os.path.join(task_path, 'struct-%s-*' % (copy_str))
    struct_path_list = glob.glob(struct_path_widecard)
    struct_path_list.sort()
    if len(struct_path_list) == 0:
        print("# cannot find results for conf %s supercell %s" %
              (conf_dir, supercell))
    sys.stdout.write("Structure: \tVac_E(eV)  E(eV) equi_E(eV)\n")
    for ii in struct_path_list:
        struct_poscar = os.path.join(ii, 'POSCAR')
        energy_shift = comput_e_shift(struct_poscar, task_name)
        structure_dir = os.path.basename(ii)
        lmp_log = os.path.join(ii, 'log.lammps')
        natoms, epa, vpa = lammps.get_nev(lmp_log)
        evac = epa * natoms - equi_epa * natoms
        sys.stdout.write(
            "%s: %7.3f  %7.3f %7.3f \n" %
            (structure_dir, evac, epa * natoms, equi_epa * natoms))
Example #2
0
def comput_lmp_nev(conf_dir, task_name, write_stable=False):
    conf_path = re.sub('confs', global_equi_name, conf_dir)
    conf_path = os.path.abspath(conf_path)
    poscar = os.path.join(conf_path, 'POSCAR')
    if write_stable:
        ele_types = vasp.get_poscar_types(poscar)
        if len(ele_types) > 1:
            raise RuntimeError(
                'stable energy and volume only for one element, current you have %s from POSCAR'
                % str(ele_types))
    ener_shift = comput_e_shift(poscar, task_name)

    lmp_path = os.path.join(conf_path, task_name)
    log_lammps = os.path.join(lmp_path, 'log.lammps')
    if os.path.isfile(log_lammps):
        natoms, epa, vpa = lammps.get_nev(log_lammps)
        epa = (epa * natoms - ener_shift) / natoms
        if write_stable:
            stable_dir = 'stables'
            os.makedirs(stable_dir, exist_ok=True)
            name_prefix = os.path.join(stable_dir,
                                       '%s.%s' % (ele_types[0], task_name))
            open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
            open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
        return natoms, epa, vpa
    else:
        return None, None, None
Example #3
0
def comput_lmp_eos(conf_dir, task_name):
    conf_path = re.sub('confs', global_task_name, conf_dir)
    conf_path = os.path.abspath(conf_path)
    conf_path = os.path.join(conf_path, task_name)
    vol_paths = glob.glob(os.path.join(conf_path, 'vol-*'))
    vol_paths.sort()
    print('Vpa(A^3)\tEpA(eV)')
    for ii in vol_paths:
        log_lammps = os.path.join(ii, 'log.lammps')
        natoms, epa, vpa = lammps.get_nev(log_lammps)
        print(vpa, epa)
def _cmpt_deepmd_reprod_traj(jdata, conf_dir, supercell, insert_ele,
                             task_name):
    fp_params = jdata['vasp_params']
    kspacing = fp_params['kspacing']

    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_name + '-k%.2f' % kspacing)
    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()

    for vs in vasp_struct:
        # compute vasp
        outcar = os.path.join(vs, 'OUTCAR')
        vasp_ener = np.array(vasp.get_energies(outcar))
        vasp_ener_file = os.path.join(vs, 'ener.vasp.out')
        # compute reprod
        struct_basename = os.path.basename(vs)
        ls = os.path.join(lmps_path, struct_basename)
        frame_widecard = os.path.join(ls, 'frame.*')
        frames = glob.glob(frame_widecard)
        frames.sort()
        lmp_ener = []
        for ii in frames:
            log_lmp = os.path.join(ii, 'log.lammps')
            natoms, epa, vpa = lammps.get_nev(log_lmp)
            lmp_ener.append(epa)
        lmp_ener = np.array(lmp_ener)
        lmp_ener = np.reshape(lmp_ener, [-1, 1])
        lmp_ener_file = os.path.join(ls, 'ener.lmp.out')
        vasp_ener = np.reshape(vasp_ener, [-1, 1]) / natoms
        error_start = 1
        lmp_ener -= lmp_ener[-1] - vasp_ener[-1]
        diff = lmp_ener - vasp_ener
        diff = diff[error_start:]
        error = np.linalg.norm(diff) / np.sqrt(np.size(lmp_ener))
        np.savetxt(vasp_ener_file, vasp_ener[error_start:])
        np.savetxt(lmp_ener_file, lmp_ener[error_start:])
        print(ls, error)