def test_get_swap_sublattice_probabilities(self): """ Tests the get_swap_sublattice_probabilities function. """ # setup system with inactive sublattice prim = bulk('Al').repeat([2, 1, 1]) chemical_symbols = [['Al'], ['Ag', 'Al']] cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols) ce = ClusterExpansion(cs, [1] * len(cs)) supercell = prim.repeat(2) supercell[1].symbol = 'Ag' ce_calc = ClusterExpansionCalculator(supercell, ce) ensemble = CanonicalEnsemble(supercell, ce_calc, temperature=100) # test get_swap_sublattice_probabilities probs = ensemble._get_swap_sublattice_probabilities() self.assertEqual(len(probs), 2) self.assertEqual(probs[0], 1) self.assertEqual(probs[1], 0) # test raise when swap not possible on either lattice supercell[1].symbol = 'Al' ce_calc = ClusterExpansionCalculator(supercell, ce) with self.assertRaises(ValueError) as context: ensemble = CanonicalEnsemble(supercell, ce_calc, temperature=100) self.assertIn('No canonical swaps are possible on any of the', str(context.exception))
def test_sublattice_probabilities(self): """ Tests the sublattice_probabilities keyword argument. """ # setup system with inactive sublattice prim = bulk('W', 'bcc', cubic=True) prim[1].symbol = 'C' chemical_symbols = [['W', 'Ti'], ['C', 'N']] cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols) ce = ClusterExpansion(cs, [1] * len(cs)) structure = prim.repeat(2) structure[0].symbol = 'Ti' structure[1].symbol = 'N' calculator = ClusterExpansionCalculator(structure, ce) # test default ensemble = WangLandauEnsemble(structure, calculator, energy_spacing=1) probs = ensemble._get_swap_sublattice_probabilities() self.assertEqual(len(probs), 2) self.assertAlmostEqual(probs[0], 0.5) self.assertAlmostEqual(probs[1], 0.5) # test override ensemble = WangLandauEnsemble(structure, calculator, energy_spacing=1, sublattice_probabilities=[0.2, 0.8]) probs = ensemble._sublattice_probabilities self.assertEqual(len(probs), 2) self.assertAlmostEqual(probs[0], 0.2) self.assertAlmostEqual(probs[1], 0.8)
def setUp(self): """Setup before each test.""" self.calculator = ClusterExpansionCalculator(self.structure, self.ce) self.ensemble = CanonicalEnsemble(structure=self.structure, calculator=self.calculator, user_tag='test-ensemble', random_seed=42, data_container_write_period=499.0, ensemble_data_write_interval=25, trajectory_write_interval=40, temperature=self.temperature)
def setUp(self): """Setup before each test.""" self.calculator = ClusterExpansionCalculator(self.structure, self.ce) self.ensemble = CanonicalAnnealing( structure=self.structure, calculator=self.calculator, T_start=self.T_start, T_stop=self.T_stop, n_steps=self.n_steps, user_tag='test-ensemble', random_seed=42, data_container_write_period=499.0, ensemble_data_write_interval=25, trajectory_write_interval=40)
def setUp(self): """Setup before each test.""" self.calculator = ClusterExpansionCalculator(self.structure, self.ce) self.ensemble = HybridEnsemble( structure=self.structure, calculator=self.calculator, ensemble_specs=self.ensemble_specs, temperature=self.temperature, boltzmann_constant=1e-5, user_tag='test-ensemble', random_seed=42, data_container_write_period=499.0, ensemble_data_write_interval=25, trajectory_write_interval=40)
def test_get_sublattice_probabilities(self): """ Tests the get_swap/flip_sublattice_probabilities function. """ # setup system with inactive sublattice prim = bulk('Al').repeat([2, 1, 1]) chemical_symbols = [['Al'], ['Ag', 'Al']] cs = ClusterSpace(prim, cutoffs=[0], chemical_symbols=chemical_symbols) ce = ClusterExpansion(cs, [1] * len(cs)) structure = prim.repeat(2) structure[1].symbol = 'Ag' calculator = ClusterExpansionCalculator(structure, ce) ensemble = WangLandauEnsemble(structure, calculator, energy_spacing=1) # test get_swap_sublattice_probabilities probs = ensemble._get_swap_sublattice_probabilities() self.assertEqual(len(probs), 2) self.assertEqual(probs[0], 1) self.assertEqual(probs[1], 0) # test get_flip_sublattice_probabilities probs = ensemble._get_flip_sublattice_probabilities() self.assertEqual(len(probs), 2) self.assertEqual(probs[0], 1) self.assertEqual(probs[1], 0) # test raise when swap not possible on either lattice structure[1].symbol = 'Al' calculator = ClusterExpansionCalculator(structure, ce) with self.assertRaises(ValueError) as context: ensemble = WangLandauEnsemble(structure, calculator, energy_spacing=1) self.assertIn('No swaps are possible on any of the', str(context.exception))
def setUp(self): """Setup before each test.""" self.calculator = ClusterExpansionCalculator(self.structure, self.ce) self.ensemble = WangLandauEnsemble( structure=self.structure, calculator=self.calculator, user_tag='test-ensemble', random_seed=42, trial_move=self.trial_move, energy_spacing=self.energy_spacing, flatness_limit=self.flatness_limit, flatness_check_interval=self.flatness_check_interval, fill_factor_limit=self.fill_factor_limit, data_container_write_period=self.data_container_write_period, ensemble_data_write_interval=self.ensemble_data_write_interval, trajectory_write_interval=self.trajectory_write_interval)
def test_mc_with_one_filled_sublattice(self): """ Tests if WL simulation works with two sublattices where one sublattice is filled/empty. """ # setup two sublattices prim = bulk('W', crystalstructure='bcc', a=1.0, cubic=True) cs = ClusterSpace(prim, [1.5], [['W', 'Ti'], ['C', 'Be']]) ce = ClusterExpansion(cs, [1] * len(cs)) # setup supercell with one filled sublattice structure = prim.copy() structure[1].symbol = 'C' structure = structure.repeat(4) structure[2].symbol = 'Ti' # run mc calculator = ClusterExpansionCalculator(structure, ce) mc = WangLandauEnsemble(structure, calculator, energy_spacing=1) mc.run(50)
def print_timing_ratios(structure, local_iters, total_iters, sizes, cutoffs): """ Prints timing ratios between local and total energy calculations. """ print( '# 1:size 2:local_iters 3:total_iters 4:atom size, 5:ce calc init time (sec)' ', 6:t_local 7:t_total 8:t_total/t_local') cs = ClusterSpace(structure, cutoffs, chemical_symbols=['Al', 'Ga']) parameters = np.array([1.2 for _ in range(len(cs))]) ce = ClusterExpansion(cs, parameters) for size in sizes: structure_cpy = structure.repeat(size) occupations = structure_cpy.get_atomic_numbers() t0 = time.time() calculator = ClusterExpansionCalculator(structure_cpy, ce) time_ce_init = time.time() - t0 t_local = time_local_energy(calculator, occupations, local_iters) t_total = time_total_energy(calculator, occupations, total_iters) print(size, local_iters, total_iters, len(structure_cpy), time_ce_init, t_local, t_total, t_total / t_local)
def setUp(self): """Setup before each test.""" self.calculator = ClusterExpansionCalculator(self.structure, self.ce) self.structure = bulk('Al').repeat(3) for i, atom in enumerate(self.structure): if i % 2 == 0: atom.symbol = 'Ga' self.ensemble = SemiGrandCanonicalEnsemble( structure=self.structure, calculator=self.calculator, user_tag='test-ensemble', random_seed=42, data_container_write_period=499.0, ensemble_data_write_interval=25, trajectory_write_interval=40, temperature=self.temperature, chemical_potentials=self.chemical_potentials, boltzmann_constant=1e-5)
def test_mc_with_one_filled_sublattice(self): """ Tests if canonical ensemble works with two sublattices where one sublattice is filled/empty. """ # setup two sublattices prim = bulk('W', 'bcc', a=3.0, cubic=True) cs = ClusterSpace(prim, [4.0], [['W', 'Ti'], ['C', 'Be']]) ce = ClusterExpansion(cs, np.arange(0, len(cs))) # setup supercell with one filled sublattice supercell = prim.copy() supercell[1].symbol = 'C' supercell = supercell.repeat(4) supercell[2].symbol = 'Ti' # run mc calc = ClusterExpansionCalculator(supercell, ce) mc = CanonicalEnsemble(supercell, calc, 300) mc.run(50)
from ase.build import make_supercell from icet import ClusterExpansion from mchammer.calculators import ClusterExpansionCalculator from mchammer.ensembles import SemiGrandCanonicalEnsemble import numpy as np from os import mkdir # step 1: Set up structure to simulate as well as calculator ce = ClusterExpansion.read('mixing_energy.ce') structure = make_supercell(ce.get_cluster_space_copy().primitive_structure, 3 * np.array([[-1, 1, 1], [1, -1, 1], [1, 1, -1]])) calculator = ClusterExpansionCalculator(structure, ce) # step 2: Carry out Monte Carlo simulations # Make sure output directory exists output_directory = 'monte_carlo_data' try: mkdir(output_directory) except FileExistsError: pass for temperature in [900, 300]: # Evolve configuration through the entire composition range for dmu in np.arange(-0.7, 0.51, 0.05): # Initialize MC ensemble mc = SemiGrandCanonicalEnsemble( structure=structure, calculator=calculator, temperature=temperature, dc_filename='{}/sgc-T{}-dmu{:+.3f}.dc'.format( output_directory, temperature, dmu), chemical_potentials={