Browse Source

wip, structure tools

Alexander Rose 5 years ago
parent
commit
5d7bb894d4

+ 10 - 2
src/mol-plugin/ui/structure/representation.tsx

@@ -28,7 +28,14 @@ abstract class BaseStructureRepresentationControls extends PluginUIComponent {
     }
 
     hide = (value: string) => {
-        this.plugin.helpers.structureRepresentation.set('remove', value, this.lociGetter)
+        if (value === '__all__') {
+            const { types } = this.plugin.structureRepresentation.registry
+            for (let i = 0, il = types.length; i < il; ++i) {
+                this.plugin.helpers.structureRepresentation.set('remove', types[i][0], this.lociGetter)
+            }
+        } else {
+            this.plugin.helpers.structureRepresentation.set('remove', value, this.lociGetter)
+        }
     }
 
     color = (value: string) => {
@@ -49,7 +56,7 @@ abstract class BaseStructureRepresentationControls extends PluginUIComponent {
                 </ButtonSelect>
                 <ButtonSelect label='Hide' onChange={this.hide}>
                     <optgroup label='Clear'>
-                        <option key={-1} value={-1}>TODO: All</option>
+                        <option key={'__all__'} value={'__all__'}>All</option>
                     </optgroup>
                     <optgroup label='Hide'>
                         {Options(types)}
@@ -86,6 +93,7 @@ class SelectionStructureRepresentationControls extends BaseStructureRepresentati
 export class StructureRepresentationControls extends PluginUIComponent {
     preset = async () => {
         const { structureRepresentation: rep } = this.plugin.helpers
+        await rep.clear()
         await rep.setFromExpression('add', 'cartoon', Q.all)
         await rep.setFromExpression('add', 'carbohydrate', Q.all)
         await rep.setFromExpression('add', 'ball-and-stick', MS.struct.modifier.union([

+ 19 - 0
src/mol-plugin/util/structure-representation-helper.ts

@@ -98,6 +98,25 @@ export class StructureRepresentationHelper {
         })
     }
 
+    async clear() {
+        const { registry } = this.plugin.structureRepresentation
+        const state = this.plugin.state.dataState;
+        const update = state.build()
+        const structures = state.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure))
+        const query = StructureElement.Query.Empty
+
+        for (const structure of structures) {
+            for (let i = 0, il = registry.types.length; i < il; ++i) {
+                const type = registry.types[i][0]
+                const reprStructure = this.getRepresentationStructure(structure.transform.ref, type)
+                if (reprStructure) {
+                    update.to(reprStructure).update({ ...reprStructure.params!.values, query })
+                }
+            }
+        }
+        await this.plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true }))
+    }
+
     private _ignoreHydrogens = false
     get ignoreHydrogens () { return this._ignoreHydrogens }
     async setIgnoreHydrogens(ignoreHydrogens: boolean) {