Skip to content

ForceField.to_file() writes files not ending with newline character #1761

Description

@mattwthompson

Describe the bug

POSIX-like systems expect files to end with the newline character (\n in Python). The toolkit does not do this. This leads to quirks with common tools, a simple case being that cating two files squishes them together.

To Reproduce.

In [1]: from openff.toolkit import ForceField

In [2]: ForceField().to_file("x.offxml")

In [3]: !cat x.offxml x.offxml
<?xml version="1.0" encoding="utf-8"?>
<SMIRNOFF version="0.3" aromaticity_model="OEAroModel_MDL"></SMIRNOFF><?xml version="1.0" encoding="utf-8"?>
<SMIRNOFF version="0.3" aromaticity_model="OEAroModel_MDL"></SMIRNOFF>
In [4]: ForceField().to_string()
Out[4]: '<?xml version="1.0" encoding="utf-8"?>\n<SMIRNOFF version="0.3" aromaticity_model="OEAroModel_MDL"></SMIRNOFF>'

Note the \n between lines but not at the end of the file. (Whether or not the newline should be added to the stringified version, it's not modified in XMLParameterIOHandler.to_file.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions