-
Notifications
You must be signed in to change notification settings - Fork 32
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
Save and load lattices in JSON format #766
Conversation
Dear @lfarv, a few tests in matlab: ALL looks ok here. I will now try to load in python and save/load json in python and back to maltab |
Dear @lfarv, I tried to load the json file in python. mat_key does not work anymore
Traceback (most recent call last): the new keywork |
The help of save_lattice and load_lattice could be updated to include save_json and load_json |
The JSON files saved by matlab and by python are different. In particular the R1-R2 and T1-T2 fields are not in the same order. |
Same for the field Energy. |
Dear @lfarv globally I find this new feature very useful and working correctly! The only issues are the mat_key (for backward compatibility) and a fixed order of the fields in json file produced by let me know and I will further test. I have seen that many functions are impacted but I did not test that all other methods are working as before (save_lattice, load_lattice, save_mat, load_mat, etc...). May be a new test could verify that all load and save did not change their output? |
Hello @simoneliuzzo
The
What do you mean ? Here JSON is mentioned in the help:
Anyway, I'll try and improve the help. |
This is more difficult. The JSON spec states that the order of fields in the structure is irrelevant. In python I may have some control on the encoding, but in Matlab, the |
@simoneliuzzo |
Dear @lfarv, I think that being able to compare to json files is important. Could you test that the modifications for json files did not harm any of the other possible file load/save? repr, mat, m, lat, lte etc... best regards |
@simoneliuzzo Now to compare JSON files, you can one of the many available 3rd party JSON comparators:
Otherwise, I'll add a few tests for other formats (and accordingly a few data files) |
With this PR, AT can save and load lattices in JSON format. JSON is a text-based format with the following properties:
.mat
format.In addition, a few modifications have been made to the global load/save package to prepare future formats:
use=lattice_name
is now used for all formats, while the specific keywords (matkey=
,lattice_key=
etc.) are still understood for compatibility,mat_file
,elegant_file
... which records the input file name is replaced by a single one:in_file
. This avoids the accumulation of different attributes, with the consequence that the last loaded file could not be identified. The file name extension is enough to know which kind of file was loaded.Finally, the file loading structure is improved to allow an easier addition of new formats.