def testBackend(self): """ Test that the backend object is correctly constructed. """ # Setup a unitcell. unit_cell = KMCUnitCell(cell_vectors=numpy.array([[2.8,0.0,0.0], [0.0,3.2,0.0], [0.0,0.5,3.0]]), basis_points=[[0.0,0.0,0.0], [0.5,0.5,0.5], [0.25,0.25,0.75]]) # Setup the lattice. lattice = KMCLattice(unit_cell=unit_cell, repetitions=(4,4,1), periodic=(True,True,False)) types = ['A','A','A','A','B','B', 'A','A','A','B','B','B', 'B','B','A','A','B','A', 'B','B','B','A','B','A', 'B','A','A','A','B','B', 'B','B','B','B','B','B', 'A','A','A','A','B','B', 'B','B','A','B','B','A'] # Setup the configuration. config = KMCConfiguration(lattice=lattice, types=types, possible_types=['A','C','B']) # A first process. coords = [[1.0,2.0,3.4],[1.1,1.2,1.3]] types0 = ["A","B"] types1 = ["B","A"] sites = [0,1,2,3,4] rate_0_1 = 3.5 process_0 = KMCProcess(coords, types0, types1, basis_sites=sites, rate_constant=rate_0_1) # A second process. types0 = ["A","C"] types1 = ["C","A"] rate_0_1 = 1.5 process_1 = KMCProcess(coords, types0, types1, basis_sites=sites, rate_constant=rate_0_1) # Construct the interactions object. processes = [process_0, process_1] interactions = KMCInteractions(processes=processes) # Construct the model. model = KMCLatticeModel(config, interactions) # Get the c++ backend out. cpp_model = model._backend() # Check that this backend object is stored on the class. self.assertTrue(model._KMCLatticeModel__backend == cpp_model)
def testRunImplicitWildcards(self): """ Test that ta valid model can run for a few steps. """ # Setup a unitcell. unit_cell = KMCUnitCell(cell_vectors=numpy.array([[1.0,0.0,0.0], [0.0,1.0,0.0], [0.0,0.0,1.0]]), basis_points=[[0.0,0.0,0.0]]) # And a lattice. lattice = KMCLattice(unit_cell=unit_cell, repetitions=(10,10,1), periodic=(True,True,False)) # Set the stating configuration types. types = ['B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'A', 'B', 'B', 'B', 'B', 'B', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'A', 'B', 'B', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'A'] # Setup the configuration. config = KMCConfiguration(lattice=lattice, types=types, possible_types=["A","B"]) # Generate the interactions with a distance so large that we get a # layer of implicite wildcards in the C++ matchlists. sites = [0] coordinates = [[ 0.000000e+00, 0.000000e+00, 0.000000e+00], [ 1.000000e+00, 0.000000e+00, 0.000000e+00], [ -1.000000e+00, 0.000000e+00, 0.000000e+00], [ 0.000000e+00, -1.000000e+00, 0.000000e+00], [ 0.000000e+00, 1.000000e+00, 0.000000e+00], [ 2.000000e+00, 2.000000e+00, 0.000000e+00]] types0 = ['A', 'B', 'B', 'B', 'B', 'A'] types1 = ['B', 'B', 'A', 'B', 'B', 'A'] process_0 = KMCProcess(coordinates, types0, types1, None, sites, 1.0) types0 = ['A', 'B', 'B', 'B', 'B', 'B'] types1 = ['B', 'B', 'A', 'B', 'B', 'B'] process_1 = KMCProcess(coordinates, types0, types1, None, sites, 1.0) types0 = ['A', 'B', 'B', 'B', 'B', 'B'] types1 = ['B', 'B', 'B', 'A', 'B', 'B'] process_2 = KMCProcess(coordinates, types0, types1, None, sites, 1.0) types0 = ['A', 'B', 'B', 'B', 'B', 'B'] types1 = ['B', 'B', 'B', 'B', 'A', 'B'] process_3 = KMCProcess(coordinates, types0, types1, None, sites, 1.0) # Processes. processes = [process_0, process_1, process_2, process_3] # No implicit wildcards. interactions = KMCInteractions(processes=processes, implicit_wildcards=False) # Create the model. model = KMCLatticeModel(config, interactions) # Get the match types out. match_types = [ l.match_type for l in model._backend().interactions().processes()[0].minimalMatchList() ] # This does not have wildcards added. ref_match_types = [1, 2, 2, 2, 2, 1] self.assertEqual( match_types, ref_match_types ) # Create with implicit wildcards - this is default behavior. interactions = KMCInteractions(processes=processes) # Create the model. model = KMCLatticeModel(config, interactions) # Check the process matchlists again. match_types = [ l.match_type for l in model._backend().interactions().processes()[0].minimalMatchList() ] ref_match_types = [1, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] # This one has the wildcards (zeroes) added. self.assertEqual( match_types, ref_match_types ) # Setup the run paramters. control_parameters = KMCControlParameters(number_of_steps=10, dump_interval=1) model.run(control_parameters)