1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use chiral_common::{Operator, OperatorOutput};
use chiral_operator::substructure::ob_ss_match::{Data, Output, OpenBabelSSMatching};

/// Computing Unit 
pub struct OpenBabelSSMatchingUnit {
    op: OpenBabelSSMatching,
    data: Data,
    output: Output
}

impl From<chiral_data::DocSMILES> for OpenBabelSSMatchingUnit {
    fn from(doc: chiral_data::DocSMILES) -> Self {
        let op = OpenBabelSSMatching::new();
        let data = Data::from(doc);
        Self { op, data, output: Output::new() }
    }
}

impl chiral_common::ComputingUnit for OpenBabelSSMatchingUnit {
    fn compute(&mut self, args: &Option<chiral_common::SerializedFormat>) {
        self.output.clear();

        if let Some(cu_input_str) = args {
            self.output = self.op.compute(cu_input_str, &self.data);
        } else {
            println!("No input!");
        }
    }

    fn serialize_output(&self) -> chiral_common::SerializedFormat {
        self.output.serialize()
    }

    fn output_len(&self) -> usize {
        self.output.len()
    }
}


#[cfg(test)]
mod tests {
    use super::*;
    use chiral_common::ComputingUnit;

    #[test]
    fn test_cu() {
        let doc_smiles = chiral_data::DocSMILES::dummy();
        let mut cu = OpenBabelSSMatchingUnit::from(doc_smiles);
        cu.compute(&Some(String::from("C(=O)O")));
        assert_eq!(cu.output_len(), 2); 
    }
}