secondary-structure.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { ParamDefinition as PD } from 'mol-util/param-definition';
  7. import { PluginBehavior } from '../../../behavior';
  8. import { CustomPropertyRegistry } from 'mol-model-props/common/custom-property-registry';
  9. import { ComputedSecondaryStructure } from 'mol-model-props/computed/secondary-structure';
  10. export const MolstarSecondaryStructure = PluginBehavior.create<{ autoAttach: boolean }>({
  11. name: 'molstar-computed-secondary-structure-prop',
  12. category: 'custom-props',
  13. display: { name: 'Computed Secondary Structure' },
  14. ctor: class extends PluginBehavior.Handler<{ autoAttach: boolean }> {
  15. private attach = ComputedSecondaryStructure.createAttachTask();
  16. private provider: CustomPropertyRegistry.StructureProvider = {
  17. option: [ComputedSecondaryStructure.Descriptor.name, 'Computed Secondary Structure'],
  18. descriptor: ComputedSecondaryStructure.Descriptor,
  19. defaultSelected: this.params.autoAttach,
  20. attachableTo: () => true,
  21. attach: this.attach
  22. }
  23. register(): void {
  24. this.ctx.customStructureProperties.register(this.provider);
  25. }
  26. update(p: { autoAttach: boolean }) {
  27. let updated = this.params.autoAttach !== p.autoAttach
  28. this.params.autoAttach = p.autoAttach;
  29. this.provider.defaultSelected = p.autoAttach;
  30. return updated;
  31. }
  32. unregister() {
  33. this.ctx.customStructureProperties.unregister(ComputedSecondaryStructure.Descriptor.name);
  34. }
  35. },
  36. params: () => ({
  37. autoAttach: PD.Boolean(false)
  38. })
  39. });