To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit b275cb13 authored by psd's avatar psd
Browse files

Exercise-10

parent 6f005725
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import itertools\n",
"import numpy as np\n",
"from numpy.linalg import norm\n",
"import spglib\n",
"from glob import glob\n",
"\n",
"from ase import Atoms\n",
"from ase.io import read\n",
"from ase.spacegroup import crystal\n",
"from ase.spacegroup import Spacegroup\n",
"from ase.data import atomic_numbers, atomic_names\n",
"import nglview"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Crystallographic point groups"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"14 P 21/c\n",
" setting 1\n",
" centrosymmetric 1\n",
" primitive vectors\n",
" 1.0000000000 0.0000000000 0.0000000000\n",
" 0.0000000000 1.0000000000 0.0000000000\n",
" 0.0000000000 0.0000000000 1.0000000000\n",
" reciprocal vectors\n",
" 1 0 0\n",
" 0 1 0\n",
" 0 0 1\n",
" 1 subtranslations\n",
" 0.0000000000 0.0000000000 0.0000000000\n",
" 2 symmetry operations (rot+trans)\n",
" 1 0 0 0 1 0 0 0 1 0.0000000000 0.0000000000 0.0000000000\n",
" -1 0 0 0 1 0 0 0 -1 0.0000000000 0.5000000000 0.5000000000\n",
"\n",
"\n"
]
}
],
"source": [
"a=5.117\n",
"b=5.175\n",
"c=5.291\n",
"alpha=90\n",
"beta=99.22\n",
"gamma=90\n",
"thespacegroup=14\n",
"print(Spacegroup(thespacegroup))\n",
"\n",
"hfo2 = crystal(symbols=['Hf','O','O'],\n",
" basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],\n",
" spacegroup=thespacegroup, \n",
" cellpar=[a, b, c, alpha, beta, gamma])\n",
"#hfo2.write('hfo2.xyz')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"bondatoms = []\n",
"symbols = hfo2.get_chemical_symbols()\n",
"for i in range(len(hfo2)):\n",
" for j in range(i):\n",
" if (symbols[i] == 'Hf' and symbols[j] == 'O' and hfo2.get_distance(i, j) < 2.6):\n",
" bondatoms.append((i, j))\n",
" elif (symbols[i] == 'O' and symbols[j] == 'Hf' and hfo2.get_distance(i, j) < 2.6):\n",
" bondatoms.append((i, j))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "173ee9fd9ff14be7a76bdd69a69afbe2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NGLWidget()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"nglview.show_ase(hfo2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Questions:\n",
"\n",
" -how many atoms are contained in the unit cell?\n",
" -compute the volume of the unit cell "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## "
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"def ase_to_spgcell(ase_atoms=None, cell=None, inverse=False):\n",
" if not inverse:\n",
" assert ase_atoms is not None\n",
" return (ase_atoms.get_cell(),\n",
" ase_atoms.get_scaled_positions(),\n",
" ase_atoms.get_atomic_numbers())\n",
" else:\n",
" assert cell is not None\n",
" return Atoms(cell=cell[0],\n",
" scaled_positions=cell[1],\n",
" numbers=cell[2])"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"def a_equiv_b(a,b):\n",
" \"\"\"Function that identifies whether two crystals are equivalent\"\"\"\n",
"\n",
" # getting symmetry datasets for both crystals\n",
" cryst_a = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=a), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)\n",
" cryst_b = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=b), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)\n",
"\n",
" samecell = np.allclose(cryst_a['std_lattice'], cryst_b['std_lattice'], atol=1e-5)\n",
" samenatoms = len(cryst_a['std_positions']) == len(cryst_b['std_positions'])\n",
" samespg = cryst_a['number'] == cryst_b['number']\n",
" \n",
" def test_rotations_translations(cryst_a, cryst_b, repeat):\n",
" cell = cryst_a['std_lattice']\n",
" pristine = crystal('Mg', [(0, 0., 0.)], \n",
" spacegroup=int(cryst_a['number']),\n",
" cellpar=[cell[0]/repeat[0], cell[1]/repeat[1], cell[2]/repeat[2]]).repeat(repeat)\n",
"\n",
" sym_set_p = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=pristine), symprec=1e-5,\n",
" angle_tolerance=-1.0, hall_number=0)\n",
"\n",
" for _,trans in enumerate(zip(sym_set_p['rotations'], sym_set_p['translations'])):\n",
" pnew=(np.matmul(trans[0],cryst_a['std_positions'].T).T + trans[1]) % 1.0\n",
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import itertools\n",
"import numpy as np\n",
"from numpy.linalg import norm\n",
"import spglib\n",
"from glob import glob\n",
"\n",
"from ase import Atoms\n",
"from ase.io import read\n",
"from ase.spacegroup import crystal\n",
"from ase.spacegroup import Spacegroup\n",
"from ase.data import atomic_numbers, atomic_names\n",
"import nglview"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Crystallographic point groups"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a=...\n",
"b=...\n",
"c=...\n",
"alpha=...\n",
"beta=...\n",
"gamma=...\n",
"thespacegroup=...\n",
"print Spacegroup(thespacegroup)\n",
"\n",
"hfo2 = crystal(['...','...','...'],basis=[(...,...,...),(...,...,...),(...,...,...)], \n",
" spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bondatoms = []\n",
"symbols = hfo2.get_chemical_symbols()\n",
"for i in range(len(hfo2)):\n",
" for j in range(i):\n",
" if (symbols[i] == 'Hf' and symbols[j] == 'O' and hfo2.get_distance(i, j) < 2.6):\n",
" bondatoms.append((i, j))\n",
" elif (symbols[i] == 'O' and symbols[j] == 'Hf' and hfo2.get_distance(i, j) < 2.6):\n",
" bondatoms.append((i, j))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Questions:\n",
"\n",
" -how many atoms are contained in the unit cell?\n",
" -compute the volume of the unit cell "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def ase_to_spgcell(ase_atoms=None, cell=None, inverse=False):\n",
" if not inverse:\n",
" assert ase_atoms is not None\n",
" return (ase_atoms.get_cell(),\n",
" ase_atoms.get_scaled_positions(),\n",
" ase_atoms.get_atomic_numbers())\n",
" else:\n",
" assert cell is not None\n",
" return Atoms(cell=cell[0],\n",
" scaled_positions=cell[1],\n",
" numbers=cell[2])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def a_equiv_b(a,b):\n",
" \"\"\"Function that identifies whether two crystals are equivalent\"\"\"\n",
"\n",
" # getting symmetry datasets for both crystals\n",
" cryst_a = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=a), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)\n",
" cryst_b = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=b), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)\n",
"\n",
" samecell = np.allclose(cryst_a['std_lattice'], cryst_b['std_lattice'], atol=1e-5)\n",
" samenatoms = len(cryst_a['std_positions']) == len(cryst_b['std_positions'])\n",
" samespg = cryst_a['number'] == cryst_b['number']\n",
" \n",
" def test_rotations_translations(cryst_a, cryst_b, repeat):\n",
" cell = cryst_a['std_lattice']\n",
" pristine = crystal('Mg', [(0, 0., 0.)], \n",
" spacegroup=int(cryst_a['number']),\n",
" cellpar=[cell[0]/repeat[0], cell[1]/repeat[1], cell[2]/repeat[2]]).repeat(repeat)\n",
"\n",
" sym_set_p = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=pristine), symprec=1e-5,\n",
" angle_tolerance=-1.0, hall_number=0)\n",
"\n",
" for _,trans in enumerate(zip(sym_set_p['rotations'], sym_set_p['translations'])):\n",
" pnew=(np.matmul(trans[0],cryst_a['std_positions'].T).T + trans[1]) % 1.0\n",
" fulln = np.concatenate([cryst_a['std_types'][:, None], pnew], axis=1)\n",
" fullb = np.concatenate([cryst_b['std_types'][:, None], cryst_b['std_positions']], axis=1)\n",
" sorted_n = np.array(sorted([ list(row) for row in list(fulln) ]))\n",
" sorted_b = np.array(sorted([ list(row) for row in list(fullb) ]))\n",
" if np.allclose(sorted_n, sorted_b, atol=1e-5):\n",
" return True\n",
" return False\n",
"\n",
" if samecell and samenatoms and samespg:\n",
" cell = cryst_a['std_lattice']\n",
" rng1 = range(1, int(norm(cell[0])/2.))\n",
" rng2 = range(1, int(norm(cell[1])/2.))\n",
" rng3 = range(1, int(norm(cell[2])/2.))\n",
"\n",
" for repeat in itertools.product(rng1, rng2, rng3):\n",
" if test_rotations_translations(cryst_a, cryst_b, repeat):\n",
" return True\n",
"\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"atoms = read('./quartz_alpha.xyz')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
%% Cell type:code id: tags:
``` python
import itertools
import numpy as np
from numpy.linalg import norm
import spglib
from glob import glob
from ase import Atoms
from ase.io import read
from ase.spacegroup import crystal
from ase.spacegroup import Spacegroup
from ase.data import atomic_numbers, atomic_names
import nglview
```
%% Cell type:markdown id: tags:
## Crystallographic point groups
%% Cell type:code id: tags:
``` python
a=...
b=...
c=...
alpha=...
beta=...
gamma=...
thespacegroup=...
print(Spacegroup(thespacegroup))
hfo2 = crystal(['...','...','...'],basis=[(...,...,...),(...,...,...),(...,...,...)],
spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])
```
%% Cell type:code id: tags:
``` python
bondatoms = []
symbols = hfo2.get_chemical_symbols()
for i in range(len(hfo2)):
for j in range(i):
if (symbols[i] == 'Hf' and symbols[j] == 'O' and hfo2.get_distance(i, j) < 2.6):
bondatoms.append((i, j))
elif (symbols[i] == 'O' and symbols[j] == 'Hf' and hfo2.get_distance(i, j) < 2.6):
bondatoms.append((i, j))
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(hfo2)
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
Questions:
-how many atoms are contained in the unit cell?
-compute the volume of the unit cell
%% Cell type:markdown id: tags:
##
%% Cell type:code id: tags:
``` python
def ase_to_spgcell(ase_atoms=None, cell=None, inverse=False):
if not inverse:
assert ase_atoms is not None
return (ase_atoms.get_cell(),
ase_atoms.get_scaled_positions(),
ase_atoms.get_atomic_numbers())
else:
assert cell is not None
return Atoms(cell=cell[0],
scaled_positions=cell[1],
numbers=cell[2])
```
%% Cell type:code id: tags:
``` python
def a_equiv_b(a,b):
"""Function that identifies whether two crystals are equivalent"""
# getting symmetry datasets for both crystals
cryst_a = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=a), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)
cryst_b = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=b), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)
samecell = np.allclose(cryst_a['std_lattice'], cryst_b['std_lattice'], atol=1e-5)
samenatoms = len(cryst_a['std_positions']) == len(cryst_b['std_positions'])
samespg = cryst_a['number'] == cryst_b['number']
def test_rotations_translations(cryst_a, cryst_b, repeat):
cell = cryst_a['std_lattice']
pristine = crystal('Mg', [(0, 0., 0.)],
spacegroup=int(cryst_a['number']),
cellpar=[cell[0]/repeat[0], cell[1]/repeat[1], cell[2]/repeat[2]]).repeat(repeat)
sym_set_p = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=pristine), symprec=1e-5,
angle_tolerance=-1.0, hall_number=0)
for _,trans in enumerate(zip(sym_set_p['rotations'], sym_set_p['translations'])):
pnew=(np.matmul(trans[0],cryst_a['std_positions'].T).T + trans[1]) % 1.0
fulln = np.concatenate([cryst_a['std_types'][:, None], pnew], axis=1)
fullb = np.concatenate([cryst_b['std_types'][:, None], cryst_b['std_positions']], axis=1)
sorted_n = np.array(sorted([ list(row) for row in list(fulln) ]))
sorted_b = np.array(sorted([ list(row) for row in list(fullb) ]))
if np.allclose(sorted_n, sorted_b, atol=1e-5):
return True
return False
if samecell and samenatoms and samespg:
cell = cryst_a['std_lattice']
rng1 = range(1, int(norm(cell[0])/2.))
rng2 = range(1, int(norm(cell[1])/2.))
rng3 = range(1, int(norm(cell[2])/2.))
for repeat in itertools.product(rng1, rng2, rng3):
if test_rotations_translations(cryst_a, cryst_b, repeat):
return True
return False
```
%% Cell type:markdown id: tags:
## Task 1
%% Cell type:code id: tags:
``` python
atoms = read('./quartz_alpha.xyz')
nglview.show_ase(atoms)
```
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
'''
..TO DO..
'''
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(reduced)
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
## Task 2
%% Cell type:code id: tags:
``` python
'''
..TO DO..
'''
```
12
Lattice="5.117 0.0 0.0 0.0 5.175 0.0 -0.8477544617904331 0.0 5.222642374556621" Properties=species:S:1:pos:R:3:tags:I:1 spacegroup="P 21/c" unit_cell=conventional pbc="T T T"
Hf 1.23595907 0.20700000 1.08630961 0
Hf 3.45716370 2.79450000 1.52501157 0
Hf 3.03328647 4.96800000 4.13633276 0
Hf 0.81208184 2.38050000 3.69763080 0
O 0.08448720 1.71810000 1.81225690 1
O 4.60863557 4.30560000 0.79906428 1
O 4.18475834 3.45690000 3.41038547 1
O -0.33939003 0.86940000 4.42357809 1
O 1.89061086 3.92265000 2.50686834 2
O 2.80251191 1.33515000 0.10445285 2
O 2.37863468 1.25235000 2.71577403 2
O 1.46673363 3.83985000 5.11818953 2
144
Lattice="9.81999180292937 -1.57917512379296e-15 0.0 0.0 17.0087247325836 0.0 0.0 0.0 10.804" Properties=species:S:1:pos:R:3 pbc="T T T"
O 1.38650516 1.12431739 0.62933000
O 3.84150311 5.37649857 0.62933000
O 0.78805795 4.89077118 4.23066333
O 3.24305590 0.63859000 4.23066333
O 0.28043484 6.74145498 2.42999667
O 2.73543279 2.48927380 2.42999667
O 1.38650516 7.38004498 4.77267000
O 3.84150311 3.12786380 4.77267000
O 0.78805795 3.61359118 1.17133667
O 3.24305590 7.86577237 1.17133667
O 0.28043484 1.76290739 2.97200333
O 2.73543279 6.01508857 2.97200333
Si 2.36063135 -0.00000000 0.00000000
Si 4.81562931 4.25218118 0.00000000
Si 1.27468227 6.29654791 3.60133333
Si 3.72968022 2.04436672 3.60133333
Si 1.27468227 2.20781446 1.80066667
Si 3.72968022 6.45999564 1.80066667
O 6.29650106 1.12431739 0.62933000
O 8.75149901 5.37649857 0.62933000
O 5.69805385 4.89077118 4.23066333
O 8.15305180 0.63859000 4.23066333
O 5.19043074 6.74145498 2.42999667
O 7.64542869 2.48927380 2.42999667
O 6.29650106 7.38004498 4.77267000
O 8.75149901 3.12786380 4.77267000
O 5.69805385 3.61359118 1.17133667
O 8.15305180 7.86577237 1.17133667
O 5.19043074 1.76290739 2.97200333
O 7.64542869 6.01508857 2.97200333
Si 7.27062726 -0.00000000 0.00000000
Si 9.72562521 4.25218118 0.00000000
Si 6.18467817 6.29654791 3.60133333
Si 8.63967613 2.04436672 3.60133333
Si 6.18467817 2.20781446 1.80066667
Si 8.63967613 6.45999564 1.80066667
O 1.38650516 9.62867975 0.62933000
O 3.84150311 13.88086094 0.62933000
O 0.78805795 13.39513355 4.23066333
O 3.24305590 9.14295237 4.23066333
O 0.28043484 15.24581735 2.42999667
O 2.73543279 10.99363616 2.42999667
O 1.38650516 15.88440735 4.77267000
O 3.84150311 11.63222616 4.77267000
O 0.78805795 12.11795355 1.17133667
O 3.24305590 16.37013473 1.17133667
O 0.28043484 10.26726975 2.97200333
O 2.73543279 14.51945094 2.97200333
Si 2.36063135 8.50436237 0.00000000
Si 4.81562931 12.75654355 0.00000000
Si 1.27468227 14.80091027 3.60133333
Si 3.72968022 10.54872909 3.60133333
Si 1.27468227 10.71217683 1.80066667
Si 3.72968022 14.96435801 1.80066667
O 6.29650106 9.62867975 0.62933000
O 8.75149901 13.88086094 0.62933000
O 5.69805385 13.39513355 4.23066333
O 8.15305180 9.14295237 4.23066333
O 5.19043074 15.24581735 2.42999667
O 7.64542869 10.99363616 2.42999667
O 6.29650106 15.88440735 4.77267000
O 8.75149901 11.63222616 4.77267000