Skip to content

Commit c2aa98f

Browse files
authored
Merge pull request #191 from WMD-group/oxidation_states
Oxidation states
2 parents 7d1ee94 + bc9c44b commit c2aa98f

File tree

6 files changed

+200
-53
lines changed

6 files changed

+200
-53
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# generated using pymatgen
2+
data_CsPbI3
3+
_symmetry_space_group_name_H-M 'P 1'
4+
_cell_length_a 4.84714164
5+
_cell_length_b 10.65044663
6+
_cell_length_c 18.03119927
7+
_cell_angle_alpha 90.00000000
8+
_cell_angle_beta 90.00000000
9+
_cell_angle_gamma 90.00000000
10+
_symmetry_Int_Tables_number 1
11+
_chemical_formula_structural CsPbI3
12+
_chemical_formula_sum 'Cs4 Pb4 I12'
13+
_cell_volume 930.84665829
14+
_cell_formula_units_Z 4
15+
loop_
16+
_symmetry_equiv_pos_site_id
17+
_symmetry_equiv_pos_as_xyz
18+
1 'x, y, z'
19+
loop_
20+
_atom_type_symbol
21+
_atom_type_oxidation_number
22+
Cs+ 1.0
23+
Pb2+ 2.0
24+
I- -1.0
25+
loop_
26+
_atom_site_type_symbol
27+
_atom_site_label
28+
_atom_site_symmetry_multiplicity
29+
_atom_site_fract_x
30+
_atom_site_fract_y
31+
_atom_site_fract_z
32+
_atom_site_occupancy
33+
Cs+ Cs0 1 0.75000000 0.58127558 0.17211973 1.0
34+
Cs+ Cs1 1 0.25000000 0.41872442 0.82788027 1.0
35+
Cs+ Cs2 1 0.75000000 0.08127558 0.32788027 1.0
36+
Cs+ Cs3 1 0.25000000 0.91872442 0.67211973 1.0
37+
Pb2+ Pb4 1 0.25000000 0.66184885 0.43921676 1.0
38+
Pb2+ Pb5 1 0.75000000 0.33815115 0.56078324 1.0
39+
Pb2+ Pb6 1 0.25000000 0.16184885 0.06078324 1.0
40+
Pb2+ Pb7 1 0.75000000 0.83815115 0.93921676 1.0
41+
I- I8 1 0.75000000 0.83721116 0.50204455 1.0
42+
I- I9 1 0.25000000 0.16278884 0.49795545 1.0
43+
I- I10 1 0.75000000 0.33721116 0.99795545 1.0
44+
I- I11 1 0.25000000 0.66278884 0.00204455 1.0
45+
I- I12 1 0.25000000 0.52927197 0.61230824 1.0
46+
I- I13 1 0.75000000 0.47072803 0.38769176 1.0
47+
I- I14 1 0.25000000 0.02927197 0.88769176 1.0
48+
I- I15 1 0.75000000 0.97072803 0.11230824 1.0
49+
I- I16 1 0.25000000 0.79631664 0.28730552 1.0
50+
I- I17 1 0.75000000 0.20368336 0.71269448 1.0
51+
I- I18 1 0.25000000 0.29631664 0.21269448 1.0
52+
I- I19 1 0.75000000 0.70368336 0.78730552 1.0

examples/Oxidation_states/oxidation_states.ipynb

Lines changed: 126 additions & 46 deletions
Large diffs are not rendered by default.

smact/oxidation_states.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
from numpy import mean
1414
from pymatgen.core import Structure
15-
from pymatgen.core.periodic_table import Specie as pmgSpecies
15+
from pymatgen.core.periodic_table import Species as pmgSpecies
16+
from pymatgen.core.periodic_table import get_el_sp
1617

1718
from smact import Element, Species, data_directory
1819

@@ -146,7 +147,13 @@ def compound_probability(
146147
if not all(isinstance(i, pmgSpecies) for i in species):
147148
raise TypeError("Structure must have oxidation states.")
148149
else:
149-
structure = [Species(i.symbol, i.oxi_state) for i in structure]
150+
structure = [
151+
Species(
152+
get_el_sp(i.species_string).symbol,
153+
get_el_sp(i.species_string).oxi_state,
154+
)
155+
for i in structure
156+
]
150157
else:
151158
raise TypeError(
152159
"Input requires a list of SMACT or Pymatgen Species or a Structure."

smact/properties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List, Optional, Union
22

3-
from numpy import product, sqrt
3+
import numpy as np
44

55
import smact
66

@@ -70,10 +70,10 @@ def band_gap_Harrison(
7070
V1_bar = (V1_An + V1_Cat) / 2
7171
V2 = 2.16 * hbarsq_over_m / (d**2)
7272
V3 = (Cat.eig - An.eig) / 2
73-
alpha_m = (1.11 * V1_bar) / sqrt(V2**2 + V3**2)
73+
alpha_m = (1.11 * V1_bar) / np.sqrt(V2**2 + V3**2)
7474

7575
# Calculate Band gap [(3-43) Harrison 1980 ]
76-
Band_gap = (3.60 / 3.0) * (sqrt(V2**2 + V3**2)) * (1 - alpha_m)
76+
Band_gap = (3.60 / 3.0) * (np.sqrt(V2**2 + V3**2)) * (1 - alpha_m)
7777
if verbose:
7878
print("V1_bar = ", V1_bar)
7979
print("V2 = ", V2)
@@ -150,7 +150,7 @@ def compound_electroneg(
150150
elementlist[i] = [elementlist[i] ** stoichslist[i]]
151151

152152
# Calculate geometric mean (n-th root of product)
153-
prod = product(elementlist)
153+
prod = np.prod(elementlist)
154154
compelectroneg = (prod) ** (1.0 / (sum(stoichslist)))
155155

156156
if verbose:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"@module": "pymatgen.core.structure", "@class": "Structure", "charge": 0, "lattice": {"matrix": [[4.84714164, -0.0, 0.0], [0.0, 10.65044663, 0.0], [0.0, 0.0, 18.03119927]], "pbc": [true, true, true], "a": 4.84714164, "b": 10.65044663, "c": 18.03119927, "alpha": 90.0, "beta": 90.0, "gamma": 90.0, "volume": 930.846658290349}, "properties": {}, "sites": [{"species": [{"element": "Cs", "oxidation_state": 1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.58127558, 0.17211973], "xyz": [3.63535623, 6.190844542112295, 3.103525149928597], "properties": {"magmom": -0.0}, "label": "Cs"}, {"species": [{"element": "Cs", "oxidation_state": 1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.41872442, 0.82788027], "xyz": [1.21178541, 4.4596020878877045, 14.927674120071401], "properties": {"magmom": -0.0}, "label": "Cs"}, {"species": [{"element": "Cs", "oxidation_state": 1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.08127558, 0.32788027], "xyz": [3.63535623, 0.8656212271122954, 5.912074485071402], "properties": {"magmom": -0.0}, "label": "Cs"}, {"species": [{"element": "Cs", "oxidation_state": 1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.91872442, 0.67211973], "xyz": [1.21178541, 9.784825402887703, 12.119124784928596], "properties": {"magmom": -0.0}, "label": "Cs"}, {"species": [{"element": "Pb", "oxidation_state": 2, "spin": null, "occu": 1.0}], "abc": [0.25, 0.66184885, 0.43921676], "xyz": [1.21178541, 7.0489858540518755, 7.919604922283765], "properties": {"magmom": 0.0}, "label": "Pb"}, {"species": [{"element": "Pb", "oxidation_state": 2, "spin": null, "occu": 1.0}], "abc": [0.75, 0.33815115, 0.56078324], "xyz": [3.63535623, 3.6014607759481243, 10.111594347716235], "properties": {"magmom": 0.0}, "label": "Pb"}, {"species": [{"element": "Pb", "oxidation_state": 2, "spin": null, "occu": 1.0}], "abc": [0.25, 0.16184885, 0.06078324], "xyz": [1.21178541, 1.7237625390518754, 1.0959947127162348], "properties": {"magmom": 0.0}, "label": "Pb"}, {"species": [{"element": "Pb", "oxidation_state": 2, "spin": null, "occu": 1.0}], "abc": [0.75, 0.83815115, 0.93921676], "xyz": [3.63535623, 8.926684090948124, 16.935204557283765], "properties": {"magmom": 0.0}, "label": "Pb"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.83721116, 0.50204455], "xyz": [3.63535623, 8.91667277762039, 9.052465323467478], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.16278884, 0.49795545], "xyz": [1.21178541, 1.733773852379609, 8.978733946532522], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.33721116, 0.99795545], "xyz": [3.63535623, 3.5914494626203908, 17.99433358153252], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.66278884, 0.00204455], "xyz": [1.21178541, 7.0589971673796095, 0.036865688467478494], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.52927197, 0.61230824], "xyz": [1.21178541, 5.6369828692399615, 11.040651890102982], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.47072803, 0.38769176], "xyz": [3.63535623, 5.013463760760039, 6.990547379897015], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.02927197, 0.88769176], "xyz": [1.21178541, 0.3117595542399611, 16.006147014897014], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.97072803, 0.11230824], "xyz": [3.63535623, 10.338687075760038, 2.0250522551029846], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.79631664, 0.28730552], "xyz": [1.21178541, 8.481127874900922, 5.180463082490969], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.20368336, 0.71269448], "xyz": [3.63535623, 2.1693187550990767, 12.850736187509028], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.25, 0.29631664, 0.21269448], "xyz": [1.21178541, 3.1559045599009234, 3.835136552509029], "properties": {"magmom": -0.0}, "label": "I"}, {"species": [{"element": "I", "oxidation_state": -1, "spin": null, "occu": 1.0}], "abc": [0.75, 0.70368336, 0.78730552], "xyz": [3.63535623, 7.494542070099076, 14.19606271749097], "properties": {"magmom": -0.0}, "label": "I"}]}

smact/tests/test_core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import unittest
55

6+
from pymatgen.core import Structure
67
from pymatgen.core.periodic_table import Specie
78

89
import smact
@@ -17,6 +18,7 @@
1718

1819
files_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "files")
1920
TEST_OX_STATES = os.path.join(files_dir, "test_oxidation_states.txt")
21+
TEST_STRUCT = os.path.join(files_dir, "mp-540839_CsPbI3_oxi.json")
2022

2123

2224
class TestSequenceFunctions(unittest.TestCase):
@@ -417,7 +419,7 @@ def test_lattice_parameters(self):
417419
self.assertAlmostEqual(wurtz[0], 5.13076)
418420
self.assertAlmostEqual(wurtz[2], 8.3838)
419421

420-
# ---------- Lattice parameters -----------
422+
# ---------- smact.oxidation_states module -----------
421423
def test_oxidation_states(self):
422424
ox = smact.oxidation_states.Oxidation_state_probability_finder()
423425
self.assertAlmostEqual(
@@ -429,3 +431,8 @@ def test_oxidation_states(self):
429431
0.74280230326,
430432
)
431433
self.assertEqual(len(ox.get_included_species()), 173)
434+
435+
def test_compound_probability_structure(self):
436+
structure = Structure.from_file(TEST_STRUCT)
437+
ox = smact.oxidation_states.Oxidation_state_probability_finder()
438+
self.assertEqual(ox.compound_probability(structure), 1.0)

0 commit comments

Comments
 (0)