bmrb-io / PyNMRSTAR

A Python module for reading, writing, and manipulating NMR-STAR files.
MIT License
28 stars 3 forks source link

Problem frame without tags won't print loop #99

Closed locsmith closed 3 years ago

locsmith commented 3 years ago

consider

from pynmrstar import Entry, Saveframe, Loop

def test_frame_no_loop():
    entry = Entry.from_scratch('ni')
    frame = Saveframe.from_scratch('spam', 'swallow')
    entry.add_saveframe(frame)
    frame.add_tag('parrot', 'swallow')
    loop = Loop.from_scratch('bedlvere')
    frame.add_loop(loop)
    loop.add_tag(['galahad','excalibur'])
    loop.add_data(['guinivere', 'excalibur'])

    print(entry)

if __name__ == '__main__':
    test_frame_no_loop()

this prints

data_ni

save_spam
   _swallow.parrot  swallow

   loop_
      _bedlvere.galahad
      _bedlvere.excalibur

     guinivere   excalibur    

   stop_

save_

but

from pynmrstar import Entry, Saveframe, Loop

def test_frame_no_loop():
    entry = Entry.from_scratch('ni')
    frame = Saveframe.from_scratch('spam', 'swallow')
    entry.add_saveframe(frame)
    # frame.add_tag('parrot', 'swallow')
    loop = Loop.from_scratch('bedlvere')
    frame.add_loop(loop)
    loop.add_tag(['galahad','excalibur'])
    loop.add_data(['guinivere', 'excalibur'])

    print(entry)

if __name__ == '__main__':
    test_frame_no_loop()

prints the text below missing the loop bedlevre

data_ni

save_spam

save_
jonwedell commented 3 years ago

This is definitely a bug, thanks for the report! It appears that when a saveframe with no tags exists, a shortcut in the string formatting logic is triggered which erroneously skips printing any loops contained within the saveframe.

I should be able to have a fix released by the end of the day, along with some other performance improvements and other optimizations that I haven't yet released.

varioustoxins commented 3 years ago

many thanks!

jonwedell commented 3 years ago

Just a heads up, I have some other changes I'm working to include in the next release as well, so this is taking me a bit longer than expected. I'll definitely have it out by the end of the week though.

jonwedell commented 3 years ago

This should be resolved. Please take a look at the change log, as some bigger behind-the-scenes changes have been made with this release which are unlikely to affect you, but it is probably worth checking.