def if_in_the_database(compound, source_type): # source_type: 0:auid_tc.json 1:auid_none_tc.json 2:icsd.json resources = { 0: './data/resources/auid_tc.json', 1: './data/resources/auid_none_tc.json', 2: './data/resources/icsd.json' } auid_tc = json.load(open(resources[source_type])) _, n_list = decompose_formula(compound) retrival = [] result = [] for k, v in auid_tc.items(): _2, n_list2 = decompose_formula(v['compound']) if (_ == _2) and (ration_equal(n_list, n_list2)): retrival.append( (v['compound'], v['agl_thermal_conductivity_300K'], v['auid'])) result.append(True) else: result.append(False) return retrival, any(result)
def screen(n_ele, kappa, Egap): pred = np.load('./data/icsd/pred_tc.npy') info = np.load('./data/icsd/pred_tc_with_info.npy') Egap_database = json.load(open('./data/resources/Egap.json')) cmp = info[:, 1] cmp_list = [] for index, j in enumerate(cmp): auid = info[index][0] E_gap = Egap_database[auid]['Egap'] if E_gap is not None: E_gap = float(E_gap) ele_list, num_list = decompose_formula(j) total_num = np.sum(num_list) if (total_num < n_ele) and (pred[index] < kappa) and (E_gap > Egap): cmp_list.append((j, pred[index], auid, E_gap)) return cmp_list
def info_with_the_element(element): train_icsd = np.load('./data/train_icsd.npy') # tc=np.load('./result/pred_tc_log.npy') tc = np.load('./result/pred_tc.npy') tc_info = np.load('./result/pred_tc_with_info.npy') descriptor_with_the_element = [] tc_with_the_element = [] for index, info in enumerate(tc_info): # print(index) formula = info[1] ele, ele_number = decompose_formula(formula) if element in ele: descriptor_with_the_element.append(list(train_icsd[index])) tc_with_the_element.append(tc[index]) descriptor_with_the_element = np.array(descriptor_with_the_element) return descriptor_with_the_element, tc_with_the_element
def predict_thermal_conductivity(formula): """ :param formula: string type and standard format. like'Cu1Bi1S2' :return: the predicted thermal conductivity based on the XGBoost model. """ CW = get_atom_related_properties(formula=formula) # the following codes downloads crystal properties from aflow repository. element, element_number = decompose_formula(formula=formula) input_dict = {} for index, j in enumerate(element): input_dict[j] = element_number[index] print(input_dict) n_species = len(element) print(n_species) if n_species == 1: result = search().filter((K.species == element[0]) & (K.nspecies == n_species)).orderby( K.energy_cell) if n_species == 2: result = search().filter((K.species == element[0]) & (K.species == element[1]) & (K.nspecies == n_species)).orderby( K.energy_cell) if n_species == 3: result = search().filter((K.species == element[0]) & (K.species == element[1]) & (K.species == element[2]) & (K.nspecies == n_species)).orderby( K.energy_cell) if n_species == 4: result = search().filter((K.species == element[0]) & (K.species == element[1]) & (K.species == element[2]) & (K.species == element[3]) & (K.nspecies == n_species)).orderby( K.energy_cell) else: print("materials of n_species more than 4 are not considered yet.") compound_list = [] property_list = [] for entry in result: property = [] compound_list.append(entry.raw['compound']) property.append(entry.lattice_system_relax) property.append(entry.spacegroup_relax) property.append(entry.nspecies) property.append(entry.natoms) property.append(entry.volume_atom) property.append(entry.volume_cell) property.append(entry.density) property_list.append(property) target_comp = [] target_prop = [] for index, compound in enumerate(compound_list): ele, ele_n = decompose_formula(compound) input_n = [input_dict[x] for x in ele] if ration_equal(input_n, ele_n): target_comp.append(compound) target_prop.append(property_list[index]) # print(target_comp) # print(target_prop) for i in target_prop: lattice_system = i[0].strip() i[0] = lattice_dict[lattice_system] # print(target_prop) # [[3, 62, 3, 16, 22.5172, 360.275, 6.20653], # [3, 62, 3, 16, 22.5207, 360.332, 6.20556], # [3, 62, 3, 16, 22.4966, 359.945, 6.21222], # [3, 62, 3, 16, 22.4606, 359.37, 6.22217]] # the properties are similar in the list of target_prop. we can choose the one whose energy/cell is the minimum. cs = np.array(target_prop[0]) # cs=[ls,sg,nspecies,natoms_c,v_a,v_c,density] # cs=np.array([3, 62, 3, 16, 22.5172, 360.275, 6.20653]) descriptor = np.concatenate((cs, CW), axis=0) descriptor_final = np.reshape(descriptor, newshape=(1, descriptor.shape[0])) scaler = pickle.load( file=open(os.path.join('./models', 'scaler_ptc_ab.pkl'), 'rb')) descriptor_final = scaler.transform(descriptor_final) optimized_Model = pickle.load(file=open('./models/ptc_ab.pkl', 'rb')) predict_tc = optimized_Model.predict(descriptor_final) return np.exp(predict_tc)