Commit 7389f941 authored by spiasko's avatar spiasko
Browse files

ex11 gelöst

parent f88897db
%% 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=5.117
b=5.175
c=5.291
alpha=90
beta=99.22
gamma=90
thespacegroup=14
thespacegroup='P 21/c'
print(Spacegroup(thespacegroup))
hfo2 = crystal(symbols=['Hf','O','O'],
basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],
spacegroup=thespacegroup,
cellpar=[a, b, c, alpha, beta, gamma])
#hfo2.write('hfo2.xyz')
hfo2 = crystal(['Hf','O','O'],basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],
spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])
```
%%%% Output: stream
14 P 21/c
setting 1
centrosymmetric 1
primitive vectors
1.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000
reciprocal vectors
1 0 0
0 1 0
0 0 1
1 subtranslations
0.0000000000 0.0000000000 0.0000000000
2 symmetry operations (rot+trans)
1 0 0 0 1 0 0 0 1 0.0000000000 0.0000000000 0.0000000000
-1 0 0 0 1 0 0 0 -1 0.0000000000 0.5000000000 0.5000000000
%% 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
cell = ase_to_spgcell(ase_atoms=atoms)
lattice, scaled_positions, numbers = spglib.find_primitive(cell, symprec=1e-5)
reduced = ase_to_spgcell(cell=(lattice, scaled_positions, numbers),inverse=True)
'''
..TO DO..
'''
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(reduced)
```
%%%% Output: display_data
%%%% Output: error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-10-e82cf4dbf780> in <module>
----> 1 nglview.show_ase(reduced)
NameError: name 'reduced' is not defined
%% Cell type:markdown id: tags:
## Task 2
%% Cell type:code id: tags:
``` python
versions = [read(atoms) for atoms in glob('./quartz_alpha*')]
'''
..TO DO..
for outer in range(len(versions)-1):
for inner in range(outer+1,len(versions)):
print('Comparing: ',outer,inner)
print('Equivalent: ',a_equiv_b(versions[outer],versions[inner]))
'''
```
......
%% 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=...
a=5.117
b=5.175
c=5.291
alpha=90
beta=99.22
gamma=90
thespacegroup='P 21/c'
print(Spacegroup(thespacegroup))
hfo2 = crystal(['...','...','...'],basis=[(...,...,...),(...,...,...),(...,...,...)],
hfo2 = crystal(['Hf','O','O'],basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],
spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])
```
%%%% Output: stream
14 P 21/c
setting 1
centrosymmetric 1
primitive vectors
1.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000
reciprocal vectors
1 0 0
0 1 0
0 0 1
1 subtranslations
0.0000000000 0.0000000000 0.0000000000
2 symmetry operations (rot+trans)
1 0 0 0 1 0 0 0 1 0.0000000000 0.0000000000 0.0000000000
-1 0 0 0 1 0 0 0 -1 0.0000000000 0.5000000000 0.5000000000
%% 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
%%%% Output: error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-10-e82cf4dbf780> in <module>
----> 1 nglview.show_ase(reduced)
NameError: name 'reduced' is not defined
%% Cell type:markdown id: tags:
## Task 2
%% Cell type:code id: tags:
``` python
'''
..TO DO..
'''
```
......
This diff is collapsed.
This diff is collapsed.
&control
verbosity='high'
calculation='scf'
restart_mode='from_scratch'
prefix='SI'
pseudo_dir = './',
outdir='./'
wf_collect=.true.
/
&system
ibrav=1
celldm(1)=10.26121694631474912930
nat=8,
ntyp=1,
ecutwfc = 30,
occupations='smearing',
degauss=0.001
/
&electrons
conv_thr = 1.0e-8
mixing_beta = 0.5
/
&ions
/
ATOMIC_SPECIES
Si 28.086 Si.pbe-mt_fhi.UPF
ATOMIC_POSITIONS crystal
Si 0.000000 0.000000 0.000000
Si 0.000000 0.500000 0.500000
Si 0.500000 0.000000 0.500000
Si 0.500000 0.500000 0.000000
Si 0.750000 0.250000 0.750000
Si 0.250000 0.250000 0.250000
Si 0.250000 0.750000 0.750000
Si 0.750000 0.750000 0.250000
K_POINTS automatic
1 1 1 0 0 0
This diff is collapsed.
#!/bin/bash --login
#SBATCH --job-name="TASK_0"
#SBATCH --nodes=1 # the number of ranks (total)
#SBATCH --ntasks-per-node=12 # the number of ranks per node
##SBATCH --ntasks-per-core=1 # enable this if you want hyperthreading
#SBATCH --cpus-per-task=1 # use this for threaded applications
#SBATCH --time=00:10:00
#SBATCH --constraint=gpu
#SBATCH --account=YOUR_ACCOUNT
##SBATCH --partition=normal
#SBATCH --output="c1"
module load daint-gpu
export CRAY_CUDA_MPS=1
module load QuantumESPRESSO/6.3-CrayIntel-18.08
#======START=====
a=5.43
alat=`echo "${a} / 0.529177" | bc -l`
cat >pw.in << EOF
&control
verbosity='high'
calculation='scf'
restart_mode='from_scratch'
prefix='SI'
pseudo_dir = './',
outdir='./'
wf_collect=.true.
/
&system
ibrav=1
celldm(1)=${alat}
nat=8,
ntyp=1,
ecutwfc = 30,
occupations='smearing',
degauss=0.001
/
&electrons
conv_thr = 1.0e-8
mixing_beta = 0.5
/
&ions
/
ATOMIC_SPECIES
Si 28.086 Si.pbe-mt_fhi.UPF
ATOMIC_POSITIONS crystal
Si 0.000000 0.000000 0.000000
Si 0.000000 0.500000 0.500000
Si 0.500000 0.000000 0.500000
Si 0.500000 0.500000 0.000000
Si 0.750000 0.250000 0.750000
Si 0.250000 0.250000 0.250000
Si 0.250000 0.750000 0.750000
Si 0.750000 0.750000 0.250000
K_POINTS automatic
1 1 1 0 0 0
EOF
srun -n $SLURM_NTASKS --ntasks-per-node=$SLURM_NTASKS_PER_NODE -c $SLURM_CPUS_PER_TASK --cpu_bind=rank --hint=nomultithread pw.x <pw.in > si.out
This diff is collapsed.
&control
verbosity='high'
calculation='scf'
restart_mode='from_scratch'
prefix='SI'
pseudo_dir = './',
outdir='./'
wf_collect=.true.
/
&system
ibrav=1
celldm(1)=10.26121694631474912930
nat=8,
ntyp=1,
ecutwfc = 30,
occupations='smearing',
degauss=0.001
/
&electrons
conv_thr = 1.0e-8
mixing_beta = 0.5
/
&ions
/
ATOMIC_SPECIES
Si 28.086 Si.pbe-mt_fhi.UPF
ATOMIC_POSITIONS crystal
Si 0.000000 0.000000 0.000000
Si 0.000000 0.500000 0.500000
Si 0.500000 0.000000 0.500000
Si 0.500000 0.500000 0.000000
Si 0.750000 0.250000 0.750000
Si 0.250000 0.250000 0.250000
Si 0.250000 0.750000 0.750000
Si 0.750000 0.750000 0.250000
K_POINTS automatic
2 2 2 0 0 0
This diff is collapsed.
#!/bin/bash --login
#SBATCH --job-name="TASK_0b"
#SBATCH --nodes=1 # the number of ranks (total)
#SBATCH --ntasks-per-node=12 # the number of ranks per node