molstar
Version:
A comprehensive macromolecular library.
89 lines • 4.72 kB
JavaScript
/**
* Copyright (c) 2021 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.AnimateStructureSpin = void 0;
var tslib_1 = require("tslib");
var commands_1 = require("../../../mol-plugin/commands");
var mol_state_1 = require("../../../mol-state");
var param_definition_1 = require("../../../mol-util/param-definition");
var objects_1 = require("../../objects");
var transforms_1 = require("../../transforms");
var model_1 = require("../model");
exports.AnimateStructureSpin = model_1.PluginStateAnimation.create({
name: 'built-in.animate-structure-spin',
display: { name: 'Spin Structure' },
isExportable: true,
params: function () { return ({
durationInMs: param_definition_1.ParamDefinition.Numeric(3000, { min: 100, max: 10000, step: 100 })
}); },
initialState: function () { return ({ t: 0 }); },
getDuration: function (p) { return ({ kind: 'fixed', durationMs: p.durationInMs }); },
setup: function (_, __, plugin) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var state, reprs, update, changed, _i, reprs_1, r, spins;
return (0, tslib_1.__generator)(this, function (_a) {
state = plugin.state.data;
reprs = state.select(mol_state_1.StateSelection.Generators.ofType(objects_1.PluginStateObject.Molecule.Structure.Representation3D));
update = state.build();
changed = false;
for (_i = 0, reprs_1 = reprs; _i < reprs_1.length; _i++) {
r = reprs_1[_i];
spins = state.select(mol_state_1.StateSelection.Generators.ofTransformer(transforms_1.StateTransforms.Representation.SpinStructureRepresentation3D, r.transform.ref));
if (spins.length > 0)
continue;
changed = true;
update.to(r.transform.ref)
.apply(transforms_1.StateTransforms.Representation.SpinStructureRepresentation3D, { t: 0 }, { tags: 'animate-structure-spin' });
}
if (!changed)
return [2 /*return*/];
return [2 /*return*/, update.commit({ doNotUpdateCurrent: true })];
});
});
},
teardown: function (_, __, plugin) {
var state = plugin.state.data;
var reprs = state.select(mol_state_1.StateSelection.Generators.ofType(objects_1.PluginStateObject.Molecule.Structure.Representation3DState)
.withTag('animate-structure-spin'));
if (reprs.length === 0)
return;
var update = state.build();
for (var _i = 0, reprs_2 = reprs; _i < reprs_2.length; _i++) {
var r = reprs_2[_i];
update.delete(r.transform.ref);
}
return update.commit();
},
apply: function (animState, t, ctx) {
var _a;
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var state, anims, update, d, newTime, _i, anims_1, m;
return (0, tslib_1.__generator)(this, function (_b) {
switch (_b.label) {
case 0:
state = ctx.plugin.state.data;
anims = state.select(mol_state_1.StateSelection.Generators.ofTransformer(transforms_1.StateTransforms.Representation.SpinStructureRepresentation3D));
if (anims.length === 0) {
return [2 /*return*/, { kind: 'finished' }];
}
update = state.build();
d = (t.current - t.lastApplied) / ctx.params.durationInMs;
newTime = (animState.t + d) % 1;
for (_i = 0, anims_1 = anims; _i < anims_1.length; _i++) {
m = anims_1[_i];
update.to(m).update((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (_a = m.params) === null || _a === void 0 ? void 0 : _a.values), { t: newTime }));
}
return [4 /*yield*/, commands_1.PluginCommands.State.Update(ctx.plugin, { state: state, tree: update, options: { doNotLogTiming: true } })];
case 1:
_b.sent();
return [2 /*return*/, { kind: 'next', state: { t: newTime } }];
}
});
});
}
});
//# sourceMappingURL=spin-structure.js.map
;