Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move aiida-fleur xml_util #23

Merged
merged 79 commits into from Mar 22, 2021
Merged

Move aiida-fleur xml_util #23

merged 79 commits into from Mar 22, 2021

Conversation

janssenhenning
Copy link
Contributor

@janssenhenning janssenhenning commented Mar 2, 2021

This pull requests moves (and redesigns if necessary) most of the content of the tools/xml_util module in aiida_fleur (status of the masci_tools_parsers branch)

One fundamental change I made is that I introduced more splitting of responsibilities of these XML modifying functions. There are now 3 (or 4) categories of XML setter functions

  • Basic functions take a xpath and cannot create all the tags necessary if the xpath evaluation has no result (meaning xml_create_tag can only create a tag if all parent tags are already present)
  • Functions that take 2 xpaths. One of them is used for the evaluation (most of the time in one of the basic functions). The other one CANNOT include any complex syntax (like [@name='species-name']). This simple xpath is used in the schema dictionary to find out more information about the operation to perform. For example it can find out the enforced order of subtags or the types an attribute can have. These functions can create parent if they are not present
  • Functions that do not require an xpath to function (some of them still take an optional argument complex_xpath to customize behaviour). These are essentially all the user-friendly methods from aiida-fleur with some extensions
  • nmmpmat functions also do not need a xpath. However, they do not change the xmltree but the provided nmmp_mat file

In addition I implemented an equivalent for the Fleurinpmodifier in aiida-fleur, which operates on a concrete inp.xml (and n_mmp_mat if necessary) file. The usage is almost the same (except for initialisation and application to the file)

from masci_tools.io.fleurxmlmodifier import FleurXMLModifier

fm = FleurXMLModififier() #Note: we do not specify the inp.xml here. This is done to make evtl. integration of this class with Fleurinpmodifier less awkward
fm.set_inpchanges({'Kmax':9.0}) #Adding tasks is exactly the same (except these functions have more leniancy. i.e. automatic str conversion, case insensitivity for keys)
new_xmltree = fm.modify_xmlfile('/path/to/original/inp.xml')

Other small changes:

  • Added load_inpxml and load_outxml for easy access to an xmltree and version specific schema dict
  • Restructured module index in docs, since it was getting quite big

TODO:

  • Tests for xml_setters_names
  • Tests for xml_setters_nmmpmat
  • Tests for new functions in common_xml_util
  • Tests for load_inpxml, load_outxml and FleurXMLModifier

… be used in the old way `create_tag_xpath` or utilizing the schema_dictionary functionality `create_tag`
Split up into functions that can create missing tags on the fly and basic functions that rely on the tags being there and which do not have access to the schema_dict

Added:
   - replace tag, delete tag/attribute
   - setting attributes/text (Thes functions were unified under one and only provided the first as a special alias)
Added:
   - set_simple_tag for single/multiple tags with only attributes
   - set_complex_tag Recursive handling for all kinds of inputs (ATTENTION: will delete all tags in several before rewriting)
   - set_species/set_inpchanges moved unchanged from aiida_fleur (masci_tools parser branch)

TODO:
   - move conversion of attribute/text into strings into the xml_set_attrib_value and xml_set_text value
   - settle on a more consistent function name scheme to indicate the interface in the function name (schema_dict+name; schema_dict+base xpath; concrete xpaths with minimal requirements)
- This is essentially FleurinpModifier without provenance
Could be used as a superclass for FleurinpModifier. We just would need to call apply_modifications

For ease of integration with FleurinpModifier the files to be modified are only provided once the modifications are supposed to happen `modify_xmlfile`
Notes:
  - change_atomgr_att -> set_atomgroup
  - change_atomgr_att_label -> set_atomgroup_label
  - add_num_to_att -> add_number_to_attrib (now also supports occurrences)
  - add_number_to_first_attrib (behaviour of add_num_to_att)
  - attribute/text setting from attributename with support for occurrences and complex xpaths
  - new function rotate_nmmpmat modifies exisiting density matrix block and rotates it according to the given angles
  - FleurXMLModifier.apply_modifications supports passing of extra functions for subclasses of this. This can be used for example to
    integrate functions using aiida nodes in to the same function without introducing aiida dependencies
if a method starts with xml_ it REQUIRES atleast one xpath as argument
I don't know id I should use these functions in the parsers, since they are essentially the initial loading phase of these, but this could introduce some ugly dependencies
All these functions will always return success since it does not make sense to make them obvious to use fro the outside (since inside they are always used without suc_return=False). There should always be a more high level function using the schema_dict, which will call these converters in the background
We might have to restructure the source code reference to be more structured since its becoming quite large
@janssenhenning janssenhenning marked this pull request as ready for review March 10, 2021 17:52
@janssenhenning janssenhenning merged commit e56ca82 into develop Mar 22, 2021
@janssenhenning janssenhenning deleted the aiida_fleur_xml_setters branch March 24, 2021 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant