Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if task_type == 'static' \
or (task_type == 'surface' and static):
fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_eam_fs, model_param)
if task_type == 'elastic':
fc = lammps.make_lammps_elastic('conf.lmp', ntypes, lammps.inter_eam_fs, model_param,
etol, ftol, maxiter, maxeval)
if task_type == 'vacancy' \
or (task_type == 'eos' and change_box) \
or (task_type == 'interstitial'):
fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale2equi, lammps.inter_eam_fs,
model_param, B0, bp, etol, ftol, maxiter, maxeval)
if reprod_opt:
fc = lammps.make_lammps_eval('conf.lmp', ntypes, lammps.inter_eam_fs, model_param)
with open(os.path.join(output_dir, 'in.lammps'), 'w') as fp:
fp.write(fc)
os.symlink(os.path.relpath(ii), jj)
share_models = [os.path.join(task_path,ii) for ii in model_name]
for ii in range(len(dss)) :
struct_path = os.path.join(task_path, 'struct-%s-%s-%03d' % (insert_ele,copy_str,ii))
print('# generate %s' % (struct_path))
os.makedirs(struct_path, exist_ok=True)
os.chdir(struct_path)
for jj in ['conf.lmp', 'lammps.in'] + model_name :
if os.path.isfile(jj):
os.remove(jj)
# make conf
dss[ii].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)
# save supercell
np.savetxt('supercell.out', supercell, fmt='%d')
os.chdir(cwd)
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'] + model_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', type_map, ptypes)
# link models
for (ii,jj) in zip(share_models, model_name) :
os.symlink(os.path.relpath(ii), jj)
# make lammps input
scale = (vol / vpa) ** (1./3.)
if task_type=='deepmd':
fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale,lammps.inter_deepmd, model_name)
elif task_type =='meam':
fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale,lammps.inter_meam, model_param)
with open(os.path.join(vol_path, 'lammps.in'), 'w') as fp :
fp.write(fc)
os.chdir(cwd)
if 'scale2equi' in task_param:
scale2equi = task_param['scale2equi']
fc = lammps.make_lammps_press_relax('conf.lmp', ntypes, scale2equi[int(output_dir[-6:])],
self.inter_func,
self.model_param, B0, bp, etol, ftol, maxiter, maxeval)
else:
fc = lammps.make_lammps_equi('conf.lmp', ntypes, self.inter_func, self.model_param,
etol, ftol, maxiter, maxeval, True)
elif [relax_pos, relax_shape, relax_vol] == [False, False, False]:
fc = lammps.make_lammps_eval('conf.lmp', ntypes, self.inter_func, self.model_param)
else:
raise RuntimeError("not supported calculation setting for LAMMPS")
elif cal_type == 'static':
fc = lammps.make_lammps_eval('conf.lmp', ntypes, self.inter_func, self.model_param)
else:
raise RuntimeError("not supported calculation type for LAMMPS")
with open(os.path.join(output_dir, 'in.lammps'), 'w') as fp:
fp.write(fc)
def make_input_file(self,
output_dir,
task_type,
task_param):
lammps.cvt_lammps_conf(os.path.join(output_dir, 'POSCAR'), os.path.join(output_dir,'conf.lmp'))
with open(os.path.join(output_dir, 'task.json'), 'w') as fp:
json.dump(task_param, fp, indent=4)
# lines in lammps.in related to model
# line_model = "pair_style eam/alloy \n"
# line_model += "pair_coeff * * %s " % (os.path.basename(self.model))
# for ii in self.type_map:
# line_model += ii + ' '
# line_model += '\n'
etol = 1e-12
ftol = 1e-6
maxiter = 5000
maxeval = 500000
change_box = True
B0 = 70
bp = 0
def cmpt_deepmd_lammps(jdata, conf_dir, task_name) :
conf_path = os.path.abspath(conf_dir)
conf_poscar = os.path.join(conf_path, 'POSCAR')
task_path = re.sub('confs', global_task_name, conf_path)
task_path = os.path.join(task_path, task_name)
equi_stress = Stress(np.loadtxt(os.path.join(task_path, 'equi.stress.out')))
lst_dfm_path = glob.glob(os.path.join(task_path, 'dfm-*'))
lst_strain = []
lst_stress = []
for ii in lst_dfm_path :
strain = np.loadtxt(os.path.join(ii, 'strain.out'))
stress = lammps.get_stress(os.path.join(ii, 'log.lammps'))
# convert from pressure to stress
stress = -stress
lst_strain.append(Strain(strain))
lst_stress.append(Stress(stress))
et = ElasticTensor.from_independent_strains(lst_strain, lst_stress, eq_stress = equi_stress, vasp = False)
# et = ElasticTensor.from_independent_strains(lst_strain, lst_stress, eq_stress = None)
# bar to GPa
# et = -et / 1e4
print_et(et)
result = os.path.join(task_path,'result')
result_et(et,conf_dir,result)
if 'upload_username' in jdata.keys() and task_name=='deepmd':
upload_username=jdata['upload_username']
util.insert_data('elastic','deepmd',upload_username,result)