From af7857c7395d67f782a0577876881843580bd7f4 Mon Sep 17 00:00:00 2001 From: davous267 Date: Thu, 28 Oct 2021 14:56:05 +0200 Subject: [PATCH] Script for appending PDBs to UNF improved --- other_scripts/unf_add_pdb.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/other_scripts/unf_add_pdb.py b/other_scripts/unf_add_pdb.py index 7f48843..9d98523 100644 --- a/other_scripts/unf_add_pdb.py +++ b/other_scripts/unf_add_pdb.py @@ -19,7 +19,13 @@ def parse_args(argv): def modify_unf(unfFile, pdbFile, molName, molPos, molRot): file = open(unfFile, "r") - parsedData = json.loads(file.read()) + fileContent = file.read() + jsonPartEndIdx = fileContent.find("#INCLUDED_FILE ") + if jsonPartEndIdx > -1: + jsonPart = fileContent[0:jsonPartEndIdx] + else: + jsonPart = fileContent + parsedData = json.loads(jsonPart) idCounter = parsedData["idCounter"] # Back slashes are replaced because they are escaped in JSON @@ -53,6 +59,8 @@ def modify_unf(unfFile, pdbFile, molName, molPos, molRot): with open(OUTPUT_FILE_NAME, "w") as outfile: json.dump(parsedData, outfile) + if jsonPartEndIdx > -1: + outfile.write(fileContent[jsonPartEndIdx:]) # After the JSON-based operations are finished, let's # append the PDB content to the end of the UNF file