def gen_cosine_matrix(self):
     query = self.ions_list()
     try:
         cosine_matrix = compute_distance_matrix(
             [fms.parent_mass for fms in query],
             [
                 filter_data(
                     np.array(
                         fms.fragmolspectrum_set.get(energy=1).spectrum),
                     fms.parent_mass,
                     0.0,
                     0.0,
                     0.0,
                     0,
                 ) for fms in query
             ],
             0.002,
             5,
         )
         cosine_matrix = Array2DModel.objects.create(
             value=cosine_matrix.tolist())
         self.cosine_matrix = cosine_matrix
         self.save()
     except Exception as ex:
         pass
         # raise ex
     return self
 def get_cosine(self, params):
     parent_mass = [p[0].parent_mass for p in params]
     spectrum = [
         p[0].fragmolspectrum_set.get(energy=p[1]).spectrum for p in params
     ]
     # filter_data(data, mz_parent, min_intensity, parent_filter_tolerance, matched_peaks_window,min_matched_peaks_search)
     spectrum = [
         filter_data(
             np.array(spectrum[i]),
             parent_mass[i],
             self.frag_compare_conf.filter_min_intensity,
             self.frag_compare_conf.filter_parent_filter_tolerance,
             self.frag_compare_conf.filter_matched_peaks_window,
             self.frag_compare_conf.filter_min_matched_peaks_search,
         ) for i in range(2)
     ]
     # cosine_score(spectrum1_mz, spectrum1_data, spectrum2_mz, spectrum2_data, mz_tolerance, min_matched_peaks)
     return cosine_score(
         parent_mass[0],
         spectrum[0],
         parent_mass[1],
         spectrum[1],
         self.frag_compare_conf.cosine_mz_tolerance,
         self.frag_compare_conf.cosine_min_matched_peaks,
     )