project-gemmi / gemmi

macromolecular crystallography library and utilities
https://project-gemmi.github.io/
Mozilla Public License 2.0
232 stars 46 forks source link

calculating 1/d^2 is returning an array containing the same number. #339

Closed scatter3d closed 1 month ago

scatter3d commented 1 month ago

Screenshot 2024-10-17 at 13 39 52 Screenshot 2024-10-17 at 13 44 37 Screenshot 2024-10-17 at 15 58 26 Screenshot 2024-10-17 at 16 00 36

wojdyr commented 1 month ago

I can't reproduce it:

>>> cell = gemmi.UnitCell(100, 100, 100, 90, 90, 90)
>>> arr = numpy.array([[0,0,4], [0,0,8]])
>>> cell.calculate_1_d2_array(arr)
array([0.0016, 0.0064])

What gemmi version?

BTW, pasting code as text (code) is better than screenshots.

scatter3d commented 1 month ago

I'm running version 0.6.4. This was working as expected a few months ago.

for struct, dataset in m_datasets.items():
    # this is a gemmi mtz object
    mtz_obj = dataset.data.mtz
    # this is a gemmi miller array
    mil_array = mtz_obj.make_miller_array()
    print(mil_array)
    # this is a numpy array of 1/d^2
    x_1_d2_a = np.array(mtz_obj.cell.calculate_1_d2_array(mil_array))
    # this is another way to calculate the numpy array of 1/d^2
    x_1_d2_b = np.array(mtz_obj.make_1_d2_array())
    print(np.min((x_1_d2_a)))
    print(np.max((x_1_d2_a)))
    print(np.min((x_1_d2_b)))
    print(np.max((x_1_d2_b)))

[[ 0 0 4] [ 0 0 8] [ 0 0 12] ... [41 4 6] [41 5 0] [41 5 1]] 0.0007120317076972292 0.0007120317076972292 0.00071203173 0.00071203173

If I run your code snippet:

cell = gemmi.UnitCell(100, 100, 100, 90, 90, 90)
arr = np.array([[0,0,4], [0,0,8]])
cell.calculate_1_d2_array(arr)

I return, array([0.0016, 0.0016])

wojdyr commented 1 month ago

I checked gemmi 0.6.6 and 0.6.7 and I get expected results, i.e. array([0.0016, 0.0064]). You could try updating.

Actually, since it was working for you a few months ago (with the same gemmi version?), then I don't know what happened.

scatter3d commented 4 weeks ago

I recreated my python environment and updated to 0.6.7 - this resolved the issue.

Thanks!