grisoniFr / scaffold_hopping_whales

Code to perform scaffold hopping and virtual screening using WHALES descriptors.
MIT License
31 stars 17 forks source link

ValueError: shapes (11,3) and (11,1) not aligned: 3 (dim 1) != 11 (dim 0) #3

Open alyferryhalo opened 10 months ago

alyferryhalo commented 10 months ago

While reproducing virtual_screening_pipeline, I faced with this error:

# compute descriptors as an array
whales_template, lab = do_whales.whales_from_mol(template)
# convert the arrays into a pandas dataframe
df_whales_template = pd.DataFrame(whales_template.reshape(-1, len(whales_template)),index=['template'],columns=lab)
df_whales_template
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [26], in <cell line: 2>()
      1 # compute descriptors as an array
----> 2 whales_template, lab = do_whales.whales_from_mol(template)
      3 # convert the arrays into a pandas dataframe
      4 df_whales_template = pd.DataFrame(whales_template.reshape(-1, len(whales_template)),index=['template'],columns=lab)

File ~/Documents/scaffold_hopping_whales/code/do_whales.py:40, in whales_from_mol(mol, charge_threshold, do_charge, property_name)
     37 coords, w, err = mol_properties.get_coordinates_and_prop(mol, property_name, do_charge)
     38 if err == 0:  # no errors in charge
     39     # does descriptors
---> 40     x, lab = do_lcd(coords, w, charge_threshold)
     41 else:
     42     x = np.full((33,), -999.0)

File ~/Documents/scaffold_hopping_whales/code/do_whales.py:87, in do_lcd(coords, w, thr)
     84 # applies sign
     85 res = apply_sign(w, res, thr)
---> 87 x_all, lab_all = extract_lcm(res)  # MDs and labels
     89 return x_all, lab_all

File ~/Documents/scaffold_hopping_whales/code/do_whales.py:132, in extract_lcm(data, start, end, step, lab_string)
    130 # Calculates percentiles according to the specified settings
    131 perc = range(start, end + 1, step)
--> 132 x = np.percentile(data, list(perc), axis=0)
    133 x = np.concatenate((x[:, 0], x[:, 1], x[:, 2]), axis=0)  # Flattens preserving the ordering
    135 # rounds the descriptors to the third decimal place

File <__array_function__ internals>:180, in percentile(*args, **kwargs)

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/lib/function_base.py:4166, in percentile(a, q, axis, out, overwrite_input, method, keepdims, interpolation)
   4164 if not _quantile_is_valid(q):
   4165     raise ValueError("Percentiles must be in the range [0, 100]")
-> 4166 return _quantile_unchecked(
   4167     a, q, axis, out, overwrite_input, method, keepdims)

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/lib/function_base.py:4424, in _quantile_unchecked(a, q, axis, out, overwrite_input, method, keepdims)
   4416 def _quantile_unchecked(a,
   4417                         q,
   4418                         axis=None,
   (...)
   4421                         method="linear",
   4422                         keepdims=False):
   4423     """Assumes that q is in [0, 1], and is an ndarray"""
-> 4424     r, k = _ureduce(a,
   4425                     func=_quantile_ureduce_func,
   4426                     q=q,
   4427                     axis=axis,
   4428                     out=out,
   4429                     overwrite_input=overwrite_input,
   4430                     method=method)
   4431     if keepdims:
   4432         return r.reshape(q.shape + k)

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/lib/function_base.py:3725, in _ureduce(a, func, **kwargs)
   3722 else:
   3723     keepdim = (1,) * a.ndim
-> 3725 r = func(a, **kwargs)
   3726 return r, keepdim

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/lib/function_base.py:4593, in _quantile_ureduce_func(a, q, axis, out, overwrite_input, method)
   4591     else:
   4592         arr = a.copy()
-> 4593 result = _quantile(arr,
   4594                    quantiles=q,
   4595                    axis=axis,
   4596                    method=method,
   4597                    out=out)
   4598 return result

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/lib/function_base.py:4710, in _quantile(arr, quantiles, axis, method, out)
   4708     result_shape = virtual_indexes.shape + (1,) * (arr.ndim - 1)
   4709     gamma = gamma.reshape(result_shape)
-> 4710     result = _lerp(previous,
   4711                    next,
   4712                    gamma,
   4713                    out=out)
   4714 if np.any(slices_having_nans):
   4715     if result.ndim == 0 and out is None:
   4716         # can't write to a scalar

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/lib/function_base.py:4529, in _lerp(a, b, t, out)
   4527 diff_b_a = subtract(b, a)
   4528 # asanyarray is a stop-gap until gh-13105
-> 4529 lerp_interpolation = asanyarray(add(a, diff_b_a * t, out=out))
   4530 subtract(b, diff_b_a * (1 - t), out=lerp_interpolation, where=t >= 0.5)
   4531 if lerp_interpolation.ndim == 0 and out is None:

File ~/opt/anaconda3/envs/td_test/lib/python3.8/site-packages/numpy/matrixlib/defmatrix.py:218, in matrix.__mul__(self, other)
    215 def __mul__(self, other):
    216     if isinstance(other, (N.ndarray, list, tuple)) :
    217         # This promotes 1-D vectors to row vectors
--> 218         return N.dot(self, asmatrix(other))
    219     if isscalar(other) or not hasattr(other, '__rmul__') :
    220         return N.dot(self, other)

File <__array_function__ internals>:180, in dot(*args, **kwargs)

ValueError: shapes (11,3) and (11,1) not aligned: 3 (dim 1) != 11 (dim 0)

I made no changes in code and tried a couple of different molecules but this error didn't disappear.