-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: epic/SOF-4126
Are you sure you want to change the base?
Feature/sof 4154 #56
Conversation
36052a4
to
a8a9cd2
Compare
|
||
@staticmethod | ||
def _parse_structure_node_attributes(export_data, attributes): | ||
"""Parse an AiiDA StructureData node.""" |
There was a problem hiding this comment.
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], | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some ideas/questions:
- Isolate instance into a JSON template configurable with parameters and use it here
- add functions for parsing
lattice
,basis
separately to increase modularity
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
express/parsers/formats/zip.py
Outdated
self.zip_dir_name = os.path.dirname(self.zip_path) | ||
self.zip_file = zipfile.ZipFile(self.zip_path) | ||
except: | ||
# safely ignore broken zip file |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
express/express/parsers/formats/xml.py
Lines 20 to 22 in a8a9cd2
except: | |
# safely ignore broken xml file | |
pass |
cd4e81d
to
e9fcffa
Compare
50b3c8c
to
8fd7d04
Compare
There was a problem hiding this 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.
return structures | ||
|
||
# TODO: This is probably not how we want to handle this. | ||
final_structure_strings = initial_structure_strings |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
.
assert all(len(kind['symbols']) == 1 for kind in kinds.values()) | ||
|
||
instance = json.loads(TEMPLATES_MATERIALS_PATH.read_text()) | ||
instance.update({ |
There was a problem hiding this comment.
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 calledmaterial.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]
...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance = json.loads(TEMPLATES_MATERIALS_PATH.read_text()) | ||
instance.update({ | ||
'_id': export_data['uuid'], | ||
'created_at': export_data['ctime'], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 .
- To provide better error indication. - To optimize read and JSON parsing operations.
As opposed to the structures() method.
With other parser constructors.
8fd7d04
to
862915f
Compare
I've cycled the base to trigger the correct representation of this PR on GitHub. |
No description provided.