Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def detect_batch_size(batch_size, system=None):
if type(batch_size) == int:
return batch_size
elif batch_size == "auto":
# automaticcaly set batch size, batch_size = 32 // atom_numb (>=1, <=fram_numb)
s = dpdata.LabeledSystem(system, fmt='deepmd/npy')
return int(min( np.ceil(32.0 / float(s["coords"].shape[1]) ), s["coords"].shape[0]))
else:
raise RuntimeError("Unsupported batch size")
def setUp(self):
self.places = 5
self.e_places = 5
self.f_places = 5
self.v_places = 2
assert os.path.isdir('out_data_post_fp_pwscf'), 'out data for post fp pwscf should exist'
if os.path.isdir('iter.000000') :
shutil.rmtree('iter.000000')
shutil.copytree('out_data_post_fp_pwscf', 'iter.000000')
with open (param_pwscf_file, 'r') as fp :
jdata = json.load (fp)
post_fp(0, jdata)
self.system_1 = dpdata.LabeledSystem('iter.000000/orig', fmt = 'deepmd/raw')
self.system_2 = dpdata.LabeledSystem('iter.000000/02.fp/data.000', fmt = 'deepmd/raw')
def test_coll(self):
with open (param_file, 'r') as fp :
jdata = json.load (fp)
jdata['out_dir'] = self.odir
coll_vasp_md(jdata)
sys = dpdata.LabeledSystem(self.odir + '/02.md/sys-004/deepmd//', fmt = 'deepmd/raw')
self.assertEqual(sys.get_nframes(), 2)
if sys.data['coords'][0][1][0] < sys.data['coords'][1][1][0]:
idx = [1, 0]
else :
idx = [0, 1]
ref_coord = self.ref_coord[idx]
ref_cell = self.ref_cell[idx]
ref_e = self.ref_e[idx]
ref_f = self.ref_f[idx]
ref_v = self.ref_v[idx]
ref_at = self.ref_at
for ff in range(2) :
self.assertAlmostEqual(ref_e[ff], sys.data['energies'][ff])
for ii in range(2) :
# goto input
cwd = os.getcwd()
os.chdir(target_folder)
jdata = json.load(open(param_file))
sys_configs_prefix = jdata.get('sys_configs_prefix', '')
sys_configs = jdata.get('sys_configs', [])
if verbose :
max_str_len = max([len(str(ii)) for ii in sys_configs])
max_form_len = 16
ptr_fmt = '%%%ds %%%ds natoms %%6d nframes %%6d' % (max_str_len+5, max_form_len)
# init systems
init_data = []
init_data_prefix = jdata.get('init_data_prefix', '')
init_data_sys = jdata.get('init_data_sys', [])
for ii in init_data_sys:
init_data.append(dpdata.LabeledSystem(os.path.join(init_data_prefix, ii), fmt='deepmd/npy'))
# collect systems from iter dirs
coll_data = {}
numb_sys = len(sys_configs)
model_devi_jobs = jdata.get('model_devi_jobs', {})
numb_jobs = len(model_devi_jobs)
iters = ['iter.%06d' % ii for ii in range(numb_jobs)]
# loop over iters to collect data
for ii in range(len(iters)) :
iter_data = glob.glob(os.path.join(iters[ii], '02.fp', 'data.[0-9]*[0-9]'))
iter_data.sort()
for jj in iter_data :
sys = dpdata.LabeledSystem(jj, fmt = 'deepmd/npy')
if merge:
sys_str = sys.formula
else:
sys_str = (os.path.basename(jj).split('.')[-1])
init_data_prefix = jdata.get('init_data_prefix', '')
init_data_sys = jdata.get('init_data_sys', [])
for ii in init_data_sys:
init_data.append(dpdata.LabeledSystem(os.path.join(init_data_prefix, ii), fmt='deepmd/npy'))
# collect systems from iter dirs
coll_data = {}
numb_sys = len(sys_configs)
model_devi_jobs = jdata.get('model_devi_jobs', {})
numb_jobs = len(model_devi_jobs)
iters = ['iter.%06d' % ii for ii in range(numb_jobs)]
# loop over iters to collect data
for ii in range(len(iters)) :
iter_data = glob.glob(os.path.join(iters[ii], '02.fp', 'data.[0-9]*[0-9]'))
iter_data.sort()
for jj in iter_data :
sys = dpdata.LabeledSystem(jj, fmt = 'deepmd/npy')
if merge:
sys_str = sys.formula
else:
sys_str = (os.path.basename(jj).split('.')[-1])
if sys_str in coll_data.keys():
coll_data[sys_str].append(sys)
else:
coll_data[sys_str] = sys
# print information
if verbose:
for ii in range(len(init_data)):
print(ptr_fmt % (str(init_data_sys[ii]),
init_data[ii].formula,
init_data[ii].get_natoms(),
init_data[ii].get_nframes() ))
keys = list(coll_data.keys())
fp_jdata = json.load(open(fp_json))
# fp settings
mass_map = jdata['mass_map']
type_map = jdata['type_map']
fp_style = fp_jdata['fp_style']
fp_pp_path = fp_jdata['fp_pp_path']
fp_pp_files = fp_jdata['fp_pp_files']
cwd_ = os.getcwd()
os.chdir(target_folder)
fp_pp_path = os.path.abspath(fp_pp_path)
os.chdir(cwd_)
# init data sys
init_data_prefix = jdata['init_data_prefix']
init_data_sys = jdata['init_data_sys']
for idx,ii in enumerate(init_data_sys):
sys = dpdata.LabeledSystem(os.path.join(init_data_prefix, ii), fmt = 'deepmd/npy', type_map = type_map)
nframes = sys.get_nframes()
sys_dir = os.path.join(output, 'init_system.%03d' % idx)
os.makedirs(sys_dir, exist_ok = True)
if verbose :
print('# working on ' + sys_dir)
with open(os.path.join(sys_dir,'record'), 'w') as fp:
fp.write(os.path.join(init_data_prefix, ii) + '\n')
for ff in range(nframes) :
task_dir = os.path.join(sys_dir, 'task.%06d' % ff)
os.makedirs(task_dir, exist_ok = True)
sys.to_vasp_poscar(os.path.join(task_dir, 'POSCAR'), frame_idx=ff)
# make fp
cwd_ = os.getcwd()
os.chdir(task_dir)
for pp in fp_pp_files :
if os.path.lexists(pp) :
system_index.sort()
set_tmp = set(system_index)
system_index = list(set_tmp)
system_index.sort()
cwd = os.getcwd()
for ss in system_index :
sys_output = glob.glob(os.path.join(work_path, "task.%s.*/output"%ss))
sys_input = glob.glob(os.path.join(work_path, "task.%s.*/input"%ss))
sys_output.sort()
sys_input.sort()
flag=True
for ii,oo in zip(sys_input,sys_output) :
if flag:
_sys = dpdata.LabeledSystem(oo, fmt = 'qe/pw/scf', type_map = jdata['type_map'])
if len(_sys)>0:
all_sys=_sys
flag=False
else:
pass
else:
_sys = dpdata.LabeledSystem(oo, fmt = 'qe/pw/scf', type_map = jdata['type_map'])
if len(_sys)>0:
all_sys.append(_sys)
sys_data_path = os.path.join(work_path, 'data.%s'%ss)
all_sys.to_deepmd_raw(sys_data_path)
all_sys.to_deepmd_npy(sys_data_path, set_size = len(sys_output))
flag=True
if ("type_map" in jdata) and isinstance(jdata["type_map"], list):
type_map = jdata["type_map"]
else:
type_map = None
for oo in valid_outcars :
if flag:
_sys = dpdata.LabeledSystem(oo, type_map= type_map)
if len(_sys)>0:
all_sys=_sys
flag=False
else:
pass
else:
_sys = dpdata.LabeledSystem(oo, type_map= type_map)
if len(_sys)>0:
all_sys.append(_sys)
# create deepmd data
if all_sys.get_nframes() >= coll_ndata :
all_sys = all_sys.sub_system(np.arange(coll_ndata))
all_sys.to_deepmd_raw('deepmd')
all_sys.to_deepmd_npy('deepmd', set_size = all_sys.get_nframes())
os.chdir(path_md)
os.chdir(cwd)
def get_system_cls(jdata):
if jdata.get("labeled", False):
return dpdata.LabeledSystem
return dpdata.System