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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
use chrono::NaiveDate;
use std::{marker::PhantomData, str::FromStr};

#[derive(Debug)]
pub(crate) struct Continuation<T> {
    pub continuation: u32,
    pub remaining: String,
    pub phantom: PhantomData<T>,
}

///Holds name of an author utilized by multiple
///parsers such as author and journal author parsers
#[derive(Debug, Clone, PartialEq)]
pub struct Author(pub String);

/// Experimental techniques utilized in obtaining
/// structure data
#[derive(Debug, Clone, PartialEq)]
pub enum ExperimentalTechnique {
    XRayDiffraction,
    FiberDiffraction,
    NeutronDiffraction,
    ElectronCrystallography,
    ElectronMicroscopy,
    SolidStateNmr,
    SolutionNmr,
    SolutionScattering,
}

impl FromStr for ExperimentalTechnique {
    type Err = String;
    fn from_str(inp: &str) -> std::result::Result<Self, <Self as std::str::FromStr>::Err> {
        match inp {
            "X-RAY DIFFRACTION" => Ok(ExperimentalTechnique::XRayDiffraction),
            "FIBER DIFFRACTION" => Ok(ExperimentalTechnique::FiberDiffraction),
            "NEUTRON DIFFRACTION" => Ok(ExperimentalTechnique::NeutronDiffraction),
            "ELECTRON CRYSTALLOGRAPHY" => Ok(ExperimentalTechnique::ElectronCrystallography),
            "ELECTRON MICROSCOPY" => Ok(ExperimentalTechnique::ElectronMicroscopy),
            "SOLID-STATE NMR" => Ok(ExperimentalTechnique::SolidStateNmr),
            "SOLUTION NMR" => Ok(ExperimentalTechnique::SolutionNmr),
            "SOLUTION SCATTERING" => Ok(ExperimentalTechnique::SolutionScattering),
            _ => Err(format!("Unknown experimental result {}", inp)),
        }
    }
}

/// Represents keys of CMPND and SOURCE records
#[derive(Debug, PartialEq, Clone)]
pub enum Token {
    MoleculeId(u32),
    Molecule(String),
    Chain { identifiers: Vec<String> },
    Fragment(String),
    Synonym { synonyms: Vec<String> },
    Ec { commission_numbers: Vec<String> },
    Engineered(bool),
    Mutation(bool),
    OtherDetails(String),
    Synthetic(String),
    OrganismScientific(String),
    OrganismCommon { organisms: Vec<String> },
    OrganismTaxId { id: Vec<u32> },
    Strain(String),
    Variant(String),
    CellLine(String),
    Atcc(u32),
    Organ(String),
    Tissue(String),
    Cell(String),
    Organelle(String),
    Secretion(String),
    CellularLocation(String),
    Plasmid(String),
    Gene { gene: Vec<String> },
    ExpressionSystem(String),
    ExpressionSystemCommon { systems: Vec<String> },
    ExpressionSystemTaxId { id: Vec<u32> },
    ExpressionSystemStrain(String),
    ExpressionSystemVariant(String),
    ExpressionSystemCellLine(String),
    ExpressionSystemAtcc(u32),
    ExpressionSystemOrgan(String),
    ExpressionSystemTissue(String),
    ExpressionSystemCell(String),
    ExpressionSystemOrganelle(String),
    ExpressionSystemCellularLocation(String),
    ExpressionSystemVectorType(String),
    ExpressionSystemVector(String),
    ExpressionSystemPlasmid(String),
    ExpressionSystemGene(String),
}

/// Represents a modification made to this pdb entry.
#[derive(Debug, Clone)]
pub struct Revdat {
    pub modification_number: u32,
    pub modification_date: NaiveDate,
    pub idcode: String,
    pub modification_type: ModificationType,
    pub modification_detail: Vec<String>,
}

/// modification type of REVDAT record
#[derive(Debug, Clone)]
pub enum ModificationType {
    /// initial release of the entry. Indicated as 0
    /// in a REVDAT record
    InitialRelease,
    /// modifications other than initial release
    /// Indicated with 1 in a REVDAT record.
    OtherModification,
    /// modification type other than 0 or 1
    UnknownModification,
}

/// Serial Number Type of a JRNL REFN record
#[derive(Debug, Clone, PartialEq)]
pub enum SerialNumber {
    Issn,
    Essn,
}

/// contains HEADER recor information
#[derive(Debug, Clone)]
pub struct Header {
    pub classification: String,
    pub deposition_date: NaiveDate,
    pub id_code: String,
}

impl std::default::Default for Header {
    fn default() -> Self {
        Header {
            classification: String::default(),
            deposition_date: NaiveDate::from_ymd(1900, 1, 1),
            id_code: String::default(),
        }
    }
}

/// result of a TITLE record
#[derive(Debug, Clone, Default)]
pub struct Title {
    pub title: String,
}

/// contains pdb entry ids which removed
/// this one from PDB
#[derive(Debug, Clone)]
pub struct Obslte {
    pub replacement_date: NaiveDate,
    pub replacement_ids: Vec<String>,
}

impl std::default::Default for Obslte {
    fn default() -> Self {
        Obslte {
            replacement_date: NaiveDate::from_ymd(1900, 1, 1),
            replacement_ids: Vec::new(),
        }
    }
}

/// if this entry is a part of bigger
/// structure, this struct holds ids of other
/// parts of the bigger structure
#[derive(Debug, Clone, Default)]
pub struct Split {
    pub id_codes: Vec<String>,
}

/// fallacies of this entry
#[derive(Debug, Clone, Default)]
pub struct Caveat {
    pub id_code: String,
    pub comment: String,
}

/// pdb entry ids made obsolete by this entry
#[derive(Debug, Clone)]
pub struct Sprsde {
    pub sprsde_date: NaiveDate,
    pub id_code: String,
    pub superseeded: Vec<String>,
}

impl std::default::Default for Sprsde {
    fn default() -> Self {
        Sprsde {
            sprsde_date: NaiveDate::from_ymd(1900, 1, 1),
            superseeded: Vec::new(),
            id_code: String::default(),
        }
    }
}

#[derive(Debug, Clone, Default)]
pub struct Seqres {
    pub chain_id: Option<char>,
    pub residues: Vec<String>,
}

/// model type of the entry
#[derive(Debug, Clone, Default)]
pub struct Mdltyp {
    pub structural_annotation: Vec<String>,
}

/// collection of revisions
#[derive(Debug, Clone, Default)]
pub struct Revdats {
    pub revdat: Vec<Revdat>,
}

/// collection of tokens in a CMPND record
#[derive(Debug, Clone, Default)]
pub struct Cmpnd {
    pub tokens: Vec<Token>,
}

/// collection of tokens in a SOURCE record
#[derive(Debug, Clone, Default)]
pub struct Source {
    pub tokens: Vec<Token>,
}

/// keywords related to the entry
#[derive(Debug, Clone, Default)]
pub struct Keywds {
    pub keywords: Vec<String>,
}

/// author collection
#[derive(Debug, Clone, Default)]
pub struct Authors {
    pub authors: Vec<Author>,
}

/// journal author collection
#[derive(Debug, Clone, Default)]
pub struct JournalAuthors {
    pub authors: Vec<Author>,
}

/// journal title
#[derive(Debug, Clone, Default)]
pub struct JournalTitle {
    pub title: String,
}

/// journal editor collection
#[derive(Debug, Clone, Default)]
pub struct JournalEditors {
    pub name: Vec<Author>,
}

/// journal reference
#[derive(Debug, Clone, Default)]
pub struct JournalReference {
    pub publication_name: String,
    pub volume: Option<u32>,
    pub page: Option<u32>,
    pub year: Option<u32>,
}

/// journal Citation fields
#[derive(Debug, Clone, Default)]
pub struct JournalCitation {
    pub serial_type: Option<SerialNumber>,
    pub serial: Option<String>,
}

/// journal publication fields
#[derive(Debug, Clone, Default)]
pub struct JournalPublication {
    pub publication: String,
}

/// journal PubMed id
#[derive(Debug, Clone, Default)]
pub struct JournalPubMedId {
    pub id: u32,
}

/// digital object identifier of related e-pub
#[derive(Debug, Clone, Default)]
pub struct JournalDoi {
    pub id: String,
}

/// experimanetal techniques used for exploring
/// structure of this entry
#[derive(Debug, Clone, Default)]
pub struct Experimental {
    pub techniques: Vec<ExperimentalTechnique>,
}

/// number of models in this file
#[derive(Debug, Clone, Default)]
pub struct Nummdl {
    pub num: u32,
}

/// main enum unifying all record parser results.
/// all sub parsers return a cariant of this
#[derive(Debug, Clone)]
pub enum Record {
    Header(Header),
    Title(Title),
    Obslte(Obslte),
    Split(Split),
    Caveat(Caveat),
    Sprsde(Sprsde),
    Seqres(Seqres),
    Mdltyp(Mdltyp),
    Revdats(Revdats),
    Cmpnd(Cmpnd),
    Source(Source),
    Keywds(Keywds),
    JournalAuthors(JournalAuthors),
    JournalTitle(JournalTitle),
    JournalEditors(JournalEditors),
    JournalReference(JournalReference),
    JournalCitation(JournalCitation),
    JournalPublication(JournalPublication),
    JournalPubMedId(JournalPubMedId),
    JournalDoi(JournalDoi),
    Experimental(Experimental),
    Nummdl(Nummdl),
    Authors(Authors),
}