cosmol-viewer 0.1.1__cp37-abi3-win32.whl → 0.1.5.dev5__cp37-abi3-win32.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,389 @@
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 string into molecule data.
11
+
12
+ # Args
13
+ - sdf: Path to an SD 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(open("./molecule.sdf", "r", encoding="utf-8").read())
25
+ ```
26
+ """
27
+ ...
28
+
29
+ def parse_mmcif(
30
+ mmcif: str
31
+ ) -> ProteinData:
32
+ """
33
+ Parse an MMCIF string into protein data.
34
+
35
+ # Args
36
+ - mmcif: Path to an MMCIF string containing MMCIF content.
37
+
38
+ # Returns
39
+ - ProteinData: Parsed protein data object.
40
+
41
+ # Example
42
+ ```python
43
+ from cosmol_viewer import parse_mmcif
44
+ prot = parse_mmcif(open("./protein.cif", "r", encoding="utf-8").read())
45
+ ```
46
+ """
47
+ ...
48
+
49
+ class Scene:
50
+ """
51
+ A 3D scene container for visualizing molecular or geometric shapes.
52
+
53
+ This class allows adding, updating, and removing shapes in a 3D scene,
54
+ as well as modifying scene-level properties like scale and background color.
55
+
56
+ Supported shape types:
57
+ - PySphere
58
+ - PyStick
59
+ - PyMolecules
60
+
61
+ Shapes can be optionally identified with a string `id`,
62
+ which allows updates and deletion.
63
+ """
64
+
65
+ def __init__(self) -> None:
66
+ """
67
+ Creates a new empty scene.
68
+
69
+ # Example
70
+ ```python
71
+ scene = Scene()
72
+ ```
73
+ """
74
+ ...
75
+
76
+ def add_shape(self, shape: Union["Sphere", "Stick", "Molecules", "Protein"], id: Optional[str] = None) -> None:
77
+ """
78
+ Add a shape to the scene.
79
+
80
+ # Args
81
+ - shape: A shape instance (Sphere, Stick, Molecules, or Protein).
82
+ - id: Optional string ID to associate with the shape.
83
+
84
+ If the `id` is provided and a shape with the same ID exists,
85
+ the new shape will replace it.
86
+
87
+ # Example
88
+ ```python
89
+ scene.add_shape(sphere)
90
+ scene.add_shape(stick, id="bond1")
91
+ ```
92
+ """
93
+ ...
94
+
95
+ def update_shape(self, id: str, shape: Union["Sphere", "Stick", "Molecules", "Protein"]) -> None:
96
+ """
97
+ Update an existing shape in the scene by its ID.
98
+
99
+ # Args
100
+ - id: ID of the shape to update.
101
+ - shape: New shape object to replace the existing one.
102
+
103
+ # Example
104
+ ```python
105
+ scene.update_shape("atom1", updated_sphere)
106
+ ```
107
+ """
108
+ ...
109
+
110
+ def delete_shape(self, id: str) -> None:
111
+ """
112
+ Remove a shape from the scene by its ID.
113
+
114
+ # Args
115
+ - id: ID of the shape to remove.
116
+
117
+ # Example
118
+ ```python
119
+ scene.delete_shape("bond1")
120
+ ```
121
+ """
122
+ ...
123
+
124
+ def recenter(self, center: List[float]) -> None:
125
+ """
126
+ Recenter the scene at a given point.
127
+
128
+ # Args
129
+ - center: An XYZ array of 3 float values representing the new center.
130
+
131
+ # Example
132
+ ```python
133
+ scene.recenter([0.0, 0.0, 0.0])
134
+ ```
135
+ """
136
+ ...
137
+
138
+ def scale(self, scale: float) -> None:
139
+ """
140
+ Set the global scale factor of the scene.
141
+
142
+ This affects the visual size of all shapes uniformly.
143
+
144
+ # Args
145
+ - scale: A positive float scaling factor.
146
+
147
+ # Example
148
+ ```python
149
+ scene.scale(1.5)
150
+ ```
151
+ """
152
+ ...
153
+
154
+ def set_background_color(self, background_color: List[float]) -> None:
155
+ """
156
+ Set the background color of the scene.
157
+
158
+ # Args
159
+ - background_color: An RGB array of 3 float values between 0.0 and 1.0.
160
+
161
+ # Example
162
+ ```python
163
+ scene.set_background_color([1.0, 1.0, 1.0]) # white background
164
+ ```
165
+ """
166
+ ...
167
+
168
+ def use_black_background(self) -> None:
169
+ """
170
+ Set the background color of the scene to black.
171
+
172
+ # Example
173
+ ```python
174
+ scene.use_black_background()
175
+ ```
176
+ """
177
+ ...
178
+
179
+ class Viewer:
180
+ """
181
+ A viewer that renders 3D scenes in different runtime environments
182
+ (e.g., Jupyter, Colab, or native GUI).
183
+
184
+ The `Viewer` automatically selects a backend:
185
+ - Jupyter/Colab → WebAssembly canvas (inline display)
186
+ - Python script/terminal → native GUI window (if supported)
187
+
188
+ Use `Viewer.render(scene)` to create and display a viewer instance.
189
+ """
190
+
191
+ @staticmethod
192
+ def get_environment() -> str:
193
+ """
194
+ Get the current runtime environment.
195
+
196
+ # Returns
197
+ - str: One of "Jupyter", "Colab", "PlainScript", or "IPythonTerminal".
198
+
199
+ # Example
200
+ ```python
201
+ env = Viewer.get_environment()
202
+ print(env) # e.g., "Jupyter"
203
+ ```
204
+ """
205
+ ...
206
+
207
+ @staticmethod
208
+ def render(scene: "Scene", width: float = 800.0, height: float = 600.0) -> "Viewer":
209
+ """
210
+ Render a 3D scene.
211
+
212
+ # Args
213
+ - scene: The scene to render.
214
+ - width: The viewport width in pixels (default: 800).
215
+ - height: The viewport height in pixels (default: 600).
216
+
217
+ # Returns
218
+ - Viewer: The created viewer instance.
219
+
220
+ # Example
221
+ ```python
222
+ from cosmol_viewer import Viewer, Scene, Sphere
223
+ scene = Scene()
224
+ scene.add_shape(Sphere([0, 0, 0], 1.0))
225
+ viewer = Viewer.render(scene)
226
+ ```
227
+ """
228
+ ...
229
+
230
+ @staticmethod
231
+ def play(
232
+ frames: List["Scene"],
233
+ interval: float,
234
+ loops: int,
235
+ width: float = 800.0,
236
+ height: float = 600.0,
237
+ smooth: bool = False
238
+ ) -> "Viewer":
239
+ """
240
+ Play an animation of multiple frames.
241
+
242
+ # Args
243
+ - frames: List of Scene objects as animation frames.
244
+ - interval: Frame interval in seconds.
245
+ - loops: Number of loops to repeat (-1 for infinite).
246
+ - width: The viewport width in pixels.
247
+ - height: The viewport height in pixels.
248
+ - smooth: Whether to smooth the animation by
249
+ interpolating between frames.
250
+
251
+ # Returns
252
+ - Viewer: The created viewer instance.
253
+
254
+ # Example
255
+ ```python
256
+ viewer = Viewer.play([scene1, scene2], interval=0.5, loops=3)
257
+ ```
258
+ """
259
+ ...
260
+
261
+ def update(self, scene: "Scene") -> None:
262
+ """
263
+ Update the viewer with a new scene.
264
+
265
+ Works for both Web-based rendering (Jupyter/Colab) and native GUI windows.
266
+
267
+ ⚠️ Note (Jupyter/Colab): Animation updates may be limited by
268
+ notebook rendering capacity.
269
+
270
+ # Args
271
+ - scene: The updated scene.
272
+
273
+ # Example
274
+ ```python
275
+ scene.add_shape(Sphere([1, 1, 1], 0.5))
276
+ viewer.update(scene)
277
+ ```
278
+ """
279
+ ...
280
+
281
+ def save_image(self, path: str) -> None:
282
+ """
283
+ Save the current image to a file.
284
+
285
+ # Args
286
+ - path: File path for the saved image.
287
+
288
+ # Example
289
+ ```python
290
+ viewer.save_image("output.png")
291
+ ```
292
+ """
293
+ ...
294
+
295
+ class Sphere:
296
+ """
297
+ A sphere shape in the scene.
298
+
299
+ # Args
300
+ - center: [x, y, z] coordinates of the sphere center.
301
+ - radius: Radius of the sphere.
302
+
303
+ # Example
304
+ ```python
305
+ sphere = Sphere([0, 0, 0], 1.0).color([1, 0, 0])
306
+ ```
307
+ """
308
+
309
+ def __init__(self, center: List[float], radius: float) -> None: ...
310
+ def set_center(self, center: List[float]) -> "Sphere": ...
311
+ def set_radius(self, radius: float) -> "Sphere": ...
312
+ def color(self, color: List[float]) -> "Sphere": ...
313
+ def color_rgba(self, color: List[float]) -> "Sphere": ...
314
+ def opacity(self, opacity: float) -> "Sphere": ...
315
+
316
+
317
+ class Stick:
318
+ """
319
+ A cylindrical stick (or capsule) connecting two points.
320
+
321
+ # Args
322
+ - start: Starting point [x, y, z].
323
+ - end: Ending point [x, y, z].
324
+ - thickness: Stick radius.
325
+
326
+ # Example
327
+ ```python
328
+ stick = Stick([0,0,0], [1,1,1], 0.1).opacity(0.5)
329
+ ```
330
+ """
331
+
332
+ def __init__(self, start: List[float], end: List[float], thickness: float) -> None: ...
333
+ def color(self, color: List[float]) -> "Stick": ...
334
+ def color_rgba(self, color: List[float]) -> "Stick": ...
335
+ def opacity(self, opacity: float) -> "Stick": ...
336
+ def set_thickness(self, thickness: float) -> "Stick": ...
337
+ def set_start(self, start: List[float]) -> "Stick": ...
338
+ def set_end(self, end: List[float]) -> "Stick": ...
339
+
340
+
341
+ class Molecules:
342
+ """
343
+ A molecular shape object.
344
+
345
+ # Example
346
+ ```python
347
+ mol = parse_sdf(open("molecule.sdf", "r", encoding="utf-8").read())
348
+ molecules = Molecules(mol).centered().color([0,1,0])
349
+ ```
350
+ """
351
+
352
+ def __init__(self, molecule_data: "MoleculeData") -> None: ...
353
+ def get_center(self) -> List[float]: ...
354
+ def centered(self) -> "Molecules": ...
355
+ def color(self, color: List[float]) -> "Molecules": ...
356
+ def color_rgba(self, color: List[float]) -> "Molecules": ...
357
+ def opacity(self, opacity: float) -> "Molecules": ...
358
+ def reset_color(self) -> "Molecules": ...
359
+
360
+ class MoleculeData:
361
+ """
362
+ Internal representation of molecule data returned by `parse_sdf`.
363
+ """
364
+ ...
365
+
366
+ class Protein:
367
+ """
368
+ A protein shape object.
369
+
370
+ # Example
371
+ ```python
372
+ mmcif_data = parse_mmcif(open("2AMD.cif", "r", encoding="utf-8").read())
373
+ prot = Protein(mmcif_data).centered().color([0,1,0])
374
+ ```
375
+ """
376
+
377
+ def __init__(self, molecule_data: "MoleculeData") -> None: ...
378
+ def get_center(self) -> List[float]: ...
379
+ def centered(self) -> "Molecules": ...
380
+ def color(self, color: List[float]) -> "Molecules": ...
381
+ def color_rgba(self, color: List[float]) -> "Molecules": ...
382
+ def opacity(self, opacity: float) -> "Molecules": ...
383
+ def reset_color(self) -> "Molecules": ...
384
+
385
+ class ProteinData:
386
+ """
387
+ Internal representation of protein data returned by `parse_mmcif`.
388
+ """
389
+ ...
Binary file
cosmol_viewer/py.typed ADDED
File without changes
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.4
2
+ Name: cosmol-viewer
3
+ Version: 0.1.5.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
+ <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
+ A high-performance molecular viewer for `Python` and `Rust`, backed by `Rust`.
24
+ Supports both static rendering and smooth animation playback — including inside Jupyter notebooks.
25
+
26
+
27
+ A compact, high-performance renderer for molecular and scientific shapes with two usage patterns:
28
+
29
+ - **Static rendering + update** — push individual scene updates from your application or simulation.
30
+ - **Play (recommended for demonstrations & smooth playback)** — precompute frames and hand the sequence to the viewer to play back with optional interpolation (`smooth`).
31
+
32
+ ---
33
+
34
+ ## Quick concepts
35
+
36
+ - **Scene**: container for shapes (molecules, spheres, lines, etc.).
37
+ - **Viewer.render(scene, ...)**: create a static viewer bound to a canvas (native or notebook). Good for static visualization.
38
+ - **viewer.update(scene)**: push incremental changes (real-time / streaming use-cases).
39
+ - **Viewer.play(frames, interval, loops, width, height, smooth)**: *recommended* for precomputed animations and demonstrations. The viewer takes care of playback timing and looping.
40
+
41
+ **Why prefer `play` for demos?**
42
+ - Single call API (hand off responsibility to the viewer).
43
+ - Built-in timing & loop control.
44
+ - Optional `smooth` interpolation between frames for visually pleasing playback even when input frame rate is low.
45
+
46
+ **Why keep `update`?**
47
+ - `update` is ideal for real-time simulations, MD runs, or streaming data where frames are not precomputed. It provides strict fidelity (no interpolation) and minimal latency.
48
+
49
+ ---
50
+
51
+ ## Installation
52
+
53
+ ```sh
54
+ pip install cosmol-viewer
55
+ ```
56
+
57
+ ---
58
+
59
+ ## Quick Start
60
+ See examples in [Google Colab](https://colab.research.google.com/drive/1Sw72QWjQh_sbbY43jGyBOfF1AQCycmIx?usp=sharing).
61
+ ### 1. Static molecular rendering
62
+
63
+ ```python
64
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
65
+
66
+ with open("molecule.sdf", "r") as f:
67
+ sdf = f.read()
68
+ mol = Molecules(parse_sdf(sdf)).centered()
69
+
70
+ scene = Scene()
71
+ scene.scale(0.1)
72
+ scene.add_shape(mol, "mol")
73
+
74
+ viewer = Viewer.render(scene, width=600, height=400)
75
+
76
+ print("Press Any Key to exit...", end='', flush=True)
77
+ _ = input() # Keep the viewer open until you decide to close
78
+ ```
79
+
80
+ ### 2. Animation playback with `Viewer.play`
81
+
82
+ ```python
83
+ from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
84
+ import time
85
+
86
+ interval = 0.033 # ~30 FPS
87
+
88
+ frames = []
89
+
90
+ for i in range(1, 10):
91
+ with open(f"frames/frame_{i}.sdf", "r") as f:
92
+ sdf = f.read()
93
+ mol = Molecules(parse_sdf(sdf)).centered()
94
+
95
+ scene = Scene()
96
+ scene.scale(0.1)
97
+ scene.add_shape(mol, "mol")
98
+
99
+ frames.append(scene)
100
+
101
+ Viewer.play(frames, interval=interval, loops=1, width=600, height=400, smooth=True)
102
+ ```
103
+
104
+ ## Documentation
105
+
106
+ For API reference and advanced usage, please see the [latest documentation](https://cosmol-repl.github.io/COSMol-viewer).
107
+
@@ -0,0 +1,7 @@
1
+ cosmol_viewer-0.1.5.dev5.dist-info/METADATA,sha256=dRDKxadRG0w5bgVf9teyHcUiycCYXIahuaPNAljCakE,3677
2
+ cosmol_viewer-0.1.5.dev5.dist-info/WHEEL,sha256=Wk5Fd_lTEzYPUyNAg_8onKUGSv_hYjos3aDyUsI9euQ,91
3
+ cosmol_viewer/__init__.py,sha256=K33zoYpHqUVvpFdMVxmCtw4uKj9ZXrGuQD4D4DuUmjk,135
4
+ cosmol_viewer/__init__.pyi,sha256=0wSXySnkje07Z-LqpQtrx5lqudkNa_8mAzCLm-Z2I6A,10609
5
+ cosmol_viewer/cosmol_viewer.pyd,sha256=9Hugh5gzubhj8KjouKPWATgzWteZWk2cuxtDd-wrLqk,16866816
6
+ cosmol_viewer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ cosmol_viewer-0.1.5.dev5.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: maturin (1.9.1)
2
+ Generator: maturin (1.10.2)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp37-abi3-win32
@@ -1,57 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cosmol-viewer
3
- Version: 0.1.1
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
- A high-performance molecular visualization library built with Rust and WebGPU, designed for seamless integration into Python workflows.
12
-
13
- - ⚡ Fast: Native-speed rendering powered by Rust and GPU acceleration
14
-
15
- - 🧬 Flexible: Load molecules from .sdf, .pdb, and dynamically update 3D structures
16
-
17
- - 📓 Notebook-friendly: Fully supports Jupyter and Google Colab — ideal for education, research, and live demos
18
-
19
- - 🔁 Real-time updates: Update molecular coordinates on-the-fly for simulations or animations
20
-
21
- - 🎨 Customizable: Control styles, camera, and rendering settings programmatically
22
-
23
- # Installation
24
-
25
- ```sh
26
- pip install cosmol-viewer==0.1.1
27
- ```
28
-
29
- # Usage
30
-
31
- ```python
32
- from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
33
-
34
- # === Step 1: Load and render a molecule ===
35
- with open("molecule.sdf", "r") as f:
36
- sdf = f.read()
37
- mol = Molecules(parse_sdf(sdf)).centered()
38
-
39
- scene = Scene()
40
- scene.scale(0.1)
41
- scene.add_shape(mol, "mol")
42
-
43
- viewer = Viewer.render(scene) # Launch the viewer
44
-
45
- # === Step 2: Update the same molecule dynamically ===
46
- import time
47
-
48
- for i in range(1, 10): # Simulate multiple frames
49
- with open(f"frames/frame_{i}.sdf", "r") as f:
50
- sdf = f.read()
51
- updated_mol = Molecules(parse_sdf(sdf)).centered()
52
-
53
- scene.update_shape("mol", updated_mol)
54
- viewer.update(scene)
55
-
56
- time.sleep(0.033) # ~30 FPS
57
- ```
@@ -1,5 +0,0 @@
1
- cosmol_viewer-0.1.1.dist-info/METADATA,sha256=vBi1xxURedVVx8L5IHJLvkbH-FNA0kaC1jz8EVzsd6Q,1697
2
- cosmol_viewer-0.1.1.dist-info/WHEEL,sha256=UcECe7RMSN54PK7UjTb4XiJPfalDkexpKph-K5Oo0Os,90
3
- cosmol_viewer/__init__.py,sha256=K33zoYpHqUVvpFdMVxmCtw4uKj9ZXrGuQD4D4DuUmjk,135
4
- cosmol_viewer/cosmol_viewer.pyd,sha256=Kb9SfX6Sv8NJIQLVhLR5IQODJIoGsZFOkt04tWtPVgE,10196480
5
- cosmol_viewer-0.1.1.dist-info/RECORD,,