cosmol-viewer 0.1.2.dev5__cp37-abi3-macosx_10_12_x86_64.whl → 0.1.3.dev2__cp37-abi3-macosx_10_12_x86_64.whl

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.

@@ -0,0 +1,315 @@
1
+ from typing import Optional, Union, List
2
+
3
+ def parse_sdf(
4
+ sdf: str,
5
+ keep_h: bool = True,
6
+ multimodel: bool = True,
7
+ onemol: bool = False
8
+ ) -> "MoleculeData":
9
+ """
10
+ Parse an SDF file or string into molecule data.
11
+
12
+ # Args
13
+ - sdf: Path to an SDF file or a string containing SDF content.
14
+ - keep_h: Whether to keep explicit hydrogen atoms (default: True).
15
+ - multimodel: Whether to allow multiple models in one file (default: True).
16
+ - onemol: Whether to merge multiple models into one molecule (default: False).
17
+
18
+ # Returns
19
+ - MoleculeData: Parsed molecule data object.
20
+
21
+ # Example
22
+ ```python
23
+ from cosmol_viewer import parse_sdf
24
+ mol = parse_sdf("molecule.sdf")
25
+ ```
26
+ """
27
+ ...
28
+
29
+
30
+ class Scene:
31
+ """
32
+ A 3D scene container for visualizing molecular or geometric shapes.
33
+
34
+ This class allows adding, updating, and removing shapes in a 3D scene,
35
+ as well as modifying scene-level properties like scale and background color.
36
+
37
+ Supported shape types:
38
+ - PySphere
39
+ - PyStick
40
+ - PyMolecules
41
+
42
+ Shapes can be optionally identified with a string `id`,
43
+ which allows updates and deletion.
44
+ """
45
+
46
+ def __init__(self) -> None:
47
+ """
48
+ Creates a new empty scene.
49
+
50
+ # Example
51
+ ```python
52
+ scene = Scene()
53
+ ```
54
+ """
55
+ ...
56
+
57
+ def add_shape(self, shape: Union["Sphere", "Stick", "Molecules"], id: Optional[str] = None) -> None:
58
+ """
59
+ Add a shape to the scene.
60
+
61
+ # Args
62
+ - shape: A shape instance (PySphere, PyStick, or PyMolecules).
63
+ - id: Optional string ID to associate with the shape.
64
+
65
+ If the `id` is provided and a shape with the same ID exists,
66
+ the new shape will replace it.
67
+
68
+ # Example
69
+ ```python
70
+ scene.add_shape(sphere)
71
+ scene.add_shape(stick, id="bond1")
72
+ ```
73
+ """
74
+ ...
75
+
76
+ def update_shape(self, id: str, shape: Union["Sphere", "Stick", "Molecules"]) -> None:
77
+ """
78
+ Update an existing shape in the scene by its ID.
79
+
80
+ # Args
81
+ - id: ID of the shape to update.
82
+ - shape: New shape object to replace the existing one.
83
+
84
+ # Example
85
+ ```python
86
+ scene.update_shape("atom1", updated_sphere)
87
+ ```
88
+ """
89
+ ...
90
+
91
+ def delete_shape(self, id: str) -> None:
92
+ """
93
+ Remove a shape from the scene by its ID.
94
+
95
+ # Args
96
+ - id: ID of the shape to remove.
97
+
98
+ # Example
99
+ ```python
100
+ scene.delete_shape("bond1")
101
+ ```
102
+ """
103
+ ...
104
+
105
+ def scale(self, scale: float) -> None:
106
+ """
107
+ Set the global scale factor of the scene.
108
+
109
+ This affects the visual size of all shapes uniformly.
110
+
111
+ # Args
112
+ - scale: A positive float scaling factor.
113
+
114
+ # Example
115
+ ```python
116
+ scene.scale(1.5)
117
+ ```
118
+ """
119
+ ...
120
+
121
+ def set_background_color(self, background_color: List[float]) -> None:
122
+ """
123
+ Set the background color of the scene.
124
+
125
+ # Args
126
+ - background_color: An RGB array of 3 float values between 0.0 and 1.0.
127
+
128
+ # Example
129
+ ```python
130
+ scene.set_background_color([1.0, 1.0, 1.0]) # white background
131
+ ```
132
+ """
133
+ ...
134
+
135
+ class Viewer:
136
+ """
137
+ A viewer that renders 3D scenes in different runtime environments
138
+ (e.g., Jupyter, Colab, or native GUI).
139
+
140
+ The `Viewer` automatically selects a backend:
141
+ - Jupyter/Colab → WebAssembly canvas (inline display)
142
+ - Python script/terminal → native GUI window (if supported)
143
+
144
+ Use `Viewer.render(scene)` to create and display a viewer instance.
145
+ """
146
+
147
+ @staticmethod
148
+ def get_environment() -> str:
149
+ """
150
+ Get the current runtime environment.
151
+
152
+ # Returns
153
+ - str: One of "Jupyter", "Colab", "PlainScript", or "IPythonTerminal".
154
+
155
+ # Example
156
+ ```python
157
+ env = Viewer.get_environment()
158
+ print(env) # e.g., "Jupyter"
159
+ ```
160
+ """
161
+ ...
162
+
163
+ @staticmethod
164
+ def render(scene: "Scene", width: float = 800.0, height: float = 600.0) -> "Viewer":
165
+ """
166
+ Render a 3D scene.
167
+
168
+ # Args
169
+ - scene: The scene to render.
170
+ - width: The viewport width in pixels (default: 800).
171
+ - height: The viewport height in pixels (default: 600).
172
+
173
+ # Returns
174
+ - Viewer: The created viewer instance.
175
+
176
+ # Example
177
+ ```python
178
+ from cosmol_viewer import Viewer, Scene, Sphere
179
+ scene = Scene()
180
+ scene.add_shape(Sphere([0, 0, 0], 1.0))
181
+ viewer = Viewer.render(scene)
182
+ ```
183
+ """
184
+ ...
185
+
186
+ @staticmethod
187
+ def play(
188
+ frames: List["Scene"],
189
+ interval: float,
190
+ loops: int,
191
+ width: float = 800.0,
192
+ height: float = 600.0
193
+ ) -> "Viewer":
194
+ """
195
+ Play an animation of multiple frames.
196
+
197
+ # Args
198
+ - frames: List of Scene objects as animation frames.
199
+ - interval: Frame interval in seconds.
200
+ - loops: Number of loops to repeat (-1 for infinite).
201
+ - width: The viewport width in pixels.
202
+ - height: The viewport height in pixels.
203
+
204
+ # Returns
205
+ - Viewer: The created viewer instance.
206
+
207
+ # Example
208
+ ```python
209
+ viewer = Viewer.play([scene1, scene2], interval=0.5, loops=3)
210
+ ```
211
+ """
212
+ ...
213
+
214
+ def update(self, scene: "Scene") -> None:
215
+ """
216
+ Update the viewer with a new scene.
217
+
218
+ Works for both Web-based rendering (Jupyter/Colab) and native GUI windows.
219
+
220
+ ⚠️ Note (Jupyter/Colab): Animation updates may be limited by
221
+ notebook rendering capacity.
222
+
223
+ # Args
224
+ - scene: The updated scene.
225
+
226
+ # Example
227
+ ```python
228
+ scene.add_shape(Sphere([1, 1, 1], 0.5))
229
+ viewer.update(scene)
230
+ ```
231
+ """
232
+ ...
233
+
234
+ def save_image(self, path: str) -> None:
235
+ """
236
+ Save the current image to a file.
237
+
238
+ # Args
239
+ - path: File path for the saved image.
240
+
241
+ # Example
242
+ ```python
243
+ viewer.save_image("output.png")
244
+ ```
245
+ """
246
+ ...
247
+
248
+ class Sphere:
249
+ """
250
+ A sphere shape in the scene.
251
+
252
+ # Args
253
+ - center: [x, y, z] coordinates of the sphere center.
254
+ - radius: Radius of the sphere.
255
+
256
+ # Example
257
+ ```python
258
+ sphere = Sphere([0, 0, 0], 1.0).color([1, 0, 0])
259
+ ```
260
+ """
261
+
262
+ def __init__(self, center: List[float], radius: float) -> None: ...
263
+ def set_center(self, center: List[float]) -> "Sphere": ...
264
+ def set_radius(self, radius: float) -> "Sphere": ...
265
+ def color(self, color: List[float]) -> "Sphere": ...
266
+ def color_rgba(self, color: List[float]) -> "Sphere": ...
267
+ def opacity(self, opacity: float) -> "Sphere": ...
268
+
269
+
270
+ class Stick:
271
+ """
272
+ A cylindrical stick (or capsule) connecting two points.
273
+
274
+ # Args
275
+ - start: Starting point [x, y, z].
276
+ - end: Ending point [x, y, z].
277
+ - thickness: Stick radius.
278
+
279
+ # Example
280
+ ```python
281
+ stick = Stick([0,0,0], [1,1,1], 0.1).opacity(0.5)
282
+ ```
283
+ """
284
+
285
+ def __init__(self, start: List[float], end: List[float], thickness: float) -> None: ...
286
+ def color(self, color: List[float]) -> "Stick": ...
287
+ def color_rgba(self, color: List[float]) -> "Stick": ...
288
+ def opacity(self, opacity: float) -> "Stick": ...
289
+ def set_thickness(self, thickness: float) -> "Stick": ...
290
+ def set_start(self, start: List[float]) -> "Stick": ...
291
+ def set_end(self, end: List[float]) -> "Stick": ...
292
+
293
+
294
+ class Molecules:
295
+ """
296
+ A molecular shape object parsed from SDF data.
297
+
298
+ # Example
299
+ ```python
300
+ mol = parse_sdf("molecule.sdf")
301
+ molecules = Molecules(mol).centered().color([0,1,0])
302
+ ```
303
+ """
304
+
305
+ def __init__(self, molecule_data: "MoleculeData") -> None: ...
306
+ def centered(self) -> "Molecules": ...
307
+ def color(self, color: List[float]) -> "Molecules": ...
308
+ def color_rgba(self, color: List[float]) -> "Molecules": ...
309
+ def opacity(self, opacity: float) -> "Molecules": ...
310
+
311
+ class MoleculeData:
312
+ """
313
+ Internal representation of molecule data returned by `parse_sdf`.
314
+ """
315
+ ...
Binary file
cosmol_viewer/py.typed ADDED
File without changes
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.4
2
+ Name: cosmol-viewer
3
+ Version: 0.1.3.dev2
4
+ Summary: Molecular visualization tools
5
+ Author-email: 95028 <wjt@cosmol.org>
6
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
7
+ Project-URL: Repository, https://github.com/COSMol-repl/COSMol-viewer
8
+
9
+ # COSMol-viewer
10
+
11
+ <div align="center">
12
+ <a href="https://crates.io/crates/cosmol_viewer">
13
+ <img src="https://img.shields.io/crates/v/cosmol_viewer.svg" alt="crates.io Latest Release"/>
14
+ </a>
15
+ <a href="https://pypi.org/project/cosmol_viewer/">
16
+ <img src="https://img.shields.io/pypi/v/cosmol_viewer.svg" alt="PyPi Latest Release"/>
17
+ </a>
18
+ <a href="https://cosmol-repl.github.io/COSMol-viewer">
19
+ <img src="https://img.shields.io/badge/docs-latest-blue.svg" alt="Documentation Status"/>
20
+ </a>
21
+ </div>
22
+
23
+ **COSMol-viewer** is a high-performance molecular visualization library, written in **Rust** and powered by **WebGPU**, designed for seamless integration into **Python** workflows.
24
+
25
+ - ⚡ **High-speed rendering** — GPU-accelerated performance at native speed
26
+ - 🧬 **Flexible input** — Load structures from `.sdf`, `.pdb`, or dynamically generated coordinates
27
+ - 📓 **Notebook-ready** — Fully compatible with Jupyter and Google Colab, ideal for teaching, research, and interactive demos
28
+ - 🔁 **Dynamic visualization** — Update molecular structures on-the-fly or play smooth preloaded animations
29
+ - 🎨 **Customizable** — Fine-grained control of rendering styles, camera, and scene parameters
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ ```sh
36
+ pip install cosmol-viewer
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Quick Start
42
+
43
+ ```python
44
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
45
+
46
+ # === Step 1: Load and render a molecule ===
47
+ with open("molecule.sdf", "r") as f:
48
+ sdf = f.read()
49
+ mol = Molecules(parse_sdf(sdf)).centered()
50
+
51
+ scene = Scene()
52
+ scene.scale(0.1)
53
+ scene.add_shape(mol, "mol")
54
+
55
+ viewer = Viewer.render(scene, width=600, height=400) # Launch viewer
56
+
57
+ print("Press Any Key to exit...", end='', flush=True)
58
+ _ = input() # Keep the viewer open until you decide to close
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Animation Modes
64
+
65
+ COSMol-viewer supports **two complementary animation workflows**, depending on whether you prefer **real-time updates** or **preloaded playback**.
66
+
67
+ ### 1. Real-Time Updates (Frame-by-Frame Streaming)
68
+
69
+ Update the molecule directly inside an existing scene:
70
+
71
+ ```python
72
+ import time
73
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
74
+
75
+ scene = Scene()
76
+ scene.scale(0.1)
77
+
78
+ # Initial load
79
+ with open("frames/frame_1.sdf", "r") as f:
80
+ sdf = f.read()
81
+ mol = Molecules(parse_sdf(sdf)).centered()
82
+ scene.add_shape(mol, "mol")
83
+
84
+ viewer = Viewer.render(scene, width=600, height=400)
85
+
86
+ # Update in real time
87
+ for i in range(2, 10):
88
+ with open(f"frames/frame_{i}.sdf", "r") as f:
89
+ sdf = f.read()
90
+ updated_mol = Molecules(parse_sdf(sdf)).centered()
91
+
92
+ scene.update_shape("mol", updated_mol)
93
+ viewer.update(scene)
94
+
95
+ time.sleep(0.033) # ~30 FPS
96
+
97
+ print("Press Any Key to exit...", end='', flush=True)
98
+ _ = input()
99
+ ```
100
+
101
+ **Use cases:**
102
+ - Visualizing the *progress* of a simulation step-by-step
103
+ - Interactive experiments or streaming scenarios where frames are not known in advance
104
+
105
+ **Trade-offs:**
106
+ - ✅ Low memory usage — no need to preload frames
107
+ - ⚠️ Playback smoothness depends on computation / I/O speed → may stutter if frame generation is slow
108
+
109
+ ---
110
+
111
+ ### 2. Preloaded Playback (One-Shot Animation) (Start from 0.1.3)
112
+
113
+ Load all frames into memory first, then play them back smoothly:
114
+
115
+ ```python
116
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
117
+
118
+ frames = []
119
+ interval = 0.033 # ~30 FPS
120
+
121
+ # Preload all frames
122
+ for i in range(1, 10):
123
+ with open(f"frames/frame_{i}.sdf", "r") as f:
124
+ sdf = f.read()
125
+ mol = Molecules(parse_sdf(sdf)).centered()
126
+
127
+ scene = Scene()
128
+ scene.scale(0.1)
129
+ scene.add_shape(mol, "mol")
130
+ frames.append(scene)
131
+
132
+ # Playback once
133
+ Viewer.play(frames, interval=interval, loops=1, width=600, height=400)
134
+
135
+ print("Press Any Key to exit...", end='', flush=True)
136
+ _ = input()
137
+ ```
138
+
139
+ **Use cases:**
140
+ - Smooth, stable playback for presentations or teaching
141
+ - Demonstrating precomputed trajectories (e.g., molecular dynamics snapshots)
142
+
143
+ **Trade-offs:**
144
+ - ✅ Very smooth playback, independent of computation speed
145
+ - ⚠️ Requires preloading all frames → higher memory usage
146
+ - ⚠️ Longer initial load time for large trajectories
147
+
148
+ ---
149
+
150
+ ## Choosing the Right Mode
151
+
152
+ - ✅ Use **real-time updates** if your frames are generated on-the-fly or memory is limited
153
+ - ✅ Use **preloaded playback** if you want guaranteed smooth animations and can preload your trajectory
154
+
155
+ ---
156
+
157
+ ## Exiting the Viewer
158
+
159
+ > **Important:** The viewer is bound to the Python process.
160
+ > When your script finishes, the rendering window will close automatically.
161
+
162
+ To keep the visualization alive until you are ready to exit, always add:
163
+
164
+ ```python
165
+ print("Press Any Key to exit...", end='', flush=True)
166
+ _ = input()
167
+ ```
168
+
169
+ This ensures:
170
+ - The window stays open for inspection
171
+ - The user decides when to end visualization
172
+ - Prevents premature termination at the end of the script
173
+
174
+ ---
175
+
176
+ ## Documentation
177
+
178
+ For API reference and advanced usage, please see the [latest documentation](https://cosmol-repl.github.io/COSMol-viewer).
179
+
@@ -0,0 +1,7 @@
1
+ cosmol_viewer-0.1.3.dev2.dist-info/METADATA,sha256=BpvjCIRGgH-ituEwGJsGtC4x6NlZp2KVTMSaKjaDbmc,5289
2
+ cosmol_viewer-0.1.3.dev2.dist-info/WHEEL,sha256=EXWYGIlQOGI1SAWXpNs-tKqcTH553LQS8liEUK4J-U8,104
3
+ cosmol_viewer/__init__.py,sha256=K33zoYpHqUVvpFdMVxmCtw4uKj9ZXrGuQD4D4DuUmjk,135
4
+ cosmol_viewer/__init__.pyi,sha256=JzeDsMSjCE2ErFohX6fzrWVPUYVsEPksIVqc0b6J6DU,8256
5
+ cosmol_viewer/cosmol_viewer.abi3.so,sha256=0Q2ZXaeZOz-mm_FE8m-pG-qJ96hNMl1gnUeG3NCbc2g,14423592
6
+ cosmol_viewer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ cosmol_viewer-0.1.3.dev2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.9.1)
2
+ Generator: maturin (1.9.4)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp37-abi3-macosx_10_12_x86_64
@@ -1,70 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cosmol-viewer
3
- Version: 0.1.2.dev5
4
- Summary: Molecular visualization tools
5
- Author-email: 95028 <wjt@cosmol.org>
6
- Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
7
- Project-URL: Repository, https://github.com/COSMol-repl/COSMol-viewer
8
-
9
- # COSMol-viewer
10
-
11
- <div align="center">
12
- <a href="https://crates.io/crates/cosmol_viewer">
13
- <img src="https://img.shields.io/crates/v/cosmol_viewer.svg" alt="crates.io Latest Release"/>
14
- </a>
15
- <a href="https://pypi.org/project/cosmol_viewer/">
16
- <img src="https://img.shields.io/pypi/v/cosmol_viewer.svg" alt="PyPi Latest Release"/>
17
- </a>
18
- </div>
19
-
20
- A high-performance molecular visualization library built with Rust and WebGPU, designed for seamless integration into Python workflows.
21
-
22
- - ⚡ Fast: Native-speed rendering powered by Rust and GPU acceleration
23
-
24
- - 🧬 Flexible: Load molecules from .sdf, .pdb, and dynamically update 3D structures
25
-
26
- - 📓 Notebook-friendly: Fully supports Jupyter and Google Colab — ideal for education, research, and live demos
27
-
28
- - 🔁 Real-time updates: Update molecular coordinates on-the-fly for simulations or animations
29
-
30
- - 🎨 Customizable: Control styles, camera, and rendering settings programmatically
31
-
32
- # Installation
33
-
34
- ```sh
35
- pip install cosmol-viewer
36
- ```
37
-
38
- # Examples
39
-
40
- See examples in [Google Colab](https://colab.research.google.com/drive/1Sw72QWjQh_sbbY43jGyBOfF1AQCycmIx?usp=sharing).
41
-
42
- # Usage
43
-
44
- ```python
45
- from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
46
-
47
- # === Step 1: Load and render a molecule ===
48
- with open("molecule.sdf", "r") as f:
49
- sdf = f.read()
50
- mol = Molecules(parse_sdf(sdf)).centered()
51
-
52
- scene = Scene()
53
- scene.scale(0.1)
54
- scene.add_shape(mol, "mol")
55
-
56
- viewer = Viewer.render(scene) # Launch the viewer
57
-
58
- # === Step 2: Update the same molecule dynamically ===
59
- import time
60
-
61
- for i in range(1, 10): # Simulate multiple frames
62
- with open(f"frames/frame_{i}.sdf", "r") as f:
63
- sdf = f.read()
64
- updated_mol = Molecules(parse_sdf(sdf)).centered()
65
-
66
- scene.update_shape("mol", updated_mol)
67
- viewer.update(scene)
68
-
69
- time.sleep(0.033) # ~30 FPS
70
- ```
@@ -1,5 +0,0 @@
1
- cosmol_viewer-0.1.2.dev5.dist-info/METADATA,sha256=mItC7QaLVwxiP0EMtO16NA0EJlsXO15bv7Wnvy3FlOk,2116
2
- cosmol_viewer-0.1.2.dev5.dist-info/WHEEL,sha256=7HjpuF5o5lgtMF3pBy6MlpnMVqynhBW3YA6IoSreuqI,104
3
- cosmol_viewer/__init__.py,sha256=K33zoYpHqUVvpFdMVxmCtw4uKj9ZXrGuQD4D4DuUmjk,135
4
- cosmol_viewer/cosmol_viewer.abi3.so,sha256=TWd_W03e5sG3Aj1OoehjvPkzlbnXA0qiRv3Y515B1FM,14427304
5
- cosmol_viewer-0.1.2.dev5.dist-info/RECORD,,