Exemplo n.º 1
0
def test_analyse_average_distribution_function():
    from carmm.analyse.distribution_functions import average_distribution_function

    #Build model
    from data.model_gen import get_example_slab as slab
    slab_1 = slab(adsorbate=True)
    slab_2 = slab(adsorbate=True)
    slab_2.positions *= 1.05
    slab_trajectory = [slab_1, slab_2]

    all_data, snapshots = average_distribution_function(
        trajectory=slab_trajectory, samples=2)
    assert (len(all_data) == 420)
    assert (1e-5 > abs(sum(all_data) - 1754.778323))

    # Example how to plot data
    from carmm.analyse.distribution_functions import plot_distribution_function
    from matplotlib import pyplot as plt
    # Clean axes before new plot
    plt.cla()

    # Plot all snapshots
    for i in range(len(snapshots)):
        plot_distribution_function(snapshots[i], color='#808080', density=True)
    # Plot mean (i.e. average bins over all data, rather than separate snapshots).
    # This probably need double checking with something known e.g. H2O TODO
    plot_distribution_function(
        all_data,
        title='Last ' + str(len(snapshots)) + ' Snapshots',
        density=True,
        # Additional graph plotting variables
        label='Mean',
        color="#000000")
    plt.legend()
Exemplo n.º 2
0
def test_build_cutout():

    from carmm.build.cutout import cutout_sphere

    #### Traditional ASE functionality #####
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)
    #########

    cutout = cutout_sphere(slab, 13)
    assert (len(cutout) == 12)
Exemplo n.º 3
0
def test_analyse_planes():

    from carmm.analyse.planes import get_interplane_distances

    #### Traditional ASE functionality #####
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)
    #########

    distances_sorted = sorted(get_interplane_distances(slab))
    # As the adsorbate is 3 Angstrom above the surface, this should be the shortest distance
    assert (1e-5 > abs(3.0 - distances_sorted[0]))
Exemplo n.º 4
0
def test_run_k_grid():
    from carmm.run.aims_calculator import get_k_grid
    from ase.build import molecule


    #### Traditional ASE functionality #####
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)
    #########
    sampling_density = 0.02 # example value of sampling density /Angstrom
    k_grid = get_k_grid(slab, sampling_density, verbose=True)
    assert k_grid == (6, 6, 1)
    assert get_k_grid(molecule("CO2"), sampling_density) == None
Exemplo n.º 5
0
def test_distance_between_centers_of_mass():

    from carmm.analyse.molecules import calculate_molecules
    from carmm.analyse.planes import distance_between_centers_of_mass
    from data.model_gen import get_example_slab as slab
    ### Traditional ASE functionality #####
    slab = slab(adsorbate=True)
    molecules = calculate_molecules(slab)
    A_mol = slab[molecules[0]]
    B_mol = slab[molecules[1]]
    distance_between_centers_of_mass(A_mol, B_mol)
    #print(distances_between_centers_of_mass(A_mol, B_mol))
    value = distance_between_centers_of_mass(A_mol, B_mol)
    assert(1e-5 > value - 6.32082)
Exemplo n.º 6
0
def test_neighbours():
    '''
    Test neighbour function
    '''
    from carmm.analyse.neighbours import neighbours
    # Build model
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)

    # Calculate neighbours
    all_neighbour_atoms, shell_list = neighbours(slab, [13], 1, verbose=True)

    # Verify results
    assert (all_neighbour_atoms == [1, 2, 4, 10, 11, 12, 13, 14, 15, 16])
    assert (shell_list == [[13], [1, 2, 4, 10, 11, 12, 14, 15, 16]])
Exemplo n.º 7
0
def test_analyse_bonds():

    from carmm.analyse.bonds import analyse_all_bonds

    #### Traditional ASE functionality #####
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)
    # Deform the z-coordinate for C so the Au-C bond length is too short, to test deformation
    slab.positions[-3][2] -= 1.5
    #########

    abnormal_count, abnormal_bond_names = analyse_all_bonds(slab,
                                                            abnormal=True)

    assert (len(abnormal_count) == 1)
Exemplo n.º 8
0
def test_analyse_angles():

    from carmm.analyse.angles import analyse_all_angles

    #### Traditional ASE functionality #####
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)
    #########

    elements, indices, angles = analyse_all_angles(slab, verbose=True)

    index_au = elements.index(('Au', 'Au', 'Au'))
    assert (len(elements) == 2)
    assert (len(indices) == 2 and len(indices[index_au]) == 648)
    assert (len(angles) == 2 and len(angles[index_au]) == 648)
Exemplo n.º 9
0
def test_analyse_get_sorted_distances():
    from carmm.analyse.bonds import get_sorted_distances

    #Build a model
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)

    distances = get_sorted_distances(slab)
    # Check values are stil lthe same and ordering is correct
    assert (len(distances) == 210)
    assert (1e-5 > abs(distances[0] - 1.178657))
    assert (1e-5 > abs(distances[-1] - 7.132005))

    # Test plot
    from carmm.analyse.distribution_functions import plot_distribution_function
    plt = plot_distribution_function(distances,
                                     title='Radial Distribution Function')
Exemplo n.º 10
0
def test_analyse_radial_distribution_function():
    from carmm.analyse.distribution_functions import radial_distribution_function

    #Build model
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)

    distances = radial_distribution_function(model=slab,
                                             radius=10,
                                             position=0,
                                             verbose=True)
    assert (len(distances) == 88)
    assert (1e-5 > abs(distances[0] - 2.938999))
    assert (1e-5 > abs(distances[87] - 9.936709))

    from carmm.analyse.distribution_functions import plot_distribution_function
    plt = plot_distribution_function(distances,
                                     title='Radial Distribution Function')
Exemplo n.º 11
0
def test_build_symmetry_mirror():

    ###### EXAMPLE OF USE - MIRROR AND TRANSLATION ########
    #from ase.visualize import view
    from data.model_gen import get_example_slab as slab
    from carmm.build.neb.symmetry import mirror, translation, rotate_fcc

    for surface_facet in ['111', '100', '110']:
        # Toy model of CO2 on top of Au FCC(111)
        model = slab(adsorbate=True, surface=surface_facet)
        #view(model)

        # Retrieve index of the C atom
        index = [atom.index for atom in model if atom.symbol == "C"]

        # Mirror model in the x plane with respect to C atom
        # C atom remains in place, the rest of unit cell is shifted accordingly
        model = mirror(model,
                       center_index=index[0],
                       plane='y',
                       surf=surface_facet)
        #view(model)

        # Translate one row of atoms at a time in x and y
        # Move adsorbate to the middle of the unit cell
        model = translation(model, axis=0, surface=surface_facet)
        model = translation(model, axis=1, surface=surface_facet)
        #view(model)

        ### ASSERTION ###
        eps = 1e-8
        # Check if Oxygen moves as expected
        if surface_facet == "111":
            assert (model[19].position - [4.01974776, 2.0844678, 15.39968345] <
                    [eps, eps, eps]).all()
        elif surface_facet == "100":
            assert (model[19].position - [3.50559559, 3.65087324, 15.07818683]
                    < [eps, eps, eps]).all()
        elif surface_facet == "110":
            assert (model[19].position - [5.33165608, 3.65087324, 14.4695] <
                    [eps, eps, eps]).all()
Exemplo n.º 12
0
def test_build_alloy():

    from carmm.build.alloy import binary_alloy

    #### Traditional ASE functionality #####
    from data.model_gen import get_example_slab as slab
    slab = slab()
    #########

    alloy_slab = binary_alloy(slab, 'Pd', 8)
    assert(alloy_slab.get_chemical_symbols().count('Pd') == 8)
    assert(alloy_slab.get_chemical_symbols().count('Au') == 10)

    #### Ternary_alloy test ####
    from carmm.build.alloy import ternary_alloy

    ternary_slab = ternary_alloy(slab, 'Pd', 'Zn', 4, 5)
    # This currently fails.
    # TODO: Improve ternary so it preserves the requested composition for 2nd element
    # assert(ternary_slab.get_chemical_symbols().count('Pd') == 4)
    assert(ternary_slab.get_chemical_symbols().count('Zn') == 5)
Exemplo n.º 13
0
def test_molecules():
    '''
    Test function for number of molecules in model

    '''
    from ase.visualize import view
    from carmm.analyse.molecules import calculate_molecules
    # Build model
    from data.model_gen import get_example_slab as slab
    slab = slab(adsorbate=True)

    # Calculate neighbours
    molecules = calculate_molecules(slab)

    # View seperate molecules and recombine
    A_mol = slab[molecules[0]]
    B_mol = slab[molecules[1]]
    #view(A_mol)
    #view(B_mol)
    #view(slab)
    # Verify results
    assert (len(molecules) == 2)