def testLocalConfigurations(self): """ Test that the local configurations are correctly set up """ coordinates = numpy.array([[1.0,2.0,3.0], [2.3,5.5,3.2]]) elements1 = ["First", "Second"] elements2 = ["Second", "First"] # Construct the process. process = KMCProcess(coordinates, elements1, elements2, basis_sites=[9], rate_constant=1.0) # Get the local configurations out. c1 = process.localConfigurations()[0] c2 = process.localConfigurations()[1] # Construct the two reference local configurations. ref_c1 = KMCLocalConfiguration(coordinates, elements1, center=0) ref_c2 = KMCLocalConfiguration(coordinates, elements2, center=0) # Check coordinates. self.assertAlmostEqual( numpy.linalg.norm(c1.coordinates() - ref_c1.coordinates()), 0.0, 12 ) self.assertAlmostEqual( numpy.linalg.norm(c2.coordinates() - ref_c2.coordinates()), 0.0, 12 ) # Check types. self.assertAlmostEqual( c1.types(), ref_c1.types() ) self.assertAlmostEqual( c2.types(), ref_c2.types() )
def testLocalConfigurations(self): """ Test that the local configurations are correctly set up """ coordinates = numpy.array([[1.0, 2.0, 3.0], [2.3, 5.5, 3.2]]) elements1 = ["First", "Second"] elements2 = ["Second", "First"] # Construct the process. process = KMCProcess(coordinates, elements1, elements2, basis_sites=[9], rate_constant=1.0) # Get the local configurations out. c1 = process.localConfigurations()[0] c2 = process.localConfigurations()[1] # Construct the two reference local configurations. ref_c1 = KMCLocalConfiguration(coordinates, elements1, center=0) ref_c2 = KMCLocalConfiguration(coordinates, elements2, center=0) # Check coordinates. self.assertAlmostEqual( numpy.linalg.norm(c1.coordinates() - ref_c1.coordinates()), 0.0, 12) self.assertAlmostEqual( numpy.linalg.norm(c2.coordinates() - ref_c2.coordinates()), 0.0, 12) # Check types. self.assertAlmostEqual(c1.types(), ref_c1.types()) self.assertAlmostEqual(c2.types(), ref_c2.types())
def testConstructionSorting(self): """ Test that the coordinates elements and move vectors gets sorted """ # Set the input. coordinates = [[0.0, 0.0, 0.0], [3.0, 3.0, 3.0], [1.0, 1.0, 1.0], [1.1, 1.1, 1.1], [1.5, 1.5, 1.5], [2.5, 2.5, 2.5]] elements_before = ["A", "B", "C", "P", "D", "E"] elements_after = ["B", "C", "D", "P", "A", "E"] basis_sites = [0] rate_constant = 1.0 move_vectors = [(0, [ 1.5, 1.5, 1.5]), (1, [-3.0,-3.0,-3.0]), (2, [ 2.0, 2.0, 2.0]), (4, [-0.5,-0.5,-0.5])] # Construct. p = KMCProcess(coordinates=coordinates, elements_before=elements_before, elements_after=elements_after, move_vectors=move_vectors, basis_sites=basis_sites, rate_constant=1.0) # Get the configurations out. config_before = p.localConfigurations()[0] config_after = p.localConfigurations()[1] # Check that the coordinates, elements and move vectors # have been sorted. ref_coords = numpy.array([[ 0., 0., 0. ], [ 1., 1., 1. ], [ 1.1, 1.1, 1.1], [ 1.5, 1.5, 1.5], [ 2.5, 2.5, 2.5], [ 3., 3., 3.]]) # Before move. coords = config_before.coordinates() norm = numpy.linalg.norm(ref_coords - coords) self.assertAlmostEqual( norm, 0.0, 10 ) # After move. coords = config_after.coordinates() norm = numpy.linalg.norm(ref_coords - coords) self.assertAlmostEqual( norm, 0.0, 10 ) # Check the elements before move. ref_types = [[(1, "A")], [(1, "C")], [(1, "P")], [(1, "D")], [(1, "E")], [(1, "B")]] self.assertEqual( ref_types, config_before.types() ) # Check the elements after move. ref_types = [[(1, "B")], [(1, "D")], [(1, "P")], [(1, "A")], [(1, "E")], [(1, "C")]] self.assertEqual( ref_types, config_after.types() ) ref_vectors = [(0, [ 1.5, 1.5, 1.5]), (1, [ 2.0, 2.0, 2.0]), (3, [-0.5,-0.5,-0.5]), (5, [-3.0,-3.0,-3.0])] ret_vectors = p.moveVectors() for ref, ret in zip(ref_vectors, ret_vectors): # Check the 'from' index. self.assertEqual(ref[0], ret[0]) # Check the vector. norm = numpy.linalg.norm(numpy.array(ref[1]) - numpy.array(ret[1])) self.assertAlmostEqual( norm, 0.0, 10 )
def testConstructionSorting(self): """ Test that the coordinates elements and move vectors gets sorted """ # Set the input. coordinates = [[0.0, 0.0, 0.0], [3.0, 3.0, 3.0], [1.0, 1.0, 1.0], [1.1, 1.1, 1.1], [1.5, 1.5, 1.5], [2.5, 2.5, 2.5]] elements_before = ["A", "B", "C", "P", "D", "E"] elements_after = ["B", "C", "D", "P", "A", "E"] basis_sites = [0] rate_constant = 1.0 move_vectors = [(0, [1.5, 1.5, 1.5]), (1, [-3.0, -3.0, -3.0]), (2, [2.0, 2.0, 2.0]), (4, [-0.5, -0.5, -0.5])] # Construct. p = KMCProcess(coordinates=coordinates, elements_before=elements_before, elements_after=elements_after, move_vectors=move_vectors, basis_sites=basis_sites, rate_constant=1.0) # Get the configurations out. config_before = p.localConfigurations()[0] config_after = p.localConfigurations()[1] # Check that the coordinates, elements and move vectors # have been sorted. ref_coords = numpy.array([[0., 0., 0.], [1., 1., 1.], [1.1, 1.1, 1.1], [1.5, 1.5, 1.5], [2.5, 2.5, 2.5], [3., 3., 3.]]) # Before move. coords = config_before.coordinates() norm = numpy.linalg.norm(ref_coords - coords) self.assertAlmostEqual(norm, 0.0, 10) # After move. coords = config_after.coordinates() norm = numpy.linalg.norm(ref_coords - coords) self.assertAlmostEqual(norm, 0.0, 10) # Check the elements before move. ref_types = [[(1, "A")], [(1, "C")], [(1, "P")], [(1, "D")], [(1, "E")], [(1, "B")]] self.assertEqual(ref_types, config_before.types()) # Check the elements after move. ref_types = [[(1, "B")], [(1, "D")], [(1, "P")], [(1, "A")], [(1, "E")], [(1, "C")]] self.assertEqual(ref_types, config_after.types()) ref_vectors = [(0, [1.5, 1.5, 1.5]), (1, [2.0, 2.0, 2.0]), (3, [-0.5, -0.5, -0.5]), (5, [-3.0, -3.0, -3.0])] ret_vectors = p.moveVectors() for ref, ret in zip(ref_vectors, ret_vectors): # Check the 'from' index. self.assertEqual(ref[0], ret[0]) # Check the vector. norm = numpy.linalg.norm(numpy.array(ref[1]) - numpy.array(ret[1])) self.assertAlmostEqual(norm, 0.0, 10)