Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
13 changes: 13 additions & 0 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,7 @@
/// - `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 {
Expand All @@ -27,6 +29,8 @@
PDB,
/// SDF file format.
SDF,
/// XTC file format.
XTC,
/// Automatically detect format from file extension.
Guess,
}
Expand All @@ -39,6 +43,8 @@
PDB(PDBFormat<'a>),
/// Handler for the SDF format.
SDF(SDFFormat),
/// Handler for the XTC format.
XTC(XTCFormat),
}

impl Format<'_> {
Expand All @@ -54,6 +60,7 @@
"xyz" => Ok(Format::XYZ(XYZFormat)),
"pdb" => Ok(Format::PDB(PDBFormat::new())),
"sdf" => Ok(Format::SDF(SDFFormat)),
"xtc" => Ok(Format::XTC(XTCFormat)),

Check warning on line 63 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L63

Added line #L63 was not covered by tests
_ => Err(CError::GenericError("unknown file format".to_string())),
}
}
Expand All @@ -69,6 +76,7 @@
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)),

Check warning on line 79 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L79

Added line #L79 was not covered by tests
TextFormat::Guess => Self::new(path),
}
}
Expand Down Expand Up @@ -120,6 +128,7 @@
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),

Check warning on line 131 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L131

Added line #L131 was not covered by tests
}
}

Expand All @@ -128,6 +137,7 @@
Format::XYZ(format) => format.read(reader),
Format::PDB(format) => format.read(reader),
Format::SDF(format) => format.read(reader),
Format::XTC(format) => format.read(reader),

Check warning on line 140 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L140

Added line #L140 was not covered by tests
}
}

Expand All @@ -136,6 +146,7 @@
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),

Check warning on line 149 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L149

Added line #L149 was not covered by tests
}
}

Expand All @@ -144,6 +155,7 @@
Format::XYZ(format) => format.forward(reader),
Format::PDB(format) => format.forward(reader),
Format::SDF(format) => format.forward(reader),
Format::XTC(format) => format.forward(reader),

Check warning on line 158 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L158

Added line #L158 was not covered by tests
}
}

Expand All @@ -152,6 +164,7 @@
Format::XYZ(format) => format.finalize(writer),
Format::PDB(format) => format.finalize(writer),
Format::SDF(format) => format.finalize(writer),
Format::XTC(format) => format.finalize(writer),

Check warning on line 167 in src/format.rs

View check run for this annotation

Codecov / codecov/patch

src/format.rs#L167

Added line #L167 was not covered by tests
}
}
}
1 change: 1 addition & 0 deletions src/formats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod pdb;
pub mod pdb_connectivity;
pub mod sdf;
pub mod xtc;
pub mod xyz;
32 changes: 32 additions & 0 deletions src/formats/xtc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::{
fs::File,
io::{BufRead, BufReader, BufWriter, Write},

Check warning on line 3 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L3

warning: unused imports: `BufRead` and `Write` --> src/formats/xtc.rs:3:10 | 3 | io::{BufRead, BufReader, BufWriter, Write}, | ^^^^^^^ ^^^^^ | = note: `#[warn(unused_imports)]` on by default
Raw output
src/formats/xtc.rs:3:10:w:warning: unused imports: `BufRead` and `Write`
 --> src/formats/xtc.rs:3:10
  |
3 |     io::{BufRead, BufReader, BufWriter, Write},
  |          ^^^^^^^                        ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default


__END__
};

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<File>) -> Result<Frame, CError> {

Check warning on line 13 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L13

warning: unused variable: `reader` --> src/formats/xtc.rs:13:29 | 13 | fn read_next(&mut self, reader: &mut BufReader<File>) -> Result<Frame, CError> { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_reader` | = note: `#[warn(unused_variables)]` on by default
Raw output
src/formats/xtc.rs:13:29:w:warning: unused variable: `reader`
  --> src/formats/xtc.rs:13:29
   |
13 |     fn read_next(&mut self, reader: &mut BufReader<File>) -> Result<Frame, CError> {
   |                             ^^^^^^ help: if this is intentional, prefix it with an underscore: `_reader`
   |
   = note: `#[warn(unused_variables)]` on by default


__END__
todo!();

Check warning on line 14 in src/formats/xtc.rs

View check run for this annotation

Codecov / codecov/patch

src/formats/xtc.rs#L13-L14

Added lines #L13 - L14 were not covered by tests
}

fn read(&mut self, reader: &mut BufReader<File>) -> Result<Option<Frame>, CError> {

Check warning on line 17 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L17

warning: unused variable: `reader` --> src/formats/xtc.rs:17:24 | 17 | fn read(&mut self, reader: &mut BufReader<File>) -> Result<Option<Frame>, CError> { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_reader`
Raw output
src/formats/xtc.rs:17:24:w:warning: unused variable: `reader`
  --> src/formats/xtc.rs:17:24
   |
17 |     fn read(&mut self, reader: &mut BufReader<File>) -> Result<Option<Frame>, CError> {
   |                        ^^^^^^ help: if this is intentional, prefix it with an underscore: `_reader`


__END__
todo!();

Check warning on line 18 in src/formats/xtc.rs

View check run for this annotation

Codecov / codecov/patch

src/formats/xtc.rs#L17-L18

Added lines #L17 - L18 were not covered by tests
}

fn write_next(&mut self, writer: &mut BufWriter<File>, frame: &Frame) -> Result<(), CError> {

Check warning on line 21 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L21

warning: unused variable: `writer` --> src/formats/xtc.rs:21:30 | 21 | fn write_next(&mut self, writer: &mut BufWriter<File>, frame: &Frame) -> Result<(), CError> { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_writer`
Raw output
src/formats/xtc.rs:21:30:w:warning: unused variable: `writer`
  --> src/formats/xtc.rs:21:30
   |
21 |     fn write_next(&mut self, writer: &mut BufWriter<File>, frame: &Frame) -> Result<(), CError> {
   |                              ^^^^^^ help: if this is intentional, prefix it with an underscore: `_writer`


__END__

Check warning on line 21 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L21

warning: unused variable: `frame` --> src/formats/xtc.rs:21:60 | 21 | fn write_next(&mut self, writer: &mut BufWriter<File>, frame: &Frame) -> Result<(), CError> { | ^^^^^ help: if this is intentional, prefix it with an underscore: `_frame`
Raw output
src/formats/xtc.rs:21:60:w:warning: unused variable: `frame`
  --> src/formats/xtc.rs:21:60
   |
21 |     fn write_next(&mut self, writer: &mut BufWriter<File>, frame: &Frame) -> Result<(), CError> {
   |                                                            ^^^^^ help: if this is intentional, prefix it with an underscore: `_frame`


__END__
todo!();

Check warning on line 22 in src/formats/xtc.rs

View check run for this annotation

Codecov / codecov/patch

src/formats/xtc.rs#L21-L22

Added lines #L21 - L22 were not covered by tests
}

fn forward(&self, reader: &mut BufReader<File>) -> Result<Option<u64>, CError> {

Check warning on line 25 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L25

warning: unused variable: `reader` --> src/formats/xtc.rs:25:23 | 25 | fn forward(&self, reader: &mut BufReader<File>) -> Result<Option<u64>, CError> { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_reader`
Raw output
src/formats/xtc.rs:25:23:w:warning: unused variable: `reader`
  --> src/formats/xtc.rs:25:23
   |
25 |     fn forward(&self, reader: &mut BufReader<File>) -> Result<Option<u64>, CError> {
   |                       ^^^^^^ help: if this is intentional, prefix it with an underscore: `_reader`


__END__
todo!();

Check warning on line 26 in src/formats/xtc.rs

View check run for this annotation

Codecov / codecov/patch

src/formats/xtc.rs#L25-L26

Added lines #L25 - L26 were not covered by tests
}

fn finalize(&self, writer: &mut BufWriter<File>) -> Result<(), CError> {

Check warning on line 29 in src/formats/xtc.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] src/formats/xtc.rs#L29

warning: unused variable: `writer` --> src/formats/xtc.rs:29:24 | 29 | fn finalize(&self, writer: &mut BufWriter<File>) -> Result<(), CError> { | ^^^^^^ help: if this is intentional, prefix it with an underscore: `_writer`
Raw output
src/formats/xtc.rs:29:24:w:warning: unused variable: `writer`
  --> src/formats/xtc.rs:29:24
   |
29 |     fn finalize(&self, writer: &mut BufWriter<File>) -> Result<(), CError> {
   |                        ^^^^^^ help: if this is intentional, prefix it with an underscore: `_writer`


__END__
todo!();

Check warning on line 30 in src/formats/xtc.rs

View check run for this annotation

Codecov / codecov/patch

src/formats/xtc.rs#L29-L30

Added lines #L29 - L30 were not covered by tests
}
}