33from typing import Dict , List
44
55import numpy as np
6- from pydantic import BaseModel
6+ from pydantic import Field
77from pymatgen .analysis .bond_valence import BVAnalyzer
88from pymatgen .core import Structure
99from pymatgen .core .periodic_table import Specie
1010from typing_extensions import Literal
1111
12+ from emmet .core .material_property import PropertyDoc
13+ from emmet .core .mpid import MPID
1214
13- class OxidationStateDoc (BaseModel ):
1415
15- possible_species : List [str ]
16- possible_valences : List [float ]
17- average_oxidation_states : Dict [str , float ]
18- method : Literal ["BVAnalyzer" , "oxi_state_guesses" ]
19- structure : Structure
16+ class OxidationStateDoc (PropertyDoc ):
17+ """Oxidation states computed from the structure"""
18+
19+ possible_species : List [str ] = Field (
20+ description = "Possible charged species in this material"
21+ )
22+ possible_valences : List [float ] = Field (
23+ description = "List of valences for each site in this material"
24+ )
25+ average_oxidation_states : Dict [str , float ] = Field (
26+ description = "Average oxidation states for each unique species"
27+ )
28+ method : str = Field (description = "Method used to compute oxidation states" )
2029
2130 @classmethod
22- def from_structure (cls , structure : Structure ):
31+ def from_structure (cls , structure : Structure , material_id : MPID , ** kwargs ): # type: ignore[override]
2332 structure .remove_oxidation_states ()
2433 try :
2534 bva = BVAnalyzer ()
@@ -49,12 +58,9 @@ def from_structure(cls, structure: Structure):
4958 "possible_species" : list (possible_species ),
5059 "possible_valences" : valences ,
5160 "average_oxidation_states" : oxi_state_dict ,
52- "method" : "BVAnalyzer" ,
53- "structure" : structure ,
61+ "method" : "Bond Valence Analysis" ,
5462 }
5563
56- return cls (** d )
57-
5864 except Exception as e :
5965 logging .error ("BVAnalyzer failed with: {}" .format (e ))
6066
@@ -76,12 +82,13 @@ def from_structure(cls, structure: Structure):
7682 "possible_species" : list (possible_species ),
7783 "possible_valences" : valences ,
7884 "average_oxidation_states" : first_oxi_state_guess ,
79- "method" : "oxi_state_guesses" ,
80- "structure" : structure ,
85+ "method" : "Oxidation State Guess" ,
8186 }
8287
83- return cls (** d )
84-
8588 except Exception as e :
8689 logging .error ("Oxidation state guess failed with: {}" .format (e ))
8790 raise e
91+
92+ return super ().from_structure (
93+ structure = structure , material_id = material_id , ** d , ** kwargs
94+ )
0 commit comments