forked from mbkumar/defect_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vac_analysis_1.py
89 lines (77 loc) · 2.81 KB
/
vac_analysis_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import os
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from pymatgen.io.cifio import CifParser
from pymatgen.core.structure import Structure
from pymatgen.io.cifio import CifParser
from pymatgen.defects.point_defects import Vacancy
import pymatgen.defects.point_defects
struct_dir = 'Binary oxide dataset/20130524/comp_structures'
filelist = os.listdir(struct_dir)
for filen in filelist:
if os.path.splitext(filen)[1] != '.cif':
filelist.remove(filen)
for filen in filelist:
if os.path.splitext(filen)[1] != '.cif':
filelist.remove(filen)
# Use the number as struct identifier
# Store the remaining string as formula
struct_descript_dict = {}
for filen in filelist[0:20]:
name = os.path.splitext(filen)[0]
item = name.split('--')
key = item[0]
struct_descript_dict[key] = {'formula':''.join(item[1].split())}
#print item
#read the file to pymatgen struct
filename = os.path.join(struct_dir,filen)
try:
struct = CifParser(filename).get_structures()[0]
except:
print filename
del struct_descript_dict[key]
continue
try:
vac = Vacancy(struct)
except:
print struct_descript_dict[key]['formula']
del struct_descript_dict[key]
continue
no_vac = vac.defectsite_count()
#print no_vac
# add number of vacancies to descriptor
struct_descript_dict[key]['no_vac'] = no_vac
#Create a list storing a dictionary of vacancy properties for each vacancy
vacancy_list = []
valences = vac.valences.values()
valences.sort()
#print valences
try:
anion_cation_charge_ratio = abs(valences[-1]/valences[0])
except: #BVAnalyzer fails sometimes and valences are set to 0
print struct_descript_dict[key]['formula']
print valences
anion_cation_charge_ratio = 0
radii = vac.ionic_radii.values()
radii.sort()
try:
anion_cation_radii_ratio = radii[-1]/radii[0]
except:
#print radii
anion_cation_radii_ratio = 0
for i in range(no_vac):
vac_prop_dict = {}
vac_prop_dict['coordination_no'] = vac.get_defectsite_coordination_number(i)
vac_prop_dict['coordinated_elements'] = vac.get_coordinated_elements(i)
vac_prop_dict['eff_charge'] = vac.get_defectsite_effective_charge(i)
vac_prop_dict['el'] = vac.get_defectsite(i).species_string
#vac_prop_dict['surf_area'] = vac.get_surface_area(i)
#vac_prop_dict['volume'] = vac.get_volume(i)
vac_prop_dict['chrg_ratio'] = anion_cation_charge_ratio
vac_prop_dict['radii_ratio'] = anion_cation_radii_ratio
vacancy_list.append(vac_prop_dict)
struct_descript_dict[key]['vacancies'] = vacancy_list
#print struct_descript_dict