use super::pdb::{PdbOptions, render_selected};
use molframe_core::diagnostic::{Code, Diagnostic};
use molframe_core::io::{Select, SelectAll, TextOutput};
use molframe_core::structure::Structure;
use std::io::Write;
pub fn write_to<W: Write>(
structure: &Structure,
options: &PdbOptions,
output: &mut W,
) -> Result<(), Vec<Diagnostic>> {
write_selected_to(structure, options, &SelectAll, output)
}
pub fn write_selected_to<W: Write>(
structure: &Structure,
options: &PdbOptions,
select: &impl Select,
output: &mut W,
) -> Result<(), Vec<Diagnostic>> {
let mut output = TextOutput::new(output);
render_selected(&mut output, structure, options, select)?;
output
.finish()
.map_err(|error| vec![output_diagnostic(error)])
}
fn output_diagnostic(error: impl std::fmt::Display) -> Diagnostic {
Diagnostic::new(Code::E7901).with_context("reason", error.to_string())
}