Skip to content

Crystal matrix representations are shown too imprecisely #820

@dagewa

Description

@dagewa

The str representation of a Crystal shows matrix elements with "% 5.4f" format, like this:

>>> print(Crystal((0.02,0,0,0,0.02,0,0,0,0.02), "P1"))
Crystal:
    Unit cell: 50.000, 50.000, 50.000, 90.000, 90.000, 90.000
    Space group: P 1
    U matrix:  {{ 1.0000,  0.0000,  0.0000},
                { 0.0000,  1.0000,  0.0000},
                { 0.0000,  0.0000,  1.0000}}
    B matrix:  {{ 0.0200,  0.0000,  0.0000},
                {-0.0000,  0.0200,  0.0000},
                {-0.0000, -0.0000,  0.0200}}
    A = UB:    {{ 0.0200,  0.0000,  0.0000},
                { 0.0000,  0.0200,  0.0000},
                { 0.0000, -0.0000,  0.0200}}

If we construct a Crystal that differs from this by the least significant digit of the displayed A matrix values we get a rather notable change in the unit cell:

>>> print(Crystal((0.0201,0,0,0,0.0201,0,0,0,0.0201), "P1"))
Crystal:
    Unit cell: 49.751, 49.751, 49.751, 90.000, 90.000, 90.000
    Space group: P 1
    U matrix:  {{ 1.0000,  0.0000,  0.0000},
                { 0.0000,  1.0000,  0.0000},
                { 0.0000,  0.0000,  1.0000}}
    B matrix:  {{ 0.0201,  0.0000,  0.0000},
                {-0.0000,  0.0201,  0.0000},
                {-0.0000, -0.0000,  0.0201}}
    A = UB:    {{ 0.0201,  0.0000,  0.0000},
                { 0.0000,  0.0201,  0.0000},
                { 0.0000,  0.0000,  0.0201}}

Other tests show that a difference of 1 in the least significant digit of the "% 5.4f" representation of a rotation matrix appears to equate to approximately a 0.01° error, which isn't so bad. But imprecision in the B matrix is more problematic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions