123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /**
- * Copyright (C) 2022, Protein Bioinformatics Research Group, RCNS
- *
- * Licensed under CC BY-NC 4.0, see LICENSE file for more info.
- *
- * @author Gabor Tusnady <tusnady.gabor@ttk.hu>
- * @author Csongor Gerdan <gerdan.csongor@ttk.hu>
- */
- import { mmCIF_Database } from "molstar/lib/mol-io/reader/cif/schema/mmcif";
- import { Mat4, Vec3 } from "molstar/lib/mol-math/linear-algebra";
- import { MmcifFormat } from "molstar/lib/mol-model-formats/structure/mmcif";
- import { Model } from "molstar/lib/mol-model/structure";
- import { AtomicConformation } from "molstar/lib/mol-model/structure/model/properties/atomic";
- import { createStructureRepresentationParams } from "molstar/lib/mol-plugin-state/helpers/structure-representation-params";
- import { StateTransforms } from "molstar/lib/mol-plugin-state/transforms";
- import { PluginUIContext } from "molstar/lib/mol-plugin-ui/context";
- import { Expression } from "molstar/lib/mol-script/language/expression";
- import { Color } from "molstar/lib/mol-util/color";
- import { rotateCamera as RC } from "./camera";
- import { TmDetDescriptorCache } from "./prop";
- import { getChainExpression as GCE, getCurrentHierarchy as GCH, transformationForStateTransform, transformWholeModel } from "./transformation";
- import { PDBTMTransformationMatrix } from "./types";
- export namespace DebugUtil {
- let plugin: PluginUIContext;
- let logEnabled = false;
- export function init(ctx: PluginUIContext) {
- plugin = ctx;
- }
- //
- // logging
- //
- export function enableLog() {
- logEnabled = true;
- console.log('DebugUtil Enabled', logEnabled);
- }
- export function disableLog() {
- logEnabled = false;
- }
- export function log(...args: any[]) {
- if (logEnabled) {
- console.log(...args);
- }
- }
- //
- //
- // lin.alg.
- //
- export function transformVector(v: Vec3, matrix: Mat4): Vec3 {
- const result = Vec3.transformMat4(Vec3(), v, matrix);
- log("transformVector: Input v & matrix:", v, Mat4.makeTable(matrix));
- log("transformVector: Result vector:", result);
- return result;
- }
- export function descriptorMxToMat4(matrix: PDBTMTransformationMatrix): Mat4 {
- log("descriptorMxToMat4: Input:", matrix);
- const result = transformationForStateTransform(matrix);
- log("descriptorMxToMat4: Result:", result);
- return result;
- }
- //
- // structure utils
- //
- export const getChainExpression = GCE;
- export function getCellOfFirstStructure() {
- return getCell();
- }
- export function getCell(structureIndex: number = 0, modelIndex: number = 0) {
- return getCurrentHierarchy().models[structureIndex].structures[modelIndex].cell;
- }
- export function getCurrentHierarchy() {
- return GCH(plugin);
- }
- export function getModelOfFirstStructure() {
- return getCellOfFirstStructure().obj?.data.model;
- }
- // in case of mmCIF format
- export function dumpAtomProperties(authAtomId: number) {
- const model: Model|undefined = getModelOfFirstStructure();
- log("First model:", model);
- if(!model) {
- return;
- }
- const rowCount = model.atomicHierarchy.atoms._rowCount;
- const conformation: AtomicConformation = model.atomicConformation;
- const db: mmCIF_Database = (model.sourceData as MmcifFormat).data.db;
- const atom_site = db.atom_site;
- for (let index = 0; index < rowCount; index++) {
- if (conformation.atomId.value(index) == authAtomId) {
- log("Model Atom Conformation:", {
- atomIdParameter: authAtomId,
- atomId: conformation.atomId.value(index),
- coords: [
- conformation.x[index],
- conformation.y[index],
- conformation.z[index]
- ],
- xyzDefined: conformation.xyzDefined
- });
- log("Atom Source Data (mmCIF database):", {
- authId: atom_site.auth_atom_id.value(index),
- compId: atom_site.auth_comp_id.value(index),
- authAsymId: atom_site.auth_asym_id.value(index),
- authSeqId: atom_site.auth_seq_id.value(index),
- coords: [
- atom_site.Cartn_x.value(index),
- atom_site.Cartn_y.value(index),
- atom_site.Cartn_z.value(index)
- ]
- });
- }
- }
- }
- export function getCachesOfEachStructure() {
- let sIndex = 0;
- getCurrentHierarchy().structures.forEach(struct => {
- let cIndex = 0;
- struct.components.forEach(component => {
- log(`struct: ${sIndex}; component: ${cIndex}`, component.cell.cache);
- cIndex++;
- });
- sIndex++;
- });
- }
- export function color(expression: Expression, color: number[], structureIndex: number = 0, modelIndex: number = 0) {
- const structure = getCell(structureIndex, modelIndex);
- const stateBuilder = plugin.build().to(structure);
- stateBuilder.apply(
- StateTransforms.Model.StructureSelectionFromExpression,
- { expression: expression }
- )
- .apply(
- StateTransforms.Representation.StructureRepresentation3D,
- createStructureRepresentationParams(plugin, structure.obj?.data, {
- type: 'ball-and-stick',
- color: 'uniform', colorParams: { value: Color.fromArray(color, 0) }
- })
- );
- stateBuilder.commit();
- }
- export function transform(entityId: string) {
- const tmx = TmDetDescriptorCache.get(entityId)?.additional_entry_annotations.membrane.transformation_matrix;
- transformWholeModel(plugin, tmx!);
- }
- //
- // Camera
- //
- export function rotateCamera() {
- RC(plugin);
- }
- export function requestCameraReset() {
- requestAnimationFrame(() => plugin.canvas3d?.requestCameraReset({ durationMs: 1000 }));
- }
- }
|