#!/usr/bin/env python # coding: utf-8 # ## Find adsorption sites and structures on MgO # # The Adsorption Finder in `scm.structures.builder.adsorption` locates on-top, bridge, and hollow sites on the upper face of a periodic slab. It can then place an adsorbate using one or two selected binding atoms. # # This example analyzes an MgO slab and generates water adsorption structures in two modes: # # * one hydrogen atom binds to the surface; # * the oxygen and one hydrogen atom bind together. # # The finder creates starting structures; it does not optimize their geometries or rank their adsorption energies. from collections import Counter from scm import plams from scm.base import ChemicalSystem from scm.structures.builder.adsorption import ( AdsorptionFinderOptions, analyze_adsorption_sites, find_adsorption_structures, site_filter_label, ) # ## Build the MgO slab # # The slab is periodic in two dimensions. The Adsorption Finder identifies the upper face automatically from its geometry and lattice vectors. slab = ChemicalSystem( """System Atoms Mg 0.0 0.0 0.0 O 1.322017850211738e-15 1.322017850211738e-15 -2.104999999999995 Mg 1.488459774397683 1.488459774397683 -2.104999999999995 O 1.488459774397683 1.488459774397683 0.0 Mg 1.322017850211738e-15 0.0 -4.209999999999989 O 1.488459774397683 1.488459774397682 -4.209999999999989 Mg 3.645674996751427e-16 2.976919548795365 0.0 O 1.993152683986753e-16 2.976919548795365 -2.104999999999995 Mg 1.488459774397683 4.465379323193049 -2.104999999999995 O 1.488459774397683 4.465379323193049 0.0 Mg 1.983960700459199e-16 2.976919548795365 -4.209999999999989 O 1.488459774397683 4.465379323193048 -4.209999999999989 Mg 2.976919548795365 0.0 0.0 O 2.976919548795365 1.322017850211738e-15 -2.104999999999995 Mg 4.465379323193049 1.488459774397683 -2.104999999999995 O 4.465379323193049 1.488459774397683 0.0 Mg 2.976919548795365 0.0 -4.209999999999989 O 4.465379323193049 1.488459774397682 -4.209999999999989 Mg 2.976919548795364 2.976919548795365 0.0 O 2.976919548795364 2.976919548795365 -2.104999999999995 Mg 4.465379323193049 4.465379323193049 -2.104999999999995 O 4.465379323193049 4.465379323193049 0.0 Mg 2.976919548795364 2.976919548795365 -4.209999999999989 O 4.465379323193049 4.465379323193048 -4.209999999999989 End Lattice 5.95383909759073 0.0 0.0 0.0 5.95383909759073 0.0 End End""" ) plams.view(slab, direction="tilt_x", guess_bonds=True, picture_path="picture1.png") # ## Analyze and visualize adsorption sites # # The default options use SOAP descriptors to reduce symmetry-equivalent sites. The returned analysis includes each site's family, position, surface normal, and supporting substrate atoms. analysis_options = AdsorptionFinderOptions() analysis = analyze_adsorption_sites(slab, analysis_options) print(f"Raw sites: {analysis.raw_site_count}") print(f"Symmetry-reduced sites: {analysis.reduced_site_count}") print(f"Site families: {dict(Counter(site.family for site in analysis.sites))}") for site in analysis.sites: print(f"{site.site_index:2d}: {site_filter_label(site, slab)}") # For visualization, add virtual He atoms slightly above the detected coordinate and add it to a region. These markers are added only to a copy of the slab and are not used during structure generation. The three views make it easier to verify both the in-plane positions and the surface side on which the sites were found. for site in analysis.sites: marked_slab = slab.copy() marked_slab.guess_bonds() marker_position = site.position + 2.0 * site.normal marked_slab.add_atom("He", coords=marker_position) marked_slab.add_atom_to_region(len(marked_slab)-1, "highlight") title = site_filter_label(site, slab) site_images = { label: plams.view(marked_slab, direction=direction, width=350, height=280, show_regions=True) for label, direction in {f"top-view {title}": "along_z", f"side-view {title}": "tilt_x"}.items() } plams.plot_image_grid(site_images, rows=1, save_path="picture2.png"); # ## Select the binding atoms in water # # Binding indices are zero-based. Creating water from the SMILES string `O` gives oxygen index 0 and hydrogen indices 1 and 2. Printing the atoms makes the selection explicit and avoids relying on an assumed order for a different adsorbate. water = ChemicalSystem.from_smiles("O") for index, atom in enumerate(water.atoms): print(index, atom.symbol) plams.view(water, direction="along_pca3", guess_bonds=True, width=250, height=220, show_atom_labels=True, picture_path="picture3.png") # ## Generate structures with one H binding atom # # Set `binding_count=1` and select hydrogen index 1. Reusing `analysis` avoids repeating the surface-site calculation. Limiting the accepted candidates keeps this example compact. from rdkit import RDLogger RDLogger.DisableLog("rdApp.warning") h_options = AdsorptionFinderOptions( binding_count=1, binding_atom_indices=(1,), conformer_count=2, max_candidates=4, max_attempts=48, ) h_result = find_adsorption_structures( substrate=slab, adsorbate=water, options=h_options, analysis=analysis, ) h_structures = { f"{candidate.site_label}, candidate {index}": candidate.candidate_system for index, candidate in enumerate(h_result.accepted_candidates, start=1) } print(f"Accepted {len(h_structures)} of {len(h_result.attempts)} attempted placements") h_images = { label: plams.view(system, direction="tilt_x", guess_bonds=False, width=320, height=260) for label, system in h_structures.items() } plams.plot_image_grid(h_images, rows=2, save_path="picture4.png"); # ## Generate structures with O-H binding atoms # # For two-atom binding, use oxygen index 0 and hydrogen index 1. Two binding atoms require a site with at least two supporting surface atoms, so the accepted structures in this example use bridge sites. oh_options = AdsorptionFinderOptions( binding_count=2, binding_atom_indices=(0, 1), conformer_count=2, max_candidates=4, max_attempts=48, ) oh_result = find_adsorption_structures( substrate=slab, adsorbate=water, options=oh_options, analysis=analysis, ) oh_structures = { f"{candidate.site_label}, candidate {index}": candidate.candidate_system for index, candidate in enumerate(oh_result.accepted_candidates, start=1) } print(f"Accepted {len(oh_structures)} of {len(oh_result.attempts)} attempted placements") for label, system in oh_structures.items(): oh_images = { f"{label} ({direction})": plams.view(system, direction=direction, guess_bonds=False, width=360, height=280) for direction in ("along_z", "tilt_x") } plams.plot_image_grid(oh_images, rows=1, save_path="picture5.png");