nom_pdb/title_section/header.rs
1// Copyright (c) 2020 Tianyi Shi
2//
3// This software is released under the MIT License.
4// https://opensource.org/licenses/MIT
5
6//! Parsing the [Header](http://www.wwpdb.org/documentation/file-format-content/format33/sect2.html#HEADER).
7//! The HEADER record uniquely identifies a PDB entry through the idCode field.
8//! This record also provides a classification for the entry. Finally, it contains
9//! the date when the coordinates were deposited to the PDB archive.
10//!
11//! # Record Format
12//!
13//! | COLUMNS | DATA TYPE | FIELD | DEFINITION |
14//! |---------|--------------|----------------|-------------------------------------------|
15//! | 1 - 6 | Record name | HEADER | |
16//! | 11 - 50 | String(40)/`String` | `classification` | Classifies the molecule(s). |
17//! | 51 - 59 | Date/`chrono::NaiveDate` | `deposition_date` | Deposition date. This is the date the coordinates were received at the PDB. |
18//! | 63 - 66 | IDcode/`String` | `id_code` | This identifier is unique within the PDB. |
19use crate::common::parser::{parse_date, take_trim_own, FieldParser};
20use crate::types::*;
21use nom::{bytes::complete::take, character::complete::multispace1, IResult};
22
23pub struct HeaderParser;
24
25impl FieldParser for HeaderParser {
26 type Output = Header;
27 fn parse(inp: &[u8]) -> IResult<&[u8], Self::Output> {
28 let inp = &inp[4..];
29 let (inp, classification) = unsafe { take_trim_own(inp, 40usize)? };
30 let (inp, deposition_date) = parse_date(inp)?;
31 let inp = &inp[3..];
32 let (inp, id_code) = take(4usize)(inp)?;
33 let (inp, _) = multispace1(inp)?;
34 Ok((
35 inp,
36 Header {
37 classification,
38 deposition_date,
39 id_code: unsafe { std::str::from_utf8_unchecked(id_code).to_owned() },
40 },
41 ))
42 }
43}
44
45pub struct HeaderParserStreaming;
46pub struct HeaderParserParallel;
47
48// #[cfg(test)]
49// mod tests {
50// use super::*;
51// use chrono::NaiveDate;
52// #[test]
53// fn test_parse_header() {
54// let i = " VIRAL PROTEIN 27-MAR-98 1A8O \nTITLE HIV CAPSID C-TERMINAL DOMAIN ";
55// let (i, r) = HeaderParser::parse(i).unwrap();
56// assert_eq!(
57// i.to_owned(),
58// "TITLE HIV CAPSID C-TERMINAL DOMAIN "
59// .to_owned()
60// );
61// assert_eq!(
62// r,
63// Header {
64// classification: "VIRAL PROTEIN".to_owned(),
65// deposition_date: NaiveDate::from_ymd(1998i32, 3u32, 27u32),
66// id_code: "1A8O".to_owned()
67// }
68// )
69// }
70// }