Search Structures and Prepare Slabs With CatKit

Preparations

Import requests library for http request and define API endpoints

In [30]:
import requests
import pprint
import ase.io
import ase.visualize
try:# catch module change from Python2->3
    import io
except:
    import StringIO as io

API = 'http://api.catalysis-hub.org'
PROTOTYPE_ENDPOINT = API + '/apps/prototypeSearch/prototype/'
STRUCTURE_ENDPOINT = API + '/apps/prototypeSearch/get_structure/'
CATKIT_SLAB_ENDPOINT = API + '/apps/catKitDemo/generate_slab_cif/'
CATKIT_SITE_ENDPOINT = API + '/apps/catKitDemo/get_adsorption_sites'

Ok, we use the prototype search API to find us some Calcium Titanate structures that are Perovkites.

In [31]:
r = requests.post(PROTOTYPE_ENDPOINT, json={"prototype":"ABC3_1_a_b_c_221"}).json()
In [32]:
#print(r)
prototypes = r['prototypes']
#print(str(len(prototypes)) + ' Prototypes')

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.

In [33]:
for i, prototype in enumerate(prototypes):
    pprint.pprint(prototype)
    if i == 2:
        break
#pprint.pprint(r)    
{'density': 'None',
 'handle': 'AFLOWDATA-LIB3_RAW-OSbTi_sv-T0009.CBA:LDAU2-CONTCAR.relax.vasp',
 'n_atoms': '5',
 'n_parameters': '1',
 'n_permutations': '6',
 'n_species': '3',
 'n_wyckoffs': '3',
 'parameter_names': "['a']",
 'parameters': '[4.14820577933]',
 'permutations': 'None',
 'prototype': 'ABC3_1_a_b_c_221',
 'repository': 'AFLOW',
 'scarcity': '1.66672638678261',
 'spacegroup': '221',
 'species': "['O', 'Sb', 'Ti']",
 'stoichiometry': 'ABC3',
 'tags': '\n',
 'volume': 'None',
 'wyckoffs': "['c', 'b', 'a']"}
{'density': 'None',
 'handle': 'AFLOWDATA-LIB3_RAW-Cr_pvPSn-ICSD_53145.ABC-CONTCAR.relax.vasp',
 'n_atoms': '5',
 'n_parameters': '1',
 'n_permutations': '6',
 'n_species': '3',
 'n_wyckoffs': '3',
 'parameter_names': "['a']",
 'parameters': '[4.23589828301]',
 'permutations': 'None',
 'prototype': 'ABC3_1_a_b_c_221',
 'repository': 'AFLOW',
 'scarcity': '0.148512970405554',
 'spacegroup': '221',
 'species': "['Cr', 'P', 'Sn']",
 'stoichiometry': 'ABC3',
 'tags': '\n',
 'volume': 'None',
 'wyckoffs': "['c', 'b', 'a']"}
{'density': 'None',
 'handle': 'AFLOWDATA-LIB3_RAW-IrOPb_d-T0009.CAB:LDAU2-CONTCAR.relax.vasp',
 'n_atoms': '5',
 'n_parameters': '1',
 'n_permutations': '6',
 'n_species': '3',
 'n_wyckoffs': '3',
 'parameter_names': "['a']",
 'parameters': '[4.01311583981]',
 'permutations': 'None',
 'prototype': 'ABC3_1_a_b_c_221',
 'repository': 'AFLOW',
 'scarcity': '333.357143580209',
 'spacegroup': '221',
 'species': "['Ir', 'O', 'Pb']",
 'stoichiometry': 'ABC3',
 'tags': '\n',
 'volume': 'None',
 'wyckoffs': "['b', 'c', 'a']"}

For actually getting the structure we can use a different endpoint.

In [34]:
print(STRUCTURE_ENDPOINT)
for prototype in prototypes:
    structure_cif = requests.post(STRUCTURE_ENDPOINT, json=prototype)
    pprint.pprint(structure_cif)
    
    pprint.pprint(structure_cif.json()['structure'])
    break
http://api.catalysis-hub.org/apps/prototypeSearch/get_structure/
<Response [200]>
('data_image0\n'
 '_cell_length_a       4.14821\n'
 '_cell_length_b       4.14821\n'
 '_cell_length_c       4.14821\n'
 '_cell_angle_alpha    90\n'
 '_cell_angle_beta     90\n'
 '_cell_angle_gamma    90\n'
 '\n'
 '_symmetry_space_group_name_H-M    "P 1"\n'
 '_symmetry_int_tables_number       1\n'
 '\n'
 'loop_\n'
 '  _symmetry_equiv_pos_as_xyz\n'
 "  'x, y, z'\n"
 '\n'
 'loop_\n'
 '  _atom_site_label\n'
 '  _atom_site_occupancy\n'
 '  _atom_site_fract_x\n'
 '  _atom_site_fract_y\n'
 '  _atom_site_fract_z\n'
 '  _atom_site_thermal_displace_type\n'
 '  _atom_site_B_iso_or_equiv\n'
 '  _atom_site_type_symbol\n'
 '  O1       1.0000 0.00000  0.50000  0.50000  Biso   1.000  O\n'
 '  O2       1.0000 0.50000  0.00000  0.50000  Biso   1.000  O\n'
 '  O3       1.0000 0.50000  0.50000  0.00000  Biso   1.000  O\n'
 '  Sb1      1.0000 0.50000  0.50000  0.50000  Biso   1.000  Sb\n'
 '  Ti1      1.0000 0.00000  0.00000  0.00000  Biso   1.000  Ti\n')

Cut Slabs

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.

In [63]:
for prototype in prototypes:
    bulk_cif = requests.post(STRUCTURE_ENDPOINT, json=prototype).json()['structure']
    params = {
        "bulkParams": {
            "format":"vasp"
            
        },
        
        "slabParams":{
        "millerX": 1,
        "millerY": 1,
        "millerZ": 1,
        "layers": 12,
        "fixed": 6,
        "unitCellSize": 4,
        "vacuum":22,
        "format": "vasp",
       
    },
        "adsorbateParams":{
            "adsorbate":"S",
            "format":"vasp"
        },
    "bulk_cif": bulk_cif,
    }
    
    r = requests.post(CATKIT_SLAB_ENDPOINT, json=params).json()
    #pprint.pprint(r['input'])

    r = requests.post(CATKIT_SITE_ENDPOINT, json=params).json()
    #pprint.pprint(r)
    with io.StringIO() as tmp_file:
        tmp_file.write(r['inputImages'][6])
        tmp_file.seek(0)
        atoms = ase.io.read(tmp_file, format='vasp')
    break
In [64]:
ase.visualize.view(atoms * [3, 3, 1], viewer='ngl')