def amp_jobs(fdata,ndata,ntrain,job, dstype, dslist, amp_pes, Lload_amp, HL, E_conv, f_conv_list, Lgraph, ncore, n_mol, Ltwinx): ### parameter file outf = "hyperparam_" + job + ".dat" # to write input info total_images = get_total_image(fdata,ndata) # can read extxyz, OUTCAR, ntotal = len(total_images) print(f"dstype {dstype} dslist {dslist} with total {ntotal} data") tr_images, te_images = data_selection(total_images, dstype, dslist, job) if job == 'tr': ntrain = len(tr_images) # ntrain is redefined in case of job==train ntest = len(te_images) print(f"{ntest} test images") ### Force input in training f_conv = f_conv_list[0] f_coeff = 0.1 # default if len(f_conv_list) == 2: f_coeff = f_conv_list[1] ### AMP running parts if re.search("pr", job): y=[] for mol in total_images: y.append(mol.get_potential_energy()) if fdata.endswith('extxyz'): mplot_nvector([],y,fdata.split(".")[0],'sample','E(eV)') elif fdata == "OUTCAR": mplot_nvector([],y,Xtitle='sample',Ytitle='E(eV)') ### JOB == TRAINING elif re.search("tr",job): pwd = os.getcwd() ### prevent running tr in tr-directory amp_pot = None if os.path.isfile(amp_pes): if not Lload_amp: print(f"There is {amp_pes}, can't run training") sys.exit(10) else: amp_pot = amp_pes print("data training:total sets %d/%d" % (ntrain, ntotal)) f_write(outf, HL, E_conv, f_conv, f_coeff, ntotal, dstype, dslist) calc_train_images(tr_images, HL, E_conv, f_conv, f_coeff, ncore, amp_pot=amp_pot) ### Test after training:: not run in QSUB server = socket.gethostname() if server == 'chi' or server == 'login': outf = "runamp_te.dat" # to write input info title, suptitle = get_title(fdata, HL, E_conv,f_conv, f_coeff, ntrain, ntest) print("data test:train sets %d/%d" % (ntest, ntrain)) rmserr, max_res = calc_test_images(te_images, amp_pes, title, suptitle,ncore,Lgraph,Ltwinx=Ltwinx) f_write(outf, HL, E_conv, f_conv, f_coeff, ntotal,dstype, dslist, err=rmserr, max_res=max_res) ### JOB == TEST elif re.search("te",job): title, suptitle = get_title( fdata, HL, E_conv, f_conv,f_coeff, ntrain, ntest) print("data test:train sets %d/%d" % (ntest, ntrain)) rmserr, max_res = calc_test_images(te_images, amp_pes, title, suptitle,ncore,Lgraph,nmol=n_mol,Ltwinx=Ltwinx) f_write(outf, HL, E_conv, f_conv,f_coeff, ntotal,dstype, dslist, err=rmserr, max_res=max_res) return
def amp_jobs(fdata,ndata,job, dstype, dslist, amp_pes, HL, E_conv, f_conv, Lgraph, ncore, n_mol, Ltwinx): outf = "runamp_" + job + ".dat" # to write input info if ndata: if len(ndata) == 1: ini = 0 fin = ndata[0] elif len(ndata) == 2: ini = ndata[0] fin = ndata[1] ntotal = fin - ini st = '%d:%d' % (ini, fin) else: st = ':' ntotal = len(fdata) #print(st) total_images = ase.io.read(fdata, index=st) # can read extxyz, OUTCAR, ntotal = len(total_images) print(f"dstype {dstype} dslist {dslist}") tr_images, te_images = data_selection(total_images, dstype, dslist, job) ntrain = len(tr_images) ntest = len(te_images) if re.search("pr", job): y=[] for mol in total_images: y.append(mol.get_potential_energy()) if fdata.endswith('extxyz'): mplot_nvector([],y,fdata.split(".")[0],'sample','E(eV)') elif fdata == "OUTCAR": mplot_nvector([],y,Xtitle='sample',Ytitle='E(eV)') ### JOB == TRAINING elif re.search("tr",job): print("data training:total sets %d/%d" % (ntrain, ntotal)) f_write(outf, HL, E_conv, f_conv, ntotal, dstype, dslist) calc_train_images(tr_images, HL, E_conv, f_conv, ncore) ### test after training:: Do not turn on in qsub server = socket.gethostname() if server == 'chi' or server == 'login': outf = "runamp_te.dat" # to write input info title, suptitle = get_title(fdata, HL, E_conv,f_conv, ntrain, ntest) print("data test:train sets %d/%d" % (ntest, ntrain)) rmserr, max_res = calc_test_images(te_images, amp_pes, title, suptitle,Lgraph,ncore,Ltwinx=Ltwinx) f_write(outf, HL, E_conv, f_conv, ntotal,dstype, dslist, err=rmserr, max_res=max_res) ### JOB == TEST elif re.search("te",job): title, suptitle = get_title( fdata, HL, E_conv, f_conv, ntrain, ntest) print("data test:train sets %d/%d" % (ntest, ntrain)) rmserr, max_res = calc_test_images(te_images, amp_pes, title, suptitle,Lgraph,ncore,nmol=n_mol,Ltwinx=Ltwinx) f_write(outf, HL, E_conv, f_conv, ntotal,dstype, dslist, err=rmserr, max_res=max_res) elif re.search('md',job): # use first geometry atoms = ase.io.read(fdata, index='0') run_md(atoms) return
def amp_train(ntotal, images, amp_pes, HL, E_conv, f_conv, Lgraph, ncore, n_mol, Ltwinx): #total_images = ase.io.read(fdata, index=':') # can read extxyz, OUTCAR, #images_sets = Images(total_images, nsets=data_int) print("data training:total sets %d/%d" % (len(images), ntotal)) calc_train_images(images, HL, E_conv, f_conv, ncore) ### test after training:: Do not turn on in qsub title, suptitle = get_title(fdata, HL, E_conv, f_conv, len(total_images), len(images)) print("data test:total sets %d/%d" % (len(images), len(total_images))) rmserr, max_res = calc_test_images(job, images, amp_pes, title, suptitle, Lgraph, ncore, Ltwinx=Ltwinx) f_write('CONTCAR', HL, E_conv, f_conv, rmserr, max_res, job) return
def amp_jobs(fdata, job, data_int, amp_pes, HL, E_conv, f_conv, Lgraph, ncore, n_mol, Ltwinx): total_images = ase.io.read(fdata, index=':') # can read extxyz, OUTCAR, images_sets = Images(total_images, nsets=data_int) #if not os.path.isfile(amp_pes): if re.search("pr", job): y = [] for mol in total_images: y.append(mol.get_potential_energy()) if fdata.endswith('extxyz'): mplot_nvector([], y, fdata.split(".")[0], 'sample', 'E(eV)') elif fdata == "OUTCAR": mplot_nvector([], y, Xtitle='sample', Ytitle='E(eV)') ### JOB == TRAINING elif re.search("tr", job): if isinstance(data_int, int): images = images_sets.get_training_images() else: d_list = data_int[:2] images = images_sets.get_training_images(d_list=d_list) print("data training:total sets %d/%d" % (len(images), len(total_images))) calc_train_images(images, HL, E_conv, f_conv, ncore) ### test after training:: Do not turn on in qsub server = socket.gethostname() if server == 'chi': if isinstance(data_int, int): images = images_sets.get_test_images() else: if len(data_int) >= 3: if len(data_int) == 3: d_list = data_int[1:] else: d_list = data_int[2:] images = images_sets.get_test_images(d_list=d_list) else: print("There is no test set region in -di ") title, suptitle = get_title(fdata, HL, E_conv, f_conv, len(total_images), len(images)) print("data test:total sets %d/%d" % (len(images), len(total_images))) rmserr, max_res = calc_test_images(job, images, amp_pes, title, suptitle, Lgraph, ncore, Ltwinx=Ltwinx) f_write(fdata, HL, E_conv, f_conv, rmserr, max_res, job) ### JOB == TEST elif re.search("te", job): if isinstance(data_int, int): if data_int == 0: images = total_images else: images = images_sets.get_test_images() ### for data interval else: images = images_sets.get_test_images(d_list=data_int) title, suptitle = get_title(fdata, HL, E_conv, f_conv, len(total_images), len(images)) print("data test:total sets %d/%d" % (len(images), len(total_images))) rmserr, max_res = calc_test_images(job, images, amp_pes, title, suptitle, Lgraph, ncore, nmol=n_mol, Ltwinx=Ltwinx) f_write(fdata, HL, E_conv, f_conv, rmserr, max_res, job) elif re.search('md', job): # use first geometry atoms = ase.io.read(fdata, index='0') run_md(atoms) return