Is it OK if I request that both charges and formats plugin/feature types use JSON for communication with Avogadro?
Currently, the format used for the data passed between Avogadro and a plugin varies according to the type of the plugin/feature:
| Type | In | Out |
|---|---|---|
charges |
text or JSON | text |
energy |
nothing initially, then a stream of text | stream of text |
formats |
text | text |
generators |
JSON | JSON |
commands |
JSON | JSON |
For the energy type, I very much understand why the input and output are simple (values delimited by newline characters), because the exchange needs to be quick, and JSON parsing would add unnecessary overhead. Unless others feel differently, I’d say energy can just stay as it is.
For the other types though, I feel there would be significant benefits to consistently using a JSON object. For a start, the long list of subtle differences between the plugin types leads to extra complexity and confusion for plugin authors, as well as a larger documentation burden, and reducing the differences to what’s actually necessary would help that.
I’d note that the input format for the charges type is even inconsistent within the same type, depending on the calculation requested – --charges is run a simple string of a geometry in some format, while --potentials is already run with a JSON containing the geometry and an array of points. The author then has to deal with reading the geometry in separate ways. These could easily be unified.
Perhaps more importantly, it would be very hard to change the text-based I/O without breaking existing plugins, whereas the use of a JSON object makes it extensible, as the addition of new keys won’t cause problems.
If you’re not quite convinced of the point of this, one thing I think would be extremely useful to add in the future is to extend the ability of commands to send a pop-up message to the user to all types that use JSON using the message key, and to have generators send an error via error in the JSON rather than as plain text, and to extend that ability to the other types as well. Whether you’d actually like to implement that specific proposal is another question, but having I/O in most cases in JSON format would enable it.