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

Feature/sof 4154 #56

Open
wants to merge 20 commits into
base: epic/SOF-4126
Choose a base branch
from
Open

Feature/sof 4154 #56

wants to merge 20 commits into from

Conversation

csadorf
Copy link

@csadorf csadorf commented Dec 8, 2020

No description provided.


@staticmethod
def _parse_structure_node_attributes(export_data, attributes):
"""Parse an AiiDA StructureData node."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) We should declare parameters and output in docstring
(2) Nit: docstring format is different than elsewhere in the code

'elements': [{'id': _id, 'value': kinds[site['kind_name']]['name']} for _id, site in sites],
'coordinates': [{'id': _id, 'value': site['position']} for _id, site in sites],
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some ideas/questions:

  1. Isolate instance into a JSON template configurable with parameters and use it here
  2. add functions for parsing lattice, basis separately to increase modularity

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on point 1? Do you mean to have a static file as a template or a template within the code? Where would that template be configured?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From discussion: Store static template.

Consider: creating object from esse schema with https://github.com/cwacek/python-jsonschema-objects

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried using python-jsonschema-objects, however the following minimal example fails:

import esse
import python_jsonschema_objects as pjs

ES = esse.ESSE()
SCHEMA_MATERIAL = ES.get_schema_by_id('material')
builder = pjs.ObjectBuilder(SCHEMA_MATERIAL)
ns = builder.build_classes()

It's possible that I'm using it wrong, but at this point, I'll just move on and use a static template instead.

self.zip_dir_name = os.path.dirname(self.zip_path)
self.zip_file = zipfile.ZipFile(self.zip_path)
except:
# safely ignore broken zip file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's log the event here, pls, to avoid a silent loophole

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not like this either, but followed this pattern:

except:
# safely ignore broken xml file
pass

Copy link
Contributor

@triplepoint triplepoint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I really like this code. It's clean and concise without being dense and obscure. Good job.

express/parsers/apps/aiida/formats/zip.py Outdated Show resolved Hide resolved
express/parsers/apps/aiida/formats/zip.py Outdated Show resolved Hide resolved
express/parsers/apps/aiida/formats/zip.py Outdated Show resolved Hide resolved
express/parsers/apps/aiida/formats/zip.py Outdated Show resolved Hide resolved
express/parsers/apps/aiida/parser.py Outdated Show resolved Hide resolved
return structures

# TODO: This is probably not how we want to handle this.
final_structure_strings = initial_structure_strings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about the context here; is this workable? If nothing else, maybe some commentary here about why this is acceptable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, but I am also not sure how else to integrate this with existing patterns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision: Actually implement as function that returns value from initial_structure_strings().

express/parsers/apps/aiida/formats/zip.py Show resolved Hide resolved
assert all(len(kind['symbols']) == 1 for kind in kinds.values())

instance = json.loads(TEMPLATES_MATERIALS_PATH.read_text())
instance.update({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is:

  • inside the template below - materials.json (should be called material.json btw) we can add template variables, for example { ID }, or { LATTICE_VECTOR_A } like:
{
    "_id": "{{ ID }}"
    "lattice": {
       "vectors": {
        { "a": "{{ LATTICE_VECTOR_A }}" ...
   ...
}
  • then, when we want to generate the instance from it we read text, render it and load:
json.loads(Template.render(template, ID=export_data['uuid'], LATTICE_VECTORS_A=attributes['cell'][0]
...)
 

Copy link
Author

@csadorf csadorf Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied that change in 7aa402b and 3e19d11 .

instance = json.loads(TEMPLATES_MATERIALS_PATH.read_text())
instance.update({
'_id': export_data['uuid'],
'created_at': export_data['ctime'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also - when we upload the job information to our database online, the ID is likely to be reset, especially if it's a duplicate. We could add a tag to store the original AiiDA ids there. With MP materials we retain them as mp-137, for example. So tags: ["aiida-<UUID>"] could be a good start.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied that change in 3c01bbb .

@csadorf csadorf changed the base branch from epic/SOF-4126 to dev April 29, 2021 10:16
@csadorf csadorf changed the base branch from dev to epic/SOF-4126 April 29, 2021 10:16
@csadorf
Copy link
Author

csadorf commented Apr 29, 2021

I've cycled the base to trigger the correct representation of this PR on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants