Skip to content
Snippets Groups Projects
Commit 242d2959 authored by David Sehnal's avatar David Sehnal
Browse files

Structure lookup 3D

parent efa5ef1b
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ namespace Element { ...@@ -16,7 +16,7 @@ namespace Element {
export const create: (unit: number, index: number) => Element = Tuple.create; export const create: (unit: number, index: number) => Element = Tuple.create;
export const is: (x: any) => x is Element = Tuple.is; export const is: (x: any) => x is Element = Tuple.is;
export const unitId: (e: Element) => number = Tuple.fst; export const unitId: (e: Element) => number = Tuple.fst;
export const index: (e: Element) => number = Tuple.snd; export const elementIndex: (e: Element) => number = Tuple.snd;
export const areEqual: (e: Element, b: Element) => boolean = Tuple.areEqual; export const areEqual: (e: Element, b: Element) => boolean = Tuple.areEqual;
export const hashCode: (e: Element) => number = Tuple.hashCode; export const hashCode: (e: Element) => number = Tuple.hashCode;
...@@ -30,7 +30,7 @@ namespace Element { ...@@ -30,7 +30,7 @@ namespace Element {
export function updateLocation(structure: Structure, l: Location, element: Element) { export function updateLocation(structure: Structure, l: Location, element: Element) {
l.unit = structure.units[unitId(element)]; l.unit = structure.units[unitId(element)];
l.element = index(element); l.element = elementIndex(element);
return l; return l;
} }
......
...@@ -12,7 +12,6 @@ import { sortArray, sort, arraySwap, hash1 } from 'mol-data/util'; ...@@ -12,7 +12,6 @@ import { sortArray, sort, arraySwap, hash1 } from 'mol-data/util';
import Element from './element' import Element from './element'
import Unit from './unit' import Unit from './unit'
import { StructureLookup3D } from './util/lookup3d'; import { StructureLookup3D } from './util/lookup3d';
import { computeStructureBoundary } from './util/boundary';
class Structure { class Structure {
readonly unitMap: IntMap<Unit>; readonly unitMap: IntMap<Unit>;
...@@ -48,7 +47,14 @@ class Structure { ...@@ -48,7 +47,14 @@ class Structure {
} }
get boundary() { get boundary() {
return computeStructureBoundary(this); return this.lookup3d.boundary;
}
private _lookup3d?: StructureLookup3D = void 0;
get lookup3d() {
if (this._lookup3d) return this._lookup3d;
this._lookup3d = StructureLookup3D.create(this);
return this._lookup3d;
} }
constructor(units: ArrayLike<Unit>) { constructor(units: ArrayLike<Unit>) {
......
...@@ -6,93 +6,85 @@ ...@@ -6,93 +6,85 @@
import Structure from '../structure' import Structure from '../structure'
import Element from '../element' import Element from '../element'
import { Lookup3D, /*GridLookup3D,*/ Result, Box3D, Sphere3D } from 'mol-math/geometry'; import { Lookup3D, GridLookup3D, Result, Box3D, Sphere3D } from 'mol-math/geometry';
//import { ElementSet, Unit } from '../../structure'; import { Vec3 } from 'mol-math/linear-algebra';
//import { Vec3 } from 'mol-math/linear-algebra'; import { computeStructureBoundary } from './boundary';
//import { OrderedSet } from 'mol-data/int'; import { OrderedSet } from 'mol-data/int';
//import { computeStructureBoundary } from './boundary';
interface StructureLookup3D extends Lookup3D<Element> {} interface StructureLookup3D extends Lookup3D<Element> {}
namespace StructureLookup3D { namespace StructureLookup3D {
class Impl implements StructureLookup3D { class Impl implements StructureLookup3D {
//private unitLookup: Lookup3D; private unitLookup: Lookup3D;
private result = Result.create<Element>(); private result = Result.create<Element>();
//private pivot = Vec3.zero(); private pivot = Vec3.zero();
find(x: number, y: number, z: number, radius: number): Result<Element> { find(x: number, y: number, z: number, radius: number): Result<Element> {
Result.reset(this.result); Result.reset(this.result);
// const { units, elements } = this.structure; const { units } = this.structure;
// const closeUnits = this.unitLookup.find(x, y, z, radius); const closeUnits = this.unitLookup.find(x, y, z, radius);
// if (closeUnits.count === 0) return this.result; if (closeUnits.count === 0) return this.result;
// for (let t = 0, _t = closeUnits.count; t < _t; t++) { for (let t = 0, _t = closeUnits.count; t < _t; t++) {
// const i = closeUnits.indices[t]; const unit = units[closeUnits.indices[t]];
// const unitId = ElementSet.groupUnitIndex(elements, i); Vec3.set(this.pivot, x, y, z);
// const group = ElementSet.groupAt(elements, i); if (!unit.conformation.operator.isIdentity) {
// const unit = units[unitId]; Vec3.transformMat4(this.pivot, this.pivot, unit.conformation.operator.inverse);
// Vec3.set(this.pivot, x, y, z); }
// if (!unit.operator.isIdentity) { const unitLookup = unit.lookup3d;
// Vec3.transformMat4(this.pivot, this.pivot, unit.operator.inverse); const groupResult = unitLookup.find(this.pivot[0], this.pivot[1], this.pivot[2], radius);
// } for (let j = 0, _j = groupResult.count; j < _j; j++) {
// const groupLookup = Unit.getLookup3d(unit, group); Result.add(this.result, Element.create(unit.id, groupResult.indices[j]), groupResult.squaredDistances[j]);
// const groupResult = groupLookup.find(this.pivot[0], this.pivot[1], this.pivot[2], radius); }
// for (let j = 0, _j = groupResult.count; j < _j; j++) { }
// Result.add(this.result, Element.create(unitId, groupResult.indices[j]), groupResult.squaredDistances[j]);
// }
// }
return this.result; return this.result;
} }
check(x: number, y: number, z: number, radius: number): boolean { check(x: number, y: number, z: number, radius: number): boolean {
// const { units, elements } = this.structure; const { units } = this.structure;
// const closeUnits = this.unitLookup.find(x, y, z, radius); const closeUnits = this.unitLookup.find(x, y, z, radius);
// if (closeUnits.count === 0) return false; if (closeUnits.count === 0) return false;
// for (let t = 0, _t = closeUnits.count; t < _t; t++) { for (let t = 0, _t = closeUnits.count; t < _t; t++) {
// const i = closeUnits.indices[t]; const unit = units[closeUnits.indices[t]];
// const unitId = ElementSet.groupUnitIndex(elements, i); Vec3.set(this.pivot, x, y, z);
// const group = ElementSet.groupAt(elements, i); if (!unit.conformation.operator.isIdentity) {
// const unit = units[unitId]; Vec3.transformMat4(this.pivot, this.pivot, unit.conformation.operator.inverse);
// Vec3.set(this.pivot, x, y, z); }
// if (!unit.operator.isIdentity) { const groupLookup = unit.lookup3d;
// Vec3.transformMat4(this.pivot, this.pivot, unit.operator.inverse); if (groupLookup.check(this.pivot[0], this.pivot[1], this.pivot[2], radius)) return true;
// } }
// const groupLookup = Unit.getLookup3d(unit, group);
// if (groupLookup.check(this.pivot[0], this.pivot[1], this.pivot[2], radius)) return true;
// }
return false; return false;
} }
boundary: { box: Box3D; sphere: Sphere3D; }; boundary: { box: Box3D; sphere: Sphere3D; };
constructor(structure: Structure) { constructor(private structure: Structure) {
// const { units, elements } = structure; const { units } = structure;
// const unitCount = ElementSet.groupCount(elements); const unitCount = units.length;
// const xs = new Float32Array(unitCount); const xs = new Float32Array(unitCount);
// const ys = new Float32Array(unitCount); const ys = new Float32Array(unitCount);
// const zs = new Float32Array(unitCount); const zs = new Float32Array(unitCount);
// const radius = new Float32Array(unitCount); const radius = new Float32Array(unitCount);
// const center = Vec3.zero(); const center = Vec3.zero();
// for (let i = 0; i < unitCount; i++) { for (let i = 0; i < unitCount; i++) {
// const group = ElementSet.groupAt(elements, i); const unit = units[i];
// const unit = units[ElementSet.groupUnitIndex(elements, i)]; const lookup = unit.lookup3d;
// const lookup = Unit.getLookup3d(unit, group); const s = lookup.boundary.sphere;
// const s = lookup.boundary.sphere;
Vec3.transformMat4(center, s.center, unit.conformation.operator.matrix);
// Vec3.transformMat4(center, s.center, unit.operator.matrix);
xs[i] = center[0];
// xs[i] = center[0]; ys[i] = center[1];
// ys[i] = center[1]; zs[i] = center[2];
// zs[i] = center[2]; radius[i] = s.radius;
// radius[i] = s.radius; }
// }
this.unitLookup = GridLookup3D({ x: xs, y: ys, z: zs, radius, indices: OrderedSet.ofBounds(0, unitCount) });
// this.unitLookup = GridLookup3D({ x: xs, y: ys, z: zs, radius, indices: OrderedSet.ofBounds(0, unitCount) }); this.boundary = computeStructureBoundary(structure);
// this.boundary = computeStructureBoundary(structure);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment