StructureNL Object to JSON


I am working with StructureNL format for the first time. Could you please tell me how can I achieve a conversion of a dictionary of StructureNL objects to JSON format, in order to pass them to Crystal Toolkit?
Here is the snippet from Materials Virtual Lab

final_structs = {}
for chemsys in final_filtered_structs:
    final_structs[chemsys] = [struct.to_snl([{"name":"Matthew McDermott", "email":"N/A"}]) 
                              for struct in final_filtered_structs[chemsys]]

#pprint(final_structs['Y-Fe-O'][0].as_dict()) # Printing one of the StructureNL objects - this is a large dictionary!

Thanks, Pymatgen team!

Hi @devthepenguin, welcome!

The StructureNL object has a .structure attribute, you can use that to get the Structure out, and use this in Crystal Toolkit as normal.

The better solution would be for me to update Crystal Toolkit to support StructureNL.

The idea of StructureNL was to be able to store a Structure object along with associated metadata, like author, etc. For a while now, we’ve been aware of some limitations in StructureNL that suggests we should modernize the design, but it’s been on the back-burner for a while.

Hope this helps,


1 Like

Hey @mkhorton,

Thank you so much for taking the time to reply! This helps, I’ll be able to work with this now. Thanks!