def test_unique_structure_substitutions( self ): # integration test # Create a pymatgen structure with 16 sites in a 4x4 square grid coords = np.array( [ [ 0.0, 0.0, 0.0 ], [ 0.25, 0.0, 0.0 ], [ 0.5, 0., 0.0 ], [ 0.75, 0.0, 0.0 ], [ 0.0, 0.25, 0.0 ], [ 0.25, 0.25, 0.0 ], [ 0.5, 0.25, 0.0 ], [ 0.75, 0.25, 0.0 ], [ 0.0, 0.5, 0.0 ], [ 0.25, 0.5, 0.0 ], [ 0.5, 0.5, 0.0 ], [ 0.75, 0.5, 0.0 ], [ 0.0, 0.75, 0.0 ], [ 0.25, 0.75, 0.0 ], [ 0.5, 0.75, 0.0 ], [ 0.75, 0.75, 0.0 ] ] ) atom_list = [ 'Li' ] * len( coords ) lattice = Lattice.from_parameters( a = 3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90 ) parent_structure = Structure( lattice, atom_list, coords ) parent_structure.replace( 0, 'O' ) # substitute one site with 'O' ns = unique_structure_substitutions( parent_structure, 'Li', { 'Na':1, 'Li':14 } ) self.assertEqual( len( ns ), 5 ) distances = np.array( sorted( [ s.get_distance( s.indices_from_symbol('O')[0], s.indices_from_symbol('Na')[0] ) for s in ns ] ) ) np.testing.assert_array_almost_equal( distances, np.array( [ 0.75 , 1.06066 , 1.5 , 1.677051, 2.12132 ] ) ) np.testing.assert_array_equal( np.array( sorted( [ s.number_of_equivalent_configurations for s in ns ] ) ), np.array( [ 1, 2, 4, 4, 4 ] ) ) np.testing.assert_array_equal( np.array( sorted( [ s.full_configuration_degeneracy for s in ns ] ) ), np.array( [ 1, 2, 4, 4, 4 ] ) )
def create_TiAlN_structure(shuffle=True): ''' Attributes: number_of_lattice > maximum Total number of atoms in structure a > lattice parameter Returns: Pymatgen structure TiAlN. Creates possible largest square supercell ''' lattice = Lattice.cubic(a=4.16) coords = [ [0, 0, 0], [0.5, 0.5, 0], [0.5, 0, 0.5], [0, 0.5, 0.5], [0, 0, 0.5], [0.5, 0, 0], [0, 0.5, 0], [0.5, 0.5, 0.5], ] matrix = [[1, 0, 0], [0, 5, 0], [0, 0, 5]] struct = Structure(lattice, ["Ti", "Ti", "Al", "Al", "N", "N", "N", "N"], coords) struct.make_supercell(matrix) site_size = len(struct) element_number = int(site_size / 4) Al_Ti_array = ['Al'] * element_number + ['Ti'] * element_number if shuffle == True: random.shuffle(Al_Ti_array) for e, i in enumerate(Al_Ti_array): struct.replace(e, i) return struct
def test_unique_structure_substitutions(self): # integration test # Create a pymatgen structure with 16 sites in a 4x4 square grid coords = np.array([[0.0, 0.0, 0.0], [0.25, 0.0, 0.0], [0.5, 0., 0.0], [0.75, 0.0, 0.0], [0.0, 0.25, 0.0], [0.25, 0.25, 0.0], [0.5, 0.25, 0.0], [0.75, 0.25, 0.0], [0.0, 0.5, 0.0], [0.25, 0.5, 0.0], [0.5, 0.5, 0.0], [0.75, 0.5, 0.0], [0.0, 0.75, 0.0], [0.25, 0.75, 0.0], [0.5, 0.75, 0.0], [0.75, 0.75, 0.0]]) atom_list = ['Li'] * len(coords) lattice = Lattice.from_parameters(a=3.0, b=3.0, c=3.0, alpha=90, beta=90, gamma=90) parent_structure = Structure(lattice, atom_list, coords) parent_structure.replace(0, 'O') # substitute one site with 'O' ns = unique_structure_substitutions(parent_structure, 'Li', { 'Na': 1, 'Li': 14 }) self.assertEqual(len(ns), 5) distances = np.array( sorted([ s.get_distance( s.indices_from_symbol('O')[0], s.indices_from_symbol('Na')[0]) for s in ns ])) np.testing.assert_array_almost_equal( distances, np.array([0.75, 1.06066, 1.5, 1.677051, 2.12132])) np.testing.assert_array_equal( np.array( sorted([s.number_of_equivalent_configurations for s in ns])), np.array([1, 2, 4, 4, 4])) np.testing.assert_array_equal( np.array(sorted([s.full_configuration_degeneracy for s in ns])), np.array([1, 2, 4, 4, 4]))