|
1 | 1 | #![allow(dead_code)] |
2 | | -use crate::reference_tables; |
3 | 2 | use crate::structs::hierarchy::*; |
4 | | -use crate::structs::*; |
5 | 3 | use crate::transformation::TransformationMatrix; |
| 4 | +use crate::{reference_tables, PDBError}; |
| 5 | +use crate::{structs::*, Context}; |
6 | 6 | use doc_cfg::doc_cfg; |
7 | 7 | #[cfg(feature = "rayon")] |
8 | 8 | use rayon::prelude::*; |
@@ -108,20 +108,39 @@ impl PDB { |
108 | 108 | /// * `remark_type` - the remark-type-number |
109 | 109 | /// * `remark_text` - the free line of text, containing the actual remark |
110 | 110 | /// |
111 | | - /// ## Panics |
112 | | - /// It panics if the text if too long, the text contains invalid characters or the remark-type-number is not valid (wwPDB v3.30). |
113 | | - pub fn add_remark(&mut self, remark_type: usize, remark_text: String) { |
114 | | - assert!(reference_tables::valid_remark_type_number(remark_type), "The given remark-type-number is not valid, see wwPDB v3.30 for valid remark-type-numbers"); |
115 | | - assert!( |
116 | | - valid_text(&remark_text), |
117 | | - "The given remark text contains invalid characters." |
118 | | - ); |
119 | | - // As the text can only contain ASCII len() on strings is fine (it returns the length in bytes) |
120 | | - if remark_text.len() > 70 { |
121 | | - println!("WARNING: The given remark text is too long, the maximal length is 68 characters, the given string is {} characters.", remark_text.len()); |
| 111 | + /// ## Fails |
| 112 | + /// It fails if the text if too long, the text contains invalid characters or the remark-type-number is not valid (wwPDB v3.30). |
| 113 | + pub fn add_remark(&mut self, remark_type: usize, remark_text: String) -> Result<(), PDBError> { |
| 114 | + let context = Context::show(format!("REMARK {:3} {}", remark_type, remark_text)); |
| 115 | + if !reference_tables::valid_remark_type_number(remark_type) { |
| 116 | + return Err(PDBError::new( |
| 117 | + crate::ErrorLevel::InvalidatingError, |
| 118 | + "Remark-type-number invalid", |
| 119 | + "The given remark-type-number is not valid, see wwPDB v3.30 for valid remark-type-numbers", |
| 120 | + context)); |
122 | 121 | } |
| 122 | + if !valid_text(&remark_text) { |
| 123 | + return Err(PDBError::new( |
| 124 | + crate::ErrorLevel::InvalidatingError, |
| 125 | + "Remark text invalid", |
| 126 | + "The given remark text contains invalid characters.", |
| 127 | + context, |
| 128 | + )); |
| 129 | + } |
| 130 | + |
| 131 | + // As the text can only contain ASCII len() on strings is fine (it returns the length in bytes) |
| 132 | + let res = if remark_text.len() > 70 { |
| 133 | + Err(PDBError::new( |
| 134 | + crate::ErrorLevel::LooseWarning, |
| 135 | + "Remark text too long", |
| 136 | + format!("The given remark text is too long, the maximal length is 68 characters, the given string is {} characters.", remark_text.len()), |
| 137 | + context)) |
| 138 | + } else { |
| 139 | + Ok(()) |
| 140 | + }; |
123 | 141 |
|
124 | 142 | self.remarks.push((remark_type, remark_text)); |
| 143 | + res |
125 | 144 | } |
126 | 145 |
|
127 | 146 | /// Delete the remarks matching the given predicate. |
|
0 commit comments