Skip to content
Snippets Groups Projects
Commit 4b6392d5 authored by Alexander Rose's avatar Alexander Rose
Browse files

Merge branch 'master' into gl-geo

# Conflicts:
#	src/mol-geo/representation/structure/index.ts
parents b8a4365d 22190c17
No related branches found
No related tags found
No related merge requests found
...@@ -35,18 +35,15 @@ export function StructureRepresentation<Props>(reprCtor: () => UnitsRepresentati ...@@ -35,18 +35,15 @@ export function StructureRepresentation<Props>(reprCtor: () => UnitsRepresentati
create(structure: Structure, props: Props = {} as Props) { create(structure: Structure, props: Props = {} as Props) {
return Task.create('StructureRepresentation', async ctx => { return Task.create('StructureRepresentation', async ctx => {
const { elements, units } = structure; const { elements, units } = structure;
const uniqueGroups = EquivalenceClasses<number, ElementGroup>( const uniqueGroups = EquivalenceClasses<number, { unit: Unit, group: ElementGroup }>(
ElementGroup.hashCode, ({ unit, group }) => ElementGroup.hashCode(group),
(a, b) => { (a, b) => a.unit.model.id === b.unit.model.id && OrderedSet.areEqual(a.group.elements, b.group.elements)
console.log(units, a.id, b.id)
return units[a.id].model.id === units[b.id].model.id && OrderedSet.areEqual(a.elements, b.elements)
}
); );
for (let i = 0, _i = ElementSet.unitCount(elements); i < _i; i++) { for (let i = 0, _i = ElementSet.unitCount(elements); i < _i; i++) {
const group = ElementSet.unitGetByIndex(elements, i); const group = ElementSet.unitGetByIndex(elements, i);
uniqueGroups.add(i, group); const unitId = ElementSet.unitGetId(elements, i);
console.log(i, group) uniqueGroups.add(unitId, { unit: units[unitId], group });
} }
for (let i = 0, _i = uniqueGroups.groups.length; i < _i; i++) { for (let i = 0, _i = uniqueGroups.groups.length; i < _i; i++) {
...@@ -55,7 +52,6 @@ export function StructureRepresentation<Props>(reprCtor: () => UnitsRepresentati ...@@ -55,7 +52,6 @@ export function StructureRepresentation<Props>(reprCtor: () => UnitsRepresentati
// console.log('group', i) // console.log('group', i)
for (let j = 0, _j = group.length; j < _j; j++) { for (let j = 0, _j = group.length; j < _j; j++) {
groupUnits.push(units[group[j]]) groupUnits.push(units[group[j]])
// console.log(units[group[j]].operator.matrix)
} }
const elementGroup = ElementSet.unitGetByIndex(elements, group[0]) const elementGroup = ElementSet.unitGetByIndex(elements, group[0])
const repr = reprCtor() const repr = reprCtor()
......
...@@ -9,7 +9,8 @@ import Unit from '../unit' ...@@ -9,7 +9,8 @@ import Unit from '../unit'
interface ElementGroup { interface ElementGroup {
elements: OrderedSet, elements: OrderedSet,
id: number // Unique identifier of the group, usable as partial key for various "caches".
key: number
} }
namespace ElementGroup { namespace ElementGroup {
...@@ -20,7 +21,7 @@ namespace ElementGroup { ...@@ -20,7 +21,7 @@ namespace ElementGroup {
} }
export function createNew(elements: OrderedSet): ElementGroup { export function createNew(elements: OrderedSet): ElementGroup {
return { id: nextId(), elements }; return { key: nextKey(), elements };
} }
export function create(unit: Unit, elements: OrderedSet): ElementGroup { export function create(unit: Unit, elements: OrderedSet): ElementGroup {
...@@ -61,7 +62,7 @@ namespace ElementGroup { ...@@ -61,7 +62,7 @@ namespace ElementGroup {
} }
let _id = 0; let _id = 0;
function nextId() { function nextKey() {
const ret = _id; const ret = _id;
_id = (_id + 1) % 0x3fffffff; _id = (_id + 1) % 0x3fffffff;
return ret; return ret;
......
...@@ -11,11 +11,12 @@ import * as fs from 'fs' ...@@ -11,11 +11,12 @@ import * as fs from 'fs'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import CIF from 'mol-io/reader/cif' import CIF from 'mol-io/reader/cif'
import { Structure, Model, Queries as Q, Element, ElementGroup, ElementSet, Selection, Symmetry } from 'mol-model/structure' import { Structure, Model, Queries as Q, Element, ElementGroup, ElementSet, Selection, Symmetry, Unit } from 'mol-model/structure'
import { Segmentation } from 'mol-data/int' import { Segmentation, OrderedSet } from 'mol-data/int'
import to_mmCIF from 'mol-model/structure/export/mmcif' import to_mmCIF from 'mol-model/structure/export/mmcif'
import { Run } from 'mol-task'; import { Run } from 'mol-task';
import { EquivalenceClasses } from 'mol-data/util';
require('util.promisify').shim(); require('util.promisify').shim();
const readFileAsync = util.promisify(fs.readFile); const readFileAsync = util.promisify(fs.readFile);
...@@ -100,7 +101,7 @@ async function ensureBcifAvailable(pdbId: string) { ...@@ -100,7 +101,7 @@ async function ensureBcifAvailable(pdbId: string) {
} }
} }
async function getBcif(pdbId: string) { export async function getBcif(pdbId: string) {
await ensureBcifAvailable(pdbId); await ensureBcifAvailable(pdbId);
return await readCIF(getBcifPath(pdbId)); return await readCIF(getBcifPath(pdbId));
} }
...@@ -301,11 +302,35 @@ export namespace PropertyAccess { ...@@ -301,11 +302,35 @@ export namespace PropertyAccess {
console.log('exported'); console.log('exported');
} }
export function testGrouping(structure: Structure) {
const { elements, units } = Symmetry.buildAssembly(structure, '1');
console.log('grouping', units.length);
console.log('built asm');
const uniqueGroups = EquivalenceClasses<number, { unit: Unit, group: ElementGroup }>(
({ unit, group }) => ElementGroup.hashCode(group),
(a, b) => a.unit.model.id === b.unit.model.id && (a.group.key === b.group.key && OrderedSet.areEqual(a.group.elements, b.group.elements))
);
for (let i = 0, _i = ElementSet.unitCount(elements); i < _i; i++) {
const group = ElementSet.unitGetByIndex(elements, i);
const unitId = ElementSet.unitGetId(elements, i);
uniqueGroups.add(unitId, { unit: units[unitId], group });
}
console.log('group count', uniqueGroups.groups.length);
}
export async function run() { export async function run() {
const { structures, models/*, mmcif*/ } = await getBcif('1cbs'); //const { structures, models/*, mmcif*/ } = await getBcif('1cbs');
// const { structures, models } = await getBcif('3j3q'); // const { structures, models } = await getBcif('3j3q');
//const { structures, models, mmcif } = await readCIF('e:/test/quick/1cbs_updated.cif'); const { structures, models /*, mmcif*/ } = await readCIF('e:/test/quick/1hrv_updated.cif');
const { structures: s1, /*, mmcif*/ } = await readCIF('e:/test/quick/1tqn_updated.cif');
testGrouping(structures[0]);
console.log('------');
testGrouping(s1[0]);
//const { structures, models/*, mmcif*/ } = await readCIF('e:/test/quick/5j7v_updated.cif'); //const { structures, models/*, mmcif*/ } = await readCIF('e:/test/quick/5j7v_updated.cif');
//console.log(mmcif.pdbx_struct_oper_list.matrix.toArray()); //console.log(mmcif.pdbx_struct_oper_list.matrix.toArray());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment