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

mol-model within query

parent 51395c1a
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import { StructureQuery } from '../query'; ...@@ -11,6 +11,7 @@ import { StructureQuery } from '../query';
import { StructureSelection } from '../selection'; import { StructureSelection } from '../selection';
import { structureAreIntersecting } from '../utils/structure'; import { structureAreIntersecting } from '../utils/structure';
import { Vec3 } from 'mol-math/linear-algebra'; import { Vec3 } from 'mol-math/linear-algebra';
import { checkStructureMaxRadiusDistance, checkStructureMinMaxDistance } from '../utils/structure-distance';
export function pick(query: StructureQuery, pred: QueryPredicate): StructureQuery { export function pick(query: StructureQuery, pred: QueryPredicate): StructureQuery {
return ctx => { return ctx => {
...@@ -111,8 +112,6 @@ export interface WithinParams { ...@@ -111,8 +112,6 @@ export interface WithinParams {
invert?: boolean invert?: boolean
} }
function _zeroRadius(ctx: QueryContext) { return 0; }
export function within(params: WithinParams): StructureQuery { export function within(params: WithinParams): StructureQuery {
return queryCtx => { return queryCtx => {
const ctx: WithinContext = { const ctx: WithinContext = {
...@@ -126,11 +125,11 @@ export function within(params: WithinParams): StructureQuery { ...@@ -126,11 +125,11 @@ export function within(params: WithinParams): StructureQuery {
} }
if (ctx.minRadius === 0 && typeof params.minRadius === 'undefined') { if (ctx.minRadius === 0 && typeof params.minRadius === 'undefined') {
return withinMaxRadiusLookup(ctx);
} else if (ctx.minRadius === 0) {
return withinMaxRadius(ctx); return withinMaxRadius(ctx);
} else { } else {
// TODO return withinMinMaxRadius(ctx);
throw 'not implemented';
// return withinMinMaxRadius(ctx);
} }
} }
} }
...@@ -144,7 +143,7 @@ interface WithinContext { ...@@ -144,7 +143,7 @@ interface WithinContext {
invert: boolean, invert: boolean,
elementRadius: QueryFn<number> elementRadius: QueryFn<number>
} }
function withinMaxRadius({ queryCtx, selection, target, maxRadius, invert }: WithinContext) { function withinMaxRadiusLookup({ queryCtx, selection, target, maxRadius, invert }: WithinContext) {
const targetLookup = StructureSelection.unionStructure(target).lookup3d; const targetLookup = StructureSelection.unionStructure(target).lookup3d;
const ret = StructureSelection.LinearBuilder(queryCtx.inputStructure); const ret = StructureSelection.LinearBuilder(queryCtx.inputStructure);
...@@ -174,5 +173,33 @@ function withinMaxRadius({ queryCtx, selection, target, maxRadius, invert }: Wit ...@@ -174,5 +173,33 @@ function withinMaxRadius({ queryCtx, selection, target, maxRadius, invert }: Wit
return ret.getSelection(); return ret.getSelection();
} }
function withinMaxRadius({ queryCtx, selection, target, maxRadius, invert, elementRadius }: WithinContext) {
const targetStructure = StructureSelection.unionStructure(target);
const ret = StructureSelection.LinearBuilder(queryCtx.inputStructure);
StructureSelection.forEach(selection, (s, sI) => {
let withinRadius = checkStructureMaxRadiusDistance(queryCtx, targetStructure, s, maxRadius, elementRadius);
if (invert) withinRadius = !withinRadius;
if (withinRadius) ret.add(s);
if (sI % 10 === 0) queryCtx.throwIfTimedOut();
});
return ret.getSelection();
}
function withinMinMaxRadius({ queryCtx, selection, target, minRadius, maxRadius, invert, elementRadius }: WithinContext) {
const targetStructure = StructureSelection.unionStructure(target);
const ret = StructureSelection.LinearBuilder(queryCtx.inputStructure);
StructureSelection.forEach(selection, (s, sI) => {
let withinRadius = checkStructureMinMaxDistance(queryCtx, targetStructure, s, minRadius, maxRadius, elementRadius);
if (invert) withinRadius = !withinRadius;
if (withinRadius) ret.add(s);
if (sI % 10 === 0) queryCtx.throwIfTimedOut();
});
return ret.getSelection();
}
// TODO: isConnectedTo // TODO: isConnectedTo
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment