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

[BUG] Unable to save to RST7 file #130

Closed
xiki-tempula opened this issue Jul 7, 2023 · 8 comments
Closed

[BUG] Unable to save to RST7 file #130

xiki-tempula opened this issue Jul 7, 2023 · 8 comments
Labels
exscientia Related to work with Exscientia

Comments

@xiki-tempula
Copy link
Contributor

Describe the bug
I have a Gromacs topology and coordinate file and I tried to save it as RST7 file

To Reproduce

In [1]: import BioSimSpace.Sandpit.Exscientia as BSS

In [7]: mol = BSS.IO.readMolecules(['test.top', 'test.gro'])

In [8]: BSS.IO.saveMolecules('test', mol, 'rst7')
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ /exs/shared/collaboration/teams/mdteam/envs/asfe/lib/python3.8/site-packages/BioSimSpace/Sandpit │
│ /Exscientia/IO/_io.py:757 in saveMolecules                                                       │
│                                                                                                  │
│    754 │   │   │   if _isVerbose():                                                              │
│    755 │   │   │   │   raise IOError(msg) from e                                                 │
│    756 │   │   │   else:                                                                         │
│ ❱  757 │   │   │   │   raise IOError(msg) from None                                              │
│    758 │                                                                                         │
│    759 │   # Return the list of files.                                                           │
│    760 │   return files                                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: Failed to save system to format: 'rst7'

Expected behavior
It writes

Input files
Archive.zip

(please complete the following information):

  • OS: Linux
  • Version of Python: 3.8
  • Version of BioSimSpace: [e.g. 2023.1, or latest dev release]
  • sire 2023.3.0 py38h3fd9d12_0 openbiosim/label/main
  • biosimspace 2023.3.0 py38_0 openbiosim/label/main
  • I confirm that I have checked this bug still exists in the latest released version of BioSimSpace: yes
@xiki-tempula xiki-tempula added the bug Something isn't working label Jul 7, 2023
@lohedges
Copy link
Contributor

lohedges commented Jul 7, 2023

This is because the GROMACS coordinates/velocities overflow the formatting restriction of the AMBER RST7 format. As always, you can get the full error message with BSS.setVerbose(True).

In [1]: import BioSimSpace as BSS


In [2]: BSS.setVerbose(True)

In [3]: s = BSS.IO.readMolecules("test.*")

In [4]: BSS.IO.saveMolecules("test", s, "rst7")
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/lester/Code/openbiosim/biosimspace/python/BioSimSpace/IO/_io.py:743 in saveMolecules       │
│                                                                                                  │
│    740 │   │   │   │   _os.rename(file, new_file)                                                │
│    741 │   │   │   │   file = [new_file]                                                         │
│    742 │   │   │   else:                                                                         │
│ ❱  743 │   │   │   │   file = _SireIO.MoleculeParser.save(                                       │
│    744 │   │   │   │   │   system._sire_object, filebase, _property_map                          │
│    745 │   │   │   │   )                                                                         │
│    746                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: SireError::io_error: Cannot write the (perhaps some of the ) files as the following errors occurred:
Failed to write the file '/home/lester/Downloads/Archive/test.rst7' using the parser for fileformat 'RST7'. Errors reported by the parser are:
Errors converting the system to a Amber Rst7 format...
Could not write the float at index 3138, value '-1203.8' into the specified format AmberFormat( 6 x float[width = 12, precision = 7] ).
Could not write the float at index 4691, value '-1163.52' into the specified format AmberFormat( 6 x float[width = 12, precision = 7] ). (call
sire.error.get_last_error_details() for more info)

The above exception was the direct cause of the following exception:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ /home/lester/Code/openbiosim/biosimspace/python/BioSimSpace/IO/_io.py:755 in saveMolecules       │
│                                                                                                  │
│    752 │   │   except Exception as e:                                                            │
│    753 │   │   │   msg = "Failed to save system to format: '%s'" % format                        │
│    754 │   │   │   if _isVerbose():                                                              │
│ ❱  755 │   │   │   │   raise IOError(msg) from e                                                 │
│    756 │   │   │   else:                                                                         │
│    757 │   │   │   │   raise IOError(msg) from None                                              │
│    758                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: Failed to save system to format: 'rst7'

@lohedges
Copy link
Contributor

lohedges commented Jul 7, 2023

In this case, it's the velocities, so the file can be written using:

In [5]: BSS.IO.saveMolecules("test", s, "rst7", property_map={"velocity":"null"})
Out[5]: ['/home/lester/Downloads/Archive/test.rst7']

@lohedges
Copy link
Contributor

lohedges commented Jul 7, 2023

Duplicate of michellab/BioSimSpace#404.

@lohedges lohedges added exscientia Related to work with Exscientia and removed bug Something isn't working labels Jul 7, 2023
@xiki-tempula
Copy link
Contributor Author

Why would the velocity be a problem in this case? It seems to me that the velocity is fine?

@chryswoods
Copy link
Contributor

The challenge is that rst7 is a fixed format file. Numbers are written using a 12.7 specifier, meaning there is only space for 4 columns before the decimal point, then a decimal point, then 7 columns after the decimal point.

The velocity "-1203.8" needs 5 columns before the decimal point, so it can't be written using the 12.7 format specifier used by rst7.

It would be better to use the binary Amber rst format if you want velocities. It is too easy for velocities to become larger than can be fitted into a rst7 file.

@xiki-tempula
Copy link
Contributor Author

@chryswoods Thanks. Do you know which atom is giving this velocity? I don't think any atom should have a velocity this high

@xiki-tempula
Copy link
Contributor Author

Ok, you are right.
Gromacs has a velocity of nm/ps
Amber has a velocity unit of Angstroms/20.455 ps
-5.88 nm/ps is -1203.8 Angstroms/20.455 ps

@chryswoods
Copy link
Contributor

chryswoods commented Jul 7, 2023

Yes - it is a challenge with rst7 formats. It is best treated as a "legacy" file format, and alternatives that store values as binary data should be preferred (e.g. rst, trr or xdr - note that xdr stores numbers at a much lower "compressed" precision)

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

No branches or pull requests

3 participants