Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge of "Improve OBConversion::WriteString() and WriteFile() initialization" (adalke) #1923 #2176

Merged
merged 9 commits into from Apr 13, 2020

Conversation

baoilleach
Copy link
Member

@baoilleach baoilleach commented Apr 13, 2020

See discussion over at #1923. This is a merge of work by @adalke.

I needed to rebase, hence the separate PR. I also needed to update some of the tests for changes in the interim.

I've made an attempt to get the tests working on Windows (e.g. normalizing line endings), but I think that some of the tests genuinely fail on that platform, e.g. the binary file handling, but presumably these never worked in the first place.

I haven't made the change described by @fredrikw over at #1923. That test passes for me, so I've avoided making the change - I'm not sure why it's passing now.

adalke and others added 8 commits April 11, 2020 10:38
… otherwise the formats won't initialize correctly. (Issue openbabel#1922)

This commit includes a new test program which checks WriteString() and WriteFile() for most of the supported formats.

Without this patch, several of them will fail, and the FPS format will segfault.
…iple records.

My first patch set Index=1 in WriteFile() and WriteString() so that
the output format plugin could perform any initialization. This worked,
but there was still a problem with some formats when saving multiple
records, including the CML format.

The CML format uses <molecule> as the top-level element when there is
only one input molecule, and <cml> as the top-level element when there
are two or more molecules. The <cml> element contains a sequence of
<molecule> elements.

If Index==1 and IsLast()==true then it's a single-molecule file.
If Index==1 and IsLast()==false then it's a multi-molecule file.

However, OBConversion::Write() always called SetOneObjectOnly(),
which set Last=true, so the CML format always thought it was writing
a single-record output file.

The fix was to remove SetOneObjectOnly() from the Write() and
do more intialization in WriteFile() and WriteString(). Previously
Write() did Index++ *after* calling the format's WriteMolecule().
This was incorrect. It needs to be done *before*, so the value
of GetOutputIndex() matches the number of molecules which were
sent as output. (This is a better emulation of how Convert() works.)

This in turn means WriteFile() and WriteString() need to reset
Index to 0. They then call Write(), which increments Index, so
WriteMolecule() always sees Index=1 for the first molecule.
…nt changes to) the SVG writer to be consistent with the rest.
… anyone reading this: please avoid random number generators at all costs.)
@baoilleach
Copy link
Member Author

Aha - now it's failing in the tests. So I need to make @fredrikw's change after all. :-)

@baoilleach
Copy link
Member Author

Good to go, @ghutchis. The codacy warnings about subprocess refer to debug code that Andrew was using.

And just to add that I commented out the problematic pointcloud test mentioned by @fredrikw in the original PR. It uses a random number generator. sigh

@ghutchis
Copy link
Member

Just to check before I review later today - are there any API changes?

@baoilleach
Copy link
Member Author

After checking, I don't think so. There are only a few code changes. Is there any github action for api changes?

@ghutchis
Copy link
Member

The main question is whether headers are changed. I'll see if I can create an action using some of the existing tools, but for now it's human checks. 😄

@ghutchis ghutchis merged commit e71177c into openbabel:master Apr 13, 2020
@ghutchis
Copy link
Member

Looks like a good improvement, thanks for the work to both @adalke and @baoilleach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants