unitaryfund / aquapointer

Package applying quantum algorithms to find locations of water molecules in a protein cavity
GNU General Public License v3.0
8 stars 1 forks source link

Arbitrary plane slicer bug #67

Closed darcangelomauro closed 6 months ago

darcangelomauro commented 6 months ago

When taking slices of the 3d-rism density along planes which are not parallel to the x,y,z axes, occasionally it can happen that the slice turns out empty.

The bug can be reproduced by running this notebook, section "slice along skewed plane (empty slices error)". Be mindful of the fact that the first bug presented in the notebook, section "slice along y axis: error happening", has been solved with #65.

The notebook takes the DNA 3D-RISM file and the file containing the position of some known water molecules:

# load density
rism = Grid(rism_file(dna_folder)) 

# load first water network
lines = []
with open(water_file(dna_folder, 1,), 'r') as file_in:
    for line in file_in:
        lines.append(line)
waters = []
for j in range(2, len(lines)):
    ls = lines[j].split()
    coords = np.array([float(ls[6]), float(ls[7]), float(ls[8])])
    waters.append(coords)
waters = np.array(waters)

The water molecule positions are used to define a vector N which identifies a certain direction in space (which should be interpreted as the normal to the plane defined by the water molecules):

# find normal to plane defined by the three water molecules
AB = waters[1]-waters[0]
AC = waters[2]-waters[0]
N = np.cross(AB, AC)
N /= np.linalg.norm(N)

Several planes are then defined by taking the water molecule positions, waters, and moving an amount t along the normal N:

slicing_planes = []
for t in t_values:
    slicing_planes.append(
        waters + t*N
    )

The slicer is then called:

canvases = density_slices_by_planes(rism, slicing_planes)

But upon drawing the resulting canvases, they turn out empty.

Misty-W commented 6 months ago

hi @Roland-djee, as discussed with @darcangelomauro yesterday, I have isolated the bug to _shape_slice() in slicing.py and am working on a fix to correct a wrong assumption about the projected points that had resulted in a 1D array instead of a 2D array.

RolandMacDoland commented 6 months ago

hi @Roland-djee, as discussed with @darcangelomauro yesterday, I have isolated the bug to _shape_slice() in slicing.py and am working on a fix to correct a wrong assumption about the projected points that had resulted in a 1D array instead of a 2D array.

Hey @Misty-W sounds good. Do you need anything from me at this point ? Happy to help here.

Misty-W commented 6 months ago

Hey @Misty-W sounds good. Do you need anything from me at this point ? Happy to help here.

Thanks @Roland-djee, I fixed it already, just waiting for @FarLab's approval to merge.