Skip to content

Commit

Permalink
Tidy the Bevy Examples (#78)
Browse files Browse the repository at this point in the history
- use builtin CIF file.
- move all examples to the ferritin-examples directory
- begin refactoring to move these into a single test
  • Loading branch information
zachcp authored Dec 13, 2024
1 parent ad35834 commit b8d5ac6
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 1 addition & 21 deletions ferritin-bevy/Readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
# protein-renderer


## Examples

```sh
cargo run --example basic_spheres
cargo run --example basic_ballandstick
cargo run --example basic_putty
cargo run --example basic_snapshot

cargo run --example screenshot
```

![](docs/images/protein_01.png)

<div style="display: flex; justify-content: space-between;">
<img src="docs/images/protein_01.png" alt="Base" style="width: 32%;">
<img src="docs/images/protein_01_metal.png" alt="Metal" style="width: 32%;">
<img src="docs/images/protein_01_chalk.png" alt="Chalky" style="width: 32%;">
</div>
# ferritin-bevy
24 changes: 24 additions & 0 deletions ferritin-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ metal = ["candle-core/metal", "candle-nn/metal", "candle-metal-kernels"]

[dependencies]
anyhow.workspace = true
bevy = "0.15.0"
candle-core.workspace = true
candle-metal-kernels = { workspace = true, optional = true }
candle-nn.workspace = true
clap = { version = "4.5.23", features = ["derive"] }
ferritin-amplify = { path = "../ferritin-amplify" }
ferritin-esm = { path = "../ferritin-esm" }
ferritin-bevy = { path = "../ferritin-bevy" }
serde_json.workspace = true


Expand All @@ -41,3 +43,25 @@ candle-examples.workspace = true
ferritin-test-data = { path = "../ferritin-test-data" }
assert_cmd = "2.0.16"
tempfile = "3.14.0"


[[example]]
name = "bevy_basic_ball_and_stick"
path = "examples/bevy/basic_ball_and_stick.rs"


[[example]]
name = "bevy_basic_putty"
path = "examples/bevy/basic_putty.rs"

[[example]]
name = "bevy_basic_snapshot"
path = "examples/bevy/basic_snapshot.rs"

[[example]]
name = "bevy_basic_spheres"
path = "examples/bevy/basic_spheres.rs"

[[example]]
name = "bevy_screenshot"
path = "examples/bevy/screenshot.rs"
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Example allowing custom colors and rendering options
use anyhow::Result;
use bevy::prelude::*;
use ferritin_bevy::{ColorScheme, RenderOptions, StructurePlugin, StructureSettings};
use ferritin_test_data::TestFile;

fn main() -> Result<()> {
let (molfile, _handle) = TestFile::protein_01().create_temp()?;

fn main() {
let chalky = StandardMaterial {
base_color: Color::srgb(0.9, 0.9, 0.9), // Light gray color
perceptual_roughness: 1.0, // Maximum roughness for a matte look
Expand Down Expand Up @@ -33,7 +36,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(StructurePlugin::new().with_file(
"examples/1fap.cif",
molfile,
Some(StructureSettings {
render_type: RenderOptions::BallAndStick,
color_scheme: ColorScheme::ByAtomType,
Expand All @@ -42,6 +45,8 @@ fn main() {
))
.add_systems(Startup, setup)
.run();

Ok(())
}

#[derive(Component)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! Example allowing custom colors and rendering options
use anyhow::Result;
use bevy::prelude::*;
use ferritin_bevy::{ColorScheme, RenderOptions, StructurePlugin, StructureSettings};
use ferritin_test_data::TestFile;

fn main() -> Result<()> {
let (molfile, _handle) = TestFile::protein_01().create_temp()?;

fn main() {
let chalky = StandardMaterial {
base_color: Color::srgb(0.9, 0.9, 0.9), // Light gray color
perceptual_roughness: 1.0, // Maximum roughness for a matte look
Expand Down Expand Up @@ -33,7 +37,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(StructurePlugin::new().with_file(
"examples/1fap.cif",
molfile,
Some(StructureSettings {
render_type: RenderOptions::Putty,
color_scheme: ColorScheme::ByAtomType,
Expand All @@ -42,6 +46,7 @@ fn main() {
))
.add_systems(Startup, setup)
.run();
Ok(())
}

#[derive(Component)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Example allowing custom colors and rendering options
use anyhow::Result;
use bevy::{
app::AppExit,
prelude::*,
Expand All @@ -7,8 +8,11 @@ use bevy::{
winit::cursor::CursorIcon,
};
use ferritin_bevy::{ColorScheme, RenderOptions, StructurePlugin, StructureSettings};
use ferritin_test_data::TestFile;

fn main() -> Result<()> {
let (molfile, _handle) = TestFile::protein_01().create_temp()?;

fn main() {
let chalky = StandardMaterial {
base_color: Color::srgb(0.9, 0.9, 0.9), // Light gray color
perceptual_roughness: 1.0, // Maximum roughness for a matte look
Expand All @@ -25,7 +29,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(StructurePlugin::new().with_file(
"examples/1fap.cif",
molfile,
Some(StructureSettings {
render_type: RenderOptions::BallAndStick,
color_scheme: ColorScheme::ByAtomType,
Expand All @@ -35,6 +39,7 @@ fn main() {
.add_systems(Startup, setup)
.add_systems(Update, (take_screenshot_and_exit, screenshot_saving))
.run();
Ok(())
}

fn screenshot_saving(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! Example allowing custom colors and rendering options
use anyhow::Result;
use bevy::prelude::*;
use ferritin_bevy::{ColorScheme, RenderOptions, StructurePlugin, StructureSettings};
use ferritin_test_data::TestFile;

fn main() -> Result<()> {
let (molfile, _handle) = TestFile::protein_01().create_temp()?;

fn main() {
let chalky = StandardMaterial {
base_color: Color::srgb(0.9, 0.9, 0.9), // Light gray color
perceptual_roughness: 1.0, // Maximum roughness for a matte look
Expand Down Expand Up @@ -33,7 +37,7 @@ fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(StructurePlugin::new().with_file(
"examples/1fap.cif",
molfile,
Some(StructureSettings {
render_type: RenderOptions::Solid,
color_scheme: ColorScheme::ByAtomType,
Expand All @@ -42,6 +46,7 @@ fn main() {
))
.add_systems(Startup, setup)
.run();
Ok(())
}

#[derive(Component)]
Expand Down
1 change: 1 addition & 0 deletions ferritin-examples/examples/bevy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod basic_ball_and_stick;
File renamed without changes.

0 comments on commit b8d5ac6

Please sign in to comment.