openbabel / openbabel

Open Babel is a chemical toolbox designed to speak the many languages of chemical data.
http://openbabel.org/
GNU General Public License v2.0
1.02k stars 404 forks source link

Title in molfile should be limited to 80 char #2112

Open baoilleach opened 4 years ago

baoilleach commented 4 years ago

With OB 3.0, it's possible to write out a molfile where the title has more than 80 characters. The ctfile.pdf spec states that it should be limited to 80:

Molecule name. This line is unformatted, but like all other lines in a molfile cannot
extend beyond column 80. If no name is available, a blank line must be present.

This might be one of those cases where we allow this as an option (for those programs that accept titles of this length). However, the default should be to write files that conform to the spec.

Here's an example:

from openbabel import pybel
mol = pybel.readstring("smi", "C")
mol.title = "*"*100

digits = "0123456789"
mol.title = digits * 10
print(mol.write("mol"))

...the full title of 100 characters is written to the molfile.

ghutchis commented 4 years ago

I'd think the "easy" solution would be to save long titles as a property if they occur. (On read, if the title is 80 characters and matches the first 80 characters of the title property, they can be merged to ensure round-trip success.)