def test_parse_formula(self): elements_dict = { 'Ca': 1, 'Ti': 1, 'O': 3, } self.assertEqual(pmutt.parse_formula('CaTiO3'), elements_dict) elements_dict = { 'H': 1, 'F': 1, } self.assertEqual(pmutt.parse_formula('HF'), elements_dict) elements_dict = { 'H': 8, 'C': 3, } self.assertEqual(pmutt.parse_formula('CH3CH2CH3'), elements_dict)
def set_formula(formula, output_structure): """Parses stoichiometric formula unit and assigns to output_structure Parameters ---------- formula : str Stoichiometric formula unit. e.g. H2O Note that an element cannot be specified multiple times. e.g. CH3OH is not supported output_structure : dict Structure to assign value. Will assign to output_structure['elements'] """ elements = parse_formula(formula=formula) output_structure['elements'] = elements
def __init__(self, name=None, trans_model=EmptyMode(), vib_model=EmptyMode(), rot_model=EmptyMode(), elec_model=EmptyMode(), nucl_model=EmptyMode(), misc_models=None, elements=None, references=None, smiles=None, notes=None, **kwargs): self.name = name self.smiles = smiles self.notes = notes self.references = references self.trans_model = _check_obj(trans_model, **kwargs) self.vib_model = _check_obj(vib_model, **kwargs) self.rot_model = _check_obj(rot_model, **kwargs) self.elec_model = _check_obj(elec_model, **kwargs) self.nucl_model = _check_obj(nucl_model, **kwargs) # Assign elements from Atoms if necessary if elements is None: try: elements = parse_formula( \ kwargs['atoms'].get_chemical_formula('hill')) except KeyError: pass self.elements = elements # Assign misc models # TODO misc models can not be initialized by passing the class # because all the models will have the same attributes. Figure out # a way to pass them. Perhaps have a dictionary that contains the # attributes separated by species self.misc_models = _check_iterable_attr(misc_models)