diff --git a/README.md b/README.md index fce6221..21014f7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ | (Extended) XYZ | .xyz | | PDB | .pdb | | SDF | .sdf | +| XTC | .xtc | This project is a Rust port of [`chemfiles`](https://github.com/chemfiles/chemfiles/), a modern C++ library with the same purpose. diff --git a/src/format.rs b/src/format.rs index b3380be..877da69 100644 --- a/src/format.rs +++ b/src/format.rs @@ -7,6 +7,7 @@ use crate::error::CError; use crate::formats::pdb::PDBFormat; use crate::formats::sdf::SDFFormat; +use crate::formats::xtc::XTCFormat; use crate::formats::xyz::XYZFormat; use crate::frame::Frame; use std::fs::File; @@ -18,6 +19,7 @@ use std::path::Path; /// - `XYZ`: plain-text XYZ coordinate format. /// - `PDB`: Protein Data Bank format. /// - `SDF`: Structure Data File format. +/// - `XTC`: GROMACS' portable format for trajectories. /// - `Guess`: autodetect format from file extension. #[derive(Clone, Copy)] pub enum TextFormat { @@ -27,6 +29,8 @@ pub enum TextFormat { PDB, /// SDF file format. SDF, + /// XTC file format. + XTC, /// Automatically detect format from file extension. Guess, } @@ -39,6 +43,8 @@ pub enum Format<'a> { PDB(PDBFormat<'a>), /// Handler for the SDF format. SDF(SDFFormat), + /// Handler for the XTC format. + XTC(XTCFormat), } impl Format<'_> { @@ -54,6 +60,7 @@ impl Format<'_> { "xyz" => Ok(Format::XYZ(XYZFormat)), "pdb" => Ok(Format::PDB(PDBFormat::new())), "sdf" => Ok(Format::SDF(SDFFormat)), + "xtc" => Ok(Format::XTC(XTCFormat)), _ => Err(CError::GenericError("unknown file format".to_string())), } } @@ -69,6 +76,7 @@ impl Format<'_> { TextFormat::XYZ => Ok(Format::XYZ(XYZFormat)), TextFormat::PDB => Ok(Format::PDB(PDBFormat::new())), TextFormat::SDF => Ok(Format::SDF(SDFFormat)), + TextFormat::XTC => Ok(Format::XTC(XTCFormat)), TextFormat::Guess => Self::new(path), } } @@ -120,6 +128,7 @@ impl FileFormat for Format<'_> { Format::XYZ(format) => format.read_next(reader), Format::PDB(format) => format.read_next(reader), Format::SDF(format) => format.read_next(reader), + Format::XTC(format) => format.read_next(reader), } } @@ -128,6 +137,7 @@ impl FileFormat for Format<'_> { Format::XYZ(format) => format.read(reader), Format::PDB(format) => format.read(reader), Format::SDF(format) => format.read(reader), + Format::XTC(format) => format.read(reader), } } @@ -136,6 +146,7 @@ impl FileFormat for Format<'_> { Format::XYZ(format) => format.write_next(writer, frame), Format::PDB(format) => format.write_next(writer, frame), Format::SDF(format) => format.write_next(writer, frame), + Format::XTC(format) => format.write_next(writer, frame), } } @@ -144,6 +155,7 @@ impl FileFormat for Format<'_> { Format::XYZ(format) => format.forward(reader), Format::PDB(format) => format.forward(reader), Format::SDF(format) => format.forward(reader), + Format::XTC(format) => format.forward(reader), } } @@ -152,6 +164,7 @@ impl FileFormat for Format<'_> { Format::XYZ(format) => format.finalize(writer), Format::PDB(format) => format.finalize(writer), Format::SDF(format) => format.finalize(writer), + Format::XTC(format) => format.finalize(writer), } } } diff --git a/src/formats.rs b/src/formats.rs index b38f7ff..c425c7e 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -1,4 +1,5 @@ pub mod pdb; pub mod pdb_connectivity; pub mod sdf; +pub mod xtc; pub mod xyz; diff --git a/src/formats/xtc.rs b/src/formats/xtc.rs new file mode 100644 index 0000000..6110d49 --- /dev/null +++ b/src/formats/xtc.rs @@ -0,0 +1,32 @@ +use std::{ + fs::File, + io::{BufRead, BufReader, BufWriter, Write}, +}; + +use crate::{error::CError, format::FileFormat, frame::Frame}; + +pub struct XTCFormat; + +impl XTCFormat {} + +impl FileFormat for XTCFormat { + fn read_next(&mut self, reader: &mut BufReader) -> Result { + todo!(); + } + + fn read(&mut self, reader: &mut BufReader) -> Result, CError> { + todo!(); + } + + fn write_next(&mut self, writer: &mut BufWriter, frame: &Frame) -> Result<(), CError> { + todo!(); + } + + fn forward(&self, reader: &mut BufReader) -> Result, CError> { + todo!(); + } + + fn finalize(&self, writer: &mut BufWriter) -> Result<(), CError> { + todo!(); + } +}