def test_set_singlets( self ): if ( not has_ase_with_ce ): self.skipTest( "ASE version does not have CE" ) return system_types = [["Al","Mg"],["Al","Mg","Si"],["Al","Mg","Si","Cu"]] db_name = "test_singlets.db" n_concs = 4 no_throw = True msg = "" try: for basis_elems in system_types: conc_args = { "conc_ratio_min_1":[[1,0]], "conc_ratio_max_1":[[0,1]], } a = 4.05 mx_dia_name = get_max_cluster_dia_name() size_arg = {mx_dia_name:a} ceBulk = CEBulk( crystalstructure="fcc", a=a, size=[5, 5, 5], basis_elements=[basis_elems], conc_args=conc_args, \ db_name=db_name, max_cluster_size=2,**size_arg) ceBulk.reconfigure_settings() cf = CorrFunction(ceBulk) corrfuncs = cf.get_cf(ceBulk.atoms) eci = {name:1.0 for name in corrfuncs.keys()} calc = CE( ceBulk,eci ) for _ in range(n_concs): conc = np.random.rand(len(basis_elems))*0.97 conc /= np.sum(conc) conc_dict = {} for i in range(len(basis_elems)): conc_dict[basis_elems[i]] = conc[i] calc.set_composition(conc_dict) ref_cf = calc.get_cf() singlets = {} for key,value in ref_cf.items(): if ( key.startswith("c1") ): singlets[key] = value comp = calc.singlet2comp(singlets) dict_comp = "Ref {}. Computed {}".format(conc_dict,comp) for key in comp.keys(): self.assertAlmostEqual( comp[key], conc_dict[key], msg=dict_comp, places=1 ) calc.set_singlets(singlets) except Exception as exc: msg = str(exc) no_throw = False self.assertTrue( no_throw, msg=msg )
def test_double_swaps_ternary( self ): if ( not has_ase_with_ce ): # Disable this test self.skipTest("ASE version has not cluster expansion") return db_name = "test_db_ternary.db" conc_args = { "conc_ratio_min_1":[[4,0,0]], "conc_ratio_max_1":[[0,4,0]], "conc_ratio_min_1":[[2,2,0]], "conc_ratio_max_2":[[1,1,2]] } max_dia = get_max_cluster_dia_name() size_arg = {max_dia:4.05} ceBulk = CEBulk( crystalstructure="fcc", a=4.05, size=[4,4,4], basis_elements=[["Al","Mg","Si"]], \ conc_args=conc_args, db_name=db_name, max_cluster_size=3, **size_arg) ceBulk.reconfigure_settings() corr_func = CorrFunction( ceBulk ) cf = corr_func.get_cf( ceBulk.atoms ) #prefixes = [name.rpartition("_")[0] for name in cf.keys()] #prefixes.remove("") eci = {name:1.0 for name in cf.keys()} calc = CE( ceBulk, eci ) n_tests = 10 # Insert 25 Mg atoms and 25 Si atoms n = 18 for i in range(n): calc.calculate( ceBulk.atoms, ["energy"], [(i,"Al","Mg")]) calc.calculate( ceBulk.atoms, ["energy"], [(i+n,"Al","Si")]) updated_cf = calc.get_cf() brute_force = corr_func.get_cf_by_cluster_names( ceBulk.atoms, updated_cf.keys() ) for key in updated_cf.keys(): self.assertAlmostEqual( brute_force[key], updated_cf[key]) # Swap atoms for i in range(n_tests): indx1 = np.random.randint(low=0,high=len(ceBulk.atoms)) symb1 = ceBulk.atoms[indx1].symbol indx2 = indx1 symb2 = symb1 while( symb2 == symb1 ): indx2 = np.random.randint( low=0, high=len(ceBulk.atoms) ) symb2 = ceBulk.atoms[indx2].symbol calc.calculate( ceBulk.atoms, ["energy"], [(indx1,symb1,symb2),(indx2,symb2,symb1)]) update_cf = calc.get_cf() brute_force = corr_func.get_cf_by_cluster_names( ceBulk.atoms, update_cf.keys() ) for key,value in brute_force.items(): self.assertAlmostEqual( value, update_cf[key])
def init_bulk_crystal(self): max_dia_name = get_max_cluster_dia_name() size_arg = {max_dia_name: 4.05} conc = Concentration(basis_elements=[["Al", "Mg", "Si"]]) ceBulk = CEBulk(crystalstructure="fcc", a=4.05, size=[3, 3, 3], concentration=conc, db_name=db_name, max_cluster_size=3, **size_arg) ceBulk.reconfigure_settings() atoms = ceBulk.atoms.copy() calc = CE(atoms, ceBulk, ecis) return ceBulk, atoms
def init_bulk_crystal(self): conc_args = { "conc_ratio_min_1": [[2, 1, 1]], "conc_ratio_max_1": [[0, 2, 2]], } max_dia_name = get_max_cluster_dia_name() size_arg = {max_dia_name: 4.05} ceBulk = CEBulk(crystalstructure="fcc", a=4.05, size=[3, 3, 3], basis_elements=[["Al", "Mg", "Si"]], conc_args=conc_args, db_name=db_name, max_cluster_size=3, **size_arg) ceBulk.reconfigure_settings() calc = CE(ceBulk, ecis) ceBulk.atoms.set_calculator(calc) return ceBulk