Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if 'user_incar' in jdata.keys():
user_incar_path = jdata['user_incar']
assert(os.path.exists(user_incar_path))
user_incar_path = os.path.abspath(user_incar_path)
fc = open(user_incar_path).read()
kspacing =float(re.findall((r"KSPACING(.+?)\n"),fc)[0].replace('=',''))
kgamma =('T' in re.findall((r"KGAMMA(.+?)\n"),fc)[0])
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_phonon_incar(ecut, ediff, npar, kpar, kspacing = None, kgamma = None)
with open(os.path.join(task_path, 'INCAR'), 'w') as fp :
fp.write(fc)
# gen potcar
with open(task_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(os.path.join(task_path,'POTCAR'), 'w') as outfile:
for fname in potcar_list:
with open(fname) as infile:
outfile.write(infile.read())
# gen kpoints
def comput_lmp_eos(jdata,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(key=lambda k : float(k.split('-')[-1]))
result = os.path.join(conf_path,'result')
print('Vpa(A^3)\tEpA(eV)')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n VpA(A^3) EpA(eV)\n'% (conf_dir))
for ii in vol_paths :
log_lammps = os.path.join(ii, 'log.lammps')
natoms, epa, vpa = lammps.get_nev(log_lammps)
print(vpa, epa)
fp.write('%7.3f %8.4f \n' % (vpa,epa))
fp.close()
if 'upload_username' in jdata.keys() and task_name =='deepmd':
upload_username=jdata['upload_username']
util.insert_data('eos','deepmd',upload_username,result)
task_poscar = os.path.join(task_path, 'POSCAR')
cwd = os.getcwd()
os.chdir(task_path)
if os.path.isfile('POSCAR') :
os.remove('POSCAR')
os.symlink(os.path.relpath(conf_poscar), 'POSCAR')
os.chdir(cwd)
with open(task_poscar,'r') as fp :
lines = fp.read().split('\n')
ele_list = lines[5].split()
print(task_path)
# make conf.lmp
conf_file = os.path.join(task_path, 'conf.lmp')
lammps.cvt_lammps_conf(task_poscar, os.path.relpath(conf_file))
ptypes = vasp.get_poscar_types(task_poscar)
lammps.apply_type_map(conf_file, type_map, ptypes)
# make lammps.in
ntypes=len(ele_list)
unitcell=get_structure_from_poscar(task_poscar)
if task_type=='deepmd':
fc = lammps.make_lammps_phonon('conf.lmp',
unitcell.masses,
lammps.inter_deepmd,
model_name)
if task_type=='meam':
fc = lammps.make_lammps_phonon('conf.lmp',
unitcell.masses,
lammps.inter_meam,
model_param)
f_lammps_in = os.path.join(task_path, 'lammps.in')
with open(f_lammps_in, 'w') as fp :
task_poscar = os.path.join(task_path, 'POSCAR')
cwd = os.getcwd()
os.chdir(task_path)
if os.path.isfile('POSCAR') :
os.remove('POSCAR')
os.symlink(os.path.relpath(conf_poscar), 'POSCAR')
os.chdir(cwd)
with open(task_poscar,'r') as fp :
lines = fp.read().split('\n')
ele_list = lines[5].split()
print(task_path)
# make conf.lmp
conf_file = os.path.join(task_path, 'conf.lmp')
lammps.cvt_lammps_conf(task_poscar, os.path.relpath(conf_file))
ptypes = vasp.get_poscar_types(task_poscar)
lammps.apply_type_map(conf_file, type_map, ptypes)
# make lammps.in
ntypes=len(ele_list)
unitcell=get_structure_from_poscar(task_poscar)
if task_type=='deepmd':
fc = lammps.make_lammps_phonon('conf.lmp',
unitcell.masses,
lammps.inter_deepmd,
model_name)
if task_type=='meam':
fc = lammps.make_lammps_phonon('conf.lmp',
unitcell.masses,
lammps.inter_meam,
model_param)
f_lammps_in = os.path.join(task_path, 'lammps.in')
cwd = os.getcwd()
os.chdir(task_path)
if os.path.isfile('POSCAR') :
os.remove('POSCAR')
os.symlink(os.path.relpath(conf_poscar), 'POSCAR')
os.chdir(cwd)
with open(task_poscar,'r') as fp :
lines = fp.read().split('\n')
ele_list = lines[5].split()
print(task_path)
# make conf.lmp
conf_file = os.path.join(task_path, 'conf.lmp')
lammps.cvt_lammps_conf(task_poscar, os.path.relpath(conf_file))
ptypes = vasp.get_poscar_types(task_poscar)
lammps.apply_type_map(conf_file, type_map, ptypes)
# make lammps.in
ntypes=len(ele_list)
unitcell=get_structure_from_poscar(task_poscar)
if task_type=='deepmd':
fc = lammps.make_lammps_phonon('conf.lmp',
unitcell.masses,
lammps.inter_deepmd,
model_name)
if task_type=='meam':
fc = lammps.make_lammps_phonon('conf.lmp',
unitcell.masses,
lammps.inter_meam,
model_param)
f_lammps_in = os.path.join(task_path, 'lammps.in')
with open(f_lammps_in, 'w') as fp :
fp.write(fc)
def _cmpt_deepmd_lammps(jdata, conf_dir, supercell, insert_ele, task_name) :
equi_path = re.sub('confs', global_equi_name, conf_dir)
equi_path = os.path.join(equi_path, task_name.split('-')[0])
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)
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-%s-*' % (insert_ele,copy_str))
struct_path_list = glob.glob(struct_path_widecard)
print(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 ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
result = os.path.join(task_path,'result')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n'% (conf_dir))
fp.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
structure_dir = os.path.basename(ii)
lmp_log = os.path.join(ii, 'log.lammps')
def cmpt_deepmd_lammps(jdata, conf_dir, task_name, static = False) :
equi_path = re.sub('confs', global_equi_name, conf_dir)
equi_path = os.path.join(equi_path, task_name.split('-')[0])
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)
equi_natoms, equi_epa, equi_vpa = lammps.get_nev(equi_log)
struct_path_widecard = os.path.join(task_path, 'struct-*-m*m')
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" % (conf_dir))
sys.stdout.write ("Miller_Indices: \tSurf_E(J/m^2) EpA(eV) equi_EpA(eV)\n")
result = os.path.join(task_path,'result')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n'% (conf_dir))
fp.write("Miller_Indices: \tSurf_E(J/m^2) EpA(eV) equi_EpA(eV)\n")
for ii in struct_path_list :
structure_dir = os.path.basename(ii)
lmp_log = os.path.join(ii, 'log.lammps')
natoms, epa, vpa = lammps.get_nev(lmp_log)
AA = lammps.get_base_area(lmp_log)
stress = vasp.get_stress(equi_outcar)
np.savetxt(os.path.join(task_path, 'equi.stress.out'), stress)
# gen strcture
ss = Structure.from_file(task_poscar)
# gen defomations
norm_strains=np.arange(strain_start,strain_end,strain_step)
print('gen with norm '+str(norm_strains))
deformations=[]
for ii in norm_strains:
strain = Strain.from_index_amount(strain_direct, ii)
deformations.append(strain.get_deformation_matrix())
deformed_structures = [defo.apply_to_structure(ss)
for defo in deformations]
n_dfm = len(deformed_structures)
# gen incar
fc = vasp.make_vasp_relax_incar(ecut, ediff, True, False, False, npar=npar, kpar=kpar, kspacing = None, kgamma = None)
with open(os.path.join(task_path, 'INCAR'), 'w') as fp :
fp.write(fc)
# gen potcar
with open(task_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(os.path.join(task_path,'POTCAR'), 'w') as outfile:
for fname in potcar_list:
with open(fname) as infile:
outfile.write(infile.read())
# gen kpoints
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)
fc = open(relax_incar_path).read()
kspacing =float(re.findall((r"KSPACING(.+?)\n"),fc)[0].replace('=',''))
kgamma =('T' in re.findall((r"KGAMMA(.+?)\n"),fc)[0])
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, True, False, False, npar=npar,kpar=kpar, kspacing = kspacing, kgamma = kgamma)
with open(os.path.join(task_path, 'INCAR'), 'w') as fp :
fp.write(fc)
# gen potcar
with open(task_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]))
with open(os.path.join(task_path,'POTCAR'), 'w') as outfile:
for fname in potcar_list:
with open(fname) as infile:
outfile.write(infile.read())
dss.append(jj.generate_defect_structure(supercell))
# 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)
fc = open(relax_incar_path).read()
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, True, True, True, npar=npar,kpar=kpar, kspacing = kspacing, kgamma = kgamma)
with open(os.path.join(task_path, 'INCAR'), 'w') as fp :
fp.write(fc)
# gen potcar
with open(task_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]))
with open(os.path.join(task_path,'POTCAR'), 'w') as outfile:
for fname in potcar_list:
with open(fname) as infile:
outfile.write(infile.read())
# gen tasks