diff --git a/Minimum Working Exemple/run.py b/Minimum Working Exemple/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9042d0e4905312a8266949ed651a99b0ed3a780e --- /dev/null +++ b/Minimum Working Exemple/run.py @@ -0,0 +1,63 @@ +import os +import sys +import ase.io +import numpy as np +from ase import Atoms, Atom +from ase.io import Trajectory +from sklearn.metrics import mean_squared_error +from dscribe.descriptors import SOAP +from scipy.interpolate import UnivariateSpline +from sklearn.gaussian_process import GaussianProcessRegressor +from sklearn.gaussian_process.kernels import RBF +from sklearn.model_selection import train_test_split, learning_curve, validation_curve, GridSearchCV +from joblib import Parallel, delayed +from ase import neighborlist +from sklearn.preprocessing import StandardScaler +from create_descriptor import * +from tool import * + +if __name__ == '__main__': + #initialisation + atomseul='H' #atome adsorbed + poscar_file='/mnt/beegfs/gzc01/iht74/THESE/Ag/POSCAR' #slab with no adsorbate + data_folder='/mnt/beegfs/gzc01/iht74/THESE/Ag/H/data' #folder where decriptors are saved + train_file='train.traj' + atoms_train=Trajectory(train_file) + + #identification of species and adsorbate + species=[] + elem=atoms_train[0].get_chemical_symbols() + #identification de l atome seul dans la structure + for el in range(len(elem)): + if elem[el] not in species: + species.append(elem[el]) + if elem[el]== atomseul: + ats=el + + #---> we create a 2*2 supercell for adsorbate to be far enough from pbc images, comment line if not necessary + atoms=ase.io.read(poscar_file, format='vasp') + atoms*=(2,2,1) + + #create a n*n grid where adsorbtion is predicted + xx,yy,zz=pos_to_relax(poscar_file,n=20) + + #create the descritors + params={'species':species,'l_max':3,'n_max':6,'r_cut':6} + desc=create_descriptor(method='soap',params=params,ats=ats) + X_train=desc.create(atoms_train,load=False)#--> True will save the decriptor in the data folder + y_train=[at.get_potential_energy() for at in atoms_train] + + y_mean=np.mean(y_train) + y_train=y_train-y_mean + scaler=StandardScaler() + X_train=scaler.fit_transform(X_train) + + #fit and prediction + kernel=1**2 * RBF(length_scale=200,length_scale_bounds=(1/np.sqrt(2*1e-0),1/np.sqrt(2*1e-8))) + GP = GaussianProcessRegressor(kernel=kernel) + parameters = {'alpha':[1e-4,]} + g_search = GridSearchCV(GP, parameters) + g_search.fit(X_train, y_train) + + + Parallel(n_jobs=10)(delayed(run_para)([xx[i],yy[i],zz[i]],i,desc,scaler,g_search,poscar=atoms) for i in range(len(xx))) \ No newline at end of file