Browse Source

limit max resolution for (gpu) gaussian-surface

Alexander Rose 4 years ago
parent
commit
f8e9bc1e7f

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

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -100,13 +100,13 @@ export function includesUnitKind(unitKinds: UnitKind[], unit: Unit) {
 
 //
 
-const MaxCells = 500_000_000;
+const DefaultMaxCells = 500_000_000;
 
 /** guard against overly high resolution for the given box size */
-export function ensureReasonableResolution<T>(box: Box3D, props: { resolution: number } & T) {
+export function ensureReasonableResolution<T>(box: Box3D, props: { resolution: number } & T, maxCells = DefaultMaxCells) {
     const volume = Box3D.volume(box);
     const approxCells = volume / props.resolution;
-    const resolution = approxCells > MaxCells ? volume / MaxCells : props.resolution;
+    const resolution = approxCells > maxCells ? volume / maxCells : props.resolution;
     return { ...props, resolution };
 }
 

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

@@ -23,10 +23,15 @@ export const GaussianDensityParams = {
 export const DefaultGaussianDensityProps = PD.getDefaultValues(GaussianDensityParams);
 export type GaussianDensityProps = typeof DefaultGaussianDensityProps
 
+function getTextureMaxCells(webgl: WebGLContext) {
+    const d = Math.min(webgl.maxTextureSize / 2, 4096);
+    return d * d;
+}
+
 //
 
 export function computeUnitGaussianDensity(structure: Structure, unit: Unit, props: GaussianDensityProps, webgl?: WebGLContext) {
-    const { box } = unit.lookup3d.boundary;
+    const { box } = structure.lookup3d.boundary;
     const p = ensureReasonableResolution(box, props);
     const { position, radius } = getUnitConformationAndRadius(structure, unit, p);
     return Task.create('Gaussian Density', async ctx => {
@@ -35,8 +40,8 @@ export function computeUnitGaussianDensity(structure: Structure, unit: Unit, pro
 }
 
 export function computeUnitGaussianDensityTexture(structure: Structure, unit: Unit, props: GaussianDensityProps, webgl: WebGLContext, texture?: Texture) {
-    const { box } = unit.lookup3d.boundary;
-    const p = ensureReasonableResolution(box, props);
+    const { box } = structure.lookup3d.boundary;
+    const p = ensureReasonableResolution(box, props, getTextureMaxCells(webgl));
     const { position, radius } = getUnitConformationAndRadius(structure, unit, p);
     return Task.create('Gaussian Density', async ctx => {
         return GaussianDensityTexture(webgl, position, box, radius, p, texture);
@@ -44,8 +49,8 @@ export function computeUnitGaussianDensityTexture(structure: Structure, unit: Un
 }
 
 export function computeUnitGaussianDensityTexture2d(structure: Structure, unit: Unit, powerOfTwo: boolean, props: GaussianDensityProps, webgl: WebGLContext, texture?: Texture) {
-    const { box } = unit.lookup3d.boundary;
-    const p = ensureReasonableResolution(box, props);
+    const { box } = structure.lookup3d.boundary;
+    const p = ensureReasonableResolution(box, props, getTextureMaxCells(webgl));
     const { position, radius } = getUnitConformationAndRadius(structure, unit, p);
     return Task.create('Gaussian Density', async ctx => {
         return GaussianDensityTexture2d(webgl, position, box, radius, powerOfTwo, p, texture);
@@ -65,7 +70,7 @@ export function computeStructureGaussianDensity(structure: Structure, props: Gau
 
 export function computeStructureGaussianDensityTexture(structure: Structure, props: GaussianDensityProps, webgl: WebGLContext, texture?: Texture) {
     const { box } = structure.lookup3d.boundary;
-    const p = ensureReasonableResolution(box, props);
+    const p = ensureReasonableResolution(box, props, getTextureMaxCells(webgl));
     const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens, props.traceOnly);
     return Task.create('Gaussian Density', async ctx => {
         return GaussianDensityTexture(webgl, position, box, radius, p, texture);
@@ -74,7 +79,7 @@ export function computeStructureGaussianDensityTexture(structure: Structure, pro
 
 export function computeStructureGaussianDensityTexture2d(structure: Structure, powerOfTwo: boolean, props: GaussianDensityProps, webgl: WebGLContext, texture?: Texture) {
     const { box } = structure.lookup3d.boundary;
-    const p = ensureReasonableResolution(box, props);
+    const p = ensureReasonableResolution(box, props, getTextureMaxCells(webgl));
     const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens, props.traceOnly);
     return Task.create('Gaussian Density', async ctx => {
         return GaussianDensityTexture2d(webgl, position, box, radius, powerOfTwo, p, texture);