Skip to content
Snippets Groups Projects
Commit c128579f authored by James Graham's avatar James Graham
Browse files

Added converter for config->JSON

parent 96da4ee1
No related branches found
No related tags found
No related merge requests found
import json import json
import os import os
from .cfg import CFG as OldParser
class AttrDict(dict): class AttrDict(dict):
""" """
...@@ -50,3 +52,31 @@ class CFG: ...@@ -50,3 +52,31 @@ class CFG:
def __contains__(self, item): def __contains__(self, item):
return item in self._records return item in self._records
def jsonify(mappingfile, bondfile, outfile):
json_dict = AttrDict({"include": [],
"molecules": {}})
with OldParser(mappingfile) as mappings:
for mapping in mappings:
if mapping.name not in json_dict.molecules:
json_dict.molecules[mapping.name] = {}
mol = json_dict.molecules[mapping.name]
mol["beads"] = []
for line in mapping:
mol["beads"].append({"name": line[0],
"type": line[1],
"atoms": line[2:]})
with OldParser(bondfile) as bondlists:
for bondlist in bondlists:
try:
mol = json_dict.molecules[bondlist.name]
except KeyError:
continue
mol["bonds"] = []
for line in bondlist:
mol["bonds"].append(line)
with open(outfile, "w") as out:
json.dump(json_dict, out, indent=4, sort_keys=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment