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

In Chemfiles.jl output trajectory file has a compact format and thus loses precision #72

Open
Zeki-Zhang opened this issue Mar 8, 2023 · 1 comment

Comments

@Zeki-Zhang
Copy link

Zeki-Zhang commented Mar 8, 2023

This is the position matrix:

julia> xyz
3×5 Matrix{Float64}
  0.756778  -0.756778  0.0         3.81242    3.23075
  0.0        0.0       0.0         0.395536   0.109453
 -0.522494  -0.538596  0.0668583  -1.76606   -2.69293

It has full precision:

julia> xyz[:,1]
3-element Vector{Float64}:
  0.7567777232273633
  0.0
 -0.5224940120543102

After the position is written to a frame, the frame still has full precision:

julia> frame
Frame(Chemfiles.CxxPointer{Chemfiles.lib.CHFL_FRAME}(Ptr{Chemfiles.lib.CHFL_FRAME} @0x00000000053ec150, false))
julia> positions(frame)[:,1]
3-element Vector{Float64}:
  0.7567777232273633
  0.0
 -0.5224940120543102

But the file the trajectory is written to loses precision:

5
Properties=species:S:1:pos:R:3
H 0.756778 0 -0.522494
H -0.756778 0 -0.538596
O 0 0 0.0668583
O 3.81242 0.395536 -1.76606
C 3.23075 0.109453 -2.69293

@Luthaf
Copy link
Member

Luthaf commented Mar 8, 2023

Yes, the XYZ format is only written with ~6 digits of precision. Assuming the positions are in Angstroms, this should be more than enough for MD simulation trajectories.

For now, if you need perfect binary reproducibility, you should use a format that enables it, such as the NetCDF restart format (trajectory = Trajectory("filename.ncrst", "w")).

In the long term we could offer the user to select the precision to use when writing free-form text format such as xyz (but this does not guarantee perfect binary reproducibility) using the not yet implemented metadata for formats mechanism.

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

2 participants