Skip to content

Commit

Permalink
Merge pull request #191 from WMD-group/oxidation_states
Browse files Browse the repository at this point in the history
Oxidation states
  • Loading branch information
AntObi committed Dec 7, 2023
2 parents 7d1ee94 + bc9c44b commit c2aa98f
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 53 deletions.
52 changes: 52 additions & 0 deletions examples/Oxidation_states/mp-540839_CsPbI3_oxi.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# generated using pymatgen
data_CsPbI3
_symmetry_space_group_name_H-M 'P 1'
_cell_length_a 4.84714164
_cell_length_b 10.65044663
_cell_length_c 18.03119927
_cell_angle_alpha 90.00000000
_cell_angle_beta 90.00000000
_cell_angle_gamma 90.00000000
_symmetry_Int_Tables_number 1
_chemical_formula_structural CsPbI3
_chemical_formula_sum 'Cs4 Pb4 I12'
_cell_volume 930.84665829
_cell_formula_units_Z 4
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_type_symbol
_atom_type_oxidation_number
Cs+ 1.0
Pb2+ 2.0
I- -1.0
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Cs+ Cs0 1 0.75000000 0.58127558 0.17211973 1.0
Cs+ Cs1 1 0.25000000 0.41872442 0.82788027 1.0
Cs+ Cs2 1 0.75000000 0.08127558 0.32788027 1.0
Cs+ Cs3 1 0.25000000 0.91872442 0.67211973 1.0
Pb2+ Pb4 1 0.25000000 0.66184885 0.43921676 1.0
Pb2+ Pb5 1 0.75000000 0.33815115 0.56078324 1.0
Pb2+ Pb6 1 0.25000000 0.16184885 0.06078324 1.0
Pb2+ Pb7 1 0.75000000 0.83815115 0.93921676 1.0
I- I8 1 0.75000000 0.83721116 0.50204455 1.0
I- I9 1 0.25000000 0.16278884 0.49795545 1.0
I- I10 1 0.75000000 0.33721116 0.99795545 1.0
I- I11 1 0.25000000 0.66278884 0.00204455 1.0
I- I12 1 0.25000000 0.52927197 0.61230824 1.0
I- I13 1 0.75000000 0.47072803 0.38769176 1.0
I- I14 1 0.25000000 0.02927197 0.88769176 1.0
I- I15 1 0.75000000 0.97072803 0.11230824 1.0
I- I16 1 0.25000000 0.79631664 0.28730552 1.0
I- I17 1 0.75000000 0.20368336 0.71269448 1.0
I- I18 1 0.25000000 0.29631664 0.21269448 1.0
I- I19 1 0.75000000 0.70368336 0.78730552 1.0
172 changes: 126 additions & 46 deletions examples/Oxidation_states/oxidation_states.ipynb

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions smact/oxidation_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from numpy import mean
from pymatgen.core import Structure
from pymatgen.core.periodic_table import Specie as pmgSpecies
from pymatgen.core.periodic_table import Species as pmgSpecies
from pymatgen.core.periodic_table import get_el_sp

from smact import Element, Species, data_directory

Expand Down Expand Up @@ -146,7 +147,13 @@ def compound_probability(
if not all(isinstance(i, pmgSpecies) for i in species):
raise TypeError("Structure must have oxidation states.")
else:
structure = [Species(i.symbol, i.oxi_state) for i in structure]
structure = [
Species(
get_el_sp(i.species_string).symbol,
get_el_sp(i.species_string).oxi_state,
)
for i in structure
]
else:
raise TypeError(
"Input requires a list of SMACT or Pymatgen Species or a Structure."
Expand Down
8 changes: 4 additions & 4 deletions smact/properties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional, Union

from numpy import product, sqrt
import numpy as np

import smact

Expand Down Expand Up @@ -70,10 +70,10 @@ def band_gap_Harrison(
V1_bar = (V1_An + V1_Cat) / 2
V2 = 2.16 * hbarsq_over_m / (d**2)
V3 = (Cat.eig - An.eig) / 2
alpha_m = (1.11 * V1_bar) / sqrt(V2**2 + V3**2)
alpha_m = (1.11 * V1_bar) / np.sqrt(V2**2 + V3**2)

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

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

if verbose:
Expand Down
1 change: 1 addition & 0 deletions smact/tests/files/mp-540839_CsPbI3_oxi.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"}]}
9 changes: 8 additions & 1 deletion smact/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import unittest

from pymatgen.core import Structure
from pymatgen.core.periodic_table import Specie

import smact
Expand All @@ -17,6 +18,7 @@

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


class TestSequenceFunctions(unittest.TestCase):
Expand Down Expand Up @@ -417,7 +419,7 @@ def test_lattice_parameters(self):
self.assertAlmostEqual(wurtz[0], 5.13076)
self.assertAlmostEqual(wurtz[2], 8.3838)

# ---------- Lattice parameters -----------
# ---------- smact.oxidation_states module -----------
def test_oxidation_states(self):
ox = smact.oxidation_states.Oxidation_state_probability_finder()
self.assertAlmostEqual(
Expand All @@ -429,3 +431,8 @@ def test_oxidation_states(self):
0.74280230326,
)
self.assertEqual(len(ox.get_included_species()), 173)

def test_compound_probability_structure(self):
structure = Structure.from_file(TEST_STRUCT)
ox = smact.oxidation_states.Oxidation_state_probability_finder()
self.assertEqual(ox.compound_probability(structure), 1.0)

0 comments on commit c2aa98f

Please sign in to comment.