JonStargaryen преди 4 години
родител
ревизия
9e9851472d
променени са 2 файла, в които са добавени 32 реда и са изтрити 12 реда
  1. 8 8
      src/mol-model-props/computed/topology/ANVIL.ts
  2. 24 4
      src/tests/browser/render-structure.ts

+ 8 - 8
src/mol-model-props/computed/topology/ANVIL.ts

@@ -50,6 +50,7 @@ namespace Topology {
     const l = StructureElement.Location.create(void 0);
     const centroidHelper = new CentroidHelper();
     const vec = Vec3();
+    const points: Vec3[] = [];
     export async function calculate(runtime: RuntimeContext, structure: Structure, params: ANVILProps): Promise<Topology> {
         const { label_atom_id, x, y, z } = StructureProperties.atom;
         const { label_comp_id } = StructureProperties.residue;
@@ -109,6 +110,8 @@ namespace Topology {
             centroidHelper.radiusStep(vec);
         }
         const extent = 1.2 * Math.sqrt(centroidHelper.radiusSq);
+        points.push(centroid);
+        console.log('centroid: ' + centroid);
 
         const initialHphobHphil = HphobHphil.filtered(offsets, exposed, structure, label_comp_id, () => true);
         const initialMembrane = findMembrane(generateSpherePoints(params.numberOfSpherePoints, centroid, extent), centroid, params, initialHphobHphil, offsets, exposed, structure, label_comp_id);
@@ -116,6 +119,7 @@ namespace Topology {
 
         const membrane = initialMembrane.qmax! > alternativeMembrane.qmax! ? initialMembrane : alternativeMembrane;
 
+        points.push(centroid);
         return {
             membrane: createMembraneLayers(membrane, extent, params)
         };
@@ -190,25 +194,22 @@ namespace Topology {
         let qmax = 0;
 
         // construct slices of thickness 1.0 along the axis connecting the centroid and the spherePoint
-        const diam = Vec3();
-        const normedDiam = Vec3();
         for (let i = 0, il = spherePoints.length; i < il; i++) {
             const spherePoint = spherePoints[i];
+            const diam = Vec3();
             Vec3.sub(diam, centroid, spherePoint);
             Vec3.scale(diam, diam, 2);
             const diamNorm = Vec3.magnitude(diam);
-            Vec3.scale(normedDiam, diam, 1 / diamNorm);
             const qvartemp = [];
 
             const c1 = Vec3();
             const c2 = Vec3();
             for (let i = 0, il = diamNorm - params.stepSize; i < il; i += params.stepSize) {
-                const norm = Vec3.magnitude(diam);
-                Vec3.scaleAndAdd(c1, spherePoint, diam, i / norm);
-                Vec3.scaleAndAdd(c2, spherePoint, diam, (i + params.stepSize) / norm);
+                Vec3.scaleAndAdd(c1, spherePoint, diam, i / diamNorm);
+                Vec3.scaleAndAdd(c2, spherePoint, diam, (i + params.stepSize) / diamNorm);
 
                 // evaluate how well this membrane slice embeddeds the peculiar residues
-                const stats = HphobHphil.filtered(offsets, exposed, structure, label_comp_id, (testPoint: Vec3) => isInMembranePlane(testPoint, normedDiam, c1, c2));
+                const stats = HphobHphil.filtered(offsets, exposed, structure, label_comp_id, (testPoint: Vec3) => isInMembranePlane(testPoint, diam, c1, c2));
                 qvartemp.push(Membrane.initial(c1, c2, stats));
             }
 
@@ -239,7 +240,6 @@ namespace Topology {
                     if (hphob > 0) {
                         const qvaltest = qValue(stats, initialStats);
                         if (qvaltest > qmax) {
-                            console.log(qmax + ' > ' + qvaltest);
                             qmax = qvaltest;
                             membrane = Membrane.scored(c1, c2, HphobHphil.of(hphob, hphil), spherePoint, qmax);
                         }

+ 24 - 4
src/tests/browser/render-structure.ts

@@ -28,6 +28,11 @@ import { SyncRuntimeContext } from '../../mol-task/execution/synchronous';
 import { AssetManager } from '../../mol-util/assets';
 import { AccessibleSurfaceAreaProvider } from '../../mol-model-props/computed/accessible-surface-area';
 import { TopologyProvider } from '../../mol-model-props/computed/topology';
+import { SpheresBuilder } from '../../mol-geo/geometry/spheres/spheres-builder';
+import { Spheres } from '../../mol-geo/geometry/spheres/spheres';
+import { Color } from '../../mol-util/color';
+import { createRenderObject } from '../../mol-gl/render-object';
+import { Topology } from '../../mol-model-props/computed/topology/ANVIL';
 
 const parent = document.getElementById('app')!;
 parent.style.width = '100%';
@@ -118,6 +123,21 @@ function getGaussianSurfaceRepr() {
     return GaussianSurfaceRepresentationProvider.factory(reprCtx, GaussianSurfaceRepresentationProvider.getParams);
 }
 
+function getMembraneRepr(topology: Topology) {
+    const spheresBuilder = SpheresBuilder.create(topology.membrane.length, 1);
+    for (let i = 0, il = topology.membrane.length; i < il; i++) {
+        spheresBuilder.add(topology.membrane[i][0], topology.membrane[i][1], topology.membrane[i][2], 0);
+    }
+    const spheres = spheresBuilder.getSpheres();
+
+    const values = Spheres.Utils.createValuesSimple(spheres, {}, Color(0xFF0000/*666666*/), 1);
+    const state = Spheres.Utils.createRenderableState({});
+    const renderObject = createRenderObject('spheres', values, state, -1);
+    console.log(renderObject);
+    const repr = Representation.fromRenderObject('spheres', renderObject);
+    return repr;
+}
+
 async function init() {
     const ctx = { runtime: SyncRuntimeContext, assetManager: new AssetManager() };
 
@@ -156,7 +176,7 @@ async function init() {
     const ballAndStickRepr = getBallAndStickRepr();
     const molecularSurfaceRepr = getMolecularSurfaceRepr();
     const gaussianSurfaceRepr = getGaussianSurfaceRepr();
-    // const membraneRepr = getMembraneRepr();
+    const membraneRepr = getMembraneRepr(TopologyProvider.get(structure).value!);
 
     if (show.cartoon) {
         cartoonRepr.setTheme({
@@ -203,7 +223,7 @@ async function init() {
         console.timeEnd('gaussian surface');
     }
 
-    if (show.membrane) {
+    // if (show.membrane) {
         // membraneRepr.setTheme({
         //     color: reprCtx.colorThemeRegistry.create('uniform', { structure }),
         //     size: reprCtx.sizeThemeRegistry.create('physical', { structure })
@@ -211,14 +231,14 @@ async function init() {
         // console.time('membrane layer');
         // await membraneRepr.createOrUpdate({ ...MembraneRepresentationProvider.defaultValues, quality: 'custom', alpha: 1.0, flatShaded: true, doubleSided: true, resolution: 0.3 }, structure).run();
         // console.timeEnd('membrane layer');
-    }
+    // }
 
     if (show.cartoon) canvas3d.add(cartoonRepr);
     if (show.interaction) canvas3d.add(interactionRepr);
     if (show.ballAndStick) canvas3d.add(ballAndStickRepr);
     if (show.molecularSurface) canvas3d.add(molecularSurfaceRepr);
     if (show.gaussianSurface) canvas3d.add(gaussianSurfaceRepr);
-    // if (show.membrane) canvas3d.add(membraneRepr);
+    if (show.membrane) canvas3d.add(membraneRepr);
     canvas3d.requestCameraReset();
     // canvas3d.setProps({ trackball: { ...canvas3d.props.trackball, spin: true } })
 }