marrink-lab / polyply_1.0

Generate input parameters and coordinates for atomistic and coarse-grained simulations of polymers, ssDNA, and carbohydrates
Apache License 2.0
122 stars 21 forks source link

Add error message for missing `-seq` #295

Closed ricalessandri closed 1 year ago

ricalessandri commented 1 year ago

Currently, one gets the following error message if one forgets the -seq command line argument when using polyply gen_seq:

Traceback (most recent call last):
  File "/Users/alessandri/miniconda3/envs/polyply/bin/polyply", line 258, in <module>
    main()
  File "/Users/alessandri/miniconda3/envs/polyply/bin/polyply", line 254, in main
    subprogram(**args_dict)
  File "/Users/alessandri/miniconda3/envs/polyply/lib/python3.10/site-packages/polyply/src/gen_seq.py", line 377, in gen_seq
    seq_graph = generate_seq_graph(seq, macros, connects)
  File "/Users/alessandri/miniconda3/envs/polyply/lib/python3.10/site-packages/polyply/src/gen_seq.py", line 229, in generate_seq_graph
    for idx, macro_name in enumerate(sequence):
TypeError: 'NoneType' object is not iterable

which is kinda criptic.

With this PR, one gets the following error message:

Traceback (most recent call last):
  File "/Users/alessandri/miniconda3/envs/polyply/bin/polyply", line 258, in <module>
    main()
  File "/Users/alessandri/miniconda3/envs/polyply/bin/polyply", line 254, in main
    subprogram(**args_dict)
  File "/Users/alessandri/miniconda3/envs/polyply/lib/python3.10/site-packages/polyply/src/gen_seq.py", line 381, in gen_seq
    seq_graph = generate_seq_graph(seq, macros, connects)
  File "/Users/alessandri/miniconda3/envs/polyply/lib/python3.10/site-packages/polyply/src/gen_seq.py", line 231, in generate_seq_graph
    raise IOError(msg)
OSError: `sequence` is empty; maybe you forgot to pass the -seq command to `polyply gen_seq`?

which I think would help the user better. What do you think?

I coded this up quickly by looking at other error messages but let me know if I did something wrong. I tested the code and the message is printed out when it should. Please also suggest how to improve the message if needed.

fgrunewald commented 1 year ago

@ricalessandri thanks for the PR. For sure it is useful to add a legible error message for that piece of code. I would add one additional thing. In the following line in bin/polyply add required=True. Then you must pass a sequence to polyply gen_seq.

https://github.com/marrink-lab/polyply_1.0/blob/8be57193ccd285d30837ac2521f9cc54732730ca/bin/polyply#L198

Since it then is impossible to not have -seq, we should slightly rephrase the original error message to something like sequence is empty; you need to provide a sequence to gen_seq

Feel free to rephrase though.

fgrunewald commented 1 year ago

solved with #312