vermouth-martinize icon indicating copy to clipboard operation
vermouth-martinize copied to clipboard

Problem with white-spaces when parsing citations in bibtex format

Open ricalessandri opened this issue 3 years ago • 3 comments

As brought up in https://github.com/marrink-lab/polyply_1.0/pull/123#issuecomment-804225680, I've encountered the following issue which @fgrunewald agreed is probably a bug. Namely,

Spaces after the = at least in the author field (didn't test all of them), as in:

@article{P3HT_M2,
  title={Bulk heterojunction morphologies with atomistic resolution from coarse-grain solvent evaporation simulations},
  author= {Alessandri, Riccardo and Uusitalo, Jaakko J and de Vries, Alex H and Havenith, Remco WA and Marrink, Siewert J},
  journal={Journal of the American Chemical Society},
  ....
  publisher={ACS Publications}
}

break the bibtex parsing. This is the error:

--- Logging error ---
Traceback (most recent call last):
  File "/Users/riccardo/miniconda3/envs/polyply/lib/python3.8/logging/__init__.py", line 1081, in emit
    msg = self.format(record)
  File "/Users/riccardo/miniconda3/envs/polyply/lib/python3.8/logging/__init__.py", line 925, in format
    return fmt.format(record)
  File "/Users/riccardo/miniconda3/envs/polyply/lib/python3.8/logging/__init__.py", line 664, in format
    record.message = record.getMessage()
  File "/Users/riccardo/miniconda3/envs/polyply/lib/python3.8/logging/__init__.py", line 367, in getMessage
    msg = str(self.msg)
  File "/Users/riccardo/ric.alessandri/Repos/polyply/vermouth-martinize/vermouth/log_helpers.py", line 36, in __str__
    return self.fmt.format(*self.args, **self.kwargs)
ValueError: expected '}' before end of string
Call stack:
  File "/Users/riccardo/miniconda3/envs/polyply/bin/polyply", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/Users/riccardo/ric.alessandri/Repos/polyply/polyply_1.0/bin/polyply", line 277, in <module>
    main()
  File "/Users/riccardo/ric.alessandri/Repos/polyply/polyply_1.0/bin/polyply", line 273, in main
    args.func(args)
  File "/Users/riccardo/ric.alessandri/Repos/polyply/polyply_1.0/polyply/src/gen_itp.py", line 92, in gen_itp
    LOGGER.info("Please cite: " + cite_string)
  File "/Users/riccardo/miniconda3/envs/polyply/lib/python3.8/logging/__init__.py", line 1794, in info
    self.log(INFO, msg, *args, **kwargs)
  File "/Users/riccardo/ric.alessandri/Repos/polyply/vermouth-martinize/vermouth/log_helpers.py", line 113, in log
    super().log(level, Message(msg, args, kwargs), **kwargs)
  File "/Users/riccardo/ric.alessandri/Repos/polyply/vermouth-martinize/vermouth/log_helpers.py", line 96, in log
    self.logger.log(level, msg, *args, **kwargs)
  File "/Users/riccardo/ric.alessandri/Repos/polyply/vermouth-martinize/vermouth/log_helpers.py", line 94, in log
    self.logger._log(level, msg, args, **kwargs)  # pylint: disable=protected-access
Message: "Please cite: {Alessandri, R; Uusitalo, J J; de Vries, A H; Havenith, R W; Marrink, S J;  Journal of the American Chemical Society 2017; 10.1021/jacs.6b11717".format(*(), **{'extra': {'type': 'general'}})
Arguments: ()

Spaces before the = seems to not matter.

ricalessandri avatar Mar 24 '21 00:03 ricalessandri

For future reference: pybtex python-bibtexparser

Or we roll our own (not my first choice) using either pyparsing or larkparser. But that'll also depend on what we want to use for the rest of the file formats.

See also #335

pckroon avatar Mar 24 '21 09:03 pckroon

We discussed both options. But last time I checked both repros were not maintained anymore, which was the reason for not using them in the first place. The latter one actually actively is looking for new maintainers.

fgrunewald avatar Mar 24 '21 10:03 fgrunewald

That discussion is lost to the mists of my memory :') But that's a good point, and something to take into account.

pckroon avatar Mar 24 '21 11:03 pckroon