diff --git a/msspecbook/Activity09/Activity09.ipynb b/msspecbook/Activity09/Activity09.ipynb
index 3b67e7f..8c0eca7 100644
--- a/msspecbook/Activity09/Activity09.ipynb
+++ b/msspecbook/Activity09/Activity09.ipynb
@@ -9,10 +9,156 @@
"# 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",
+ "*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 a 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 Å."
+ "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 Å.\n",
+ "\n",
+ "(COFe-paper)=\n",
+ ":::{seealso}\n",
+ "based on this paper from R. S. Saiki *et al.*\n",
+ "[Phys. Rev. Lett. **63(3)** p283-6 (1989)](https://doi.org/10.1103/PhysRevLett.63.283)\n",
+ ":::\n",
+ "\n",
+ "We will try to reproduce the polar scan of the figure below of CO adsorbed in the hollow site of the Fe(001) surface with simple single scattering calculations with MsSpec and by using R-Factors to find the best adsorption geometry. We will use the simple cluster displayed on the left hand side of the figure.\n",
+ "\n",
+ ":::{figure-md} COFe-fig1\n",
+ "
\n",
+ "\n",
+ "Small cluster used for SSC calculations (left) and (right) Normalized polar scan of the C(1s) at 1202 eV for [100] and [1-10] azimths.\n",
+ ":::"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "91c03801-b46b-4844-8c89-655700419063",
+ "metadata": {},
+ "source": [
+ "::::{tab-set}\n",
+ "\n",
+ ":::{tab-item} Quiz\n",
+ "Download [this script](./COFe.py) and write the body of the function `create_cluster`. The function should return a \n",
+ "small cluster of 5 Fe atoms with the CO molecule adsorbed like in figure {numref}`Fig. %s ` below. The function\n",
+ "will accept 4 keyword arguments to control the adsorption geometry.\n",
+ "\n",
+ "```{figure-md} COFe-fig2\n",
+ "
\n",
+ "\n",
+ "Adsorption geometry of carbon monoxide on Fe(001).\n",
+ "```\n",
+ "\n",
+ "```{note}\n",
+ "Remember to use the [`ase.build.bulk`](https://wiki.fysik.dtu.dk/ase/ase/build/build.html#ase.build.bulk), the [`msspec.utils.hemispherical_cluster`](https://msspec.cnrs.fr/faq/hemispherical_cluster/hemispherical_cluster.html#hemispherical-cluster-faq) and the [`ase.build.add_adsorbate`](https://wiki.fysik.dtu.dk/ase/ase/build/surface.html#ase.build.add_adsorbate) \n",
+ "functions.\n",
+ "```\n",
+ "\n",
+ ":::\n",
+ "\n",
+ "::::"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d1be5047-fb75-4e98-a6a2-fc6f678e68ff",
+ "metadata": {},
+ "source": [
+ "```{toggle}\n",
+ "Here is the code of the `create_cluster` function\n",
+ "\n",
+ ":::{literalinclude} COFe_completed.py\n",
+ ":lines: 10-35\n",
+ ":emphasize-lines: 10-21\n",
+ ":::\n",
+ "\n",
+ "```"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c7697c4f-949b-4261-abaf-96eefaa9a6ba",
+ "metadata": {},
+ "source": [
+ "Now that the `create_cluster` function is done, look at the rest of the script. The next function is called `compute_polar_scan` and will obviously be used to compute the $\\theta$-scan of the C1s for a given cluster geometry.\n",
+ "Finally there is the *Main part* that is built in two sections:\n",
+ "\n",
+ "1. A section containing nested *for loops*\n",
+ "2. A final section for *R-Factor analysis*\n",
+ "\n",
+ "::::{tab-set}\n",
+ "\n",
+ ":::{tab-item} Quiz\n",
+ "1. Complete the nested for loops in section 1) in order to compute polar scans for CO molecule tilted from 45° to 60° with a 1° step and aligned either along the [100] direction of Fe, 30° from this direction or along [110]. The adsorption height is 0.6 Å and the bond length is 1.157 Å.\n",
+ "2. What is the best $(\\theta, \\phi)$ according to the R-Factor analysis\n",
+ ":::\n",
+ "\n",
+ "::::"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "670cbd24-efd4-4c51-89e2-f1d96c53908d",
+ "metadata": {},
+ "source": [
+ "```{toggle}\n",
+ "Here are the code of the nested *for loops*\n",
+ "\n",
+ ":::{literalinclude} COFe_completed.py\n",
+ ":lines: 58-79\n",
+ ":emphasize-lines: 10,11,13,14,16\n",
+ ":::\n",
+ "\n",
+ "Runing the code gives the following result. The CO molecule belongs to the (100), (010), (-100), (0-10) planes of iron and is tilted by 55° from the surface normal (*ie* 35° from the surface itself).\n",
+ "\n",
+ ":::{figure-md} COFe-comparison\n",
+ "
\n",
+ "\n",
+ "Best polar scan according to R-Factor analysis.\n",
+ ":::\n",
+ "\n",
+ "MsSpec uses 12 different R-Factors formula to compare the calculted curve to the experimental data. The set of parameters giving the best agreement according to the majority of those 12 R-factors is assumed to be the best solution. Here are the R-factors formula used in MsSpec\n",
+ "\n",
+ ":::{figure-md} rfactors-formula\n",
+ "
\n",
+ "\n",
+ "The 12 R-Factors used in MsSpec. The Pendry's R-Factor is n° ??\n",
+ ":::\n",
+ "\n",
+ "\n",
+ "```"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f7827b3c-0cac-42e2-a587-8b30ee3632b4",
+ "metadata": {},
+ "source": [
+ "::::{tab-set}\n",
+ "\n",
+ ":::{tab-item} Quiz\n",
+ "How many R-Factors do agree that $(\\theta,\\phi)=(55,0)$ gives the best agreement ?\n",
+ ":::\n",
+ "\n",
+ "::::"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "aa8d2dc4-286a-441d-9c21-dab6bac8145c",
+ "metadata": {},
+ "source": [
+ "```{toggle}\n",
+ "\n",
+ "6 R-factors out of 12 do agree that *variable set n°30* gives the best agreement. The set n°30 corresponds to\n",
+ "$\\theta=55°$ and $\\phi=0°$.\n",
+ "\n",
+ ":::{figure-md} results\n",
+ "
\n",
+ "\n",
+ "The number of R-Factors for which the parameter set (in abscissa) gives the best agreement.\n",
+ ":::\n",
+ "\n",
+ "\n",
+ "```"
]
}
],
diff --git a/msspecbook/Activity09/COFe.py b/msspecbook/Activity09/COFe.py
new file mode 100644
index 0000000..4d4b61e
--- /dev/null
+++ b/msspecbook/Activity09/COFe.py
@@ -0,0 +1,77 @@
+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=1., theta=45, phi=0, bond_length=1.15):
+ # Fill the body of this function. The 'cluster' object in built according to
+ # values provided by the keyword arguments:
+ # height (in angströms): the 'z' distance between the Fe surface and the C atom
+ # theta and phi (in degrees): the polar and azimuthal orientation of the CP molecule
+ # (theta=0° aligns the molecule withe the surface normal
+ # phi=0° corresponds to the [100] direction of iron)
+ # bond_length (in angströms): the C-O distance
+
+ # Keep those 2 lines at the end of your function
+ # 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)
+
+ # SSC calculations
+ calc.calculation_parameters.scattering_order = 1
+
+ # Add temperature effects
+ [atom.set('mean_square_vibration', 0.005) for atom in cluster]
+ calc.calculation_parameters.vibrational_damping = 'averaged_tl'
+
+ 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
+
+
+###############################################################################
+# Main part
+###############################################################################
+results = [] # polar angles and calculated cross_sections will be appended
+ # to this list after each 'compute_polar_scan' call
+parameters = {'theta': [], 'phi': []} # and corresponding parameters will also
+ # be stored in this dictionary
+
+# 1) Run calculations for different geometries
+for theta in ...
+ for phi in ...
+ # Create the cluster
+ cluster = ...
+
+ # Compute
+ data = ...
+
+ # 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)
+
+# 2) R-Factor analysis
+# 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/COFe_completed.py b/msspecbook/Activity09/COFe_completed.py
new file mode 100644
index 0000000..5a04b6d
--- /dev/null
+++ b/msspecbook/Activity09/COFe_completed.py
@@ -0,0 +1,92 @@
+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=1., theta=45, phi=0, bond_length=1.15):
+ # Fill the body of this function. The 'cluster' object in built according to
+ # values provided by the keyword arguments:
+ # height (in angströms): the 'z' distance between the Fe surface and the C atom
+ # theta and phi (in degrees): the polar and azimuthal orientation of the CP molecule
+ # (theta=0° aligns the molecule withe the surface normal
+ # phi=0° corresponds to the [100] direction of iron)
+ # bond_length (in angströms): the C-O distance
+
+ 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)
+
+ # Keep those 2 lines at the end of your function
+ # 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)
+
+ # SSC calculations
+ calc.calculation_parameters.scattering_order = 1
+
+ # Add temperature effects
+ [atom.set('mean_square_vibration', 0.005) for atom in cluster]
+ calc.calculation_parameters.vibrational_damping = 'averaged_tl'
+
+ 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
+
+
+###############################################################################
+# Main part
+###############################################################################
+results = [] # polar angles and calculated cross_sections will be appended
+ # to this list after each 'compute_polar_scan' call
+parameters = {'theta': [], 'phi': []} # and corresponding parameters will also
+ # be stored in this dictionary
+
+# 1) Run calculations for different geometries
+for theta in np.arange(45, 60, 1):
+ for phi in [0, 30, 45]:
+ # Create the cluster
+ cluster = create_cluster(theta=theta, phi=phi, height=0.6,
+ 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)
+
+
+# 2) R-Factor analysis
+# 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/COFe_fig1.jpg b/msspecbook/Activity09/COFe_fig1.jpg
new file mode 100644
index 0000000..bf7bc39
Binary files /dev/null and b/msspecbook/Activity09/COFe_fig1.jpg differ
diff --git a/msspecbook/Activity09/COFe_fig2.jpg b/msspecbook/Activity09/COFe_fig2.jpg
new file mode 100644
index 0000000..6402da2
Binary files /dev/null and b/msspecbook/Activity09/COFe_fig2.jpg differ
diff --git a/msspecbook/Activity09/CO_Fe_completed.py b/msspecbook/Activity09/CO_Fe_completed.py
deleted file mode 100644
index f252977..0000000
--- a/msspecbook/Activity09/CO_Fe_completed.py
+++ /dev/null
@@ -1,73 +0,0 @@
-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
deleted file mode 100644
index c6967f3..0000000
--- a/msspecbook/Activity09/CO_Fe_completed2.py
+++ /dev/null
@@ -1,76 +0,0 @@
-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/Comparison.png b/msspecbook/Activity09/Comparison.png
new file mode 100644
index 0000000..66c9b6d
Binary files /dev/null and b/msspecbook/Activity09/Comparison.png differ
diff --git a/msspecbook/Activity09/formula.jpg b/msspecbook/Activity09/formula.jpg
new file mode 100644
index 0000000..a9ad082
Binary files /dev/null and b/msspecbook/Activity09/formula.jpg differ
diff --git a/msspecbook/Activity09/results.png b/msspecbook/Activity09/results.png
new file mode 100644
index 0000000..0e5ecb1
Binary files /dev/null and b/msspecbook/Activity09/results.png differ