Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 :
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)
def comput_e_shift(poscar, task_name) :
a_types = vasp.get_poscar_types(poscar)
a_natoms = vasp.get_poscar_natoms(poscar)
ener_shift = 0
if len(a_types) > 1 :
if not os.path.isdir('stables') :
raise RuntimeError('no dir "stable". Stable energy and volume of components should be computed before calculating formation energy of an alloy')
for ii in range(len(a_types)) :
ref_e_file = a_types[ii] + '.' + task_name + '.e'
ref_e_file = os.path.join('stables', ref_e_file)
ener = float(open(ref_e_file).read())
ener_shift += a_natoms[ii] * ener
return ener_shift
share_models = glob.glob(os.path.join(task_path, '*pb'))
else:
share_models = models
for ii in range(n_dfm) :
# make dir
dfm_path = os.path.join(task_path, 'dfm-%03d' % ii)
os.makedirs(dfm_path, exist_ok=True)
os.chdir(dfm_path)
for jj in ['conf.lmp', 'lammps.in'] + model_name :
if os.path.isfile(jj):
os.remove(jj)
# make conf
deformed_structures[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)
# record strain
strain = Strain.from_deformation(deformations[ii])
np.savetxt('strain.out', strain)
# 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)
cwd = os.getcwd()
from_poscar = os.path.join(conf_path, 'POSCAR')
to_poscar = os.path.join(equi_path, 'POSCAR')
if os.path.exists(to_poscar) :
assert(filecmp.cmp(from_poscar, to_poscar))
else :
os.chdir(equi_path)
os.symlink(os.path.relpath(from_poscar), 'POSCAR')
os.chdir(cwd)
# lmp path
lmp_path = os.path.join(equi_path, task_type)
os.makedirs(lmp_path, exist_ok = True)
print(lmp_path)
# lmp conf
conf_file = os.path.join(lmp_path, 'conf.lmp')
lammps.cvt_lammps_conf(to_poscar, os.path.relpath(conf_file))
ptypes = vasp.get_poscar_types(to_poscar)
lammps.apply_type_map(conf_file, type_map, ptypes)
# lmp input
if task_type=='deepmd':
fc = lammps.make_lammps_equi(os.path.basename(conf_file),
ntypes,
lammps.inter_deepmd,
model_name)
elif task_type=='meam':
fc = lammps.make_lammps_equi(os.path.basename(conf_file),
ntypes,
lammps.inter_meam,
model_param)
with open(os.path.join(lmp_path, 'lammps.in'), 'w') as fp :
fp.write(fc)
# link models
os.chdir(lmp_path)
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)
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]
for ii in range(n_dfm) :
# make dir
dfm_path = os.path.join(task_path, 'dfm-%03d' % ii)
os.makedirs(dfm_path, exist_ok=True)
os.chdir(dfm_path)
for jj in ['conf.lmp', 'lammps.in'] + model_name :
if os.path.isfile(jj):
os.remove(jj)
# make conf
dfm_ss.deformed_structures[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)
# record strain
strain = Strain.from_deformation(dfm_ss.deformations[ii])
np.savetxt('strain.out', strain)
# 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)
cwd = os.getcwd()