ferritin_structure_mesh/
colors.rs

1//! Colors
2//!
3//! This module defines the color mapping used for rendering.
4
5use bevy::color::Srgba;
6use bevy::prelude::Color;
7use ferritin_core::info::elements::Element;
8
9/// Represents different color schemes for rendering atoms.
10#[derive(Clone)]
11pub enum ColorScheme {
12    /// A solid, single color for all atoms.
13    Solid(Color),
14    /// Colors atoms based on their element type.
15    ByAtomType,
16}
17
18/// Get default colors for elements based on the CPK color scheme
19#[rustfmt::skip]
20pub fn element_color(element: &Element) -> Srgba {
21    match element {
22        Element::H => Srgba::rgb(1.0, 1.0, 1.0),  // White
23        Element::C => Srgba::rgb(0.5, 0.5, 0.5),  // Grey
24        Element::N => Srgba::rgb(0.0, 0.0, 1.0),  // Blue
25        Element::O => Srgba::rgb(1.0, 0.0, 0.0),  // Red
26        Element::P => Srgba::rgb(1.0, 0.5, 0.0),  // Orange
27        Element::S => Srgba::rgb(1.0, 1.0, 0.0),  // Yellow
28        Element::Cl => Srgba::rgb(0.0, 1.0, 0.0), // Green
29        Element::Fe => Srgba::rgb(0.6, 0.0, 0.0), // Dark Red
30        Element::Ca => Srgba::rgb(0.5, 0.5, 0.5), // Grey
31        Element::Mg => Srgba::rgb(0.5, 1.0, 0.0), // Yellow-Green
32        Element::Na => Srgba::rgb(0.0, 0.0, 1.0), // Blue
33        Element::K => Srgba::rgb(0.8, 0.6, 1.0),  // Purple
34        Element::Zn => Srgba::rgb(0.6, 0.6, 0.6), // Grey
35        Element::Cu => Srgba::rgb(0.8, 0.4, 0.0), // Brown
36        Element::F => Srgba::rgb(0.7, 1.0, 1.0),  // Light Blue
37        Element::Br => Srgba::rgb(0.6, 0.1, 0.1), // Brown
38        Element::I => Srgba::rgb(0.4, 0.0, 0.7),  // Purple
39        Element::B => Srgba::rgb(1.0, 0.7, 0.7),  // Light Pink
40        Element::Se => Srgba::rgb(1.0, 0.5, 0.0), // Orange
41        _ => Srgba::rgb(0.5, 0.5, 0.5), // Default Grey
42         // Element::Other => Color::srgb(0.5, 0.5, 0.5), // Default Grey
43    }
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_element_colors() {
52        let color = element_color(&Element::H);
53        assert!(color.red > 0.0);
54    }
55}