def get_soap_locals(obj, Hpos, rCutHard=8.0, NradBas=5, Lmax=5, atoms_list=None): assert Lmax <= 9, "l cannot exceed 9. Lmax={}".format(Lmax) assert Lmax >= 0, "l cannot be negative.Lmax={}".format(Lmax) assert rCutHard < 10.0001 , "hard redius cuttof cannot be larger than 10 Angs. rCut={}".format(rCutHard) assert rCutHard > 4.999 , "hard redius cuttof cannot be lower than 5 Ang. rCut={}".format(rCutHard) assert NradBas >= 2 , "number of basis functions cannot be lower than 2. NradBas={}".format(NradBas) assert NradBas <= 10 , "number of basis functions cannot exceed 10. NradBas={}".format(NradBas) # get clusgeo internal format for c-code Apos, typeNs, py_Ntypes, atomtype_lst, totalAN = format_ase2clusgeo(obj) # flatten Hpos array Hpos = np.array(Hpos) py_Hsize = Hpos.shape[0] Hpos = Hpos.flatten() alp, bet = genBasis.getBasisFunc(rCutHard, NradBas) #Declaring main soap array, for atoms in atoms_list if atoms_list == None: atoms_list = atomtype_lst soap_nfeature = NradBas**2*(Lmax+1) soap = np.zeros((py_Hsize, soap_nfeature*len(atoms_list))) # convert int to c_int alphas = (c_double*len(alp))(*alp) betas = (c_double*len(bet))(*bet) l = c_int(Lmax) Hsize = c_int(py_Hsize) Ntypes = c_int(py_Ntypes) totalAN = c_int(totalAN) rCutHard = c_double(rCutHard) Nsize = c_int(NradBas) #convert int array to c_int array typeNs = (c_int * len(typeNs))(*typeNs) print(l, Hsize, Ntypes, totalAN, typeNs, Nsize) # convert to c_double arrays #Apos axyz = (c_double * len(Apos))(*Apos.tolist()) #Hpos hxyz = (c_double * len(Hpos))(*Hpos.tolist()) ### START SOAP### path_to_so = os.path.dirname(os.path.abspath(__file__)) libsoap = CDLL(path_to_so + '/src/libsoapPy.so') libsoap.soap.argtypes = [POINTER (c_double),POINTER (c_double), POINTER (c_double),POINTER (c_double),POINTER (c_double), POINTER (c_int),c_double,c_int,c_int,c_int,c_int,c_int] libsoap.soap.restype = POINTER (c_double) # double* c, double* Apos,double* Hpos,int* typeNs, # int totalAN,int Ntypes,int Nsize, int l, int Hsize); c = (c_double*(soap_nfeature*py_Ntypes*py_Hsize))() c = libsoap.soap( c, axyz, hxyz, alphas, betas, typeNs, rCutHard, totalAN, Ntypes, Nsize, l, Hsize) # return c; soap_part = np.ctypeslib.as_array( c, shape=(py_Hsize,soap_nfeature*py_Ntypes)) for i in range(py_Hsize): for j_ind, j in enumerate(atoms_list): if j in atomtype_lst: j_ind_part = atomtype_lst.tolist().index(j) soap[i, soap_nfeature*j_ind:soap_nfeature*(j_ind+1)] = soap_part[i, soap_nfeature*j_ind_part:soap_nfeature*(j_ind_part+1)] return soap
def create(atoms_list,N, L, cutoff = 0, all_atomtypes=[]): """Takes a trajectory xyz file and writes soap features """ myAlphas, myBetas = genBasis.getBasisFunc(cutoff, N) # get information about feature length n_datapoints = len(atoms_list) atoms = atoms_list[0] x = get_lastatom_soap(atoms, cutoff, myAlphas, myBetas,N,L, all_atomtypes=all_atomtypes) n_features = x.shape[1] print("soap first", x.shape) print(n_datapoints, n_features) soapmatrix = np.zeros((n_datapoints, n_features)) i = -1 for atoms in atoms_list: i +=1 #atoms print("Processing " + str(atoms.info)," Run time: " + str(time.time()-t0_total), end="\r") soapmatrix[i,:] = get_lastatom_soap(atoms, cutoff, myAlphas, myBetas, N, L, all_atomtypes=all_atomtypes) print("") # infos print("shape", soapmatrix.shape) return soapmatrix
if len(args.arguments) > 1: print('Too many arguments') exit(1) trajfile = args.arguments[0] rootname = trajfile.replace(".xyz", "") traj = ase.io.read(trajfile, index=":") print("number of snapshots:", len(traj)) feature_mat = np.zeros((len(traj), 21)) NMAX = 10 LMAX = 9 RCUT = 8.0 myAlphas, myBetas = genBasis.getBasisFunc(RCUT, NMAX) n_datapoints = len(traj) for i, atoms in zip(np.arange(len(traj)), traj): print(i) cluster = atoms[:-1] last_atom = atoms[-1] distmat = get_distance_matrix(atoms) # get number of nearest neighbours, classify as top, bridge, hollow, 4-fold hollow first_shell, nn_dist_lst, nn_type, n_atoms_per_type_lst = get_first_shell( atoms, NN_CUTOFF, distmat) nnn = len(nn_dist_lst) print("number of nearest neighbours", nnn) soap_array = get_sitecenteredsoap(cluster,