cosmol-viewer 0.1.1.dev3__tar.gz → 0.1.1.dev4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cosmol-viewer might be problematic. Click here for more details.

Files changed (27) hide show
  1. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/Cargo.lock +5 -5
  2. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/Cargo.toml +1 -1
  3. cosmol_viewer-0.1.1.dev4/PKG-INFO +58 -0
  4. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shader/canvas.rs +2 -5
  5. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shapes/molecules.rs +3 -6
  6. cosmol_viewer-0.1.1.dev4/crates/python/README.md +51 -0
  7. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/python/src/lib.rs +0 -2
  8. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/pyproject.toml +2 -1
  9. cosmol_viewer-0.1.1.dev3/PKG-INFO +0 -5
  10. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/Cargo.toml +0 -0
  11. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/lib.rs +0 -0
  12. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/parser/mod.rs +0 -0
  13. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/parser/sdf.rs +0 -0
  14. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/scene.rs +0 -0
  15. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shader/bg_fragment.glsl +0 -0
  16. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shader/bg_vertex.glsl +0 -0
  17. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shader/fragment.glsl +0 -0
  18. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shader/mod.rs +0 -0
  19. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shader/vertex.glsl +0 -0
  20. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shapes/mod.rs +0 -0
  21. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shapes/sphere.rs +0 -0
  22. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/shapes/stick.rs +0 -0
  23. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/core/src/utils.rs +0 -0
  24. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/python/Cargo.toml +0 -0
  25. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/python/build.rs +0 -0
  26. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/python/src/parser.rs +0 -0
  27. {cosmol_viewer-0.1.1.dev3 → cosmol_viewer-0.1.1.dev4}/crates/python/src/shapes.rs +0 -0
@@ -699,7 +699,7 @@ dependencies = [
699
699
 
700
700
  [[package]]
701
701
  name = "cosmol_viewer"
702
- version = "0.1.1-nightly.3"
702
+ version = "0.1.1-nightly.4"
703
703
  dependencies = [
704
704
  "bytemuck",
705
705
  "cosmol_viewer_core",
@@ -717,7 +717,7 @@ dependencies = [
717
717
 
718
718
  [[package]]
719
719
  name = "cosmol_viewer_core"
720
- version = "0.1.1-nightly.3"
720
+ version = "0.1.1-nightly.4"
721
721
  dependencies = [
722
722
  "bytemuck",
723
723
  "eframe",
@@ -731,7 +731,7 @@ dependencies = [
731
731
 
732
732
  [[package]]
733
733
  name = "cosmol_viewer_gui"
734
- version = "0.1.1-nightly.3"
734
+ version = "0.1.1-nightly.4"
735
735
  dependencies = [
736
736
  "bytemuck",
737
737
  "cosmol_viewer_core",
@@ -765,7 +765,7 @@ dependencies = [
765
765
 
766
766
  [[package]]
767
767
  name = "cosmol_viewer_wasm"
768
- version = "0.1.1-nightly.3"
768
+ version = "0.1.1-nightly.4"
769
769
  dependencies = [
770
770
  "cosmol_viewer_core",
771
771
  "eframe",
@@ -3160,7 +3160,7 @@ dependencies = [
3160
3160
 
3161
3161
  [[package]]
3162
3162
  name = "test"
3163
- version = "0.1.1-nightly.3"
3163
+ version = "0.1.1-nightly.4"
3164
3164
  dependencies = [
3165
3165
  "cosmol_viewer",
3166
3166
  "cosmol_viewer_core",
@@ -1,6 +1,6 @@
1
1
  [workspace.package]
2
2
  edition = "2024"
3
- version = "0.1.1-nightly.3"
3
+ version = "0.1.1-nightly.4"
4
4
  authors = ["9028 wjt@cosmol.org"]
5
5
  repository = "https://github.com/COSMol-repl/COSMol-viewer"
6
6
  homepage = "https://github.com/COSMol-repl/COSMol-viewer"
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: cosmol-viewer
3
+ Version: 0.1.1.dev4
4
+ Summary: Molecular visualization tools
5
+ Author-email: 95028 <wjt@cosmol.org>
6
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
7
+
8
+ # COSMol-viewer
9
+
10
+ A high-performance molecular visualization library built with Rust and WebGPU, designed for seamless integration into Python workflows.
11
+
12
+ - ⚡ Fast: Native-speed rendering powered by Rust and GPU acceleration
13
+
14
+ - 🧬 Flexible: Load molecules from .sdf, .pdb, and dynamically update 3D structures
15
+
16
+ - 📓 Notebook-friendly: Fully supports Jupyter and Google Colab — ideal for education, research, and live demos
17
+
18
+ - 🔁 Real-time updates: Update molecular coordinates on-the-fly for simulations or animations
19
+
20
+ - 🎨 Customizable: Control styles, camera, and rendering settings programmatically
21
+
22
+ # Installation
23
+
24
+ install with
25
+ ```sh
26
+ pip install cosmol-viewer==0.1.1.dev4
27
+ ```
28
+
29
+ # Usage
30
+
31
+ python:
32
+ ```python
33
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
34
+
35
+ # === Step 1: Load and render a molecule ===
36
+ with open("molecule.sdf", "r") as f:
37
+ sdf = f.read()
38
+ mol = Molecules(parse_sdf(sdf)).centered()
39
+
40
+ scene = Scene.create_viewer()
41
+ scene.scale(0.1)
42
+ scene.add_shape(mol, "mol")
43
+
44
+ viewer = Viewer.render(scene) # Launch the viewer
45
+
46
+ # === Step 2: Update the same molecule dynamically ===
47
+ import time
48
+
49
+ for i in range(1, 10): # Simulate multiple frames
50
+ with open(f"frames/frame_{i}.sdf", "r") as f:
51
+ sdf = f.read()
52
+ updated_mol = Molecules(parse_sdf(sdf)).centered()
53
+
54
+ scene.update_shape("mol", updated_mol)
55
+ viewer.update(scene)
56
+
57
+ time.sleep(0.033) # ~30 FPS
58
+ ```
@@ -39,7 +39,6 @@ impl Canvas {
39
39
  // 正值表示向上滚动,通常是“缩小”,负值是放大
40
40
  if scroll_delta != 0.0 {
41
41
  self.camera_state.scale *= (1.0 + scroll_delta * 0.001).clamp(0.1, 10.0);
42
- println!("scale {:?}", self.camera_state.scale);
43
42
  }
44
43
 
45
44
  self.camera_state = rotate_camera(self.camera_state, response.drag_motion());
@@ -289,15 +288,13 @@ impl Shader {
289
288
  for mesh in scene_data._get_meshes() {
290
289
  self.vertex3d
291
290
  .extend(mesh.vertices.iter().enumerate().map(|(i, pos)| {
292
- let mut j = i;
293
- j = i % 50;
294
291
  Vertex3d {
295
292
  position: *pos,
296
293
  normal: mesh.normals[i],
297
294
  color: mesh
298
295
  .colors
299
296
  .as_ref()
300
- .and_then(|colors| colors.get(j))
297
+ .and_then(|colors| colors.get(i))
301
298
  .unwrap_or(&[1.0, 1.0, 1.0, 1.0])
302
299
  .clone(),
303
300
  }
@@ -524,7 +521,7 @@ pub fn rotate_camera(mut camera_state: CameraState, drag_motion: Vec2) -> Camera
524
521
  pub struct Vertex3d {
525
522
  pub position: [f32; 3],
526
523
  pub normal: [f32; 3],
527
- pub color: [f32; 4], // 可选颜色属性
524
+ pub color: [f32; 4],
528
525
  }
529
526
 
530
527
  #[repr(C)]
@@ -210,10 +210,7 @@ impl Molecules {
210
210
  let radius = self.atom_types.get(i).unwrap_or(&AtomType::Unknown).radius() * 0.2;
211
211
  let color = self.atom_types.get(i).unwrap_or(&AtomType::Unknown).color();
212
212
 
213
- println!("atom: {}, color: {:?}, radius: {}", i, color, radius);
214
-
215
213
  let mut sphere = Sphere::new(*pos, radius);
216
- sphere.style = self.style; // 继承样式
217
214
  sphere.interaction = self.interaction;
218
215
  sphere = sphere.color(color);
219
216
 
@@ -226,7 +223,7 @@ impl Molecules {
226
223
  for n in mesh.normals {
227
224
  normals.push(n.map(|x| x * scale));
228
225
  }
229
- for c in mesh.colors.unwrap_or_default() {
226
+ for c in mesh.colors.unwrap() {
230
227
  colors.push(c);
231
228
  }
232
229
  for idx in mesh.indices {
@@ -243,8 +240,8 @@ impl Molecules {
243
240
  let pos_b = self.atoms[b as usize];
244
241
 
245
242
  let mut stick = Stick::new(pos_a, pos_b, 0.1); // or radius by bond type
246
- stick.style = self.style;
247
243
  stick.interaction = self.interaction;
244
+ stick = stick.color([0.5, 0.5, 0.5]);
248
245
 
249
246
  let mesh = stick.to_mesh(1.0);
250
247
 
@@ -254,7 +251,7 @@ impl Molecules {
254
251
  for n in mesh.normals {
255
252
  normals.push(n.map(|x| x * scale));
256
253
  }
257
- for c in mesh.colors.unwrap_or_default() {
254
+ for c in mesh.colors.unwrap() {
258
255
  colors.push(c);
259
256
  }
260
257
  for idx in mesh.indices {
@@ -0,0 +1,51 @@
1
+ # COSMol-viewer
2
+
3
+ A high-performance molecular visualization library built with Rust and WebGPU, designed for seamless integration into Python workflows.
4
+
5
+ - ⚡ Fast: Native-speed rendering powered by Rust and GPU acceleration
6
+
7
+ - 🧬 Flexible: Load molecules from .sdf, .pdb, and dynamically update 3D structures
8
+
9
+ - 📓 Notebook-friendly: Fully supports Jupyter and Google Colab — ideal for education, research, and live demos
10
+
11
+ - 🔁 Real-time updates: Update molecular coordinates on-the-fly for simulations or animations
12
+
13
+ - 🎨 Customizable: Control styles, camera, and rendering settings programmatically
14
+
15
+ # Installation
16
+
17
+ install with
18
+ ```sh
19
+ pip install cosmol-viewer==0.1.1.dev4
20
+ ```
21
+
22
+ # Usage
23
+
24
+ python:
25
+ ```python
26
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
27
+
28
+ # === Step 1: Load and render a molecule ===
29
+ with open("molecule.sdf", "r") as f:
30
+ sdf = f.read()
31
+ mol = Molecules(parse_sdf(sdf)).centered()
32
+
33
+ scene = Scene.create_viewer()
34
+ scene.scale(0.1)
35
+ scene.add_shape(mol, "mol")
36
+
37
+ viewer = Viewer.render(scene) # Launch the viewer
38
+
39
+ # === Step 2: Update the same molecule dynamically ===
40
+ import time
41
+
42
+ for i in range(1, 10): # Simulate multiple frames
43
+ with open(f"frames/frame_{i}.sdf", "r") as f:
44
+ sdf = f.read()
45
+ updated_mol = Molecules(parse_sdf(sdf)).centered()
46
+
47
+ scene.update_shape("mol", updated_mol)
48
+ viewer.update(scene)
49
+
50
+ time.sleep(0.033) # ~30 FPS
51
+ ```
@@ -138,8 +138,6 @@ impl Viewer {
138
138
 
139
139
  #[staticmethod]
140
140
  pub fn render(scene: &Scene, py: Python) -> Self {
141
- println!("scene {}", serde_json::to_string(&scene.inner).unwrap());
142
-
143
141
  let env_type = detect_runtime_env(py).unwrap();
144
142
  match env_type {
145
143
  RuntimeEnv::Colab | RuntimeEnv::Jupyter => {
@@ -1,8 +1,9 @@
1
1
  [project]
2
2
  name = "cosmol-viewer"
3
- version = "0.1.1.dev3"
3
+ version = "0.1.1.dev4"
4
4
  description = "Molecular visualization tools"
5
5
  authors = [{name = "95028", email = "wjt@cosmol.org"}]
6
+ repository = "https://github.com/COSMol-repl/COSMol-viewer"
6
7
 
7
8
  [build-system]
8
9
  requires = ["maturin>=1.0,<2.0"]
@@ -1,5 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cosmol-viewer
3
- Version: 0.1.1.dev3
4
- Summary: Molecular visualization tools
5
- Author-email: 95028 <wjt@cosmol.org>