diff --git a/msspecbook/material/Activity01/copper.cif b/msspecbook/material/Activity01/copper.cif new file mode 100644 index 0000000..0490639 --- /dev/null +++ b/msspecbook/material/Activity01/copper.cif @@ -0,0 +1,51 @@ +data_image0 +_chemical_formula_structural Cu26 +_chemical_formula_sum "Cu26" +_cell_length_a 14.4 +_cell_length_b 14.4 +_cell_length_c 7.2 +_cell_angle_alpha 90.0 +_cell_angle_beta 90.0 +_cell_angle_gamma 90.0 + +_space_group_name_H-M_alt "P 1" +_space_group_IT_number 1 + +loop_ + _space_group_symop_operation_xyz + 'x, y, z' + +loop_ + _atom_site_type_symbol + _atom_site_label + _atom_site_symmetry_multiplicity + _atom_site_fract_x + _atom_site_fract_y + _atom_site_fract_z + _atom_site_occupancy + Cu Cu1 1.0 0.25 0.5 0.37500000000000017 1.0000 + Cu Cu2 1.0 0.25 0.5 0.8750000000000001 1.0000 + Cu Cu3 1.0 0.3750000000000001 0.37500000000000017 0.37500000000000017 1.0000 + Cu Cu4 1.0 0.5 0.24999999999999992 0.37500000000000017 1.0000 + Cu Cu5 1.0 0.5 0.37500000000000017 0.12499999999999996 1.0000 + Cu Cu6 1.0 0.3750000000000001 0.37500000000000017 0.8750000000000001 1.0000 + Cu Cu7 1.0 0.5 0.24999999999999992 0.8750000000000001 1.0000 + Cu Cu8 1.0 0.5 0.37500000000000017 0.625 1.0000 + Cu Cu9 1.0 0.3750000000000001 0.5 0.12499999999999996 1.0000 + Cu Cu10 1.0 0.3750000000000001 0.6249999999999999 0.37500000000000017 1.0000 + Cu Cu11 1.0 0.5 0.5 0.37500000000000017 1.0000 + Cu Cu12 1.0 0.5 0.6249999999999999 0.12499999999999996 1.0000 + Cu Cu13 1.0 0.3750000000000001 0.5 0.625 1.0000 + Cu Cu14 1.0 0.3750000000000001 0.6249999999999999 0.8750000000000001 1.0000 + Cu Cu15 1.0 0.5 0.5 0.8750000000000001 1.0000 + Cu Cu16 1.0 0.5 0.6249999999999999 0.625 1.0000 + Cu Cu17 1.0 0.5 0.7500000000000003 0.37500000000000017 1.0000 + Cu Cu18 1.0 0.5 0.7500000000000003 0.8750000000000001 1.0000 + Cu Cu19 1.0 0.6249999999999999 0.37500000000000017 0.37500000000000017 1.0000 + Cu Cu20 1.0 0.6249999999999999 0.37500000000000017 0.8750000000000001 1.0000 + Cu Cu21 1.0 0.6249999999999999 0.5 0.12499999999999996 1.0000 + Cu Cu22 1.0 0.6249999999999999 0.6249999999999999 0.37500000000000017 1.0000 + Cu Cu23 1.0 0.7500000000000003 0.5 0.37500000000000017 1.0000 + Cu Cu24 1.0 0.6249999999999999 0.5 0.625 1.0000 + Cu Cu25 1.0 0.6249999999999999 0.6249999999999999 0.8750000000000001 1.0000 + Cu Cu26 1.0 0.7500000000000003 0.5 0.8750000000000001 1.0000 diff --git a/msspecbook/material/Activity01/cu.py b/msspecbook/material/Activity01/cu.py new file mode 100644 index 0000000..749851d --- /dev/null +++ b/msspecbook/material/Activity01/cu.py @@ -0,0 +1,24 @@ +from ase.io import read +from msspec.calculator import MSSPEC + + +cluster = read('copper.cif') +# view the cluster +cluster.edit() + +# The "emitter" atom is located in the middle of the 3rd plane +cluster.emitter = 10 + +# Create a "calculator" +calc = MSSPEC(spectroscopy='PED', algorithm='inversion') +calc.set_atoms(cluster) + +data = calc.get_theta_scan(level='2p3/2') + +# Plot the result with the interactive GUI +data.view() + +# Or plot using matplotlib directly +from matplotlib import pyplot as plt +data[0].views[0].plot() +plt.show() diff --git a/msspecbook/material/Activity02/PhysRevB.55.R16061.pdf b/msspecbook/material/Activity02/PhysRevB.55.R16061.pdf new file mode 100644 index 0000000..9625e08 Binary files /dev/null and b/msspecbook/material/Activity02/PhysRevB.55.R16061.pdf differ diff --git a/msspecbook/material/Activity02/SbAg.py b/msspecbook/material/Activity02/SbAg.py new file mode 100644 index 0000000..d376ab5 --- /dev/null +++ b/msspecbook/material/Activity02/SbAg.py @@ -0,0 +1,55 @@ +from ase.build import bulk +from ase.visualize import view + +from msspec.calculator import MSSPEC +from msspec.utils import hemispherical_cluster, get_atom_index, cut_plane +import numpy as np +from matplotlib import pyplot as plt + +# Create the silver cell +Ag = bulk('Ag', cubic=True) +# Orientate the cell in the [111] direction +Ag.rotate((1,1,1), (0,0,1), rotate_cell=True) +# Align the azimuth to match experimental reference +Ag.rotate(15, 'z', rotate_cell=True) + +# Create a cluster +cluster = hemispherical_cluster(Ag, diameter=20, emitter_plane=0) +cluster = cut_plane(cluster, z=-4.8) +cluster.emitter = get_atom_index(cluster, 0,0,0) +cluster[cluster.emitter].symbol = 'Sb' + +# Create a calculator +calc = MSSPEC(spectroscopy='PED', algorithm='inversion') +calc.set_atoms(cluster) + +# Define parameters +calc.source_parameters.theta = 0 +calc.source_parameters.phi = 0 + +calc.detector_parameters.angular_acceptance = 1 +calc.detector_parameters.average_sampling = 'low' + +calc.muffintin_parameters.interstitial_potential = 0 + +# Compute an azimuthal scan +data = calc.get_phi_scan(level='4d', theta=40, phi=np.linspace(0,240,121), kinetic_energy=45) + +# Normalize data between [0,1] (to ease comparison with experimental data) +dset = data[0] +dset.cross_section -= dset.cross_section.min() +dset.cross_section /= dset.cross_section.max() + +# Add experimental data points in the dataset +x, y = np.loadtxt('data.txt').T +dset.add_columns(experiment=y) + +# Add points to view +view = dset.views[0] +view.select('phi', 'experiment', legend='Exp. data') + +# Popup GUI +data.view() + +# Remove temp. files +calc.shutdown() diff --git a/msspecbook/material/Activity02/data.txt b/msspecbook/material/Activity02/data.txt new file mode 100644 index 0000000..19f61b8 --- /dev/null +++ b/msspecbook/material/Activity02/data.txt @@ -0,0 +1,121 @@ +0.000000000000000000e+00 2.273853352828327234e-01 +2.000000000000000000e+00 2.135876322898652424e-01 +4.000000000000000000e+00 1.925265592281927285e-01 +6.000000000000000000e+00 1.852631891594877511e-01 +8.000000000000000000e+00 1.852631891594877511e-01 +1.000000000000000000e+01 1.831705825411805155e-01 +1.200000000000000000e+01 1.636929472985219347e-01 +1.400000000000000000e+01 1.279608696063064543e-01 +1.600000000000000000e+01 1.040430509934481690e-01 +1.800000000000000000e+01 3.015378633541379930e-02 +2.000000000000000000e+01 4.106459224097607462e-03 +2.200000000000000000e+01 1.971550450495464929e-02 +2.400000000000000000e+01 7.007532033757153667e-02 +2.600000000000000000e+01 1.904879553613253451e-01 +2.800000000000000000e+01 3.101513022088481231e-01 +3.000000000000000000e+01 4.052906495585950619e-01 +3.200000000000000000e+01 3.678644926959027672e-01 +3.400000000000000000e+01 3.036757937102613214e-01 +3.600000000000000000e+01 2.214720340001324062e-01 +3.800000000000000000e+01 2.247878029385593501e-01 +4.000000000000000000e+01 2.837024903561691791e-01 +4.200000000000000000e+01 3.445713059080361962e-01 +4.400000000000000000e+01 4.114147115795538934e-01 +4.600000000000000000e+01 5.600722856829548624e-01 +4.800000000000000000e+01 6.969212581381016847e-01 +5.000000000000000000e+01 8.189179738707677014e-01 +5.200000000000000000e+01 9.080765164985155069e-01 +5.400000000000000000e+01 9.562807225028111535e-01 +5.600000000000000000e+01 9.888241305894533983e-01 +5.800000000000000000e+01 9.881336668388966959e-01 +6.000000000000000000e+01 9.873660563005683954e-01 +6.200000000000000000e+01 9.916558998680982118e-01 +6.400000000000000000e+01 9.856319679487668406e-01 +6.600000000000000000e+01 9.620117644994009565e-01 +6.800000000000000000e+01 8.930029985027734263e-01 +7.000000000000000000e+01 8.002870246239043306e-01 +7.200000000000000000e+01 6.744921153732785779e-01 +7.400000000000000000e+01 5.336319385472689802e-01 +7.600000000000000000e+01 3.958859203876436417e-01 +7.800000000000000000e+01 3.306385960364682242e-01 +8.000000000000000000e+01 2.830681723233798852e-01 +8.200000000000000000e+01 2.157622815497834690e-01 +8.400000000000000000e+01 2.239956241155102445e-01 +8.600000000000000000e+01 3.126826811826061703e-01 +8.800000000000000000e+01 3.836092948935748703e-01 +9.000000000000000000e+01 3.974940023194180050e-01 +9.200000000000000000e+01 2.890294760518045125e-01 +9.400000000000000000e+01 1.681544424688440620e-01 +9.600000000000000000e+01 5.857273428081174321e-02 +9.800000000000000000e+01 1.843518927289370876e-02 +1.000000000000000000e+02 3.948951199063644064e-03 +1.020000000000000000e+02 5.411750728699640106e-02 +1.040000000000000000e+02 1.168717046133502524e-01 +1.060000000000000000e+02 1.428170265275016670e-01 +1.080000000000000000e+02 1.770817723162995683e-01 +1.100000000000000000e+02 1.852631891594877511e-01 +1.120000000000000000e+02 1.827670619818080600e-01 +1.140000000000000000e+02 1.840805289029476266e-01 +1.160000000000000000e+02 2.023203439358092770e-01 +1.180000000000000000e+02 2.289994175203227400e-01 +1.200000000000000000e+02 2.320430725945487604e-01 +1.220000000000000000e+02 2.174983315399919570e-01 +1.240000000000000000e+02 1.903085890797567015e-01 +1.260000000000000000e+02 1.848716692115463522e-01 +1.280000000000000000e+02 1.870838533508997481e-01 +1.300000000000000000e+02 1.808923414647976846e-01 +1.320000000000000000e+02 1.656061876352601381e-01 +1.340000000000000000e+02 1.324214968752658039e-01 +1.360000000000000000e+02 8.695118016262873284e-02 +1.380000000000000000e+02 1.854769500506061805e-02 +1.400000000000000000e+02 0.000000000000000000e+00 +1.420000000000000000e+02 2.910410785429527400e-02 +1.440000000000000000e+02 1.010188969127969877e-01 +1.460000000000000000e+02 2.301799776698615074e-01 +1.480000000000000000e+02 3.527565800906127258e-01 +1.500000000000000000e+02 3.915987019538648140e-01 +1.520000000000000000e+02 3.464073994570029402e-01 +1.540000000000000000e+02 2.694669793425982229e-01 +1.560000000000000000e+02 2.158017450989128672e-01 +1.580000000000000000e+02 2.275203421614326316e-01 +1.600000000000000000e+02 3.068773854027863068e-01 +1.620000000000000000e+02 3.571336959618095497e-01 +1.640000000000000000e+02 4.706879815526597843e-01 +1.660000000000000000e+02 6.409924085632153767e-01 +1.680000000000000000e+02 7.767958277474236173e-01 +1.700000000000000000e+02 8.699880758924664059e-01 +1.720000000000000000e+02 9.465309757532142099e-01 +1.740000000000000000e+02 9.812603702158622099e-01 +1.760000000000000000e+02 9.992196602416892892e-01 +1.780000000000000000e+02 9.917162779443612353e-01 +1.800000000000000000e+02 9.978245891628175768e-01 +1.820000000000000000e+02 1.000000000000000000e+00 +1.840000000000000000e+02 9.875604662057533289e-01 +1.860000000000000000e+02 9.483868703110428511e-01 +1.880000000000000000e+02 8.713195437307523772e-01 +1.900000000000000000e+02 7.743174871902573919e-01 +1.920000000000000000e+02 6.499028625508473933e-01 +1.940000000000000000e+02 5.133872820820232219e-01 +1.960000000000000000e+02 3.854633893596886574e-01 +1.980000000000000000e+02 3.197097892137605313e-01 +2.000000000000000000e+02 2.625546271582531732e-01 +2.020000000000000000e+02 2.180674059888806082e-01 +2.040000000000000000e+02 2.313545375136863425e-01 +2.060000000000000000e+02 3.256001393270981925e-01 +2.080000000000000000e+02 3.901136262892592188e-01 +2.100000000000000000e+02 4.105052902445402441e-01 +2.120000000000000000e+02 3.039702372835895727e-01 +2.140000000000000000e+02 1.592176621398869174e-01 +2.160000000000000000e+02 6.314946746536785616e-02 +2.180000000000000000e+02 1.766902523683577114e-02 +2.200000000000000000e+02 1.012551589503468512e-02 +2.220000000000000000e+02 5.641599939516841328e-02 +2.240000000000000000e+02 1.259411667024434578e-01 +2.260000000000000000e+02 1.520177453041229865e-01 +2.280000000000000000e+02 1.775272950156810414e-01 +2.300000000000000000e+02 1.829980737518577261e-01 +2.320000000000000000e+02 1.838471170106117103e-01 +2.340000000000000000e+02 1.827520612175190795e-01 +2.360000000000000000e+02 2.068282879012685871e-01 +2.380000000000000000e+02 2.265482926355094906e-01 +2.400000000000000000e+02 2.403459956284773325e-01 diff --git a/msspecbook/material/Activity03/RhO_sf.py b/msspecbook/material/Activity03/RhO_sf.py new file mode 100644 index 0000000..6c66e49 --- /dev/null +++ b/msspecbook/material/Activity03/RhO_sf.py @@ -0,0 +1,17 @@ +from ase import Atoms +from ase.visualize import view +from msspec.calculator import MSSPEC + +# Create an atomic chain O-Rh +cluster = Atoms(['O', 'Rh'], positions = [(1,0,0), (0,0,4.)]) + +# Create a calculator +calc = MSSPEC(spectroscopy='PED') +calc.set_atoms(cluster) +cluster.emitter = 0 + +# Compute the scattering factor +data = calc.get_scattering_factors(kinetic_energy=723) + +# Popup the results +data.view() diff --git a/msspecbook/material/Activity03/RhO_tofill.py b/msspecbook/material/Activity03/RhO_tofill.py new file mode 100644 index 0000000..b0ed36a --- /dev/null +++ b/msspecbook/material/Activity03/RhO_tofill.py @@ -0,0 +1,23 @@ +from msspec.calculator import MSSPEC +from ase.build import fcc111, add_adsorbate +import numpy as np + +data = None +all_z = ... # -> Define a list of z values for the adsorbate + +for ... # -> Complete this for-loop over z values + # construct the cluster + cluster = fcc111('Rh', size = (2,2,1)) + cluster.pop(3) + add_adsorbate(... # -> Put the oxygen atom on the fcc site + cluster.emitter = ... # -> Oxygen is the last atom we added, so the indice is... + + # Define a calculator for single scattering calculations + calc = MSSPEC(spectroscopy='PED', algorithm='expansion') + calc.calculation_parameters.scattering_order = 1 + calc.set_atoms(cluster) + + # Compute + data = calc.get_theta_phi_scan(level='1s', kinetic_energy=723, data=data) + +data.view() diff --git a/msspecbook/material/Activity05/SurfSci_606_p1760_(2012).pdf b/msspecbook/material/Activity05/SurfSci_606_p1760_(2012).pdf new file mode 100644 index 0000000..e6b7131 Binary files /dev/null and b/msspecbook/material/Activity05/SurfSci_606_p1760_(2012).pdf differ diff --git a/msspecbook/material/Activity05/TiSe2_1_tofill.py b/msspecbook/material/Activity05/TiSe2_1_tofill.py new file mode 100644 index 0000000..60bac32 --- /dev/null +++ b/msspecbook/material/Activity05/TiSe2_1_tofill.py @@ -0,0 +1,40 @@ +from ase.build import mx2 +from ase.visualize import view +from msspec.calculator import MSSPEC +from msspec.utils import hemispherical_cluster, get_atom_index + +# Some usefull constants (a, c, d, D) for defining the structure +a=... + +# Create the TiSe2 trilayer +# use ase help for this function +TiSe2 = mx2(formula=...) + +# The preious cell is 2D, let's define the c-axis to take into account +# the Van der Waals gap between trilayers +TiSe2.cell[2] = [0, 0, ...] + +# To be aligned like in the paper +TiSe2.rotate(60, 'z', rotate_cell=True) + +# Since the material is multi-elements, "tag" each inequivalent atom +# of the unit cell with a number. The "Ti" atom is tagged 0 and "Se" +# atoms are 1 and 2. +for i in range(3): + TiSe2[i].tag = i + +cluster = hemispherical_cluster(TiSe2, emitter_tag=..., emitter_plane=..., planes=5) +cluster.emitter = get_atom_index(cluster, 0, 0, 0) + +view(cluster) + +# Create a calculator with Rehr-Albers series expansion algorithm +calc = MSSPEC(spectroscopy='PED', algorithm='expansion') +calc.set_atoms(cluster) + +data = None +for ndif in range(1,4): + calc.calculation_parameters.scattering_order = ndif + data = calc.get_theta_phi_scan(level='2p', kinetic_energy=1030, data=data) + +data.view() \ No newline at end of file diff --git a/msspecbook/material/Activity06/Cu_temperature.py b/msspecbook/material/Activity06/Cu_temperature.py new file mode 100644 index 0000000..caac050 --- /dev/null +++ b/msspecbook/material/Activity06/Cu_temperature.py @@ -0,0 +1,126 @@ +from ase.build import bulk +import numpy as np + +from msspec.calculator import MSSPEC, XRaySource +from msspec.utils import hemispherical_cluster, get_atom_index + +def create_clusters(nplanes=3): + copper = bulk('Cu', a=3.6, cubic=True) + clusters = [] + for emitter_plane in range(nplanes): + cluster = hemispherical_cluster(copper, + emitter_plane=emitter_plane, + planes=emitter_plane+1, + diameter=27, + shape='cylindrical') + cluster.absorber = get_atom_index(cluster, 0, 0, 0) + # This is how to store extra information with your cluster + cluster.info.update({ + 'emitter_plane': emitter_plane, + }) + clusters.append(cluster) + return clusters + + +def compute(clusters, all_theta=[45., 83.], + all_T=np.arange(300., 1000., 400.)): + data = None + for cluster in clusters: + # Retrieve emitter's plane from cluster object + plane = cluster.info['emitter_plane'] + + calc = MSSPEC(spectroscopy='PED', algorithm='expansion') + calc.source_parameters.energy = XRaySource.AL_KALPHA + calc.muffintin_parameters.interstitial_potential = 14.1 + + # In simple scattering, it is common practice to use a real potential and + # manually define a mean free path arbitrarily lower than the actual physical + # value in an attempt to reproduce multiple scattering effects. + calc.tmatrix_parameters.exchange_correlation = 'x_alpha_real' + calc.calculation_parameters.mean_free_path = ... # -> half of the mean free + # path (see p6785) + # Parameters for temperature effects + calc.calculation_parameters.vibrational_damping = 'averaged_tl' + calc.calculation_parameters.use_debye_model = ..... # Use the MsSpec help + calc.calculation_parameters.debye_temperature = ... # and p6791 of the paper + calc.calculation_parameters.vibration_scaling = ... # -> How much more do + # surface atoms vibrate + # than bulk atoms? + calc.detector_parameters.average_sampling = 'low' + calc.detector_parameters.angular_acceptance = 5.7 + + calc.calculation_parameters.scattering_order = 1 + + + for T in all_T: + # Define the sample temperature + calc.calculation_parameters.temperature = T + # Set the atoms and compute an azimuthal scan + calc.set_atoms(cluster) + data = calc.get_phi_scan(level='2p', theta=all_theta, + phi=np.linspace(0, 100, 51), + kinetic_energy=560, data=data) + # Small changes to add some details in both the title of the dataset + # and the figure + view = data[-1].views[-1] + t = view._plotopts['title'] + f" (plane #{plane:d}, T={T:.0f} K)" + data[-1].title = t + view.set_plot_options(autoscale=True, title=t) + calc.shutdown() + return data + + +def analysis(data, all_theta, all_T, nplanes): + # Sum cross_section for all emitter's plane at a given T + # Compute the anisotropy + results = dict.fromkeys(all_T, []) + anisotropy = [] + for dset in data: + # Retrieve temperature + T = float(dset.get_parameter('CalculationParameters', 'temperature')['value']) + # Update the sum in results + if len(results[T]) == 0: + results[T] = dset.cross_section + else: + results[T] += dset.cross_section + + anisotropy_dset = data.add_dset("Anisotropies") + anisotropy_dset.add_columns(temperature=all_T) + for theta in all_theta: + col_name = f"theta{theta:.0f}" + col_values = [] + i = np.where(dset.theta == theta)[0] + for T in all_T: + cs = results[T][i] + Imax = np.max(cs) + Imin = np.min(cs) + A = (Imax - Imin)/Imax + col_values.append(A) + anisotropy_dset.add_columns(**{col_name:col_values/np.max(col_values)}) + + + anisotropy_view = anisotropy_dset.add_view('Anisotropies', + title='Relative anisotropies for Cu(2p)', + marker='o', + xlabel='T (K)', + ylabel=r'$\frac{\Delta I / I_{max}(T)}{\Delta I_{300}' + r'/ I_{max}(300)} (\%)$', + autoscale=True) + for theta in all_theta: + col_name = f"theta{theta:.0f}" + anisotropy_view.select('temperature', col_name, + legend=r'$\theta = {:.0f} \degree$'.format(theta)) + + return data + + + +if __name__ == "__main__": + nplanes = 4 + all_theta = np.array([45, 83]) + all_theta = np.array([300., 1000.]) + + clusters = create_clusters(nplanes=nplanes) + data = compute(clusters, all_T=all_T, all_theta=all_theta) + data = analysis(data, all_T=all_T, all_theta=all_theta, nplanes=nplanes) + data.view() diff --git a/msspecbook/material/Activity06/PhysRevB.34.6784.pdf b/msspecbook/material/Activity06/PhysRevB.34.6784.pdf new file mode 100644 index 0000000..5d0e113 Binary files /dev/null and b/msspecbook/material/Activity06/PhysRevB.34.6784.pdf differ diff --git a/msspecbook/material/Activity07/Si001.py b/msspecbook/material/Activity07/Si001.py new file mode 100644 index 0000000..af37f6f --- /dev/null +++ b/msspecbook/material/Activity07/Si001.py @@ -0,0 +1,56 @@ +# coding: utf8 + +import numpy as np +from ase.build import bulk + +from msspec.calculator import MSSPEC, XRaySource +from msspec.iodata import Data +from msspec.utils import hemispherical_cluster, get_atom_index + + +# Create the cluster +a = 5.43 +Si = bulk('Si', a=a, cubic=True) +cluster = hemispherical_cluster(Si, + diameter=30, planes=4, + emitter_plane=3, + shape = 'cylindrical', + ) +for atom in cluster: + atom.set('mean_square_vibration', 0.006) + atom.set('mt_radius', 1.1) +cluster.emitter = get_atom_index(cluster, 0, 0, 0) + +# Create a calculator and set parameters +calc = MSSPEC(spectroscopy='PED', algorithm='expansion') + +calc.source_parameters.energy = XRaySource.AL_KALPHA +calc.source_parameters.theta = -54.7 +calc.source_parameters.phi = 90 +calc.spectroscopy_parameters.final_state = 1 + +calc.calculation_parameters.scattering_order = 3 +calc.tmatrix_parameters.tl_threshold = 1e-4 +calc.calculation_parameters.vibrational_damping = 'averaged_tl' +calc.calculation_parameters.RA_cutoff = 2 + +# Define path filtering options such that you only +# accept scattering paths with a forward cone <= 40° +# and whose length are <= cluster diameter +# +# + +calc.set_atoms(cluster) + +# Compute and add previous data for comparison +data = calc.get_theta_scan(level='2p', + theta=np.arange(-30., 80., 0.5), + phi=0, + kinetic_energy=1382.28) +no_filters = Data.load('path_filtering.hdf5') +data[0].add_columns(**{'no_filters': no_filters[0].cross_section}) +view = data[0].views[0] +view.select('theta', 'cross_section', index=0, legend="With path filtering") +view.select('theta', 'no_filters', legend="Without path filtering") + +data.view() diff --git a/msspecbook/material/Activity08/AlN.py b/msspecbook/material/Activity08/AlN.py new file mode 100644 index 0000000..bf2bd08 --- /dev/null +++ b/msspecbook/material/Activity08/AlN.py @@ -0,0 +1,127 @@ +from ase.build import bulk +import numpy as np +from msspec.calculator import MSSPEC, XRaySource +from msspec.utils import hemispherical_cluster, get_atom_index + +def create_clusters(nplanes=6): + def get_AlN_tags_planes(side, emitter): + AlN = # AlN is a Wurtzite crystal with a=3.11 and c=4.975 angstroms # <= HERE + [atom.set('tag', i) for i, atom in enumerate(AlN)] + if side == 'Al': + AlN.rotate([0,0,1],[0,0,-1]) + Al_planes = range(0, nplanes, 2) + N_planes = range(1, nplanes, 2) + else: + N_planes = range(0, nplanes, 2) + Al_planes = range(1, nplanes, 2) + if emitter == 'Al': + tags = [0, 2] + planes = Al_planes + else: + tags = [1, 3] + planes = N_planes + return AlN, tags, planes + + clusters = [] + for side in ('Al', 'N'): + for emitter in ('Al', 'N'): + AlN, tags, planes = get_AlN_tags_planes(side, emitter) + for emitter_tag in tags: + for emitter_plane in planes: + cluster = # hemis…, construct the cluster here with # <= HERE + # 2 planes below the emitter + cluster.absorber = get_atom_index(cluster, 0, 0, 0) + cluster.info.update({ + 'emitter_plane': emitter_plane, + 'emitter_tag' : emitter_tag, + 'emitter' : emitter, + 'side' : side, + }) + clusters.append(cluster) + print("Added cluster {}-side, emitter {}(tag {:d}) in " + "plane #{:d}".format(side, emitter, emitter_tag, + emitter_plane)) + return clusters + + +def compute(clusters, theta=np.arange(-20., 80., 1.), phi=0.): + data = None + for ic, cluster in enumerate(clusters): + # Retrieve info from cluster object + side = cluster.info['side'] + emitter = cluster.info['emitter'] + plane = cluster.info['emitter_plane'] + tag = cluster.info['emitter_tag'] + + # Set the level and the kinetic energy + if emitter == 'Al': + level = ##### # <= HERE + ke = ##### # <= HERE + elif emitter == 'N': + level = ##### # <= HERE + ke = ##### # <= HERE + + calc = # Create a calculator using the RA series expansion algorithm # <= HERE + + calc.source_parameters.energy = ##### # <= HERE + calc.source_parameters.theta = ##### # <= HERE + + calc.detector_parameters.angular_acceptance = ##### # <= HERE + calc.detector_parameters.average_sampling = 'medium' + + calc.calculation_parameters.scattering_order = max(1, min(4, plane)) + calc.calculation_parameters.path_filtering = 'forward_scattering' + calc.calculation_parameters.off_cone_events = 1 + [a.set('forward_angle', 30.) for a in cluster] + + calc.set_atoms(cluster) + + data = calc.get_theta_scan(level=level, theta=theta, phi=phi, + kinetic_energy=ke, data=data) + dset = data[-1] + dset.title = "\'{}\' side - {}({}) tag #{:d}, plane #{:d}".format( + side, emitter, level, tag, plane) + + return data + + +def analysis(data): + tmp_data = {} + for dset in data: + info = dset.get_cluster().info + side = info['side'] + emitter = info['emitter'] + try: + key = '{}_{}'.format(side, emitter) + tmp_data[key] += dset.cross_section + except KeyError: + tmp_data[key] = dset.cross_section.copy() + + tmp_data['theta'] = dset.theta.copy() + tmp_data['Al_side'] = tmp_data['Al_Al'] / tmp_data['Al_N'] + tmp_data['N_side'] = tmp_data['N_Al'] / tmp_data['N_N'] + + # now add all columns + substrate_dset = data.add_dset('Total substrate signal') + substrate_dset.add_columns(**tmp_data) + + view = substrate_dset.add_view('Ratios', + title=r'Al(2p)/N(1s) ratios on both polar ' + r'sides of AlN in the (10$\bar{1}$0) ' + r'azimuthal plane', + xlabel=r'$\Theta (\degree$)', + ylabel='Intenisty ratio') + view.select('theta', 'Al_side', legend='Al side', + where="theta >= 0 and theta <=70") + view.select('theta', 'N_side', legend='N side', + where="theta >= 0 and theta <=70") + view.set_plot_options(autoscale=True) + + return data + + +clusters = create_clusters() +data = compute(clusters) +data = analysis(data) +data.view() + diff --git a/msspecbook/material/Activity09/COFe.py b/msspecbook/material/Activity09/COFe.py new file mode 100644 index 0000000..4d4b61e --- /dev/null +++ b/msspecbook/material/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/material/Activity09/experimental_data.txt b/msspecbook/material/Activity09/experimental_data.txt new file mode 100644 index 0000000..5745a71 --- /dev/null +++ b/msspecbook/material/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 diff --git a/msspecbook/material/Activity10/COFe_mp.py b/msspecbook/material/Activity10/COFe_mp.py new file mode 100644 index 0000000..d233450 --- /dev/null +++ b/msspecbook/material/Activity10/COFe_mp.py @@ -0,0 +1,96 @@ +from ase import Atoms +from ase.build import add_adsorbate, bulk + +from msspec.calculator import MSSPEC, RFACTOR +from msspec.utils import hemispherical_cluster +from msspec.looper import Sweep, Looper + +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, folder='calc'): + calc = MSSPEC(spectroscopy='PED', algorithm='expansion', folder=folder) + 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) + calc.shutdown() + + return data + + +############################################################################### +# Main part +############################################################################### +# 1) Multiprocess calculations +theta = Sweep(key='theta', comments="The molecule tilt angle", + start=50, stop=60, step=1, unit='degree') +phi = Sweep(key='phi', comments="The molecule azimuthal angle", + values=[0,45], unit='degree') + +def process(theta, phi, **kwargs): + cluster = create_cluster(theta=theta, phi=phi, height=0.6, bond_length=1.157) + i = kwargs.get('sweep_index') + data = compute_polar_scan(cluster, folder=f'calc_{i:d}') + dset = data[-1] + return dset.theta, dset.cross_section + +looper = Looper() +looper.pipeline = process +df = looper.run(theta, phi, ncpu=4) + +# Black magic to convert the pandas dataframe object 'df' to the +# parameters dict and the resulst list (will be easier in a future +# version ;-) ). +parameters = df.to_dict('list') +results = np.reshape(parameters.pop('output'), (df.shape[0]*2,-1)) + +# 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/material/Activity10/experimental_data.txt b/msspecbook/material/Activity10/experimental_data.txt new file mode 100644 index 0000000..5745a71 --- /dev/null +++ b/msspecbook/material/Activity10/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