Skip to main content

gammalooprs/graph/
cuts.rs

1use bincode_trait_derive::{Decode, Encode};
2use gammaloop_tracing_filter::LogMessage;
3use itertools::Itertools;
4use linnet::half_edge::subgraph::{SuBitGraph, SubSetLike};
5
6use crate::cff::{CutCFFIndex, esurface::RaisedEsurfaceGroup};
7
8#[derive(Debug, Clone, Encode, Decode, PartialEq, Hash, Eq, PartialOrd, Ord)]
9pub struct CutSet {
10    pub residue_selector: ResidueSelector,
11    pub union: SuBitGraph,
12    pub canonicalize_external_shifts: bool,
13}
14
15impl LogMessage for CutSet {
16    fn log_display(&self) -> String {
17        format!("CutSet: union={}", self.union.string_label())
18    }
19}
20
21#[derive(Debug, Clone, Encode, Decode, PartialEq, Hash, Eq, PartialOrd, Ord)]
22pub struct ResidueSelector {
23    pub lu_cut: Option<RaisedEsurfaceGroup>,
24    pub left_th_cut: Option<RaisedEsurfaceGroup>,
25    pub right_th_cut: Option<RaisedEsurfaceGroup>,
26}
27
28impl ResidueSelector {
29    pub fn generate_allowed_keys(&self) -> Vec<CutCFFIndex> {
30        let allowed_keys = vec![CutCFFIndex::new_all_none()];
31        allowed_keys
32            .into_iter()
33            .flat_map(|index| {
34                if let Some(lu_cut) = &self.lu_cut {
35                    (1..=lu_cut.max_occurence)
36                        .map(|lu_cut_index| {
37                            let mut new_index = index;
38                            new_index.lu_cut_order = Some(lu_cut_index);
39                            new_index
40                        })
41                        .collect_vec()
42                } else {
43                    vec![index]
44                }
45            })
46            .flat_map(|index| {
47                if let Some(left_th_cut) = &self.left_th_cut {
48                    (1..=left_th_cut.max_occurence)
49                        .map(|left_th_cut_index| {
50                            let mut new_index = index;
51                            new_index.left_threshold_order = Some(left_th_cut_index);
52                            new_index
53                        })
54                        .collect_vec()
55                } else {
56                    vec![index]
57                }
58            })
59            .flat_map(|index| {
60                if let Some(right_th_cut) = &self.right_th_cut {
61                    (1..=right_th_cut.max_occurence)
62                        .map(|right_th_cut_index| {
63                            let mut new_index = index;
64                            new_index.right_threshold_order = Some(right_th_cut_index);
65                            new_index
66                        })
67                        .collect_vec()
68                } else {
69                    vec![index]
70                }
71            })
72            .collect()
73    }
74}
75
76impl CutSet {
77    pub fn empty(size: usize) -> Self {
78        CutSet {
79            residue_selector: ResidueSelector {
80                lu_cut: None,
81                left_th_cut: None,
82                right_th_cut: None,
83            },
84            union: SuBitGraph::empty(size),
85            canonicalize_external_shifts: false,
86        }
87    }
88}