#[test]
fn io_from_file_to_file() {
use gchemol::prelude::*;
use gchemol::Molecule;
let txt1 = String::from_file("tests/files/mol2/alanine-gv.mol2").expect("txt1 from file");
let tfile = tempfile::Builder::new()
.suffix(".mol2")
.tempfile()
.expect(".mol2 temp file");
txt1.to_file(&tfile).expect("write mol2");
let txt2 = String::from_file(tfile).expect("txt2 from file");
assert_eq!(txt1, txt2);
let mol1 = Molecule::from_file("tests/files/mol2/alanine-gv.mol2").expect("mol1 from file");
let tfile = tempfile::Builder::new()
.suffix(".xyz")
.tempfile()
.expect(".xyz temp file");
mol1.to_file(&tfile).expect("write mol2 file in xyz format");
let mol2 = Molecule::from_file(tfile).expect("mol2 from file");
assert_eq!(mol1.natoms(), mol2.natoms());
}
#[test]
fn read_write_molecules() {
use gchemol::prelude::*;
use gchemol::Molecule;
let f = "./tests/files/mol2/multi-obabel.mol2";
for mol in gchemol::io::read(&f).expect("read mol2") {
}
let mols = gchemol::io::read_all(&f).expect("read all mol2");
assert_eq!(mols.len(), 6);
let path = tempfile::Builder::new()
.suffix(".mol2")
.tempfile()
.expect(".mol2 temp file");
gchemol::io::write(&path, &mols).expect("write mol2");
gchemol::io::write_format(&path, &mols, "text/xyz").expect("write format xyz");
let file = std::fs::File::open(&path).expect("open file");
let mols = gchemol::io::read_from(file, "text/xyz").expect("read xyz from");
assert_eq!(mols.count(), 6, "Failed to read in xyz format");
let s = String::from_file(&path).expect("read str");
let mol = Molecule::from_str(&s, "text/xyz").expect("from xyz");
let s = mol.format_as("text/xyz").expect("format xyz");
assert!(!s.is_empty());
let tpl = "./tests/files/templates/xyz.tera";
let s = mol.render_with(tpl).expect("render tera");
assert!(!s.is_empty());
}