Browse Source

added traceOnly param to gaussian-surface

- avoids creating trace structure selection with slow labeling, stats and bundle params
Alexander Rose 5 years ago
parent
commit
7bee2be12d

+ 6 - 12
src/mol-plugin-state/builder/structure/representation-preset.ts

@@ -152,35 +152,29 @@ const coarseSurface = StructureRepresentationPresetProvider({
         const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref);
         if (!structureCell) return {};
 
+        const components = {
+            polymer: await presetStaticComponent(plugin, structureCell, 'polymer')
+        }
+
         const structure = structureCell.obj!.data;
         const size = Structure.getSize(structure)
-
         const gaussianProps = Object.create(null);
-        const components = Object.create(null);
-
-        let selectionType = 'polymer'
-
         if (size === Structure.Size.Gigantic) {
             Object.assign(gaussianProps, {
+                traceOnly: true,
                 radiusOffset: 1,
                 smoothness: 0.5,
                 visuals: ['structure-gaussian-surface-mesh']
             })
-            selectionType = 'trace'
-            components.trace = await presetSelectionComponent(plugin, structureCell, 'trace')
         } else if(size === Structure.Size.Huge) {
             Object.assign(gaussianProps, {
                 smoothness: 0.5,
             })
-            components.trace = await presetStaticComponent(plugin, structureCell, 'polymer')
-        } else {
-            components.trace = await presetStaticComponent(plugin, structureCell, 'polymer')
         }
 
-
         const { update, builder, typeParams, color } = reprBuilder(plugin, params);
         const representations = {
-            trace: builder.buildRepresentation(update, components.trace, { type: 'gaussian-surface', typeParams: { ...typeParams, ...gaussianProps }, color }, { tag: selectionType })
+            polymer: builder.buildRepresentation(update, components.polymer, { type: 'gaussian-surface', typeParams: { ...typeParams, ...gaussianProps }, color }, { tag: 'polymer' })
         };
 
         await plugin.updateDataState(update, { revertOnError: true });

+ 3 - 1
src/mol-repr/structure/visual/gaussian-surface-mesh.ts

@@ -68,6 +68,7 @@ export function GaussianSurfaceMeshVisual(materialId: number): UnitsVisual<Gauss
             if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true
             if (newProps.useGpu !== currentProps.useGpu) state.createGeometry = true
             if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true
+            if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true
             if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true
         }
     }, materialId)
@@ -115,7 +116,7 @@ export function StructureGaussianSurfaceMeshVisual(materialId: number): ComplexV
             if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true
             if (newProps.useGpu !== currentProps.useGpu) state.createGeometry = true
             if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true
-            if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true
+            if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true
         }
     }, materialId)
 }
@@ -161,6 +162,7 @@ export function GaussianSurfaceTextureMeshVisual(materialId: number): UnitsVisua
             if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true
             if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true
             if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true
+            if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true
             if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true
         }
     }, materialId)

+ 1 - 0
src/mol-repr/structure/visual/gaussian-surface-wireframe.ts

@@ -57,6 +57,7 @@ export function GaussianWireframeVisual(materialId: number): UnitsVisual<Gaussia
             if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true
             if (newProps.useGpu !== currentProps.useGpu) state.createGeometry = true
             if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true
+            if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true
             if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true
         }
     }, materialId)

+ 14 - 4
src/mol-repr/structure/visual/util/common.ts

@@ -109,6 +109,7 @@ export function getConformation(unit: Unit) {
 
 export const CommonSurfaceParams = {
     ignoreHydrogens: PD.Boolean(false, { description: 'Whether or not to include hydrogen atoms in the surface calculation.' }),
+    traceOnly: PD.Boolean(false, { description: 'Whether or not to only use trace atoms in the surface calculation.' }),
     includeParent: PD.Boolean(false, { description: 'Include elements of the parent structure in surface calculation to get a surface patch of the current structure.' }),
 }
 export const DefaultCommonSurfaceProps = PD.getDefaultValues(CommonSurfaceParams)
@@ -135,7 +136,7 @@ function filterId(id: AssignableArrayLike<number>, elements: SortedArray, indice
 }
 
 export function getUnitConformationAndRadius(structure: Structure, unit: Unit, props: CommonSurfaceProps) {
-    const { ignoreHydrogens, includeParent } = props
+    const { ignoreHydrogens, traceOnly, includeParent } = props
     const rootUnit = includeParent ? structure.root.unitMap.get(unit.id) : unit
 
     const { x, y, z } = getConformation(rootUnit)
@@ -153,6 +154,7 @@ export function getUnitConformationAndRadius(structure: Structure, unit: Unit, p
         for (let i = 0, il = elements.length; i < il; ++i) {
             const eI = elements[i]
             if (ignoreHydrogens && isHydrogen(rootUnit, eI)) continue
+            if (traceOnly && !isTrace(rootUnit, eI)) continue
             if (includeParent && squaredDistance(x[eI], y[eI], z[eI], center) > radiusSq) continue
 
             _indices.push(eI)
@@ -182,7 +184,7 @@ export function getUnitConformationAndRadius(structure: Structure, unit: Unit, p
     return { position, boundary, radius }
 }
 
-export function getStructureConformationAndRadius(structure: Structure, ignoreHydrogens: boolean) {
+export function getStructureConformationAndRadius(structure: Structure, ignoreHydrogens: boolean, traceOnly: boolean) {
     const l = StructureElement.Location.create(structure)
     const sizeTheme = PhysicalSizeTheme({}, {})
 
@@ -192,7 +194,7 @@ export function getStructureConformationAndRadius(structure: Structure, ignoreHy
     let rs: ArrayLike<number>
     let id: ArrayLike<number>
 
-    if (ignoreHydrogens) {
+    if (ignoreHydrogens || traceOnly) {
         const _xs: number[] = []
         const _ys: number[] = []
         const _zs: number[] = []
@@ -206,7 +208,8 @@ export function getStructureConformationAndRadius(structure: Structure, ignoreHy
             l.unit = unit
             for (let j = 0, jl = elements.length; j < jl; ++j) {
                 const eI = elements[j]
-                if (isHydrogen(unit, eI)) continue
+                if (ignoreHydrogens && isHydrogen(unit, eI)) continue
+                if (traceOnly && !isTrace(unit, eI)) continue
 
                 _xs.push(x(eI))
                 _ys.push(y(eI))
@@ -257,4 +260,11 @@ export function isHydrogen(unit: Unit, element: ElementIndex) {
     if (Unit.isCoarse(unit)) return false
     if (AtomNumber(unit.model.atomicHierarchy.atoms.type_symbol.value(element)) === _H) return true
     return false
+}
+
+function isTrace(unit: Unit, element: ElementIndex) {
+    if (Unit.isCoarse(unit)) return true
+    const atomId = unit.model.atomicHierarchy.atoms.label_atom_id.value(element)
+    if (atomId === 'CA' || atomId === 'P') return true
+    return false
 }

+ 2 - 2
src/mol-repr/structure/visual/util/gaussian.ts

@@ -60,14 +60,14 @@ export function computeUnitGaussianDensityTexture2d(structure: Structure, unit:
 //
 
 export function computeStructureGaussianDensity(structure: Structure, props: GaussianDensityProps, webgl?: WebGLContext) {
-    const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens)
+    const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens, props.traceOnly)
     return Task.create('Gaussian Density', async ctx => {
         return await GaussianDensity(ctx, position, structure.lookup3d.boundary.box, radius, props, webgl);
     });
 }
 
 export function computeStructureGaussianDensityTexture(structure: Structure, props: GaussianDensityTextureProps, webgl: WebGLContext, texture?: Texture) {
-    const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens)
+    const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens, props.traceOnly)
     return Task.create('Gaussian Density', async ctx => {
         return GaussianDensityTexture(webgl, position, structure.lookup3d.boundary.box, radius, props, texture);
     });