Skip to content

Instantly share code, notes, and snippets.

@mhoffman
Created June 13, 2018 00:35
Show Gist options
  • Save mhoffman/e0e9edf6771c3c0c5838043a022e0857 to your computer and use it in GitHub Desktop.
Save mhoffman/e0e9edf6771c3c0c5838043a022e0857 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Search Structures and Prepare Slabs With CatKit"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Preparations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import `requests` library for http request and define API endpoints"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import pprint\n",
"import ase.io\n",
"import ase.visualize\n",
"try:# catch module change from Python2->3\n",
" import io\n",
"except:\n",
" import StringIO as io\n",
"\n",
"API = 'http://api.catalysis-hub.org'\n",
"PROTOTYPE_ENDPOINT = API + '/apps/prototypeSearch/prototype/'\n",
"STRUCTURE_ENDPOINT = API + '/apps/prototypeSearch/get_structure/'\n",
"CATKIT_SLAB_ENDPOINT = API + '/apps/catKitDemo/generate_slab_cif/'\n",
"CATKIT_SITE_ENDPOINT = API + '/apps/catKitDemo/get_adsorption_sites'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Search"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok, we use the prototype search API to find us some Calcium Titanate structures that are Perovkites."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"r = requests.post(PROTOTYPE_ENDPOINT, json={\"prototype\":\"ABC3_1_a_b_c_221\"}).json()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"#print(r)\n",
"prototypes = r['prototypes']\n",
"#print(str(len(prototypes)) + ' Prototypes')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's just print one prototype to 'see' what it looks like. It will tell use where the prototype came from (repository and handle) and gives us all parameters (Spacegroup, Wyckoff Sites, and parameters), needed to create the structure but not the actual structure."
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'density': 'None',\n",
" 'handle': 'AFLOWDATA-LIB3_RAW-OSbTi_sv-T0009.CBA:LDAU2-CONTCAR.relax.vasp',\n",
" 'n_atoms': '5',\n",
" 'n_parameters': '1',\n",
" 'n_permutations': '6',\n",
" 'n_species': '3',\n",
" 'n_wyckoffs': '3',\n",
" 'parameter_names': \"['a']\",\n",
" 'parameters': '[4.14820577933]',\n",
" 'permutations': 'None',\n",
" 'prototype': 'ABC3_1_a_b_c_221',\n",
" 'repository': 'AFLOW',\n",
" 'scarcity': '1.66672638678261',\n",
" 'spacegroup': '221',\n",
" 'species': \"['O', 'Sb', 'Ti']\",\n",
" 'stoichiometry': 'ABC3',\n",
" 'tags': '\\n',\n",
" 'volume': 'None',\n",
" 'wyckoffs': \"['c', 'b', 'a']\"}\n",
"{'density': 'None',\n",
" 'handle': 'AFLOWDATA-LIB3_RAW-Cr_pvPSn-ICSD_53145.ABC-CONTCAR.relax.vasp',\n",
" 'n_atoms': '5',\n",
" 'n_parameters': '1',\n",
" 'n_permutations': '6',\n",
" 'n_species': '3',\n",
" 'n_wyckoffs': '3',\n",
" 'parameter_names': \"['a']\",\n",
" 'parameters': '[4.23589828301]',\n",
" 'permutations': 'None',\n",
" 'prototype': 'ABC3_1_a_b_c_221',\n",
" 'repository': 'AFLOW',\n",
" 'scarcity': '0.148512970405554',\n",
" 'spacegroup': '221',\n",
" 'species': \"['Cr', 'P', 'Sn']\",\n",
" 'stoichiometry': 'ABC3',\n",
" 'tags': '\\n',\n",
" 'volume': 'None',\n",
" 'wyckoffs': \"['c', 'b', 'a']\"}\n",
"{'density': 'None',\n",
" 'handle': 'AFLOWDATA-LIB3_RAW-IrOPb_d-T0009.CAB:LDAU2-CONTCAR.relax.vasp',\n",
" 'n_atoms': '5',\n",
" 'n_parameters': '1',\n",
" 'n_permutations': '6',\n",
" 'n_species': '3',\n",
" 'n_wyckoffs': '3',\n",
" 'parameter_names': \"['a']\",\n",
" 'parameters': '[4.01311583981]',\n",
" 'permutations': 'None',\n",
" 'prototype': 'ABC3_1_a_b_c_221',\n",
" 'repository': 'AFLOW',\n",
" 'scarcity': '333.357143580209',\n",
" 'spacegroup': '221',\n",
" 'species': \"['Ir', 'O', 'Pb']\",\n",
" 'stoichiometry': 'ABC3',\n",
" 'tags': '\\n',\n",
" 'volume': 'None',\n",
" 'wyckoffs': \"['b', 'c', 'a']\"}\n"
]
}
],
"source": [
"for i, prototype in enumerate(prototypes):\n",
" pprint.pprint(prototype)\n",
" if i == 2:\n",
" break\n",
"#pprint.pprint(r) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For actually getting the structure we can use a different endpoint."
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"http://api.catalysis-hub.org/apps/prototypeSearch/get_structure/\n",
"<Response [200]>\n",
"('data_image0\\n'\n",
" '_cell_length_a 4.14821\\n'\n",
" '_cell_length_b 4.14821\\n'\n",
" '_cell_length_c 4.14821\\n'\n",
" '_cell_angle_alpha 90\\n'\n",
" '_cell_angle_beta 90\\n'\n",
" '_cell_angle_gamma 90\\n'\n",
" '\\n'\n",
" '_symmetry_space_group_name_H-M \"P 1\"\\n'\n",
" '_symmetry_int_tables_number 1\\n'\n",
" '\\n'\n",
" 'loop_\\n'\n",
" ' _symmetry_equiv_pos_as_xyz\\n'\n",
" \" 'x, y, z'\\n\"\n",
" '\\n'\n",
" 'loop_\\n'\n",
" ' _atom_site_label\\n'\n",
" ' _atom_site_occupancy\\n'\n",
" ' _atom_site_fract_x\\n'\n",
" ' _atom_site_fract_y\\n'\n",
" ' _atom_site_fract_z\\n'\n",
" ' _atom_site_thermal_displace_type\\n'\n",
" ' _atom_site_B_iso_or_equiv\\n'\n",
" ' _atom_site_type_symbol\\n'\n",
" ' O1 1.0000 0.00000 0.50000 0.50000 Biso 1.000 O\\n'\n",
" ' O2 1.0000 0.50000 0.00000 0.50000 Biso 1.000 O\\n'\n",
" ' O3 1.0000 0.50000 0.50000 0.00000 Biso 1.000 O\\n'\n",
" ' Sb1 1.0000 0.50000 0.50000 0.50000 Biso 1.000 Sb\\n'\n",
" ' Ti1 1.0000 0.00000 0.00000 0.00000 Biso 1.000 Ti\\n')\n"
]
}
],
"source": [
"print(STRUCTURE_ENDPOINT)\n",
"for prototype in prototypes:\n",
" structure_cif = requests.post(STRUCTURE_ENDPOINT, json=prototype)\n",
" pprint.pprint(structure_cif)\n",
" \n",
" pprint.pprint(structure_cif.json()['structure'])\n",
" break"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Cut Slabs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So we have a structure. Would be nice if we could use the CatKit API to cut some slabs from it and place adsorbates on it."
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"for prototype in prototypes:\n",
" bulk_cif = requests.post(STRUCTURE_ENDPOINT, json=prototype).json()['structure']\n",
" params = {\n",
" \"bulkParams\": {\n",
" \"format\":\"vasp\"\n",
" \n",
" },\n",
" \n",
" \"slabParams\":{\n",
" \"millerX\": 1,\n",
" \"millerY\": 1,\n",
" \"millerZ\": 1,\n",
" \"layers\": 12,\n",
" \"fixed\": 6,\n",
" \"unitCellSize\": 4,\n",
" \"vacuum\":22,\n",
" \"format\": \"vasp\",\n",
" \n",
" },\n",
" \"adsorbateParams\":{\n",
" \"adsorbate\":\"S\",\n",
" \"format\":\"vasp\"\n",
" },\n",
" \"bulk_cif\": bulk_cif,\n",
" }\n",
" \n",
" r = requests.post(CATKIT_SLAB_ENDPOINT, json=params).json()\n",
" #pprint.pprint(r['input'])\n",
"\n",
" r = requests.post(CATKIT_SITE_ENDPOINT, json=params).json()\n",
" #pprint.pprint(r)\n",
" with io.StringIO() as tmp_file:\n",
" tmp_file.write(r['inputImages'][6])\n",
" tmp_file.seek(0)\n",
" atoms = ase.io.read(tmp_file, format='vasp')\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "43c1b1a3dcfc436283bc2f5f1b2f3d07",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(NGLWidget(), VBox(children=(Dropdown(description='Show', options=('All', 'Ti', 'O', 'Sb', 'S'),…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"ase.visualize.view(atoms * [3, 3, 1], viewer='ngl')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment