Skip to content

Instantly share code, notes, and snippets.

@mhoffman
Created July 10, 2018 22:36
Show Gist options
  • Save mhoffman/c483dece941930fbb785f019893a1c15 to your computer and use it in GitHub Desktop.
Save mhoffman/c483dece941930fbb785f019893a1c15 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## How to Obtain a Prototype Name for an Arbitrary Bulk Structure"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Some house-keeping"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import ase.build\n",
"import ase.io\n",
"import requests\n",
"import json\n",
"import pprint\n",
"try:\n",
" import io\n",
"except ImportError:\n",
" import StringIO as io\n",
"WYCKOFF_URL = 'https://api.catalysis-hub.org/apps/bulkEnumerator/get_wyckoff_from_structure'\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Generate a Bulk Structure"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First we just create a simple bulk structure, in this case Pd face-centered cubic."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"bulk = ase.build.bulk('Pd', 'fcc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we write the bulk structure into a temporary file in memory in CIF format which is understood by the API. We send the file to the backend. The filename `a.cif` is a dummy name, but necessary to signal that the provided input format is cif. If our file is in a different format, we could state this here as well."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"with io.StringIO() as cif_file:\n",
" ase.io.write(cif_file, bulk, format='cif')\n",
" response = requests.post(WYCKOFF_URL, files={'file': ('a.cif', cif_file.getvalue())})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now extract the requested information about spacegroup, wyckoff sites from the return JSON payload."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'cif': 'data_image0\\n'\n",
" '_cell_length_a 3.89001\\n'\n",
" '_cell_length_b 3.89001\\n'\n",
" '_cell_length_c 3.89001\\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",
" ' Pd1 1.0000 0.00000 0.00000 0.00000 Biso 1.000 Pd\\n'\n",
" ' Pd2 1.0000 0.00000 0.50000 0.50000 Biso 1.000 Pd\\n'\n",
" ' Pd3 1.0000 0.50000 0.00000 0.50000 Biso 1.000 Pd\\n'\n",
" ' Pd4 1.0000 0.50000 0.50000 0.00000 Biso 1.000 Pd\\n',\n",
" 'name': \"b'A_a_225'\",\n",
" 'parameter_values': [{'name': \"b'a'\", 'value': 3.8900065353415534}],\n",
" 'poscar': 'Auto-generated \\n'\n",
" '1.0\\n'\n",
" '3.89001\\t0\\t0\\t\\n'\n",
" '0\\t3.89001\\t0\\t\\n'\n",
" '0\\t0\\t3.89001\\t\\n'\n",
" 'Pd\\t\\n'\n",
" '4\\t\\n'\n",
" 'Direct\\n'\n",
" '0 0 0 \\n'\n",
" '0 0.5 0.5 \\n'\n",
" '0.5 0 0.5 \\n'\n",
" '0.5 0.5 0 \\n',\n",
" 'runtime': 0.035282135009765625,\n",
" 'spacegroup': 225,\n",
" 'species': [\"b'Pd'\"],\n",
" 'species_permutations': [\"b'Pd'\"],\n",
" 'wyckoff': [\"b'a'\"],\n",
" 'wyckoff_list': [{'if_repeatable': 1, 'multiplicity': 192, 'symbol': \"b'l'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 96, 'symbol': \"b'k'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 96, 'symbol': \"b'j'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 48, 'symbol': \"b'i'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 48, 'symbol': \"b'h'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 48, 'symbol': \"b'g'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 32, 'symbol': \"b'f'\"},\n",
" {'if_repeatable': 1, 'multiplicity': 24, 'symbol': \"b'e'\"},\n",
" {'if_repeatable': -1, 'multiplicity': 24, 'symbol': \"b'd'\"},\n",
" {'if_repeatable': -1, 'multiplicity': 8, 'symbol': \"b'c'\"},\n",
" {'if_repeatable': -1, 'multiplicity': 4, 'symbol': \"b'b'\"},\n",
" {'if_repeatable': -1, 'multiplicity': 4, 'symbol': \"b'a'\"}]}\n"
]
}
],
"source": [
"pprint.pprint(response.json())"
]
},
{
"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