def has_common_oxi_states(row): comp = Composition(row.StructuredFormula) int_comp = Composition( comp.get_integer_formula_and_factor()[0]) # get integer formular ############################################################################################### # according to the documentation of pymatgen's Composition class' oxi_state_guesses(), the default # value of the argument all_oxi_states is False, which means that it should only use most common # oxidation states of elements to make the guesses. However, it seems to be using all oxidation states. # E.g. Try the compound - KCa9V10O30, This can't be solved only with Vanadium's common oxidation state (+5) # However, this is solved by oxi_state_guesses() function, which means it's using other oxidation states as well. # Therefore, we are going to overide the elements' oxidation states with the most common oxidation states # by setting the argument oxi_states_override in oxi_state_guesses() ################################################################################################ ## create a common oxidation states dictonary to overide dic = {} for element in ElementSym('H').ox_st_dict.keys( ): # dummy element to instantiate the ElementSym class if element == 'Eu': # common and most stable ox. st. of Eu is +3, pymatgen provides both (+2 & +3). However, we select only +3 common_ox_st = (3, ) else: common_ox_st = Element(element).common_oxidation_states dic[element] = common_ox_st # return true if it could be solved using common oxi states if len(int_comp.oxi_state_guesses(oxi_states_override=dic)) > 0: return 1 else: return 0
def get_composition_from_string(s): from pymatgen import Composition, Element comp = Composition(s) for element in comp.elements: Element(element) comp = Composition(comp.get_integer_formula_and_factor()[0]) return comp.formula.replace(' ', '')
def get_composition_from_string(comp_str): """validate and return composition from string `comp_str`.""" from pymatgen import Composition, Element comp = Composition(comp_str) for element in comp.elements: Element(element) formula = comp.get_integer_formula_and_factor()[0] comp = Composition(formula) return ''.join([ '{}{}'.format(key, int(value) if value > 1 else '') for key, value in comp.as_dict().items() ])
def get_composition_from_string(comp_str): """validate and return composition from string `comp_str`.""" from pymatgen import Composition, Element comp = Composition(comp_str) for element in comp.elements: Element(element) formula = comp.get_integer_formula_and_factor()[0] comp = Composition(formula) return ''.join([ '{}{}'.format(key, int(value) if value > 1 else '') for key, value in comp.as_dict().items() ])
def has_common_oxi_states( row): # this snippet is borrowed from get_novel_perovskites.py comp = Composition(row.StructuredFormula) int_comp = Composition(comp.get_integer_formula_and_factor() [0]) # get integer formular ## create a common oxidation states dictonary to overide dic = {} for element in ElementSym('H').ox_st_dict.keys( ): # dummy element to instantiate the ElementSym class if element == 'Eu': common_ox_st = (3, ) else: common_ox_st = Element(element).common_oxidation_states dic[element] = common_ox_st # return true if it could be solved using common oxi states if len(int_comp.oxi_state_guesses(oxi_states_override=dic)) > 0: return 1 else: return 0
def get_random_packed(composition, add_specie=None, target_atoms=100, vol_per_atom=None, vol_exp=1.0, modify_species=None, use_random_seed=True): mpr = MPRester() if type(composition) == str: composition = Composition(composition) if type(add_specie) == str: add_specie = Composition(add_specie) comp_entries = mpr.get_entries(composition.reduced_formula, inc_structure=True) if vol_per_atom is None: if len(comp_entries) > 0: vols = np.min([ entry.structure.volume / entry.structure.num_sites for entry in comp_entries ]) else: # Find all Materials project entries containing the elements in the # desired composition to estimate starting volume. _entries = mpr.get_entries_in_chemsys( [str(el) for el in composition.elements], inc_structure=True) entries = [] for entry in _entries: if set(entry.structure.composition.elements) == set( composition.elements): entries.append(entry) if len(entry.structure.composition.elements) >= 2: entries.append(entry) vols = [ entry.structure.volume / entry.structure.num_sites for entry in entries ] vol_per_atom = np.mean(vols) # Find total composition of atoms in the unit cell formula, factor = composition.get_integer_formula_and_factor() composition = Composition(formula) comp = composition * np.ceil(target_atoms / composition.num_atoms) if add_specie is not None: comp += add_specie # comp = Composition(comp) # Generate dict of elements and amounts for AmorphousMaker structure = {} for el in comp: structure[str(el)] = int(comp.element_composition.get(el)) if modify_species is not None: for i, v in modify_species.items(): structure[i] += v # use packmol to get a random configured structure packmol_path = os.environ['PACKMOL_PATH'] amorphous_maker_params = { 'box_scale': (vol_per_atom * comp.num_atoms * vol_exp)**(1 / 3), 'packmol_path': packmol_path, 'xyz_paths': None, 'time_seed': use_random_seed } glass = AmorphousMaker(structure, **amorphous_maker_params) structure = glass.random_packed_structure return structure