StructureRepresentation.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {
  2. PresetStructureRepresentations,
  3. StructureRepresentationPresetProvider
  4. } from "molstar/lib/mol-plugin-state/builder/structure/representation-preset";
  5. import {TrajectoryHierarchyPresetProvider} from "molstar/lib/mol-plugin-state/builder/structure/hierarchy-preset";
  6. import {StateObjectSelector} from "molstar/lib/mol-state";
  7. import {PluginStateObject} from "molstar/lib/mol-plugin-state/objects";
  8. import {StateObject} from "molstar/lib/mol-state/object";
  9. import {StateTransformer} from "molstar/lib/mol-state/transformer";
  10. type StructureObject = StateObjectSelector<PluginStateObject.Molecule.Structure, StateTransformer<StateObject<any, StateObject.Type<any>>, StateObject<any, StateObject.Type<any>>, any>>
  11. export const RcsbRepresentationPreset: TrajectoryHierarchyPresetProvider = TrajectoryHierarchyPresetProvider({
  12. id: "rcsb-saguaro-3d",
  13. display: {
  14. name: 'Feature View 3D'
  15. },
  16. params: () => ({
  17. }),
  18. async apply(trajectory, params, plugin) {
  19. const builder = plugin.builders.structure;
  20. const model = await builder.createModel(trajectory, {modelIndex: 0});
  21. const modelProperties = await builder.insertModelProperties(model);
  22. const structure: StructureObject = await builder.createStructure(modelProperties);
  23. const structureProperties: StructureObject = await builder.insertStructureProperties(structure);
  24. const unitcell: StateObjectSelector | undefined = await builder.tryCreateUnitcell(modelProperties, undefined, { isHidden: true });
  25. const representation: StructureRepresentationPresetProvider.Result | undefined = await plugin.builders.structure.representation.applyPreset(structureProperties, PresetStructureRepresentations.auto);
  26. components:
  27. for (const c of plugin.managers.structure.hierarchy.currentComponentGroups) {
  28. for (const comp of c) {
  29. if(comp.cell.obj?.label === "Water") {
  30. plugin.managers.structure.component.toggleVisibility(c);
  31. break components;
  32. }
  33. }
  34. }
  35. components:
  36. for (const c of plugin.managers.structure.hierarchy.currentComponentGroups) {
  37. for (const comp of c) {
  38. if(comp.cell.obj?.label === "Polymer") {
  39. this.viewer.plugin.managers.structure.component.updateRepresentationsTheme([comp], { color: 'chain-id' });
  40. break components;
  41. }
  42. }
  43. }
  44. return {
  45. model,
  46. modelProperties,
  47. unitcell,
  48. structure,
  49. structureProperties,
  50. representation
  51. };
  52. }
  53. });