Пример #1
0
def test_hex():
    from javelin.unitcell import UnitCell
    positions = [[0, 1, 0], [1, 1, 0], [1, 0, 0], [0, -1, 0], [-1, -1, 0],
                 [-1, 0, 0]]
    symbols = ['C'] * 6
    unitcell = (1.4, 1.4, 1, 90, 90, 120)

    hex_cell = Structure(unitcell=UnitCell(unitcell),
                         symbols=symbols,
                         positions=positions)

    assert hex_cell.number_of_atoms == 6
    assert_array_equal(hex_cell.element, ['C', 'C', 'C', 'C', 'C', 'C'])
    assert_array_equal(hex_cell.get_atom_symbols(), ['C'])
    assert_array_equal(hex_cell.get_atom_count(), 6)
    assert_array_equal(hex_cell.get_chemical_symbols(),
                       ['C', 'C', 'C', 'C', 'C', 'C'])
    assert_array_equal(hex_cell.get_atom_Zs(), [6])
    assert_array_equal(hex_cell.get_atomic_numbers(), [6, 6, 6, 6, 6, 6])
    assert_array_equal(hex_cell.x, [0, 1, 1, 0, -1, -1])
    assert_array_equal(hex_cell.y, [1, 1, 0, -1, -1, 0])
    assert_array_equal(hex_cell.z, [0, 0, 0, 0, 0, 0])
    assert_array_equal(hex_cell.xyz, positions)
    assert_array_equal(hex_cell.get_scaled_positions(), positions)
    real_positions = [[0, 1.4, 0], [1.21243557, 0.7, 0], [1.21243557, -0.7, 0],
                      [0, -1.4, 0], [-1.21243557, -0.7, 0],
                      [-1.21243557, 0.7, 0]]
    assert_array_almost_equal(hex_cell.xyz_cartn, real_positions)
    assert_array_almost_equal(hex_cell.get_positions(), real_positions)
    assert_array_almost_equal(hex_cell.unitcell.cell, unitcell)
Пример #2
0
def test_hex():
    from javelin.unitcell import UnitCell
    positions = [[0, 1, 0], [1, 1, 0], [1, 0, 0], [0, -1, 0], [-1, -1, 0], [-1, 0, 0]]
    symbols = ['C']*6
    unitcell = (1.4, 1.4, 1, 90, 90, 120)

    hex_cell = Structure(unitcell=UnitCell(unitcell),
                         symbols=symbols,
                         positions=positions)

    assert hex_cell.number_of_atoms == 6
    assert_array_equal(hex_cell.element, ['C', 'C', 'C', 'C', 'C', 'C'])
    assert_array_equal(hex_cell.get_atom_symbols(), ['C'])
    assert_array_equal(hex_cell.get_atom_count(), 6)
    assert_array_equal(hex_cell.get_chemical_symbols(), ['C', 'C', 'C', 'C', 'C', 'C'])
    assert_array_equal(hex_cell.get_atom_Zs(), [6])
    assert_array_equal(hex_cell.get_atomic_numbers(), [6, 6, 6, 6, 6, 6])
    assert_array_equal(hex_cell.x, [0,  1,  1,  0, -1, -1])
    assert_array_equal(hex_cell.y, [1,  1,  0, -1, -1,  0])
    assert_array_equal(hex_cell.z, [0, 0, 0, 0, 0, 0])
    assert_array_equal(hex_cell.xyz, positions)
    assert_array_equal(hex_cell.get_scaled_positions(), positions)
    real_positions = [[0, 1.4, 0],
                      [1.21243557, 0.7, 0],
                      [1.21243557, -0.7, 0],
                      [0, -1.4, 0],
                      [-1.21243557, -0.7, 0],
                      [-1.21243557, 0.7, 0]]
    assert_array_almost_equal(hex_cell.xyz_cartn, real_positions)
    assert_array_almost_equal(hex_cell.get_positions(), real_positions)
    assert_array_almost_equal(hex_cell.unitcell.cell, unitcell)
Пример #3
0
def test_empty():
    structure = Structure()
    assert structure.number_of_atoms == 0
    assert_array_equal(structure.element, np.empty(0))
    assert_array_equal(structure.get_atom_symbols(), np.empty(0))
    assert_array_equal(structure.get_atom_count(), 0)
    assert_array_equal(structure.get_chemical_symbols(), np.empty(0))
    assert_array_equal(structure.get_atom_Zs(), np.empty(0))
    assert_array_equal(structure.get_atomic_numbers(), np.empty(0))
    assert_array_equal(structure.x, np.empty(0))
    assert_array_equal(structure.y, np.empty(0))
    assert_array_equal(structure.z, np.empty(0))
    assert_array_equal(structure.xyz, np.empty((0, 3)))
    assert_array_equal(structure.get_scaled_positions(), np.empty((0, 3)))
    assert_array_equal(structure.xyz_cartn, np.empty((0, 3)))
    assert_array_equal(structure.get_positions(), np.empty((0, 3)))
    assert_array_equal(structure.unitcell.cell, (1.0, 1.0, 1.0, 90.0, 90.0, 90.0))
Пример #4
0
def test_one_atom_init():
    structure = Structure(symbols=['Au'], positions=[[0.5, 0, 0.25]], unitcell=(3, 4, 5))
    assert structure.number_of_atoms == 1
    assert_array_equal(structure.element, ['Au'])
    assert_array_equal(structure.get_atom_symbols(), ['Au'])
    assert_array_equal(structure.get_atom_count(), 1)
    assert_array_equal(structure.get_chemical_symbols(), ['Au'])
    assert_array_equal(structure.get_atom_Zs(), [79])
    assert_array_equal(structure.get_atomic_numbers(), [79])
    assert_array_equal(structure.x, [0.5])
    assert_array_equal(structure.y, [0])
    assert_array_equal(structure.z, [0.25])
    assert_array_equal(structure.xyz, [[0.5, 0, 0.25]])
    assert_array_equal(structure.get_scaled_positions(), [[0.5, 0, 0.25]])
    assert_array_almost_equal(structure.xyz_cartn, [[1.5, 0, 1.25]])
    assert_array_almost_equal(structure.get_positions(), [[1.5, 0, 1.25]])
    assert_array_equal(structure.unitcell.cell, (3.0, 4.0, 5.0, 90.0, 90.0, 90.0))
Пример #5
0
def test_empty():
    structure = Structure()
    assert structure.number_of_atoms == 0
    assert_array_equal(structure.element, np.empty(0))
    assert_array_equal(structure.get_atom_symbols(), np.empty(0))
    assert_array_equal(structure.get_atom_count(), 0)
    assert_array_equal(structure.get_chemical_symbols(), np.empty(0))
    assert_array_equal(structure.get_atom_Zs(), np.empty(0))
    assert_array_equal(structure.get_atomic_numbers(), np.empty(0))
    assert_array_equal(structure.x, np.empty(0))
    assert_array_equal(structure.y, np.empty(0))
    assert_array_equal(structure.z, np.empty(0))
    assert_array_equal(structure.xyz, np.empty((0, 3)))
    assert_array_equal(structure.get_scaled_positions(), np.empty((0, 3)))
    assert_array_equal(structure.xyz_cartn, np.empty((0, 3)))
    assert_array_equal(structure.get_positions(), np.empty((0, 3)))
    assert_array_equal(structure.unitcell.cell,
                       (1.0, 1.0, 1.0, 90.0, 90.0, 90.0))
Пример #6
0
def test_one_atom_add():
    structure = Structure()
    structure.unitcell.cell = (3.0, 4.0, 5.0, 90.0, 90.0, 90.0)
    structure.add_atom(symbol='Au', position=[0.5, 0, 0.25])
    assert structure.number_of_atoms == 1
    assert_array_equal(structure.element, ['Au'])
    assert_array_equal(structure.get_atom_symbols(), ['Au'])
    assert_array_equal(structure.get_atom_count(), 1)
    assert_array_equal(structure.get_chemical_symbols(), ['Au'])
    assert_array_equal(structure.get_atom_Zs(), [79])
    assert_array_equal(structure.get_atomic_numbers(), [79])
    assert_array_equal(structure.x, [0.5])
    assert_array_equal(structure.y, [0])
    assert_array_equal(structure.z, [0.25])
    assert_array_equal(structure.xyz, [[0.5, 0, 0.25]])
    assert_array_equal(structure.get_scaled_positions(), [[0.5, 0, 0.25]])
    assert_array_almost_equal(structure.xyz_cartn, [[1.5, 0, 1.25]])
    assert_array_almost_equal(structure.get_positions(), [[1.5, 0, 1.25]])
    assert_array_equal(structure.unitcell.cell,
                       (3.0, 4.0, 5.0, 90.0, 90.0, 90.0))
Пример #7
0
def test_repeat():
    structure = Structure(unitcell=5, symbols=['Au', 'Ag'], positions=[[0, 0, 0], [0.5, 0.5, 0.5]])

    assert structure.number_of_atoms == 2
    assert_array_equal(structure.get_atom_count(), [1, 1])
    assert_array_equal(structure.get_atom_Zs(), [79, 47])
    assert_array_equal(structure.get_atomic_numbers(), [79, 47])
    assert_array_equal(structure.element, ['Au', 'Ag'])
    assert_array_equal(structure.get_atom_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.get_chemical_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.xyz, [[0., 0., 0.],
                                       [0.5, 0.5, 0.5]])
    assert_array_almost_equal(structure.xyz_cartn, [[0., 0., 0.],
                                                    [2.5, 2.5, 2.5]])

    structure.repeat((2, 3, 1))

    assert structure.number_of_atoms == 12
    assert_array_equal(structure.get_atom_count(), [6, 6])
    assert_array_equal(structure.get_atom_Zs(), [79, 47])
    assert_array_equal(structure.get_atomic_numbers(), [79, 47, 79, 47, 79, 47,
                                                        79, 47, 79, 47, 79, 47])
    assert_array_equal(structure.element, ['Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag',
                                           'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag'])
    assert_array_equal(structure.get_atom_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.get_chemical_symbols(), ['Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag',
                                                          'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag'])
    assert_array_equal(structure.xyz, np.tile([[0., 0., 0.],
                                               [0.5, 0.5, 0.5]], (6, 1)))
    assert_array_almost_equal(structure.xyz_cartn, [[0.0,  0.0, 0.0],
                                                    [2.5,  2.5, 2.5],
                                                    [0.0,  5.0, 0.0],
                                                    [2.5,  7.5, 2.5],
                                                    [0.0, 10.0, 0.0],
                                                    [2.5, 12.5, 2.5],
                                                    [5.0,  0.0, 0.0],
                                                    [7.5,  2.5, 2.5],
                                                    [5.0,  5.0, 0.0],
                                                    [7.5,  7.5, 2.5],
                                                    [5.0, 10.0, 0.0],
                                                    [7.5, 12.5, 2.5]])

    structure = Structure(unitcell=5, symbols=['Au', 'Ag'], positions=[[0, 0, 0], [0.5, 0.5, 0.5]])
    structure.repeat(2)

    assert structure.number_of_atoms == 16
    assert_array_equal(structure.get_atom_count(), [8, 8])
    assert_array_equal(structure.get_atom_Zs(), [79, 47])
    assert_array_equal(structure.get_atomic_numbers(), [79, 47, 79, 47, 79, 47, 79, 47,
                                                        79, 47, 79, 47, 79, 47, 79, 47])
    assert_array_equal(structure.element, ['Au', 'Ag', 'Au', 'Ag',
                                           'Au', 'Ag', 'Au', 'Ag',
                                           'Au', 'Ag', 'Au', 'Ag',
                                           'Au', 'Ag', 'Au', 'Ag'])
    assert_array_equal(structure.get_atom_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.get_chemical_symbols(), ['Au', 'Ag', 'Au', 'Ag',
                                                          'Au', 'Ag', 'Au', 'Ag',
                                                          'Au', 'Ag', 'Au', 'Ag',
                                                          'Au', 'Ag', 'Au', 'Ag'])
    assert_array_equal(structure.xyz, np.tile([[0., 0., 0.],
                                               [0.5, 0.5, 0.5]], (8, 1)))
    assert_array_almost_equal(structure.xyz_cartn, [[0.0, 0.0, 0.0],
                                                    [2.5, 2.5, 2.5],
                                                    [0.0, 0.0, 5.0],
                                                    [2.5, 2.5, 7.5],
                                                    [0.0, 5.0, 0.0],
                                                    [2.5, 7.5, 2.5],
                                                    [0.0, 5.0, 5.0],
                                                    [2.5, 7.5, 7.5],
                                                    [5.0, 0.0, 0.0],
                                                    [7.5, 2.5, 2.5],
                                                    [5.0, 0.0, 5.0],
                                                    [7.5, 2.5, 7.5],
                                                    [5.0, 5.0, 0.0],
                                                    [7.5, 7.5, 2.5],
                                                    [5.0, 5.0, 5.0],
                                                    [7.5, 7.5, 7.5]])
Пример #8
0
def test_repeat():
    structure = Structure(unitcell=5,
                          symbols=['Au', 'Ag'],
                          positions=[[0, 0, 0], [0.5, 0.5, 0.5]])

    assert structure.number_of_atoms == 2
    assert_array_equal(structure.get_atom_count(), [1, 1])
    assert_array_equal(structure.get_atom_Zs(), [79, 47])
    assert_array_equal(structure.get_atomic_numbers(), [79, 47])
    assert_array_equal(structure.element, ['Au', 'Ag'])
    assert_array_equal(structure.get_atom_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.get_chemical_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.xyz, [[0., 0., 0.], [0.5, 0.5, 0.5]])
    assert_array_almost_equal(structure.xyz_cartn,
                              [[0., 0., 0.], [2.5, 2.5, 2.5]])

    structure.repeat((2, 3, 1))

    assert structure.number_of_atoms == 12
    assert_array_equal(structure.get_atom_count(), [6, 6])
    assert_array_equal(structure.get_atom_Zs(), [79, 47])
    assert_array_equal(structure.get_atomic_numbers(),
                       [79, 47, 79, 47, 79, 47, 79, 47, 79, 47, 79, 47])
    assert_array_equal(structure.element, [
        'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag'
    ])
    assert_array_equal(structure.get_atom_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.get_chemical_symbols(), [
        'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag'
    ])
    assert_array_equal(structure.xyz,
                       np.tile([[0., 0., 0.], [0.5, 0.5, 0.5]], (6, 1)))
    assert_array_almost_equal(
        structure.xyz_cartn,
        [[0.0, 0.0, 0.0], [2.5, 2.5, 2.5], [0.0, 5.0, 0.0], [2.5, 7.5, 2.5],
         [0.0, 10.0, 0.0], [2.5, 12.5, 2.5], [5.0, 0.0, 0.0], [7.5, 2.5, 2.5],
         [5.0, 5.0, 0.0], [7.5, 7.5, 2.5], [5.0, 10.0, 0.0], [7.5, 12.5, 2.5]])

    structure = Structure(unitcell=5,
                          symbols=['Au', 'Ag'],
                          positions=[[0, 0, 0], [0.5, 0.5, 0.5]])
    structure.repeat(2)

    assert structure.number_of_atoms == 16
    assert_array_equal(structure.get_atom_count(), [8, 8])
    assert_array_equal(structure.get_atom_Zs(), [79, 47])
    assert_array_equal(
        structure.get_atomic_numbers(),
        [79, 47, 79, 47, 79, 47, 79, 47, 79, 47, 79, 47, 79, 47, 79, 47])
    assert_array_equal(structure.element, [
        'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag',
        'Au', 'Ag', 'Au', 'Ag'
    ])
    assert_array_equal(structure.get_atom_symbols(), ['Au', 'Ag'])
    assert_array_equal(structure.get_chemical_symbols(), [
        'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag', 'Au', 'Ag',
        'Au', 'Ag', 'Au', 'Ag'
    ])
    assert_array_equal(structure.xyz,
                       np.tile([[0., 0., 0.], [0.5, 0.5, 0.5]], (8, 1)))
    assert_array_almost_equal(
        structure.xyz_cartn,
        [[0.0, 0.0, 0.0], [2.5, 2.5, 2.5], [0.0, 0.0, 5.0], [2.5, 2.5, 7.5],
         [0.0, 5.0, 0.0], [2.5, 7.5, 2.5], [0.0, 5.0, 5.0], [2.5, 7.5, 7.5],
         [5.0, 0.0, 0.0], [7.5, 2.5, 2.5], [5.0, 0.0, 5.0], [7.5, 2.5, 7.5],
         [5.0, 5.0, 0.0], [7.5, 7.5, 2.5], [5.0, 5.0, 5.0], [7.5, 7.5, 7.5]])