|
@@ -5,8 +5,9 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
import Query from './query'
|
|
import Query from './query'
|
|
|
|
+import Selection from './selection'
|
|
import * as P from './properties'
|
|
import * as P from './properties'
|
|
-import { AtomSet, Atom } from '../structure'
|
|
|
|
|
|
+import { Structure, AtomSet, Atom } from '../structure'
|
|
import { OrderedSet, Segmentation } from 'mol-base/collections/integer'
|
|
import { OrderedSet, Segmentation } from 'mol-base/collections/integer'
|
|
|
|
|
|
export interface AtomGroupsSpec {
|
|
export interface AtomGroupsSpec {
|
|
@@ -40,7 +41,7 @@ function atomGroupsLinear(atomTest: Atom.Predicate): Query {
|
|
const { atoms, units } = structure;
|
|
const { atoms, units } = structure;
|
|
const unitIds = AtomSet.unitIds(atoms);
|
|
const unitIds = AtomSet.unitIds(atoms);
|
|
const l = Atom.Location();
|
|
const l = Atom.Location();
|
|
- const builder = AtomSet.Builder(atoms);
|
|
|
|
|
|
+ const builder = AtomSet.LinearBuilder(atoms);
|
|
|
|
|
|
for (let i = 0, _i = unitIds.length; i < _i; i++) {
|
|
for (let i = 0, _i = unitIds.length; i < _i; i++) {
|
|
const unitId = unitIds[i];
|
|
const unitId = unitIds[i];
|
|
@@ -55,7 +56,7 @@ function atomGroupsLinear(atomTest: Atom.Predicate): Query {
|
|
builder.commitUnit(unitId);
|
|
builder.commitUnit(unitId);
|
|
}
|
|
}
|
|
|
|
|
|
- return { units, atoms: builder.getSet() };
|
|
|
|
|
|
+ return Structure.create(units, builder.getSet());
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,7 +65,7 @@ function atomGroupsSegmented({ entityTest, chainTest, residueTest, atomTest }: A
|
|
const { atoms, units } = structure;
|
|
const { atoms, units } = structure;
|
|
const unitIds = AtomSet.unitIds(atoms);
|
|
const unitIds = AtomSet.unitIds(atoms);
|
|
const l = Atom.Location();
|
|
const l = Atom.Location();
|
|
- const builder = AtomSet.Builder(atoms);
|
|
|
|
|
|
+ const builder = AtomSet.LinearBuilder(atoms);
|
|
|
|
|
|
for (let i = 0, _i = unitIds.length; i < _i; i++) {
|
|
for (let i = 0, _i = unitIds.length; i < _i; i++) {
|
|
const unitId = unitIds[i];
|
|
const unitId = unitIds[i];
|
|
@@ -98,16 +99,60 @@ function atomGroupsSegmented({ entityTest, chainTest, residueTest, atomTest }: A
|
|
builder.commitUnit(unitId);
|
|
builder.commitUnit(unitId);
|
|
}
|
|
}
|
|
|
|
|
|
- return { units, atoms: builder.getSet() };
|
|
|
|
|
|
+ return Structure.create(units, builder.getSet());
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+class LinearGroupingBuilder {
|
|
|
|
+ private builders: AtomSet.Builder[] = [];
|
|
|
|
+ private builderMap: { [key: string]: AtomSet.Builder } = Object.create(null);
|
|
|
|
+
|
|
|
|
+ add(key: any, unit: number, atom: number) {
|
|
|
|
+ let b = this.builderMap[key];
|
|
|
|
+ if (!b) {
|
|
|
|
+ b = AtomSet.LinearBuilder(this.structure.atoms);
|
|
|
|
+ this.builders[this.builders.length] = b;
|
|
|
|
+ this.builderMap[key] = b;
|
|
|
|
+ }
|
|
|
|
+ b.add(unit, atom);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private allSingletons() {
|
|
|
|
+ for (let i = 0, _i = this.builders.length; i < _i; i++) {
|
|
|
|
+ if (this.builders[i].atomCount > 1) return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private singletonStructure(): Structure {
|
|
|
|
+ const atoms: Atom[] = Atom.createEmptyArray(this.builders.length);
|
|
|
|
+ for (let i = 0, _i = this.builders.length; i < _i; i++) {
|
|
|
|
+ atoms[i] = this.builders[i].singleton();
|
|
|
|
+ }
|
|
|
|
+ return Structure.create(this.structure.units, AtomSet.create(atoms));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fullSelection() {
|
|
|
|
+ const ret: Structure[] = [];
|
|
|
|
+ for (let i = 0, _i = this.builders.length; i < _i; i++) {
|
|
|
|
+ ret[i] = Structure.create(this.structure.units, this.builders[i].getSet());
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getSelection(): Selection {
|
|
|
|
+ const len = this.builders.length;
|
|
|
|
+ if (len === 0) return Selection.Empty;
|
|
|
|
+ if (len === 1) return Structure.create(this.structure.units, this.builders[0].getSet());
|
|
|
|
+ if (this.allSingletons()) return this.singletonStructure();
|
|
|
|
+ return this.fullSelection();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ constructor(private structure: Structure) { }
|
|
|
|
+}
|
|
|
|
+
|
|
function atomGroupsGrouped({ entityTest, chainTest, residueTest, atomTest, groupBy }: AtomGroupsSpec): Query {
|
|
function atomGroupsGrouped({ entityTest, chainTest, residueTest, atomTest, groupBy }: AtomGroupsSpec): Query {
|
|
return structure => {
|
|
return structure => {
|
|
throw 'nyi'
|
|
throw 'nyi'
|
|
};
|
|
};
|
|
-}
|
|
|
|
-
|
|
|
|
-// class LinearGroupingBuilder {
|
|
|
|
-
|
|
|
|
-// }
|
|
|
|
|
|
+}
|