|
13 | 13 | // limitations under the license. |
14 | 14 |
|
15 | 15 | use crate::Vector3; |
16 | | -use anyhow::{bail, Context, Result}; |
| 16 | +use anyhow::{anyhow, Context, Result}; |
17 | 17 | use faunus::topology::{AtomKind, FindByName}; |
18 | 18 | use itertools::Itertools; |
19 | 19 | use nalgebra::Matrix3; |
@@ -319,14 +319,14 @@ impl Display for Structure { |
319 | 319 |
|
320 | 320 | /// Parse a single line from an XYZ file |
321 | 321 | fn from_xyz_line(line: &str) -> Result<(String, Vector3)> { |
322 | | - if let Some([name, x, y, z]) = line.split_whitespace().collect_array() { |
323 | | - Ok(( |
324 | | - name.to_string(), |
325 | | - Vector3::new(x.parse()?, y.parse()?, z.parse()?), |
326 | | - )) |
327 | | - } else { |
328 | | - bail!("'name x y z' expected in XYZ record: {}", line); |
329 | | - } |
| 322 | + let [name, x, y, z] = line |
| 323 | + .split_whitespace() |
| 324 | + .collect_array() |
| 325 | + .ok_or_else(|| anyhow!("Invalid XYZ record: {}", line))?; |
| 326 | + Ok(( |
| 327 | + name.to_string(), |
| 328 | + Vector3::new(x.parse()?, y.parse()?, z.parse()?), |
| 329 | + )) |
330 | 330 | } |
331 | 331 |
|
332 | 332 | /// Write single ATOM record in PQR file stream |
@@ -357,18 +357,17 @@ pub struct AminoAcidModelRecord { |
357 | 357 |
|
358 | 358 | impl AminoAcidModelRecord { |
359 | 359 | pub fn from_line(line: &str) -> Result<Self> { |
360 | | - if let Some([name, _, x, y, z, charge, mass, radius]) = |
361 | | - line.split_whitespace().collect_array() |
362 | | - { |
363 | | - Ok(Self { |
364 | | - name: name.to_string(), |
365 | | - pos: Vector3::new(x.parse()?, y.parse()?, z.parse()?), |
366 | | - charge: charge.parse()?, |
367 | | - mass: mass.parse()?, |
368 | | - radius: radius.parse()?, |
369 | | - }) |
370 | | - } else { |
371 | | - bail!("Invalid AAM record: {}", line); |
372 | | - } |
| 360 | + let [name, _, x, y, z, charge, mass, radius] = line |
| 361 | + .split_whitespace() |
| 362 | + .collect_array() |
| 363 | + .ok_or_else(|| anyhow!("Invalid AAM record: {}", line))?; |
| 364 | + |
| 365 | + Ok(Self { |
| 366 | + name: name.to_string(), |
| 367 | + pos: Vector3::new(x.parse()?, y.parse()?, z.parse()?), |
| 368 | + charge: charge.parse()?, |
| 369 | + mass: mass.parse()?, |
| 370 | + radius: radius.parse()?, |
| 371 | + }) |
373 | 372 | } |
374 | 373 | } |
0 commit comments