Skip to content

Commit

Permalink
Added option -ij/--read_json to read receptor JSON file in mk_prepare…
Browse files Browse the repository at this point in the history
…_receptor.py
  • Loading branch information
rwxayheee committed Dec 11, 2024
1 parent 393372b commit ff891e7
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions meeko/cli/mk_prepare_receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def get_args():
"--read_with_prody",
metavar="MACROMOL_FILENAME",
help=f"reads PDB/mmCIF file with Prody{need_prody_msg}")
io_group.add_argument(
"-ij",
"--read_json",
metavar="MACROMOL_JSON_FILENAME",
help=f"reads receptor JSON file")
io_group.add_argument(
"-o",
"--output_basename",
Expand Down Expand Up @@ -216,17 +221,15 @@ def get_args():
)
args = parser.parse_args()

if args.read_pdb is None and args.read_with_prody is None:
parser.print_help()
msg = "Need input filename: use either -i/--read_with_prody or --read_pdb"
num_input_args = sum([args.read_pdb is not None, args.read_with_prody is not None, args.read_json is not None])
if num_input_args != 1:
msg = (
f"Need exactly one input argument: -i/--read_with_prody or --read_pdb or -ij/--read_json \n"
f"but {num_input_args} inputs were given. "
)
print(eol + msg)
sys.exit(2)

if args.read_pdb is not None and args.read_with_prody is not None:
msg = "Can't use both -i/--read_with_prody and --read_pdb"
print(eol + msg, file=sys.stderr)
sys.exit(2)

if args.write_gpf is not None and args.write_pdbqt is None:
# there's a few of places that assume this condition has been checked
msg = "--write_gpf requires --write_pdbqt because autogrid expects"
Expand Down Expand Up @@ -435,7 +438,17 @@ def main():
templates.add_json_file(fn)

# create polymers
if args.read_with_prody is not None:
if args.read_json is not None:
try:
with open(args.read_json, "r") as file:
json_string = file.read()
polymer = Polymer.from_json(json_string)

except Exception as e:
print(e)
sys.exit(1)

elif args.read_with_prody is not None:
if not _got_prody:
print(_prody_import_error, file=sys.stderr)
print("option --read_with_prody requires Prody, which is not installed.")
Expand Down

0 comments on commit ff891e7

Please sign in to comment.