molstar
Version:
A comprehensive macromolecular library.
167 lines (166 loc) • 9.27 kB
JavaScript
"use strict";
/**
* Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructureInfo = void 0;
var tslib_1 = require("tslib");
var behavior_1 = require("../../../behavior/behavior");
var structure_1 = require("../../../../mol-model/structure");
var objects_1 = require("../../../../mol-plugin-state/objects");
var mol_state_1 = require("../../../../mol-state");
exports.StructureInfo = behavior_1.PluginBehavior.create({
name: 'structure-info-prop',
category: 'custom-props',
display: { name: 'Structure Info' },
ctor: /** @class */ (function (_super) {
tslib_1.__extends(class_1, _super);
function class_1() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(class_1.prototype, "maxModelIndex", {
get: function () {
var _a, _b;
var maxIndex = -1;
var cells = this.ctx.state.data.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Model));
for (var _i = 0, cells_1 = cells; _i < cells_1.length; _i++) {
var c = cells_1[_i];
var index = ((_a = c.obj) === null || _a === void 0 ? void 0 : _a.data) && structure_1.Model.Index.get((_b = c.obj) === null || _b === void 0 ? void 0 : _b.data).value;
if (index !== undefined && index > maxIndex)
maxIndex = index;
}
return maxIndex;
},
enumerable: false,
configurable: true
});
Object.defineProperty(class_1.prototype, "maxStructureIndex", {
get: function () {
var _a, _b;
var maxIndex = -1;
var cells = this.ctx.state.data.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Structure));
for (var _i = 0, cells_2 = cells; _i < cells_2.length; _i++) {
var c = cells_2[_i];
var index = ((_a = c.obj) === null || _a === void 0 ? void 0 : _a.data) && structure_1.Structure.Index.get((_b = c.obj) === null || _b === void 0 ? void 0 : _b.data).value;
if (index !== undefined && index > maxIndex)
maxIndex = index;
}
return maxIndex;
},
enumerable: false,
configurable: true
});
Object.defineProperty(class_1.prototype, "asymIdOffset", {
get: function () {
var _a;
var auth = 0;
var label = 0;
var cells = this.ctx.state.data.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Model));
for (var _i = 0, cells_3 = cells; _i < cells_3.length; _i++) {
var c = cells_3[_i];
var m = (_a = c.obj) === null || _a === void 0 ? void 0 : _a.data;
if (m) {
var count = structure_1.Model.AsymIdCount.get(m);
var offset = structure_1.Model.AsymIdOffset.get(m).value;
if (count !== undefined && offset !== undefined) {
auth = Math.max(auth, offset.auth + count.auth);
label = Math.max(label, offset.label + count.label);
}
}
}
return { auth: auth, label: label };
},
enumerable: false,
configurable: true
});
class_1.prototype.setModelMaxIndex = function () {
var _a;
var value = this.maxModelIndex;
var cells = this.ctx.state.data.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Model));
for (var _i = 0, cells_4 = cells; _i < cells_4.length; _i++) {
var c = cells_4[_i];
var m = (_a = c.obj) === null || _a === void 0 ? void 0 : _a.data;
if (m) {
if (structure_1.Model.MaxIndex.get(m).value !== value) {
structure_1.Model.MaxIndex.set(m, { value: value }, value);
}
}
}
};
class_1.prototype.setStructureMaxIndex = function () {
var _a;
var value = this.maxModelIndex;
var cells = this.ctx.state.data.select(mol_state_1.StateSelection.Generators.rootsOfType(objects_1.PluginStateObject.Molecule.Structure));
for (var _i = 0, cells_5 = cells; _i < cells_5.length; _i++) {
var c = cells_5[_i];
var s = (_a = c.obj) === null || _a === void 0 ? void 0 : _a.data;
if (s) {
if (structure_1.Structure.MaxIndex.get(s).value !== value) {
structure_1.Structure.MaxIndex.set(s, { value: value }, value);
}
}
}
};
class_1.prototype.handleModel = function (model, oldModel) {
if (structure_1.Model.Index.get(model).value === undefined) {
var oldIndex = oldModel && structure_1.Model.Index.get(oldModel).value;
var value = oldIndex !== null && oldIndex !== void 0 ? oldIndex : (this.maxModelIndex + 1);
structure_1.Model.Index.set(model, { value: value }, value);
}
if (structure_1.Model.AsymIdOffset.get(model).value === undefined) {
var oldOffset = oldModel && structure_1.Model.AsymIdOffset.get(oldModel).value;
var value = oldOffset !== null && oldOffset !== void 0 ? oldOffset : tslib_1.__assign({}, this.asymIdOffset);
structure_1.Model.AsymIdOffset.set(model, { value: value }, value);
}
};
class_1.prototype.handleStructure = function (structure, oldStructure) {
if (structure.parent !== undefined)
return;
if (structure_1.Structure.Index.get(structure).value !== undefined)
return;
var oldIndex = oldStructure && structure_1.Structure.Index.get(oldStructure).value;
var value = oldIndex !== null && oldIndex !== void 0 ? oldIndex : (this.maxStructureIndex + 1);
structure_1.Structure.Index.set(structure, { value: value }, value);
};
class_1.prototype.handle = function (ref, obj, oldObj) {
if (objects_1.PluginStateObject.Molecule.Structure.is(obj)) {
var transform = this.ctx.state.data.tree.transforms.get(ref);
if (!transform.transformer.definition.isDecorator && obj.data.parent === undefined) {
this.handleStructure(obj.data, oldObj === null || oldObj === void 0 ? void 0 : oldObj.data);
}
}
else if (objects_1.PluginStateObject.Molecule.Model.is(obj)) {
var transform = this.ctx.state.data.tree.transforms.get(ref);
if (!transform.transformer.definition.isDecorator) {
this.handleModel(obj.data, oldObj === null || oldObj === void 0 ? void 0 : oldObj.data);
}
}
};
class_1.prototype.register = function () {
var _this = this;
this.ctx.customModelProperties.register(structure_1.Model.AsymIdOffset, true);
this.ctx.customModelProperties.register(structure_1.Model.Index, true);
this.ctx.customModelProperties.register(structure_1.Model.MaxIndex, true);
this.ctx.customStructureProperties.register(structure_1.Structure.Index, true);
this.ctx.customStructureProperties.register(structure_1.Structure.MaxIndex, true);
this.subscribeObservable(this.ctx.state.data.events.object.created, function (o) {
_this.handle(o.ref, o.obj);
_this.setModelMaxIndex();
_this.setStructureMaxIndex();
});
this.subscribeObservable(this.ctx.state.data.events.object.updated, function (o) {
_this.handle(o.ref, o.obj, o.oldObj);
});
};
class_1.prototype.unregister = function () {
this.ctx.customModelProperties.unregister(structure_1.Model.AsymIdOffset.descriptor.name);
this.ctx.customModelProperties.unregister(structure_1.Model.Index.descriptor.name);
this.ctx.customModelProperties.unregister(structure_1.Model.MaxIndex.descriptor.name);
this.ctx.customStructureProperties.unregister(structure_1.Structure.Index.descriptor.name);
this.ctx.customStructureProperties.unregister(structure_1.Structure.MaxIndex.descriptor.name);
};
return class_1;
}(behavior_1.PluginBehavior.Handler))
});