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

set xsf as default format for structures visualization #1756

Merged

Conversation

elsapassaro
Copy link
Contributor

switched to xsf format as default format in get_visualization_data
added test_xsf_visualization

@codecov-io
Copy link

codecov-io commented Jul 17, 2018

Codecov Report

Merging #1756 into release_v0.12.2 will increase coverage by 0.04%.
The diff coverage is 11.36%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           release_v0.12.2    #1756      +/-   ##
===================================================
+ Coverage            54.67%   54.71%   +0.04%     
===================================================
  Files                  246      246              
  Lines                32432    32433       +1     
===================================================
+ Hits                 17731    17745      +14     
+ Misses               14701    14688      -13
Impacted Files Coverage Δ
aiida/orm/data/structure.py 76.79% <5.12%> (-1.76%) ⬇️
aiida/restapi/translator/data/structure.py 63.63% <60%> (+29.49%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fafaac...04899d0. Read the comment docs.

Copy link
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

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

Just a few changes.

from aiida.backends.tests.dataclasses import simplify
node_uuid = self.get_dummy_data()["structuredata"][0]["uuid"]
url = self.get_url_prefix() + '/structures/' + str(
node_uuid) + '/content/visualization'
Copy link
Member

Choose a reason for hiding this comment

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

This is testing also if the default is XSF.
I think it's better to test explicitly setting the xsf format tin the url.
Also, in general (in the future) probably better not to change the default or not even have one (and make sure already now, in any case, that the frontend always requires a specific format)

@@ -83,7 +83,7 @@ def __init__(self, **kwargs):
def get_visualization_data(node, format=None, supercell_factors=[1, 1, 1]):
"""
Returns: data in specified format. If format is not specified returns data
in a format required by chemdoodle to visualize a structure.
in xsf format in order to visualize the structure with JSmol.
"""
response = {}
response["str_viz_info"] = {}
Copy link
Member

Choose a reason for hiding this comment

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

Here below, I would do (if we want to have 'xsf' as default):

if format is None:
    format = 'xsf' 

and then let the logic take care of the default.
Then, in the else, raise an exception (now instead it returns 'xsf' even if the string is unknown).

@@ -95,7 +95,7 @@ def get_visualization_data(node, format=None, supercell_factors=[1, 1, 1]):
except LicensingException as e:
response = e.message

else:
elif format == "chemdoodle":
import numpy as np
Copy link
Member

Choose a reason for hiding this comment

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

I know this was there before, but can we move this bit of logic and deal with it as with the other formats, instead of doing it specially here?
The way to do it is to add a _prepare_chemdoodle method to the StructureData class (aiida/orm/data/structure.py), see e.g. _prepare_xyz. You can move all the code generation in there.
Then chemdoodle will automatically be found among the formats, and you don't need a special case here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just one question: the _prepare_chemdoodle method should return a string (as all others prepare methods) or I can still return the json dictionary?

Copy link
Member

Choose a reason for hiding this comment

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

Mmm, good point. I think it should return a string.
Maybe you can then return a valid JSON string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I will add a JSON parse in the Javascript to retrieve the correct format to pass to chemdoodle.

Copy link
Member

Choose a reason for hiding this comment

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

indeed, I didn't think to this.
I still think that the right thing to do is to return a string in AiiDA (as the method is called _exportstring and it might need to be stored on file).
To preserve back-compatibility with people using a REST API at a earlier version, can you put in the client code a test on the type: if it's already a JSON Object, just use it, while if it's a string, parse it first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

try:
response["str_viz_info"]["data"] = node._exportstring("xsf")[0]
response["str_viz_info"]["format"] = "xsf"
except LicensingException as e:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why are checking for LicensingException here, but this was already there, so I'm discussing this with Snehal as well. For now it's ok to keep it.

@giovannipizzi giovannipizzi merged commit ee29447 into aiidateam:release_v0.12.2 Jul 18, 2018
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.

3 participants