use std::io::{IsTerminal, Write};
use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
use pixelfold_core::parser::{AssemblyChoice, Load};
use pixelfold_core::rin::{self, Ensemble};
use pixelfold_core::{AtomSet, InteractionKind, Network, Protein};
mod analyse;
mod graph;
mod load;
mod poses;
mod render;
mod report;
mod resolve;
use graph::GraphFormat;
use report::Format;
#[derive(Parser)]
#[command(
name = "pixelfold",
version,
about = "Terminal protein structure viewer and interaction engine",
subcommand_negates_reqs = true
)]
struct Cli {
#[command(subcommand)]
command: Option<Command>,
structure: Option<String>,
#[arg(short, long)]
fetch: bool,
#[arg(long, value_enum, default_value_t = ProtocolArg::Auto)]
protocol: ProtocolArg,
#[command(flatten)]
common: Common,
}
#[derive(Clone, clap::Args)]
struct Common {
#[arg(long, value_name = "DIR", global = true)]
cache_dir: Option<PathBuf>,
#[arg(long, value_enum, default_value_t = AltlocArg::Occupancy, global = true)]
altloc: AltlocArg,
#[arg(long, value_name = "N|all", value_parser = model_choice, global = true)]
model: Option<ModelChoice>,
#[arg(
long,
value_name = "ID",
num_args = 0..=1,
require_equals = true,
global = true
)]
assembly: Option<Option<String>>,
}
impl Common {
fn load(&self, model: Option<usize>) -> Load {
Load {
model,
assembly: self.assembly.as_ref().map(|id| match id {
Some(id) => AssemblyChoice::Id(id.clone()),
None => AssemblyChoice::Primary,
}),
altloc: self.altloc.into(),
}
}
fn one_model(&self) -> Result<Option<usize>> {
match self.model {
Some(ModelChoice::All) => {
anyhow::bail!("this command works on one model at a time; pass --model N")
}
Some(ModelChoice::One(number)) => Ok(Some(number)),
None => Ok(None),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum ModelChoice {
One(usize),
All,
}
fn fraction(value: &str) -> Result<f32, String> {
value
.parse()
.ok()
.filter(|fraction| (0.0..=1.0).contains(fraction))
.ok_or_else(|| format!("expected a fraction between 0 and 1, not `{value}`"))
}
fn model_choice(value: &str) -> Result<ModelChoice, String> {
if value.eq_ignore_ascii_case("all") {
return Ok(ModelChoice::All);
}
value
.parse()
.map(ModelChoice::One)
.map_err(|_| format!("expected a model number or `all`, not `{value}`"))
}
#[derive(Clone, clap::Args)]
struct Analysis {
structure: String,
#[arg(short, long, value_name = "QUERY")]
select: Option<String>,
#[arg(long, value_enum, default_value_t = Format::Table)]
format: Format,
#[command(flatten)]
common: Common,
}
#[derive(Subcommand)]
enum Command {
View {
structure: String,
#[arg(long, value_enum, default_value_t = ProtocolArg::Auto)]
protocol: ProtocolArg,
#[command(flatten)]
common: Common,
},
Interactions {
#[command(flatten)]
analysis: Analysis,
#[arg(short = 't', long = "type", value_enum, value_name = "TYPE")]
types: Vec<KindArg>,
#[arg(short, long, value_name = "CODE", conflicts_with = "select")]
ligand: Option<String>,
},
Rin {
#[arg(required = true, value_name = "STRUCTURE")]
structures: Vec<String>,
#[arg(short, long, value_name = "QUERY")]
select: Option<String>,
#[arg(short = 't', long = "type", value_enum, value_name = "TYPE")]
types: Vec<KindArg>,
#[arg(long, value_name = "FRACTION", value_parser = fraction)]
min_frequency: Option<f32>,
#[arg(long, value_enum, default_value_t = GraphFormat::Json)]
format: GraphFormat,
#[arg(long)]
analyze: bool,
#[arg(long, num_args = 2, value_names = ["FROM", "TO"])]
path: Option<Vec<String>>,
#[arg(long)]
mvsj: bool,
#[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
#[command(flatten)]
common: Common,
},
Poses {
#[arg(required = true, value_name = "POSE")]
poses: Vec<String>,
#[arg(short, long, value_name = "STRUCTURE")]
reference: String,
#[arg(short, long, value_name = "QUERY", default_value = "ligand")]
select: String,
#[arg(short, long, value_name = "CODE", conflicts_with = "select")]
ligand: Option<String>,
#[arg(long, value_name = "QUERY")]
reference_select: Option<String>,
#[arg(long, value_name = "STRUCTURE")]
receptor: Option<String>,
#[arg(long, value_enum, default_value_t = Format::Table)]
format: Format,
#[arg(long, conflicts_with = "format")]
view: bool,
#[arg(long, value_enum, requires = "view")]
protocol: Option<ProtocolArg>,
#[command(flatten)]
common: Common,
},
Ss {
#[command(flatten)]
analysis: Analysis,
},
Sasa {
#[command(flatten)]
analysis: Analysis,
},
Render {
structure: String,
#[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
#[arg(long)]
width: Option<u32>,
#[arg(long)]
height: Option<u32>,
#[arg(long, value_enum, default_value_t = ColorArg::Element)]
color: ColorArg,
#[arg(long)]
backbone: bool,
#[arg(short, long, value_name = "QUERY")]
select: Option<String>,
#[arg(long, default_value_t = 1.0)]
radius_scale: f32,
#[arg(long)]
no_depth_cue: bool,
#[arg(long, num_args = 2, value_names = ["FAR", "NEAR"])]
slab: Option<Vec<f32>>,
#[arg(long, value_enum, default_value_t = ProtocolArg::Auto)]
protocol: ProtocolArg,
#[command(flatten)]
common: Common,
},
Fetch {
query: Option<String>,
#[command(flatten)]
common: Common,
},
}
#[derive(Clone, Copy, Debug, ValueEnum)]
enum KindArg {
HydrogenBond,
SaltBridge,
Hydrophobic,
PiStacking,
PiCation,
PiHydrogenBond,
HalogenBond,
WaterBridge,
MetalCoordination,
Disulfide,
}
impl From<KindArg> for InteractionKind {
fn from(arg: KindArg) -> Self {
match arg {
KindArg::HydrogenBond => InteractionKind::HydrogenBond,
KindArg::SaltBridge => InteractionKind::SaltBridge,
KindArg::Hydrophobic => InteractionKind::Hydrophobic,
KindArg::PiStacking => InteractionKind::PiStacking,
KindArg::PiCation => InteractionKind::PiCation,
KindArg::PiHydrogenBond => InteractionKind::PiHydrogenBond,
KindArg::HalogenBond => InteractionKind::HalogenBond,
KindArg::WaterBridge => InteractionKind::WaterBridge,
KindArg::MetalCoordination => InteractionKind::MetalCoordination,
KindArg::Disulfide => InteractionKind::Disulfide,
}
}
}
#[derive(Clone, Copy, Debug, ValueEnum)]
enum ColorArg {
Element,
Bfactor,
Ss,
}
impl From<ColorArg> for pixelfold_render::Coloring {
fn from(arg: ColorArg) -> Self {
match arg {
ColorArg::Element => pixelfold_render::Coloring::Element,
ColorArg::Bfactor => pixelfold_render::Coloring::Bfactor,
ColorArg::Ss => pixelfold_render::Coloring::SecondaryStructure,
}
}
}
#[derive(Clone, Copy, Debug, ValueEnum)]
enum ProtocolArg {
Auto,
Kitty,
Iterm2,
HalfBlock,
}
impl From<ProtocolArg> for render::TerminalTarget {
fn from(arg: ProtocolArg) -> Self {
match arg {
ProtocolArg::Auto => render::TerminalTarget::Auto,
ProtocolArg::Kitty => render::TerminalTarget::Kitty,
ProtocolArg::Iterm2 => render::TerminalTarget::Iterm2,
ProtocolArg::HalfBlock => render::TerminalTarget::HalfBlock,
}
}
}
impl From<ProtocolArg> for pixelfold_tui::ViewProtocol {
fn from(arg: ProtocolArg) -> Self {
match arg {
ProtocolArg::Auto => pixelfold_tui::ViewProtocol::Auto,
ProtocolArg::Kitty => pixelfold_tui::ViewProtocol::Kitty,
ProtocolArg::Iterm2 => pixelfold_tui::ViewProtocol::Iterm2,
ProtocolArg::HalfBlock => pixelfold_tui::ViewProtocol::HalfBlock,
}
}
}
#[derive(Clone, Copy, Debug, ValueEnum)]
enum AltlocArg {
Occupancy,
A,
B,
All,
}
impl From<AltlocArg> for pixelfold_core::AltlocPolicy {
fn from(arg: AltlocArg) -> Self {
match arg {
AltlocArg::Occupancy => pixelfold_core::AltlocPolicy::Occupancy,
AltlocArg::A => pixelfold_core::AltlocPolicy::A,
AltlocArg::B => pixelfold_core::AltlocPolicy::B,
AltlocArg::All => pixelfold_core::AltlocPolicy::All,
}
}
}
fn main() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Some(command) => run(command),
None if cli.fetch => search(cli.structure, &cli.common),
None => match cli.structure {
Some(structure) => view(&structure, cli.protocol, &cli.common),
None => {
Cli::command().print_help()?;
println!();
Ok(())
}
},
}
}
fn run(command: Command) -> Result<()> {
match command {
Command::View {
structure,
protocol,
common,
} => view(&structure, protocol, &common),
Command::Fetch { query, common } => search(query, &common),
Command::Interactions {
analysis,
types,
ligand,
} => {
let query = ligand
.map(|code| format!("resn {code}"))
.or_else(|| analysis.select.clone());
let kinds: Vec<InteractionKind> = types.into_iter().map(Into::into).collect();
emit_analysis(&analysis, query.as_deref(), |protein, chosen| {
analyse::interactions(protein, chosen, &kinds)
})
}
Command::Rin {
structures,
select,
types,
min_frequency,
format,
analyze,
path,
mvsj,
output,
common,
} => {
if mvsj && common.assembly.is_some() {
anyhow::bail!("--mvsj cannot show a biological assembly yet; drop --assembly");
}
let kinds: Vec<InteractionKind> = types.into_iter().map(Into::into).collect();
let network = network_of(
&structures,
select.as_deref(),
&kinds,
min_frequency,
&common,
)?;
if let Some(endpoints) = path {
let node_of = |id: &str| {
network
.nodes
.iter()
.position(|node| node.id == id)
.with_context(|| {
let often = min_frequency.map_or(String::new(), |fraction| {
format!(" in at least {fraction} of the models")
});
format!("residue {id} is not in the network (does it interact{often}?)")
})
};
let from = node_of(&endpoints[0])?;
let to = node_of(&endpoints[1])?;
let route = rin::shortest_path(&network, from, to);
emit_to(output.as_deref(), |out| {
graph::write_path(
out,
&network,
&endpoints[0],
&endpoints[1],
route.as_deref(),
)
})
} else if mvsj {
let (url, parse_format) = mvsj_source(&structures[0])?;
let models = shown_models(&structures[0], &common)?;
let title = format!("PixelFold — {} interaction network", structures.join(", "));
emit_to(output.as_deref(), |out| {
graph::write_mvsj(out, &network, &url, parse_format, &models, &title)
})
} else if analyze {
let report = rin::analyze(&network);
emit_to(output.as_deref(), |out| {
graph::write_analysis(out, &network, &report)
})
} else if format == GraphFormat::Tsv
&& output.is_none()
&& std::io::stdout().is_terminal()
{
emit_to(None, |out| graph::write_tsv_aligned(out, &network))
} else {
emit_to(output.as_deref(), |out| graph::write(out, &network, format))
}
}
Command::Poses {
poses,
reference,
select,
ligand,
reference_select,
receptor,
format,
view,
protocol,
common,
} => {
let query = ligand.map_or(select, |code| format!("resn {code}"));
let reference_query = reference_select.unwrap_or_else(|| query.clone());
let shown = view.then(|| protocol.unwrap_or(ProtocolArg::Auto));
compare_poses(
&reference,
&reference_query,
receptor.as_deref(),
&poses,
&query,
shown.map_or(Output::Format(format), Output::View),
&common,
)
}
Command::Ss { analysis } => {
emit_analysis(&analysis, analysis.select.as_deref(), analyse::secondary)
}
Command::Sasa { analysis } => {
emit_analysis(&analysis, analysis.select.as_deref(), analyse::sasa)
}
Command::Render {
structure,
output,
width,
height,
color,
backbone,
select,
radius_scale,
no_depth_cue,
slab,
protocol,
common,
} => {
let protein = loaded(&structure, &common)?;
let selected = match select {
Some(query) => Some(
load::chosen(&protein, Some(&query))?
.iter()
.collect::<Vec<usize>>(),
),
None => None,
};
let slab = match slab.as_deref() {
None => None,
Some([far, near]) if (0.0..=1.0).contains(far) && far < near && *near <= 1.0 => {
Some((*far, *near))
}
Some(_) => {
anyhow::bail!("--slab takes two fractions FAR NEAR with 0 <= FAR < NEAR <= 1")
}
};
let params = render::RenderParams {
width,
height,
coloring: color.into(),
backbone,
radius_scale,
depth_cue: !no_depth_cue,
slab,
};
render::render(
&protein,
selected.as_deref(),
¶ms,
output.as_deref(),
protocol.into(),
)
}
}
}
fn search(query: Option<String>, common: &Common) -> Result<()> {
let dir = cache_dir(common)?;
std::fs::create_dir_all(&dir)?;
pixelfold_tui::search(query, dir)
}
fn view(structure: &str, protocol: ProtocolArg, common: &Common) -> Result<()> {
let model = common.one_model()?;
let dir = cache_dir(common)?;
let path = load::structure_path(structure, &dir)?;
pixelfold_tui::view(&path, common.load(model), protocol.into())
}
fn loaded(structure: &str, common: &Common) -> Result<Protein> {
let model = common.one_model()?;
let dir = cache_dir(common)?;
load::analysis_structure(structure, &dir, &common.load(model))
}
fn emit_analysis<R, F>(analysis: &Analysis, query: Option<&str>, report: F) -> Result<()>
where
R: report::Row + serde::Serialize,
F: Fn(&Protein, &AtomSet) -> Vec<R>,
{
if analysis.common.model != Some(ModelChoice::All) {
let protein = loaded(&analysis.structure, &analysis.common)?;
let chosen = load::chosen(&protein, query)?;
return emit(&report(&protein, &chosen), analysis.format);
}
let dir = cache_dir(&analysis.common)?;
let parsed = load::parsed(&analysis.structure, &dir)?;
let mut records = Vec::new();
let mut matched = false;
for model in parsed.model_numbers() {
let protein = parsed
.protein(&analysis.common.load(Some(model)))
.with_context(|| format!("model {model}"))?;
let chosen = load::selection(&protein, query)?;
matched |= !chosen.is_empty();
records.extend(
report(&protein, &chosen)
.into_iter()
.map(|record| report::InModel { model, record }),
);
}
if !matched {
return Err(matched_no_model(query));
}
emit(&records, analysis.format)
}
fn network_of(
structures: &[String],
query: Option<&str>,
kinds: &[InteractionKind],
min_frequency: Option<f32>,
common: &Common,
) -> Result<Network> {
if let [structure] = structures
&& common.model != Some(ModelChoice::All)
{
if min_frequency.is_some() {
anyhow::bail!(
"--min-frequency weighs edges across models; pass --model all or several files"
);
}
let protein = loaded(structure, common)?;
let chosen = load::chosen(&protein, query)?;
return Ok(rin::build(
&protein,
&analyse::selected(&protein, &chosen, kinds),
));
}
let dir = cache_dir(common)?;
let mut ensemble = Ensemble::default();
let mut matched = false;
for structure in structures {
let parsed = load::parsed(structure, &dir)?;
let models = match common.model {
Some(ModelChoice::All) => parsed.model_numbers().into_iter().map(Some).collect(),
Some(ModelChoice::One(number)) => vec![Some(number)],
None => vec![None],
};
for model in models {
let within = || match model {
Some(number) => format!("{structure}, model {number}"),
None => structure.clone(),
};
let protein = parsed.protein(&common.load(model)).with_context(within)?;
let chosen = load::selection(&protein, query)?;
matched |= !chosen.is_empty();
ensemble
.try_add(&protein, &analyse::selected(&protein, &chosen, kinds))
.map_err(|renamed| {
anyhow::anyhow!(
"{} names residue {} {}, where the models before it name it {}; \
the {} must number residues alike",
within(),
renamed.residue,
renamed.now,
renamed.before,
if structures.len() > 1 {
"files"
} else {
"models"
}
)
})?;
}
}
if !matched {
return Err(matched_no_model(query));
}
Ok(ensemble.network(min_frequency.unwrap_or(0.0)))
}
fn matched_no_model(query: Option<&str>) -> anyhow::Error {
anyhow::anyhow!(
"the selection `{}` matched no atoms in any model",
query.unwrap_or("all")
)
}
enum Output {
Format(Format),
View(ProtocolArg),
}
fn compare_poses(
reference: &str,
reference_query: &str,
receptor: Option<&str>,
poses: &[String],
query: &str,
output: Output,
common: &Common,
) -> Result<()> {
let docking = poses
.iter()
.any(|pose| pixelfold_core::sdf::is_sdf(Path::new(pose)));
anyhow::ensure!(
docking || receptor.is_none(),
"--receptor is the protein .sdf poses were docked into, and no pose is an .sdf file"
);
let dir = cache_dir(common)?;
let mut warnings = poses::Warnings::default();
let structure = load::analysis_structure(reference, &dir, &common.load(None))
.with_context(|| format!("the reference {reference}"))?;
let scoring = poses::Reference::new(&structure, reference_query, &mut warnings)
.with_context(|| format!("the reference {reference}"))?;
let receptor = match (docking, receptor) {
(false, _) => None,
(true, Some(given)) => Some(
load::analysis_structure(given, &dir, &common.load(None))
.map(|protein| scoring.receptor(protein, &mut warnings))
.with_context(|| format!("the receptor {given}"))?,
),
(true, None) => Some(poses::reference_receptor(&structure, reference_query)?),
};
let chosen = match common.model {
Some(ModelChoice::One(number)) => Some(number),
_ => None,
};
let mut records = Vec::new();
for pose in poses {
if let Some(receptor) = receptor
.as_ref()
.filter(|_| pixelfold_core::sdf::is_sdf(Path::new(pose)))
{
records.extend(poses::docked(
&scoring,
receptor,
pose,
chosen,
&mut warnings,
)?);
continue;
}
let parsed = load::parsed(pose, &dir)?;
let models = match chosen {
Some(number) => vec![number],
None => parsed.model_numbers(),
};
for model in models {
let record = parsed
.protein(&common.load(Some(model)))
.and_then(|protein| scoring.assess(protein, query, pose, model, &mut warnings))
.with_context(|| format!("{pose}, model {model}"))?;
records.push(record);
}
}
let ranked = poses::ranked(records);
match output {
Output::Format(format) => emit(&ranked, format),
Output::View(protocol) => {
anyhow::ensure!(!ranked.is_empty(), "no pose file holds a model to view");
pixelfold_tui::view_poses(
poses::viewed(ranked, |pose| load::structure_path(pose, &dir))?,
receptor,
common.load(None),
protocol.into(),
)
}
}
}
fn shown_models(structure: &str, common: &Common) -> Result<Vec<usize>> {
let numbers = load::model_numbers(structure, &cache_dir(common)?)?;
Ok(match common.model {
Some(ModelChoice::All) => (0..numbers.len()).collect(),
Some(ModelChoice::One(number)) => vec![
numbers
.iter()
.position(|&model| model == number)
.with_context(|| format!("{structure} has no model {number}"))?,
],
None => vec![0],
})
}
fn mvsj_source(structure: &str) -> Result<(String, &'static str)> {
let is_pdb_id = structure.len() == 4 && structure.chars().all(|c| c.is_ascii_alphanumeric());
if is_pdb_id {
return Ok((
format!(
"https://files.rcsb.org/download/{}.cif",
structure.to_uppercase()
),
"mmcif",
));
}
let path = Path::new(structure)
.canonicalize()
.with_context(|| format!("cannot resolve {structure} for the scene URL"))?;
let format = match path.extension().and_then(|ext| ext.to_str()) {
Some("pdb" | "ent") => "pdb",
_ => "mmcif",
};
Ok((format!("file://{}", path.display()), format))
}
fn emit<T>(records: &[T], format: Format) -> Result<()>
where
T: report::Row + serde::Serialize,
{
emit_to(None, |out| report::write(out, records, format))
}
fn emit_to(
output: Option<&Path>,
render: impl FnOnce(&mut dyn std::io::Write) -> Result<()>,
) -> Result<()> {
match output {
Some(path) => {
let mut file = std::io::BufWriter::new(
std::fs::File::create(path)
.with_context(|| format!("could not write {}", path.display()))?,
);
render(&mut file)?;
file.flush()?;
Ok(())
}
None => {
let mut out = std::io::stdout().lock();
match render(&mut out) {
Err(error) if is_broken_pipe(&error) => Ok(()),
other => other,
}
}
}
}
fn is_broken_pipe(error: &anyhow::Error) -> bool {
let pipe = |kind| kind == std::io::ErrorKind::BrokenPipe;
error
.downcast_ref::<std::io::Error>()
.is_some_and(|io| pipe(io.kind()))
|| error
.downcast_ref::<serde_json::Error>()
.and_then(serde_json::Error::io_error_kind)
.is_some_and(pipe)
}
fn cache_dir(common: &Common) -> Result<PathBuf> {
match &common.cache_dir {
Some(dir) => Ok(dir.clone()),
None => Ok(dirs::cache_dir()
.ok_or_else(|| {
anyhow::anyhow!("could not determine a cache directory; pass --cache-dir")
})?
.join("pixelfold")),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_command_line_is_well_formed() {
Cli::command().debug_assert();
}
#[test]
fn a_bare_structure_still_opens_the_viewer() {
let cli = Cli::try_parse_from(["pixelfold", "4HHB"]).expect("parses");
assert!(cli.command.is_none());
assert_eq!(cli.structure.as_deref(), Some("4HHB"));
}
#[test]
fn subcommands_take_their_own_structure() {
let cli =
Cli::try_parse_from(["pixelfold", "sasa", "1UBQ", "--format", "tsv"]).expect("parses");
let Some(Command::Sasa { analysis }) = cli.command else {
panic!("expected the sasa command");
};
assert_eq!(analysis.structure, "1UBQ");
assert_eq!(analysis.format, Format::Tsv);
}
#[test]
fn a_ligand_shorthand_and_a_selection_are_mutually_exclusive() {
assert!(
Cli::try_parse_from([
"pixelfold",
"interactions",
"1IEP",
"--ligand",
"STI",
"--select",
"chain A",
])
.is_err()
);
}
#[test]
fn interaction_types_repeat() {
let cli = Cli::try_parse_from([
"pixelfold",
"interactions",
"1IEP",
"--type",
"hydrogen-bond",
"--type",
"pi-stacking",
])
.expect("parses");
let Some(Command::Interactions { types, .. }) = cli.command else {
panic!("expected the interactions command");
};
let kinds: Vec<InteractionKind> = types.into_iter().map(Into::into).collect();
assert_eq!(
kinds,
vec![InteractionKind::HydrogenBond, InteractionKind::PiStacking]
);
}
#[test]
fn rin_takes_a_graph_format_and_an_output_file() {
let cli = Cli::try_parse_from([
"pixelfold",
"rin",
"4HHB",
"--format",
"graphml",
"-o",
"net.graphml",
])
.expect("parses");
let Some(Command::Rin {
structures,
format,
output,
..
}) = cli.command
else {
panic!("expected the rin command");
};
assert_eq!(structures, ["4HHB"]);
assert_eq!(format, GraphFormat::Graphml);
assert_eq!(output.as_deref(), Some(Path::new("net.graphml")));
}
#[test]
fn poses_take_a_reference_and_any_number_of_pose_files() {
let cli = Cli::try_parse_from([
"pixelfold",
"poses",
"--reference",
"ref.cif",
"a.cif",
"b.cif",
])
.expect("parses");
let Some(Command::Poses {
poses,
reference,
select,
ligand,
reference_select,
..
}) = cli.command
else {
panic!("expected the poses command");
};
assert_eq!(poses, ["a.cif", "b.cif"]);
assert_eq!(reference, "ref.cif");
assert_eq!(select, "ligand");
assert_eq!(ligand, None);
assert_eq!(reference_select, None);
let apart = [
"pixelfold",
"poses",
"-r",
"ref.cif",
"--ligand",
"STI",
"--reference-select",
"chain A and resn STI",
"a.cif",
];
let Some(Command::Poses {
reference_select, ..
}) = Cli::try_parse_from(apart).expect("parses").command
else {
panic!("expected the poses command");
};
assert_eq!(reference_select.as_deref(), Some("chain A and resn STI"));
let no_poses = ["pixelfold", "poses", "--reference", "ref.cif"];
assert!(Cli::try_parse_from(no_poses).is_err());
let both = [
"pixelfold",
"poses",
"-r",
"ref.cif",
"--ligand",
"STI",
"--select",
"chain B",
"a.cif",
];
assert!(Cli::try_parse_from(both).is_err());
}
}