|
@@ -10,6 +10,7 @@ import { OrderedSet, Interval } from 'mol-data/int';
|
|
|
import { EmptyLoci, Loci } from 'mol-model/loci';
|
|
|
import { LocationIterator } from 'mol-geo/util/location-iterator';
|
|
|
import { PickingId } from 'mol-geo/geometry/picking';
|
|
|
+import { StructureGroup } from 'mol-repr/structure/units-visual';
|
|
|
|
|
|
export * from './polymer/backbone-iterator'
|
|
|
export * from './polymer/gap-iterator'
|
|
@@ -64,9 +65,10 @@ export namespace PolymerGapLocationIterator {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export function getPolymerElementLoci(pickingId: PickingId, group: Unit.SymmetryGroup, id: number) {
|
|
|
+export function getPolymerElementLoci(pickingId: PickingId, structureGroup: StructureGroup, id: number) {
|
|
|
const { objectId, instanceId, groupId } = pickingId
|
|
|
if (id === objectId) {
|
|
|
+ const { structure, group } = structureGroup
|
|
|
const unit = group.units[instanceId]
|
|
|
if (unit === undefined) {
|
|
|
console.log(id, { objectId, instanceId, groupId }, group.units)
|
|
@@ -74,32 +76,32 @@ export function getPolymerElementLoci(pickingId: PickingId, group: Unit.Symmetry
|
|
|
const unitIndex = OrderedSet.indexOf(unit.elements, unit.polymerElements[groupId]) as StructureElement.UnitIndex
|
|
|
if (unitIndex !== -1) {
|
|
|
const indices = OrderedSet.ofSingleton(unitIndex)
|
|
|
- return StructureElement.Loci([{ unit, indices }])
|
|
|
+ return StructureElement.Loci(structure, [{ unit, indices }])
|
|
|
}
|
|
|
}
|
|
|
return EmptyLoci
|
|
|
}
|
|
|
|
|
|
-export function markPolymerElement(loci: Loci, group: Unit.SymmetryGroup, apply: (interval: Interval) => boolean) {
|
|
|
- const groupCount = group.units[0].polymerElements.length
|
|
|
-
|
|
|
+export function markPolymerElement(loci: Loci, structureGroup: StructureGroup, apply: (interval: Interval) => boolean) {
|
|
|
let changed = false
|
|
|
- if (StructureElement.isLoci(loci)) {
|
|
|
- for (const e of loci.elements) {
|
|
|
- const unitIdx = group.unitIndexMap.get(e.unit.id)
|
|
|
- if (unitIdx !== undefined) {
|
|
|
- if (Interval.is(e.indices)) {
|
|
|
- const min = + OrderedSet.indexOf(e.unit.polymerElements, e.unit.elements[Interval.min(e.indices)])
|
|
|
- const max = OrderedSet.indexOf(e.unit.polymerElements, e.unit.elements[Interval.max(e.indices)])
|
|
|
- if (min !== -1 && max !== -1) {
|
|
|
- if (apply(Interval.ofRange(unitIdx * groupCount + min, unitIdx * groupCount + max))) changed = true
|
|
|
- }
|
|
|
- } else {
|
|
|
- for (let i = 0, _i = e.indices.length; i < _i; i++) {
|
|
|
- const idx = OrderedSet.indexOf(e.unit.polymerElements, e.unit.elements[e.indices[i]])
|
|
|
- if (idx !== -1) {
|
|
|
- if (apply(Interval.ofSingleton(unitIdx * groupCount + idx))) changed = true
|
|
|
- }
|
|
|
+ if (!StructureElement.isLoci(loci)) return false
|
|
|
+ const { structure, group } = structureGroup
|
|
|
+ if (loci.structure !== structure) return false
|
|
|
+ const groupCount = group.units[0].polymerElements.length
|
|
|
+ for (const e of loci.elements) {
|
|
|
+ const unitIdx = group.unitIndexMap.get(e.unit.id)
|
|
|
+ if (unitIdx !== undefined) {
|
|
|
+ if (Interval.is(e.indices)) {
|
|
|
+ const min = OrderedSet.indexOf(e.unit.polymerElements, e.unit.elements[Interval.min(e.indices)])
|
|
|
+ const max = OrderedSet.indexOf(e.unit.polymerElements, e.unit.elements[Interval.max(e.indices)])
|
|
|
+ if (min !== -1 && max !== -1) {
|
|
|
+ if (apply(Interval.ofRange(unitIdx * groupCount + min, unitIdx * groupCount + max))) changed = true
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (let i = 0, _i = e.indices.length; i < _i; i++) {
|
|
|
+ const idx = OrderedSet.indexOf(e.unit.polymerElements, e.unit.elements[e.indices[i]])
|
|
|
+ if (idx !== -1) {
|
|
|
+ if (apply(Interval.ofSingleton(unitIdx * groupCount + idx))) changed = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -108,31 +110,33 @@ export function markPolymerElement(loci: Loci, group: Unit.SymmetryGroup, apply:
|
|
|
return changed
|
|
|
}
|
|
|
|
|
|
-export function getPolymerGapElementLoci(pickingId: PickingId, group: Unit.SymmetryGroup, id: number) {
|
|
|
+export function getPolymerGapElementLoci(pickingId: PickingId, structureGroup: StructureGroup, id: number) {
|
|
|
const { objectId, instanceId, groupId } = pickingId
|
|
|
if (id === objectId) {
|
|
|
+ const { structure, group } = structureGroup
|
|
|
const unit = group.units[instanceId]
|
|
|
const unitIndexA = OrderedSet.indexOf(unit.elements, unit.gapElements[groupId]) as StructureElement.UnitIndex
|
|
|
const unitIndexB = OrderedSet.indexOf(unit.elements, unit.gapElements[groupId % 2 ? groupId - 1 : groupId + 1]) as StructureElement.UnitIndex
|
|
|
if (unitIndexA !== -1 && unitIndexB !== -1) {
|
|
|
- return Link.Loci([ Link.Location(unit, unitIndexA, unit, unitIndexB) ])
|
|
|
+ return Link.Loci(structure, [ Link.Location(unit, unitIndexA, unit, unitIndexB) ])
|
|
|
}
|
|
|
}
|
|
|
return EmptyLoci
|
|
|
}
|
|
|
|
|
|
-export function markPolymerGapElement(loci: Loci, group: Unit.SymmetryGroup, apply: (interval: Interval) => boolean) {
|
|
|
+export function markPolymerGapElement(loci: Loci, structureGroup: StructureGroup, apply: (interval: Interval) => boolean) {
|
|
|
let changed = false
|
|
|
- if (Link.isLoci(loci)) {
|
|
|
- const groupCount = group.units[0].gapElements.length
|
|
|
- for (const b of loci.links) {
|
|
|
- const unitIdx = group.unitIndexMap.get(b.aUnit.id)
|
|
|
- if (unitIdx !== undefined) {
|
|
|
- const idxA = OrderedSet.indexOf(b.aUnit.gapElements, b.aUnit.elements[b.aIndex])
|
|
|
- const idxB = OrderedSet.indexOf(b.bUnit.gapElements, b.bUnit.elements[b.bIndex])
|
|
|
- if (idxA !== -1 && idxB !== -1) {
|
|
|
- if (apply(Interval.ofSingleton(unitIdx * groupCount + idxA))) changed = true
|
|
|
- }
|
|
|
+ if (!Link.isLoci(loci)) return false
|
|
|
+ const { structure, group } = structureGroup
|
|
|
+ if (loci.structure !== structure) return false
|
|
|
+ const groupCount = group.units[0].gapElements.length
|
|
|
+ for (const b of loci.links) {
|
|
|
+ const unitIdx = group.unitIndexMap.get(b.aUnit.id)
|
|
|
+ if (unitIdx !== undefined) {
|
|
|
+ const idxA = OrderedSet.indexOf(b.aUnit.gapElements, b.aUnit.elements[b.aIndex])
|
|
|
+ const idxB = OrderedSet.indexOf(b.bUnit.gapElements, b.bUnit.elements[b.bIndex])
|
|
|
+ if (idxA !== -1 && idxB !== -1) {
|
|
|
+ if (apply(Interval.ofSingleton(unitIdx * groupCount + idxA))) changed = true
|
|
|
}
|
|
|
}
|
|
|
}
|