Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Add Tests; remove unused code (#8)
Browse files Browse the repository at this point in the history
* update color tests
  • Loading branch information
zachcp authored Sep 19, 2024
1 parent cccf787 commit 7559855
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/bevy_protein_mesh_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
..default() // Use defaults for other properties
};

let metallic = StandardMaterial {
let _metallic = StandardMaterial {
base_color: Color::srgb(0.8, 0.8, 0.9), // Slight blue tint for a steel-like appearance
metallic: 1.0, // Fully metallic
perceptual_roughness: 0.1, // Very smooth surface
Expand Down
50 changes: 48 additions & 2 deletions src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
//! Colors
//!
//! This moduel defines the color mapping used for rendering.
//! This module defines the color mapping used for rendering.
use bevy::prelude::Color;
use pdbtbx::Atom;

/// Represents different color schemes for rendering atoms.
#[derive(Clone)]
pub enum ColorScheme {
/// A solid, sinel color for all atoms.
Solid(Color),
/// Colors atoms based on their element type.
ByAtomType,
// /// Colors atoms based on the chain they belong to.
// ByChain(Box<dyn Fn(&Chain) -> Color>),
// /// Colors atoms based on the secondary structure of their residue.
// BySecondaryStructure(Box<dyn Fn(&Residue) -> Color>),
// /// Colors atoms based on their residue type.
// ByResidueType(Box<dyn Fn(&Residue) -> Color>),
// /// Custom coloring function that takes atom, residue, and chain information.
// Custom(Box<dyn Fn(&Atom, &Residue, &Chain) -> Color>),
}

Expand All @@ -20,7 +27,7 @@ pub enum ColorScheme {
// ColorScheme::Custom(func) => func(atom, residue, chain),
impl ColorScheme {
pub fn get_color(&self, atom: &Atom) -> Color {
match self {
match &self {
ColorScheme::Solid(color) => *color,
ColorScheme::ByAtomType => {
match atom.element().expect("expect atom").symbol() {
Expand All @@ -34,3 +41,42 @@ impl ColorScheme {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use pdbtbx::Atom;

#[test]
fn test_get_color() {
let by_atom_scheme = ColorScheme::ByAtomType;
let create_atom =
|element: &str| Atom::new(true, 1, "", 0.0, 0.0, 0.0, 0.0, 0.0, element, 1).unwrap();
let carbon_atom = create_atom("C");
let nitrogen_atom = create_atom("N");
let oxygen_atom = create_atom("O");
let sulfur_atom = create_atom("S");
// let other_atom = create_atom("X");
// Test ByAtomType color scheme
assert_eq!(
by_atom_scheme.get_color(&carbon_atom),
Color::srgb(0.5, 0.5, 0.5)
);
assert_eq!(
by_atom_scheme.get_color(&nitrogen_atom),
Color::srgb(0.0, 0.0, 1.0)
);
assert_eq!(
by_atom_scheme.get_color(&oxygen_atom),
Color::srgb(1.0, 0.0, 0.0)
);
assert_eq!(
by_atom_scheme.get_color(&sulfur_atom),
Color::srgb(1.0, 1.0, 0.0)
);
// assert_eq!(
// by_atom_scheme.get_color(&other_atom),
// Color::srgb(1.0, 1.0, 1.0)
// );
}
}
26 changes: 0 additions & 26 deletions src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,10 @@ impl Structure {
}
}

// fn spawn_protein(
// mut commands: Commands,
// mut meshes: ResMut<Assets<Mesh>>,
// mut materials: ResMut<Assets<StandardMaterial>>,
// protein: &Structure,
// ) {
// let mesh = protein.render();
// let mesh_handle = meshes.add(mesh);

// let material = materials.add(StandardMaterial {
// base_color: Color::srgb(0.8, 0.7, 0.6),
// metallic: 0.1,
// perceptual_roughness: 0.5,
// reflectance: 0.5,
// ..default()
// });

// commands.spawn(PbrBundle {
// mesh: mesh_handle,
// material,
// transform: Transform::from_xyz(0.0, 0.0, 0.0),
// ..default()
// });
// }

#[cfg(test)]
mod tests {
use super::*;
use pdbtbx::StrictnessLevel;

#[test]
fn test_pdb_to_mesh() {
let (pdb, _errors) = pdbtbx::open("examples/1fap.cif", StrictnessLevel::Medium).unwrap();
Expand Down

0 comments on commit 7559855

Please sign in to comment.