diff --git a/msspecbook/Activity09/Activity09.ipynb b/msspecbook/Activity09/Activity09.ipynb index 93676fa..3b67e7f 100644 --- a/msspecbook/Activity09/Activity09.ipynb +++ b/msspecbook/Activity09/Activity09.ipynb @@ -1,20 +1,19 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "aa43e0e7-0c18-4750-9e2b-3a48f106d2ca", "metadata": {}, "source": [ - "# Activity 9: Comparing simulation and experiment with R-factors" + "# Activity 9: Comparing simulation and experiment with R-factors\n", + "In order to extract precise crystallographic information from electronic spectroscopy, we need to compare MsSpec calculations with experimental results and adjust the modelling parameters to simulate the experiment as accurately as possible.\n", + "\n", + "*R-factors* (reliability factors) are commonly used for this task. In the following example, we will see how MsSpec can extract the adsorption geometry of molecule.\n", + "\n", + "## The unusual tilt of CO molecule on Fe(001)\n", + "The carbon monoxide molecule can be adsorbed onto a Fe(001) surface in the hollow site. It was experimentally demonstrated that the CO molecule is tilted by 55$\\pm$2° in <100> azimuthal directions. The molecule is bonded to the Fe surface by the carbon atom and the adsorption height was estimated to be $\\sim$ 0.6 Å." ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b9b32bbf-7635-4e14-b246-468f2e74bb17", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/msspecbook/Activity09/CO_Fe_completed.py b/msspecbook/Activity09/CO_Fe_completed.py new file mode 100644 index 0000000..f252977 --- /dev/null +++ b/msspecbook/Activity09/CO_Fe_completed.py @@ -0,0 +1,73 @@ +from ase import Atoms +from ase.build import add_adsorbate, bulk + +from msspec.calculator import MSSPEC, RFACTOR +from msspec.utils import hemispherical_cluster + +import numpy as np + + +def create_cluster(height=0.8, theta=45, phi=0, bond_length=1.15): + iron = bulk('Fe', cubic=True) + cluster = hemispherical_cluster(iron, diameter=5, planes=2, emitter_plane=1) + + t = np.radians(theta) + p = np.radians(phi) + + z = bond_length * np.cos(t) + x = bond_length * np.sin(t) * np.cos(p) + y = bond_length * np.sin(t) * np.sin(p) + CO=Atoms('CO',positions=[(0,0,0),(x,y,z)]) + + add_adsorbate(cluster,CO, height=height) + + # Store some information in the cluster object + cluster.info.update(adsorbate={'theta': theta, 'phi': phi, 'height': height, 'bond_length': bond_length}) + return cluster + + +def compute_polar_scan(cluster): + calc = MSSPEC(spectroscopy='PED', algorithm='expansion') + calc.set_atoms(cluster) + + calc.calculation_parameters.scattering_order = 1 + + polar_angles = np.arange(-5, 85, 0.5) + # set the Carbon as absorber and compute the polar scan + cluster.absorber = cluster.get_chemical_symbols().index('C') + data = calc.get_theta_scan(level='1s', theta=polar_angles, kinetic_energy=1202) + + return data + + + + +results = [] +parameters = {'theta': [], 'phi': [], 'height': []} +for theta in np.arange(53, 57, 1): + for phi in [0, 30, 45]: + for height in np.arange(0.1, 0.8, 0.1): + # Create the cluster + cluster = create_cluster(theta=theta, phi=phi, height=height, + bond_length=1.157) + # Compute + data = compute_polar_scan(cluster) + + # Update lists of results and parameters + results.append(data[-1].theta.copy()) + results.append(data[-1].cross_section.copy()) + parameters['theta'].append(theta) + parameters['phi'].append(phi) + parameters['height'].append(height) + + +# Load the experimental data +exp_data = np.loadtxt('experimental_data.txt') + +# Create an R-Factor calculator +rfc = RFACTOR() +rfc.set_references(exp_data[:,0], exp_data[:,1]) + +# Perform the R-Factor analysis +data = rfc.run(*results, **parameters) +data.view() diff --git a/msspecbook/Activity09/CO_Fe_completed2.py b/msspecbook/Activity09/CO_Fe_completed2.py new file mode 100644 index 0000000..c6967f3 --- /dev/null +++ b/msspecbook/Activity09/CO_Fe_completed2.py @@ -0,0 +1,76 @@ +from ase import Atoms +from ase.build import add_adsorbate, bulk + +from msspec.calculator import MSSPEC, RFACTOR +from msspec.utils import hemispherical_cluster + +import numpy as np + + +def create_cluster(height=0.8, theta=45, phi=0, bond_length=1.15): + iron = bulk('Fe', cubic=True) + cluster = hemispherical_cluster(iron, diameter=5, planes=2, emitter_plane=1) + + t = np.radians(theta) + p = np.radians(phi) + + z = bond_length * np.cos(t) + x = bond_length * np.sin(t) * np.cos(p) + y = bond_length * np.sin(t) * np.sin(p) + CO=Atoms('CO',positions=[(0,0,0),(x,y,z)]) + + add_adsorbate(cluster,CO, height=height) + + # Store some information in the cluster object + cluster.info.update(adsorbate={'theta': theta, 'phi': phi, 'height': height, 'bond_length': bond_length}) + return cluster + + +def compute_polar_scan(cluster): + calc = MSSPEC(spectroscopy='PED', algorithm='expansion') + calc.set_atoms(cluster) + + calc.calculation_parameters.scattering_order = 1 + + polar_angles = np.arange(-5, 85, 0.5) + # set the Carbon as absorber and compute the polar scan + cluster.absorber = cluster.get_chemical_symbols().index('C') + data = calc.get_theta_scan(level='1s', theta=polar_angles, kinetic_energy=1202) + + return data + + + + +results = [] +parameters = {'theta': [], 'phi': [], 'height': []} +for theta in np.arange(53, 57, 1): + for phi in [0, 45]: + for height in np.arange(0.1, 0.8, 0.1): + cs = [] + for _phi in [phi, phi+90, phi+180, phi+270]: + # Create the cluster + cluster = create_cluster(theta=theta, phi=phi, height=height, + bond_length=1.157) + # Compute + data = compute_polar_scan(cluster) + cs.append(data[-1].cross_section.copy()) + + # Update lists of results and parameters + results.append(data[-1].theta.copy()) + results.append(np.sum(cs, axis=0)) + parameters['theta'].append(theta) + parameters['phi'].append(phi) + parameters['height'].append(height) + + +# Load the experimental data +exp_data = np.loadtxt('experimental_data.txt') + +# Create an R-Factor calculator +rfc = RFACTOR() +rfc.set_references(exp_data[:,0], exp_data[:,1]) + +# Perform the R-Factor analysis +data = rfc.run(*results, **parameters) +data.view() diff --git a/msspecbook/Activity09/experimental_data.txt b/msspecbook/Activity09/experimental_data.txt new file mode 100644 index 0000000..5745a71 --- /dev/null +++ b/msspecbook/Activity09/experimental_data.txt @@ -0,0 +1,250 @@ +# Polar angle (°) C1s/O1s Signal (a.u.) +-5.163000000000000256e+00 3.649999999999999911e-01 +-4.858999999999990216e+00 3.639999999999999902e-01 +-4.556000000000000050e+00 3.629999999999999893e-01 +-4.251999999999999780e+00 3.619999999999999885e-01 +-3.947999999999990184e+00 3.609999999999999876e-01 +-3.677999999999999936e+00 3.599999999999999867e-01 +-3.375000000000000000e+00 3.579999999999999849e-01 +-3.104999999999999982e+00 3.569999999999999840e-01 +-2.766999999999999904e+00 3.559999999999999831e-01 +-2.462999999999989864e+00 3.549999999999999822e-01 +-2.193000000000000060e+00 3.539999999999999813e-01 +-1.991000000000000103e+00 3.529999999999999805e-01 +-1.754999999999999893e+00 3.519999999999999796e-01 +-1.519000000000009898e+00 3.509999999999999787e-01 +-1.215000000000000080e+00 3.499999999999999778e-01 +-1.012000000000000011e+00 3.499999999999999778e-01 +-6.749999999999970468e-01 3.499999999999999778e-01 +-4.389999999999930069e-01 3.509999999999999787e-01 +-1.009999999999989934e-01 3.519999999999999796e-01 +2.019999999999979867e-01 3.529999999999999805e-01 +5.739999999999979563e-01 3.529999999999999805e-01 +9.789999999999989821e-01 3.539999999999999813e-01 +1.417000000000000037e+00 3.539999999999999813e-01 +1.956999999999990081e+00 3.539999999999999813e-01 +2.327999999999999847e+00 3.549999999999999822e-01 +2.564999999999999947e+00 3.559999999999999831e-01 +2.766999999999999904e+00 3.579999999999999849e-01 +2.970000000000000195e+00 3.589999999999999858e-01 +3.071000000000000174e+00 3.609999999999999876e-01 +3.239999999999989999e+00 3.619999999999999885e-01 +3.407999999999999918e+00 3.629999999999999893e-01 +3.576999999999999957e+00 3.649999999999999911e-01 +3.712000000000000188e+00 3.659999999999999920e-01 +3.813000000000000167e+00 3.679999999999999938e-01 +3.880999999999999783e+00 3.679999999999999938e-01 +3.947999999999990184e+00 3.699999999999999956e-01 +4.352999999999989988e+00 3.699999999999999956e-01 +4.758000000000000007e+00 3.709999999999999964e-01 +5.197000000000000064e+00 3.709999999999999964e-01 +5.602000000000000313e+00 3.719999999999999973e-01 +5.972999999999999865e+00 3.719999999999999973e-01 +6.243000000000000327e+00 3.729999999999999982e-01 +6.479000000000000092e+00 3.739999999999999991e-01 +6.682000000000000384e+00 3.750000000000000000e-01 +6.884000000000000341e+00 3.760000000000000009e-01 +6.985000000000000320e+00 3.770000000000000018e-01 +7.187999999999999723e+00 3.780000000000000027e-01 +7.322999999999989740e+00 3.790000000000000036e-01 +7.389999999999999680e+00 3.810000000000000053e-01 +7.491999999999999993e+00 3.820000000000000062e-01 +7.727999999999989988e+00 3.830000000000000071e-01 +8.064999999999999503e+00 3.830000000000000071e-01 +8.403000000000009351e+00 3.840000000000000080e-01 +8.808000000000010488e+00 3.840000000000000080e-01 +9.212999999999990308e+00 3.850000000000000089e-01 +9.618000000000000327e+00 3.840000000000000080e-01 +9.921000000000010033e+00 3.830000000000000071e-01 +1.025900000000000034e+01 3.830000000000000071e-01 +1.063000000000000078e+01 3.820000000000000062e-01 +1.103500000000000014e+01 3.810000000000000053e-01 +1.143999999999999950e+01 3.800000000000000044e-01 +1.174399999999999977e+01 3.800000000000000044e-01 +1.208099999999999952e+01 3.790000000000000036e-01 +1.245199999999999996e+01 3.790000000000000036e-01 +1.289100000000000001e+01 3.790000000000000036e-01 +1.316099999999999959e+01 3.800000000000000044e-01 +1.343099999999999916e+01 3.810000000000000053e-01 +1.366699999999999982e+01 3.820000000000000062e-01 +1.400399999999999956e+01 3.830000000000000071e-01 +1.430799999999999983e+01 3.850000000000000089e-01 +1.454400000000000048e+01 3.860000000000000098e-01 +1.471299999999999919e+01 3.870000000000000107e-01 +1.508399999999999963e+01 3.870000000000000107e-01 +1.562400000000000055e+01 3.870000000000000107e-01 +1.612999999999999901e+01 3.880000000000000115e-01 +1.663700000000000045e+01 3.880000000000000115e-01 +1.704200000000000159e+01 3.880000000000000115e-01 +1.744699999999999918e+01 3.880000000000000115e-01 +1.791900000000000048e+01 3.890000000000000124e-01 +1.825600000000000023e+01 3.900000000000000133e-01 +1.855999999999999872e+01 3.900000000000000133e-01 +1.889799999999999969e+01 3.920000000000000151e-01 +1.910000000000000142e+01 3.930000000000000160e-01 +1.933599999999999852e+01 3.930000000000000160e-01 +1.953900000000000148e+01 3.950000000000000178e-01 +1.987600000000000122e+01 3.960000000000000187e-01 +2.011199999999999832e+01 3.950000000000000178e-01 +2.048400000000000176e+01 3.940000000000000169e-01 +2.078699999999999903e+01 3.930000000000000160e-01 +2.112500000000000000e+01 3.920000000000000151e-01 +2.149599999999999866e+01 3.910000000000000142e-01 +2.190099999999999980e+01 3.900000000000000133e-01 +2.227199999999999847e+01 3.890000000000000124e-01 +2.264300000000000068e+01 3.880000000000000115e-01 +2.314999999999999858e+01 3.870000000000000107e-01 +2.362199999999999989e+01 3.860000000000000098e-01 +2.409400000000000119e+01 3.850000000000000089e-01 +2.460099999999999909e+01 3.850000000000000089e-01 +2.520799999999999841e+01 3.840000000000000080e-01 +2.578200000000000003e+01 3.830000000000000071e-01 +2.632199999999999918e+01 3.820000000000000062e-01 +2.692899999999999849e+01 3.820000000000000062e-01 +2.746900000000000119e+01 3.810000000000000053e-01 +2.810999999999999943e+01 3.800000000000000044e-01 +2.871799999999999997e+01 3.800000000000000044e-01 +2.922400000000000020e+01 3.790000000000000036e-01 +2.973000000000000043e+01 3.790000000000000036e-01 +3.016900000000000048e+01 3.780000000000000027e-01 +3.067500000000000071e+01 3.770000000000000018e-01 +3.128200000000000003e+01 3.770000000000000018e-01 +3.155199999999999960e+01 3.780000000000000027e-01 +3.195700000000000074e+01 3.800000000000000044e-01 +3.219299999999999784e+01 3.820000000000000062e-01 +3.246300000000000097e+01 3.840000000000000080e-01 +3.280100000000000193e+01 3.850000000000000089e-01 +3.324000000000000199e+01 3.870000000000000107e-01 +3.354299999999999926e+01 3.890000000000000124e-01 +3.388100000000000023e+01 3.900000000000000133e-01 +3.431900000000000261e+01 3.920000000000000151e-01 +3.469100000000000250e+01 3.940000000000000169e-01 +3.502799999999999869e+01 3.960000000000000187e-01 +3.546699999999999875e+01 3.970000000000000195e-01 +3.580400000000000205e+01 3.990000000000000213e-01 +3.610799999999999699e+01 4.010000000000000231e-01 +3.637800000000000011e+01 4.030000000000000249e-01 +3.661399999999999721e+01 4.040000000000000258e-01 +3.691799999999999926e+01 4.060000000000000275e-01 +3.722200000000000131e+01 4.079999999999999738e-01 +3.742399999999999949e+01 4.099999999999999756e-01 +3.762700000000000244e+01 4.109999999999999765e-01 +3.779500000000000171e+01 4.119999999999999774e-01 +3.803099999999999881e+01 4.139999999999999791e-01 +3.830100000000000193e+01 4.149999999999999800e-01 +3.850399999999999778e+01 4.159999999999999809e-01 +3.867300000000000182e+01 4.179999999999999827e-01 +3.890899999999999892e+01 4.189999999999999836e-01 +3.921300000000000097e+01 4.199999999999999845e-01 +3.938100000000000023e+01 4.209999999999999853e-01 +3.965100000000000335e+01 4.229999999999999871e-01 +3.988799999999999812e+01 4.239999999999999880e-01 +4.009000000000000341e+01 4.249999999999999889e-01 +4.039399999999999835e+01 4.259999999999999898e-01 +4.073100000000000165e+01 4.269999999999999907e-01 +4.103499999999999659e+01 4.279999999999999916e-01 +4.130499999999999972e+01 4.299999999999999933e-01 +4.160900000000000176e+01 4.309999999999999942e-01 +4.187899999999999778e+01 4.319999999999999951e-01 +4.221600000000000108e+01 4.329999999999999960e-01 +4.248599999999999710e+01 4.329999999999999960e-01 +4.275600000000000023e+01 4.339999999999999969e-01 +4.295799999999999841e+01 4.349999999999999978e-01 +4.322800000000000153e+01 4.359999999999999987e-01 +4.346500000000000341e+01 4.380000000000000004e-01 +4.376800000000000068e+01 4.390000000000000013e-01 +4.403799999999999670e+01 4.400000000000000022e-01 +4.424099999999999966e+01 4.420000000000000040e-01 +4.444299999999999784e+01 4.430000000000000049e-01 +4.461200000000000188e+01 4.440000000000000058e-01 +4.478099999999999881e+01 4.450000000000000067e-01 +4.494899999999999807e+01 4.460000000000000075e-01 +4.521900000000000119e+01 4.470000000000000084e-01 +4.545600000000000307e+01 4.480000000000000093e-01 +4.582699999999999818e+01 4.480000000000000093e-01 +4.619800000000000040e+01 4.480000000000000093e-01 +4.650200000000000244e+01 4.490000000000000102e-01 +4.683899999999999864e+01 4.490000000000000102e-01 +4.724399999999999977e+01 4.500000000000000111e-01 +4.751400000000000290e+01 4.510000000000000120e-01 +4.775000000000000000e+01 4.510000000000000120e-01 +4.808800000000000097e+01 4.520000000000000129e-01 +4.852600000000000335e+01 4.530000000000000138e-01 +4.886399999999999721e+01 4.540000000000000147e-01 +4.923499999999999943e+01 4.540000000000000147e-01 +4.964000000000000057e+01 4.540000000000000147e-01 +5.001100000000000279e+01 4.530000000000000138e-01 +5.034899999999999665e+01 4.530000000000000138e-01 +5.071999999999999886e+01 4.540000000000000147e-01 +5.102400000000000091e+01 4.540000000000000147e-01 +5.136099999999999710e+01 4.550000000000000155e-01 +5.173199999999999932e+01 4.560000000000000164e-01 +5.210300000000000153e+01 4.570000000000000173e-01 +5.254200000000000159e+01 4.580000000000000182e-01 +5.281199999999999761e+01 4.580000000000000182e-01 +5.314999999999999858e+01 4.580000000000000182e-01 +5.352100000000000080e+01 4.570000000000000173e-01 +5.382500000000000284e+01 4.570000000000000173e-01 +5.422899999999999920e+01 4.570000000000000173e-01 +5.466799999999999926e+01 4.570000000000000173e-01 +5.503900000000000148e+01 4.580000000000000182e-01 +5.541100000000000136e+01 4.580000000000000182e-01 +5.581600000000000250e+01 4.600000000000000200e-01 +5.618699999999999761e+01 4.600000000000000200e-01 +5.655799999999999983e+01 4.600000000000000200e-01 +5.696300000000000097e+01 4.600000000000000200e-01 +5.743500000000000227e+01 4.590000000000000191e-01 +5.794200000000000017e+01 4.590000000000000191e-01 +5.848100000000000165e+01 4.600000000000000200e-01 +5.912299999999999756e+01 4.600000000000000200e-01 +5.946000000000000085e+01 4.590000000000000191e-01 +5.986500000000000199e+01 4.590000000000000191e-01 +6.013499999999999801e+01 4.580000000000000182e-01 +6.040500000000000114e+01 4.560000000000000164e-01 +6.074199999999999733e+01 4.550000000000000155e-01 +6.107999999999999829e+01 4.540000000000000147e-01 +6.138400000000000034e+01 4.530000000000000138e-01 +6.185600000000000165e+01 4.520000000000000129e-01 +6.236200000000000188e+01 4.520000000000000129e-01 +6.283500000000000085e+01 4.520000000000000129e-01 +6.330700000000000216e+01 4.510000000000000120e-01 +6.371200000000000330e+01 4.500000000000000111e-01 +6.398199999999999932e+01 4.490000000000000102e-01 +6.428600000000000136e+01 4.480000000000000093e-01 +6.469100000000000250e+01 4.470000000000000084e-01 +6.496099999999999852e+01 4.450000000000000067e-01 +6.533199999999999363e+01 4.440000000000000058e-01 +6.566899999999999693e+01 4.420000000000000040e-01 +6.604000000000000625e+01 4.410000000000000031e-01 +6.634399999999999409e+01 4.400000000000000022e-01 +6.674899999999999523e+01 4.380000000000000004e-01 +6.712000000000000455e+01 4.369999999999999996e-01 +6.755899999999999750e+01 4.359999999999999987e-01 +6.806499999999999773e+01 4.349999999999999978e-01 +6.857099999999999795e+01 4.339999999999999969e-01 +6.897599999999999909e+01 4.329999999999999960e-01 +6.917900000000000205e+01 4.319999999999999951e-01 +6.958400000000000318e+01 4.299999999999999933e-01 +6.995499999999999829e+01 4.289999999999999925e-01 +7.035999999999999943e+01 4.269999999999999907e-01 +7.076500000000000057e+01 4.249999999999999889e-01 +7.117000000000000171e+01 4.229999999999999871e-01 +7.157500000000000284e+01 4.209999999999999853e-01 +7.194599999999999795e+01 4.189999999999999836e-01 +7.238500000000000512e+01 4.179999999999999827e-01 +7.299200000000000443e+01 4.169999999999999818e-01 +7.370099999999999341e+01 4.169999999999999818e-01 +7.430800000000000693e+01 4.159999999999999809e-01 +7.491599999999999682e+01 4.159999999999999809e-01 +7.545600000000000307e+01 4.139999999999999791e-01 +7.612999999999999545e+01 4.129999999999999782e-01 +7.670399999999999352e+01 4.109999999999999765e-01 +7.717700000000000671e+01 4.099999999999999756e-01 +7.771699999999999875e+01 4.099999999999999756e-01 +7.818899999999999295e+01 4.109999999999999765e-01 +7.886400000000000432e+01 4.129999999999999782e-01 +7.970799999999999841e+01 4.139999999999999791e-01 +8.055100000000000193e+01 4.159999999999999809e-01 +8.139499999999999602e+01 4.179999999999999827e-01 +8.220499999999999829e+01 4.209999999999999853e-01 +8.291299999999999670e+01 4.219999999999999862e-01