@judah-silva/rnacanvas 0.0.1

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.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # 🧬 RNA Canvas
2
+
3
+ A reusable, customizable 3D canvas component built with **Babylon.js** and **React**, designed for interactive molecular visualization and selection tools.
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @judah-silva/rnacanvas @babylonjs/core
9
+ # or
10
+ yarn add @judah-silva/rnacanvas @babylonjs/core
@@ -0,0 +1,528 @@
1
+ import { Mesh, TransformNode, Scene, Matrix, Nullable, Quaternion, Observer, Engine, UniversalCamera } from '@babylonjs/core';
2
+
3
+ /**
4
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
5
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
6
+ * No code shall be distributed or modified without the permission of the PI.
7
+ * @author Judah Silva <silva.judah7@outlook.com>
8
+ */
9
+
10
+ declare class Residue extends Group<MeshObject> {
11
+ constructor(name: string);
12
+ addChild(child: MeshObject): void;
13
+ hasMesh(uuid: string): boolean;
14
+ }
15
+
16
+ /**
17
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
18
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
19
+ * No code shall be distributed or modified without the permission of the PI.
20
+ * @author Judah Silva <silva.judah7@outlook.com>
21
+ */
22
+
23
+ declare class MeshObject {
24
+ private _mesh;
25
+ userData: Object;
26
+ constructor(name: string);
27
+ setParent(parent: Residue | null): void;
28
+ applyVertexData(positions: number[], indices: number[]): void;
29
+ applyHighlight(): void;
30
+ resetHighlight(): void;
31
+ /**
32
+ * Cretes a material with the given color and sets it to the mesh
33
+ * @param color String in the format of #RRGGBB
34
+ */
35
+ createAndSetMaterial(color: string): void;
36
+ setNewMesh(mesh: Mesh): MeshObject;
37
+ get mesh(): Mesh;
38
+ get uuid(): string;
39
+ }
40
+
41
+ /**
42
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
43
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
44
+ * No code shall be distributed or modified without the permission of the PI.
45
+ * @author Judah Silva <silva.judah7@outlook.com>
46
+ */
47
+
48
+ declare abstract class Group<T extends MeshObject | Group<MeshObject>> {
49
+ protected _node: TransformNode;
50
+ protected _children: Set<T>;
51
+ constructor(name: string, scene: Scene);
52
+ setParent(parent: Group<Group<MeshObject>> | null): void;
53
+ removeChild(child: T): void;
54
+ get node(): TransformNode;
55
+ get children(): Set<T>;
56
+ }
57
+
58
+ declare class Matrix4 {
59
+ private _matrix;
60
+ constructor();
61
+ fromArray(array: number[]): this;
62
+ get matrix(): Matrix;
63
+ }
64
+
65
+ declare class Quat {
66
+ private _quaternion;
67
+ constructor();
68
+ rotateByQuaternion(quaternion: Quat): void;
69
+ setToQuaternion(quaternion: Nullable<Quaternion>): void;
70
+ setFromMatrix(matrix: Matrix4): this;
71
+ setFromEuler(eulerAngle: Vec3): this;
72
+ get quaternion(): Quaternion;
73
+ }
74
+
75
+ declare class Vec3 {
76
+ private _vector3;
77
+ static Zero: Vec3;
78
+ constructor(x: number, y: number, z: number);
79
+ clone(): Vec3;
80
+ normalize(): void;
81
+ applyAxisAngle(axis: Vec3, angle: number): Vec3;
82
+ applyQuaternion(quat: Quat): void;
83
+ multiplyScalar(scalar: number): void;
84
+ add(vec: Vec3): void;
85
+ length(): number;
86
+ equals(other: Vec3): boolean;
87
+ get x(): number;
88
+ get y(): number;
89
+ get z(): number;
90
+ }
91
+
92
+ /**
93
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
94
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
95
+ * No code shall be distributed or modified without the permission of the PI.
96
+ * @author Judah Silva <silva.judah7@outlook.com>
97
+ */
98
+
99
+ interface userData {
100
+ atomInfo: Vec3[];
101
+ fileName: string;
102
+ }
103
+ /**
104
+ * A MotifObject is a collection of residue meshes in one object.
105
+ * It is a wrapper class around the Babylon TransformNode.
106
+ */
107
+ declare class Motif extends Group<Residue> {
108
+ userData: userData;
109
+ private _quat;
110
+ constructor(name: string);
111
+ addChild(child: Residue): void;
112
+ setPosition(x: number, y: number, z: number): void;
113
+ translate(x: number, y: number, z: number): void;
114
+ rotate(axis: Vec3, angle: number): void;
115
+ rotateByQuaternion(quat: Quat): void;
116
+ setQuaternion(quat: Quat): void;
117
+ multiplyScalar(scalar: number): void;
118
+ private _nanCheck;
119
+ get uuid(): string;
120
+ get quat(): Quat;
121
+ get position(): Vec3;
122
+ }
123
+
124
+ /**
125
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
126
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
127
+ * No code shall be distributed or modified without the permission of the PI.
128
+ * @author Judah Silva <silva.judah7@outlook.com>
129
+ */
130
+
131
+ declare namespace Events {
132
+ enum EventType {
133
+ POINTER_DOWN = "pointerDown",
134
+ POINTER_UP = "pointerUp",
135
+ POINTER_MOVE = "pointerMove",
136
+ POINTER_WHEEL = "pointerWheel",
137
+ KEY_DOWN = "keyDown",
138
+ KEY_UP = "keyUp",
139
+ TOUCH_START = "touchStart",
140
+ TOUCH_END = "touchEnd",
141
+ TOUCH_MOVE = "touchMove",
142
+ PINCH_START = "pinchStart",
143
+ PINCH = "pinch",
144
+ PINCH_END = "pinchEnd",
145
+ OBJECT_SELECTED = "objectSelected",
146
+ OBJECT_DESELECTED = "objectDeselected",
147
+ RESIZE = "resize",
148
+ RENDER = "render",
149
+ ENGINE_STARTED = "engineStarted",
150
+ ENGINE_STOPPED = "engineStopped"
151
+ }
152
+ interface Event {
153
+ type: EventType | string;
154
+ originalEvent?: globalThis.Event;
155
+ canceled: boolean;
156
+ timestamp: number;
157
+ }
158
+ interface PointerEvent extends Event {
159
+ position: {
160
+ x: number;
161
+ y: number;
162
+ };
163
+ button?: number;
164
+ buttons?: number;
165
+ ctrlKey?: boolean;
166
+ altKey?: boolean;
167
+ shiftKey?: boolean;
168
+ metaKey?: boolean;
169
+ deltaX?: number;
170
+ deltaY?: number;
171
+ pickedResidue?: Residue;
172
+ }
173
+ interface KeyboardEvent extends Event {
174
+ key: string;
175
+ code: string;
176
+ ctrlKey: boolean;
177
+ altKey: boolean;
178
+ shiftKey: boolean;
179
+ metaKey: boolean;
180
+ repeat: boolean;
181
+ rotationAxis: Vec3;
182
+ translationDirection: Vec3;
183
+ }
184
+ interface PinchEvent extends Event {
185
+ scale: number;
186
+ center: {
187
+ x: number;
188
+ y: number;
189
+ };
190
+ }
191
+ interface SelectionEvent extends Event {
192
+ residue?: Residue;
193
+ motif?: Motif;
194
+ multiSelect?: boolean;
195
+ }
196
+ }
197
+
198
+ /**
199
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
200
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
201
+ * No code shall be distributed or modified without the permission of the PI.
202
+ * @author Judah Silva <silva.judah7@outlook.com>
203
+ */
204
+
205
+ /**
206
+ * Class to handle event registration, notification, and removal.
207
+ * Limited to managing events for one scene.
208
+ */
209
+ declare class EventManager {
210
+ private _eventObservables;
211
+ private _pointerObserver;
212
+ private _keyboardObserver;
213
+ private _renderObserver;
214
+ private _activeKeys;
215
+ private _pendingDeselect;
216
+ constructor();
217
+ /**
218
+ * Dispose of the event listeners and triggers
219
+ */
220
+ dispose(): void;
221
+ /**
222
+ * Register an event of a certain type
223
+ * @param eventType String event type. Can be custom or standard.
224
+ * @param callback Callback function to run when the event is triggered
225
+ * @returns Babylon Observer instance for later removal
226
+ */
227
+ on<T extends Events.Event>(eventType: Events.EventType | string, callback: (event: T) => void): Observer<Events.Event>;
228
+ /**
229
+ * Remove a registered event observer
230
+ * @param observer Babylon Observer with the registered callback
231
+ */
232
+ off(observer: Observer<Events.Event>): void;
233
+ /**
234
+ * Emit a custom event, triggering listeners registered with that event type.
235
+ * @param eventType A string event type. Can be custom or standard.
236
+ * @param eventData Event info object partial.
237
+ */
238
+ emit(eventType: string, eventData: Partial<Events.Event>): void;
239
+ /**
240
+ * Method to notify listeners of a type of event
241
+ * @param eventType A string event type. Can be custom or standard.
242
+ * @param event Event info object
243
+ */
244
+ notifyObservers(eventType: string, event: Events.Event): void;
245
+ /**
246
+ * Method to set up pointer and keyboard events on the scene.
247
+ * Comes preset with POINTER_DOWN, POINTER_UP, POINTER_MOVE, KEYBOARD_DOWN, and KEYBOARD_UP event triggering.
248
+ * @param scene A RenderScene object
249
+ */
250
+ setupEventHandling(scene: RenderScene): void;
251
+ /**
252
+ * Initialize observables for all standard event types
253
+ */
254
+ private _initializeObservables;
255
+ /**
256
+ * Helper function to get the residue that contains a picked mesh using the transform node of a motif
257
+ * @param node {TransformNode} Motif's TransformNode
258
+ * @param meshUUID Stringified uniqueId of the picked mesh
259
+ * @param sceneChildren Map of Motifs that exist in the scene
260
+ * @returns The Residue that contains the picked mesh, or null if it does not exist
261
+ */
262
+ private _getResidueFromMotifNode;
263
+ }
264
+
265
+ /**
266
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
267
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
268
+ * No code shall be distributed or modified without the permission of the PI.
269
+ * @author Judah Silva <silva.judah7@outlook.com>
270
+ */
271
+
272
+ declare class RenderScene {
273
+ private _canvas;
274
+ private _scene;
275
+ private _engine;
276
+ private _camera;
277
+ private _children;
278
+ private _eventManager;
279
+ private _isDisposed;
280
+ isRunning: boolean;
281
+ constructor(canvas: HTMLCanvasElement, hexColor: string, cameraPositionZ: number, renderWidth: number, renderHeight: number);
282
+ start(): void;
283
+ stop(): void;
284
+ dispose(): void;
285
+ add(motif: Motif): void;
286
+ remove(motif: Motif): void;
287
+ setBackgroundColor(hexColor: string): void;
288
+ private _reattachToScene;
289
+ private _handleResize;
290
+ /**
291
+ * Returns the Babylon.js Scene object.
292
+ */
293
+ get scene(): Scene;
294
+ /**
295
+ * Returns the engine.
296
+ */
297
+ get engine(): Engine;
298
+ /**
299
+ * Returns the camera.
300
+ */
301
+ get camera(): UniversalCamera;
302
+ /**
303
+ * Returns the event manager
304
+ */
305
+ get eventManager(): EventManager;
306
+ /**
307
+ * Returns the set of children.
308
+ */
309
+ get children(): Map<string, Motif>;
310
+ /**
311
+ * Returns the current render width
312
+ */
313
+ get renderWidth(): number;
314
+ /**
315
+ * Returns the current render height
316
+ */
317
+ get renderHeight(): number;
318
+ }
319
+
320
+ /**
321
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
322
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
323
+ * No code shall be distributed or modified without the permission of the PI.
324
+ * @author Judah Silva <jusilva@csumb.edu>
325
+ */
326
+
327
+ declare function updateAllMotifs(motifMeshArray: Motif[]): Promise<void>;
328
+
329
+ /**
330
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
331
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
332
+ * No code shall be distributed or modified without the permission of the PI.
333
+ * @author Sameer Dingore <sdingore@csumb.edu>
334
+ * @author Judah Silva
335
+ */
336
+
337
+ /**
338
+ * ________________________________________________________________________________________________
339
+ */
340
+ /**
341
+ * reads the json file and returns the motif structure mesh as THREE.Group
342
+ * @param motifJSONFileName
343
+ * json file name with coordinates of the motif
344
+ * @param motifColorHex
345
+ * color of the motif structure
346
+ * @param highLightColorHex
347
+ * color of the highlighted motif structure
348
+ * @returns {Promise<Motif>}
349
+ * @async
350
+ */
351
+ declare function getMotif(motifJSONFileName: string, motifColorHex?: string): Promise<Motif>;
352
+
353
+ /**
354
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
355
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
356
+ * No code shall be distributed or modified without the permission of the PI.
357
+ * @author Judah Silva
358
+ */
359
+ /**
360
+ * ________________________________________________________________________________________________
361
+ */
362
+ /**
363
+ * Get the vertices and indices from the nucleotide data
364
+ * @param nucleotideData {number[][]}
365
+ * @returns Object of { vertices: number[][], indices: number[][] }
366
+ */
367
+ declare function getPoints(nucleotideData: number[][]): {
368
+ vertices: number[][];
369
+ indices: number[][];
370
+ };
371
+
372
+ /**
373
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
374
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
375
+ * No code shall be distributed or modified without the permission of the PI.
376
+ * @author Sameer Dingore <sdingore@csumb.edu>
377
+ */
378
+
379
+ /**
380
+ * ________________________________________________________________________________________________
381
+ */
382
+ interface MotifProps {
383
+ motif: Motif;
384
+ locked: boolean;
385
+ position?: Vec3;
386
+ rotation?: Quat;
387
+ }
388
+ /**
389
+ * ________________________________________________________________________________________________
390
+ */
391
+ interface CustomEventProps {
392
+ event: Events.Event;
393
+ eventType: Events.EventType;
394
+ callback: (event: Events.Event) => void;
395
+ }
396
+ /**
397
+ * ________________________________________________________________________________________________
398
+ */
399
+ interface CanvasProps {
400
+ title?: string;
401
+ rendererWidth?: number;
402
+ rendererHeight?: number;
403
+ rendererBackgroundColor?: string;
404
+ rendererSizeIsWindow?: boolean;
405
+ cameraPositionZ?: number;
406
+ motifProps: MotifProps[];
407
+ customEventProps?: CustomEventProps[];
408
+ }
409
+
410
+ /**
411
+ * Copyright (c) 2025 RNA3DS Lab CSUMB.
412
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
413
+ * No code shall be distributed or modified without the permission of the PI.
414
+ * @author Sameer Dingore <sdingore@csumb.edu>
415
+ * @author Judah Silva <silva.judah7@outlook.com>
416
+ */
417
+
418
+ /**
419
+ * ________________________________________________________________________________________________
420
+ */
421
+ /**
422
+ * Canvas component renders the 3D canvas and the motifs on it.
423
+ * @param param0 {CanvasProps} A CanvasProps object
424
+ * @function Canvas {JSX.Element}
425
+ * @returns {JSX.Element}
426
+ */
427
+ declare function Canvas({ rendererHeight, rendererWidth, rendererBackgroundColor, rendererSizeIsWindow, cameraPositionZ, motifProps, customEventProps, }: CanvasProps): JSX.Element;
428
+
429
+ /**
430
+ * Copyright (c) 2025 RNA3DS Lab CSUMB.
431
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
432
+ * No code shall be distributed or modified without the permission of the PI.
433
+ * @author Judah Silva <silva.judah7@outlook.com>
434
+ */
435
+ interface ScoreInfo {
436
+ score: number;
437
+ selId: string;
438
+ refId: string;
439
+ }
440
+ declare enum CanvasAttributeTypes {
441
+ SELECTED_MOTIFS = "selectedMotifs",
442
+ LOCKED_MOTIF_IDS = "lockedMotifIds",
443
+ HLOCKED_MOTIF_IDS = "hardLockedMotifIds",
444
+ SCORE_RMSD = "scoreRMSD",
445
+ KABSCH_RMSD = "kabschRMSD"
446
+ }
447
+ declare class CanvasDataManager {
448
+ private static _selectedMotifIds;
449
+ private static _lockedMotifIds;
450
+ private static _hardLockedMotifIds;
451
+ private static _scoreRMSD;
452
+ private static _kabschRMSD;
453
+ private static _listeners;
454
+ static get selectedMotifIds(): Set<string>;
455
+ static setSelectedMotifIds(selectedMotifIds: Set<string>): void;
456
+ static get lockedMotifIds(): string[];
457
+ static setLockedMotifIds(lockedMotifIds: string[]): void;
458
+ static get hardLockedMotifIds(): string[];
459
+ static setHardLockedMotifIds(hardLockedMotifIds: string[]): void;
460
+ static get scoreRMSD(): ScoreInfo[][];
461
+ static setScoreRMSD(scoreRMSD: ScoreInfo[][]): void;
462
+ static get kabschRMSD(): number[][];
463
+ static setKabschRMSD(kabschRMSD: number[][]): void;
464
+ static subscribe(canvasAttributeType: CanvasAttributeTypes, callback: () => void): () => void;
465
+ }
466
+
467
+ /**
468
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
469
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
470
+ * No code shall be distributed or modified without the permission of the PI.
471
+ * @author Sameer Dingore <sdingore@csumb.edu>
472
+ * @author Judah Silva <jusilva@csumb.edu>
473
+ */
474
+
475
+ /**
476
+ * @param motif1 The motif to rotate to
477
+ * @param motif2 The motif that will be rotated
478
+ * @returns An object with the best rotation matrix and best rmsd
479
+ */
480
+ declare function kabschSlidingWindow(motif1: Motif, motif2: Motif): {
481
+ matrix: number[][];
482
+ rmsd: number;
483
+ };
484
+ declare function calculateAllKabschRMSD(motifMeshArray: Motif[]): number[][];
485
+
486
+ /**
487
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
488
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
489
+ * No code shall be distributed or modified without the permission of the PI.
490
+ * @author Judah Silva <jusilva@csumb.edu>
491
+ */
492
+
493
+ declare function calculateRMSD(selectedMotifMeshArray: Motif[], motifMeshArray: Motif[]): ScoreInfo[][];
494
+
495
+ /**
496
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
497
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
498
+ * No code shall be distributed or modified without the permission of the PI.
499
+ * @author Sameer Dingore <sdingore@csumb.edu>
500
+ * @author Shahidul Islam <sislam@csumb.edu>
501
+ */
502
+
503
+ /**
504
+ * Calculates the RMSD between two arrays of vector points
505
+ * @param coordinates1 An array of Vector3 coordinates
506
+ * @param coordinates2 An array of Vector3 coordinates
507
+ * @returns The RMSD score of the two coordinate arrays
508
+ */
509
+ declare function getRMSD(coordinates1: Vec3[], coordinates2: Vec3[]): number;
510
+ /**
511
+ * Calculates the RMSD score between the two motifs
512
+ * @param motif1 A Motif object
513
+ * @param motif2 A Motif object
514
+ * @returns The RMSD score of the motifs
515
+ */
516
+ declare function getRMSD(motif1: Motif, motif2: Motif): number;
517
+ declare function calculateRMSDSlide(coordinates1: Vec3[], coordinates2: Vec3[]): number;
518
+
519
+ /**
520
+ * Copyright (c) 2024 RNA3DS Lab CSUMB.
521
+ * All code written for RNA3DS Lab is protected under the terms of the NDA.
522
+ * No code shall be distributed or modified without the permission of the PI.
523
+ * @author Judah Silva <jusilva@csumb.edu>
524
+ */
525
+
526
+ declare function rotateAllPoints(atomCoords: Vec3[], quat: Quat): Vec3[];
527
+
528
+ export { Canvas, CanvasAttributeTypes, CanvasDataManager, type CanvasProps, type CustomEventProps, EventManager, Events, Group, Matrix4, MeshObject, Motif, type MotifProps, Quat, RenderScene, Residue, type ScoreInfo, Vec3, calculateAllKabschRMSD, calculateRMSD, calculateRMSDSlide, getMotif, getPoints, getRMSD, kabschSlidingWindow, rotateAllPoints, updateAllMotifs };