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

Error in output when writing to .rst7 file #1604

Open
sbkoby23 opened this issue Mar 17, 2022 · 9 comments
Open

Error in output when writing to .rst7 file #1604

sbkoby23 opened this issue Mar 17, 2022 · 9 comments

Comments

@sbkoby23
Copy link

Hello,

I am trying to write a single frame to a .rst7 format and am getting several weird issues. I am attempting to run the following commands:
import pytraj as pt
traj = pt.load('complex0.rst7', 'complex0.prm7')
traj.save('complex_t.rst7', overwrite=True)

First of all, the output is saved as 'complex_t.rst7.1'. Second, the last line of the output file which specifies the box parameters is incorrect. It should read:
90.0000000 90.0000000 90.0000000 90.0000000 90.0000000 90.0000000
However, the output I am getting is the following:
0.0000000 90.0000000 90.0000000 90.0000000 90.0000000 90.0000000

Is there a work around for this issue?

@tuckerburgin
Copy link

Ah, I was just about to write a new issue of my own for exactly this problem (the errant 0 in the box line).

In my case the correct output is:

81.7526855 81.7526855 81.7526855 90.0000000 90.0000000 90.0000000

But I'm getting:

0.0000000 81.7526852 81.7526852 90.0000000 90.0000000 90.0000000

That is to say, this isn't a matter of the leading '9' being cut off in your case, it really is being set to zero.

I'm not sure when this started to be an issue but I know for sure it hasn't always been; I found this bug after running old code that used to work fine and getting an error that wasn't there before that I ended up tracing back to this. I'm currently working with version 2.0.5.

For now, I've just switched my workflow to mdtraj, but it's quite a bit slower for this particular task, so I'd love a pytraj workaround or fix...

By the way, the name having '.1' appended to it is a separate issue having to do with the 'multi' kwarg in traj.save (and related methods). That particular issue is much older... I've taken to including a step to rename the output file to remove the '.1' in all my code, but obviously that shouldn't be necessary.

@drroe
Copy link
Contributor

drroe commented May 26, 2022

For the sake of troubleshooting, can you try to run this with cpptraj? E.g.

cpptraj -p complex0.prm7 -y complex0.rst7 -x complex0.rst7

or using the input

parm complex0.prm7
trajin complex0.rst7
trajout complex0.rst7

and see if you get the same behavior?

@hainm
Copy link
Contributor

hainm commented May 26, 2022

Can you please upload dummy file examples to reproduce?

How did you get pytraj?

@tuckerburgin
Copy link

Passing the broken restart file through cpptraj as suggested did not work (I think that's what you wanted me to do, right?) It gave the following output after trajin:

Warning: Box information present in trajectory but lengths are zero.
Warning: DISABLING BOX in topology 'vmd-md-b.prmtop'!

The output then has the exact same box line as the input (in fact the input and output files are exactly identical).

Sorry for not including files to reproduce with before:

dummy_files.zip

I get this issue by simply loading these two files together and then saving it as a restart file. It seems not to be dependent on the style I use when loading or saving, but for example this works (as in, this reproduces the problem):

traj = pytraj.load('minimization.rst7_0_ts_guess_960.0.rst7_7_835_fwd.rst7','vmd-md-b.prmtop')
pytraj.write_traj('test.rst7', traj, format='rst7', frame_indices=[0], options='multi', overwrite=True, velocity=False)

However, when I tried to reproduce this issue on my personal (MacOS) machine instead of on the remote Linux machine I was originally working on, I could not; the box line is written correctly, despite using the exact same input files, commands, and version of pytraj. Besides the OS, the only difference that comes to mind between these two environments is that the one that works has a direct installation of cpptraj (Amber is not installed) whereas the one that's not working has cpptraj through an installation of Amber 20. Both versions of cpptraj are 4.25.6. In both cases I believe I installed pytraj through conda. It's been a long time since I did either of these installations, and I was not the one who did the Amber installation. Sorry I can't be more specific.

@hainm
Copy link
Contributor

hainm commented May 26, 2022

Dear @tuckerburgin
Thank you for your detail report. I can not reproduce the issue the pytraj in ambertools 22 (via conda install)

Using my macbook:

In [7]: traj = traj = pt.load('./minimization.rst7_0_ts_guess_960.0.rst7_7_835_init.rst7', 'vmd-md-b.prmtop')

In [8]: traj.save('complex_t.rst7', overwrite=True)

In [9]: !tail -1 complex_t.rst7.1
  81.7526028  81.7526028  81.7526028  90.0000000  90.0000000  90.0000000

In [10]: !tail -1 minimization.rst7_0_ts_guess_960.0.rst7_7_835_init.rst7
  81.7526028  81.7526028  81.7526028  90.0000000  90.0000000  90.0000000

Is there a work around for this issue?

So the best workaround is to install ambertools v22 that includes pytraj. It's super easy to install ambertools via conda now (https://ambermd.org/GetAmber.php)

conda install -c conda-forge ambertools=22 compilers

PS: I don't have time to make a stand alone release for pytraj nowadays, so ambertools is the best source.

@hainm
Copy link
Contributor

hainm commented May 26, 2022

ah, I realized @sbkoby23 and @tuckerburgin are two different persons. I apologize to not reply to @sbkoby23 sooner.

@sbkoby23 Please read my comment above. Thanks.

@hainm
Copy link
Contributor

hainm commented May 26, 2022

By the way, the name having '.1' appended to it is a separate issue having to do with the 'multi' kwarg in traj.save (and related methods). That particular issue is much older... I've taken to including a step to rename the output file to remove the '.1' in all my code, but obviously that shouldn't be necessary.

  • if not using multi, all the files will be appended into a single file (I guess).
  • If using multi, separate files will be written. If having more than 1 frame, we will have more than file, and thus the .1 is the solution. Can you please use keepext option too?
    pt.write_traj(basename, traj, overwrite=True, options="multi keepext")

So the file(s) will be <filename>.<ext>.rst7 rather than <filename>.rst7.<ext>

@drroe
Copy link
Contributor

drroe commented May 27, 2022

@tuckerburgin I also cannot reproduce the issue with your files. What version of cpptraj are you using? If possible, can you try the latest GitHub version (6.6.1) and see if the issue persists on your platform?

@drroe
Copy link
Contributor

drroe commented May 27, 2022

if not using multi, all the files will be appended into a single file (I guess).

So for cpptraj, Amber restart files do not have the multi option, because the Amber restart format only supports 1 structure per file. If there is only 1 frame to write, cpptraj does not append the frame number, otherwise it has to in order to keep the files separate. The keepext option will make it so that the number comes before the extension, which is useful for programs like VMD which base format detection on filename extension.

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

No branches or pull requests

4 participants