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
Inconsistent dtype for universe.dimensions #2190
Comments
The problem seems to be solvable by changing the dtype on and on with maybe some caution with |
With these changed it looks good. I also found these lines: https://github.com/MDAnalysis/mdanalysis/blob/develop/package/MDAnalysis/core/universe.py#L491 |
I'm pretty sure that we needed doubles at some point for triclinic pbc, so I think |
@richardjgowers AFAIK triclinic PBC are handled exclusively in You're right regarding precision problems with PBC transformations. Such problems can occur even with orthorombic boxes leading to atom positions ending up exactly on the upper box boundary instead of on the lower. The reason is that the box inverse is not precise enough in single precision. I encountered that when testing a wrap-unwrap-wrap cycle. |
Hmm yeah you're right, box is put in as a `coordinate*` which is float.
Maybe I'm remembering that the box inverse had to be double...
…On Wed, 30 Jan 2019 at 10:14 Johannes Zeman ***@***.***> wrote:
@richardjgowers <https://github.com/richardjgowers> AFAIK triclinic PBC
are handled exclusively in lib.distances, and that uses float32 boxes.
IIRC all routines in lib.distances use lib.util.check_box(), which does
the type conversion to float32 regardless of input dtype.
You're right regarding precision problems with PBC transformations. Such
problems can occur even with orthorombic boxes leading to atom positions
ending up exactly on the upper box boundary instead of on the lower. The
reason is that the box inverse is not precise enough in single precision. I
encountered that when testing a wrap-unwrap-wrap cycle.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2190 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AI0jB65XPreEzONBVi6MH-daAgyDdwtWks5vIcTpgaJpZM4aZ5p4>
.
|
|
@zemanj yeah it's probably just a non specific call to |
I think we need a decision here... Should we
If we opt for 2., I think we can close this. |
Opt 1 is easier to enforce: we can add a test in the base reader test class that asserts that |
@dimensions.setter
def dimensions(self, box):
self._unitcell[:] = box.astype(np.float32, copy=False) Ideally, we add a validation check here so that one cannot supply an invalid box. EDIT: |
A check for a valid box could look as follows:
Maybe one could also change the order of the tests and first check if a valid matrix representation exists, that might simplify things a bit. Moreover, if any of the values is changed, a corresponding warning should be raised. |
@jbarnoud I think maybe you could argue that round tripping via MDAnalysis shouldn't mangle precision, so if we get data as float64 we should keep it that way, but we don't do that for positions, so why for box? @zemanj enforcing option 1 seems possible like you've outlined. There's not many (any?) readers that redefine |
@zemanj using |
if that's the case, then we should not convert the dtype in the dimensions setter but in the getter.
We might run into problems with matrix representations if we choose |
@zemanj sure but I also don't like having it in the Maybe just hacking the setter/init to force a float32 dtype is a nice fix for today's needs. |
Expected behavior
The
dtype
of the dimensions for a standard (not in-memory) universe should be consistent with an in-memory universe. This is in particular important for the low-lewel C functions like themake_whole
function which will fail for the in-memory trajectory, since it requires a float.Actual behavior
The dimension of the standard universe representation is a
float
and the in-memory representation is adouble
.Code to reproduce the behavior
Currently version of MDAnalysis
I'm using Python 3.6 and the dev version of MDAnalysis on MacOS
The text was updated successfully, but these errors were encountered: