def set_inpchanges(xmltree, schema_dict, change_dict, path_spec=None): """ This method sets all the attribute and texts provided in the change_dict. The first occurrence of the attribute/tag is set :param xmltree: xml tree that represents inp.xml :param schema_dict: InputSchemaDict containing all information about the structure of the input :params change_dict: dictionary {attrib_name : value} with all the wanted changes. :param path_spec: dict, with ggf. necessary further specifications for the path of the attribute An example of change_dict:: change_dict = {'itmax' : 1, 'l_noco': True, 'ctail': False, 'l_ss': True} :returns: an xmltree of the inp.xml file with changes. """ from masci_tools.util.xml.xml_setters_xpaths import xml_set_first_attrib_value, xml_set_first_text from masci_tools.util.xml.common_functions import split_off_attrib from masci_tools.util.case_insensitive_dict import CaseInsensitiveDict if path_spec is None: path_spec = {} path_spec = CaseInsensitiveDict(path_spec) for key, change_value in change_dict.items(): #Special alias for xcFunctional since name is not a very telling attribute name if key == 'xcFunctional': key = 'name' if key not in schema_dict['attrib_types'] and key not in schema_dict['simple_elements']: raise ValueError(f"You try to set the key:'{key}' to : '{change_value}', but the key is unknown" ' to the fleur plug-in') text_attrib = key not in schema_dict['attrib_types'] key_spec = path_spec.get(key, {}) #This method only support unique and unique_path attributes if 'exclude' not in key_spec: key_spec['exclude'] = ['other'] elif 'other' not in key_spec['exclude']: key_spec['exclude'].append('other') key_xpath = get_attrib_xpath(schema_dict, key, **key_spec) if not text_attrib: #Split up path into tag path and attribute name (original name of key could have different cases) key_xpath, key = split_off_attrib(key_xpath) if text_attrib: xml_set_first_text(xmltree, schema_dict, key_xpath, key_xpath, change_value) else: xml_set_first_attrib_value(xmltree, schema_dict, key_xpath, key_xpath, key, change_value) return xmltree
def shift_value(xmltree, schema_dict, change_dict, mode='abs', path_spec=None): """ Shifts numerical values of attributes directly in the inp.xml file. The first occurrence of the attribute is shifted :param xmltree: xml tree that represents inp.xml :param schema_dict: InputSchemaDict containing all information about the structure of the input :param change_dict: a python dictionary with the keys to shift and the shift values. :param mode: 'abs' if change given is absolute, 'rel' if relative :param path_spec: dict, with ggf. necessary further specifications for the path of the attribute :returns: a xml tree with shifted values An example of change_dict:: change_dict = {'itmax' : 1, 'dVac': -0.123} """ from masci_tools.util.case_insensitive_dict import CaseInsensitiveDict if path_spec is None: path_spec = {} path_spec = CaseInsensitiveDict(path_spec) for key, value_given in change_dict.items(): key_spec = path_spec.get(key, {}) #This method only support unique and unique_path attributes if 'exclude' not in key_spec: key_spec['exclude'] = ['other'] elif 'other' not in key_spec['exclude']: key_spec['exclude'].append('other') xmltree = add_number_to_first_attrib(xmltree, schema_dict, key, value_given, mode=mode, **key_spec) return xmltree