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
53
54
55
56
57
58
59
60
61
//! OpenBabel Substructure Match
//! 

use serde::{Serialize, Deserialize};

/// Input
pub type Input = chiral_common::SMARTS;

/// Output
pub type MatchResult = Vec<Vec<i32>>;

#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
pub struct Output {
    pub results: Vec<(MatchResult, chiral_common::DatasetID)>
}

impl chiral_common::OperatorOutput for Output {
    fn blank() -> Self { Self { results: vec![] } }
     
    fn len(&self) -> usize { self.results.len() }

    fn clear(&mut self) {
        self.results.clear();
    }

    fn serialize(&self) -> String { serde_json::to_string(self).unwrap() }
    fn deserialize(content: &String) -> Self { serde_json::from_str(content).unwrap() }
}

/// Report
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Report {
    pub input: Input,
    pub dsk: chiral_common::kinds::Dataset,
    pub output: Output
}

impl chiral_common::OperatorReport for Report {
    fn serialize(&self) -> String { serde_json::to_string(self).unwrap() }

    fn deserialize(content: &String) -> Self { serde_json::from_str(content).unwrap() }

    fn extend(&mut self, other: Self) {
        self.output.results.extend(other.output.results);
    }

    fn print(&self) {
        println!(" Report of OpenBabel Substructure Search\n");
        println!(" Input");
        println!("\t smiles: {}", self.input);
        println!(" Operator");
        println!(" Dataset");
        println!("\t kind: {}", self.dsk);
        println!(" Output");
        for (matches, id) in self.output.results.iter() {
            println!("\t {id}\t {matches:?}");
        }
        println!("\t Count: {}", self.output.results.len());
    }
}