Browse Source

add and use Structure.areParentsEquivalent

Alexander Rose 5 years ago
parent
commit
cc34425712

+ 5 - 0
src/mol-model/structure/structure/structure.ts

@@ -507,6 +507,11 @@ namespace Structure {
         )
     }
 
+    /** Check if the structures or their parents are equivalent */
+    export function areParentsEquivalent(a: Structure, b: Structure) {
+        return areEquivalent(a.parent || a, b.parent || b)
+    }
+
     export class ElementLocationIterator implements Iterator<StructureElement> {
         private current = StructureElement.create();
         private unitIndex = 0;

+ 1 - 1
src/mol-repr/structure/complex-visual.ts

@@ -165,7 +165,7 @@ export function ComplexVisual<G extends Geometry, P extends ComplexParams & Geom
     }
 
     function lociApply(loci: Loci, apply: (interval: Interval) => boolean) {
-        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructure))) {
+        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areParentsEquivalent(loci.structure, currentStructure))) {
             return apply(Interval.ofBounds(0, locationIt.groupCount * locationIt.instanceCount))
         } else {
             return eachLocation(loci, currentStructure, apply)

+ 1 - 1
src/mol-repr/structure/units-visual.ts

@@ -214,7 +214,7 @@ export function UnitsVisual<G extends Geometry, P extends UnitsParams & Geometry
     }
 
     function lociApply(loci: Loci, apply: (interval: Interval) => boolean) {
-        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructureGroup.structure))) {
+        if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areParentsEquivalent(loci.structure, currentStructureGroup.structure))) {
             return apply(Interval.ofBounds(0, locationIt.groupCount * locationIt.instanceCount))
         } else {
             return eachLocation(loci, currentStructureGroup, apply)

+ 2 - 2
src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts

@@ -119,7 +119,7 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
 function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     let changed = false
     if (Link.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         const { getLinkIndex } = structure.carbohydrates
         for (const l of loci.links) {
             const idx = getLinkIndex(l.aUnit, l.aUnit.elements[l.aIndex], l.bUnit, l.bUnit.elements[l.bIndex])
@@ -128,7 +128,7 @@ function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval
             }
         }
     } else if (StructureElement.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         // TODO mark link only when both of the link elements are in a StructureElement.Loci
         const { getElementIndex, getLinkIndices, elements } = structure.carbohydrates
         for (const e of loci.elements) {

+ 1 - 1
src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts

@@ -196,7 +196,7 @@ function eachCarbohydrate(loci: Loci, structure: Structure, apply: (interval: In
     const { getElementIndex, getAnomericCarbons } = structure.carbohydrates
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
-    if (!Structure.areEquivalent(loci.structure, structure)) return false
+    if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
     for (const e of loci.elements) {
         // TODO make more efficient by handling/grouping `e.indices` by residue index
         // TODO only call apply when the full alt-residue of the unit is part of `e`

+ 2 - 2
src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts

@@ -133,7 +133,7 @@ function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: In
     const { getTerminalLinkIndex } = structure.carbohydrates
     let changed = false
     if (Link.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         for (const l of loci.links) {
             const idx = getTerminalLinkIndex(l.aUnit, l.aUnit.elements[l.aIndex], l.bUnit, l.bUnit.elements[l.bIndex])
             if (idx !== undefined) {
@@ -141,7 +141,7 @@ function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: In
             }
         }
     } else if (StructureElement.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         // TODO mark link only when both of the link elements are in a StructureElement.Loci
         const { getElementIndex, getTerminalLinkIndices, elements } = structure.carbohydrates
         for (const e of loci.elements) {

+ 1 - 1
src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts

@@ -107,7 +107,7 @@ function eachCrossLink(loci: Loci, structure: Structure, apply: (interval: Inter
     const crossLinks = structure.crossLinkRestraints
     let changed = false
     if (Link.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         for (const b of loci.links) {
             const indices = crossLinks.getPairIndices(b.aIndex, b.aUnit, b.bIndex, b.bUnit)
             if (indices) {

+ 2 - 2
src/mol-repr/structure/visual/inter-unit-link-cylinder.ts

@@ -97,7 +97,7 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) {
 function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) {
     let changed = false
     if (Link.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         for (const b of loci.links) {
             const idx = structure.links.getBondIndex(b.aIndex, b.aUnit, b.bIndex, b.bUnit)
             if (idx !== -1) {
@@ -105,7 +105,7 @@ function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval)
             }
         }
     } else if (StructureElement.isLoci(loci)) {
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         // TODO mark link only when both of the link elements are in a StructureElement.Loci
         for (const e of loci.elements) {
             OrderedSet.forEach(e.indices, v => {

+ 2 - 2
src/mol-repr/structure/visual/intra-unit-link-cylinder.ts

@@ -121,7 +121,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval:
     let changed = false
     if (Link.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         const unit = group.units[0]
         if (!Unit.isAtomic(unit)) return false
         const groupCount = unit.links.edgeCount * 2
@@ -136,7 +136,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval:
         }
     } else if (StructureElement.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         const unit = group.units[0]
         if (!Unit.isAtomic(unit)) return false
         const groupCount = unit.links.edgeCount * 2

+ 1 - 1
src/mol-repr/structure/visual/util/element.ts

@@ -72,7 +72,7 @@ export function eachElement(loci: Loci, structureGroup: StructureGroup, apply: (
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (!Structure.areEquivalent(loci.structure, structure)) return false
+    if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
     const elementCount = group.elements.length
     for (const e of loci.elements) {
         const unitIdx = group.unitIndexMap.get(e.unit.id)

+ 1 - 1
src/mol-repr/structure/visual/util/nucleotide.ts

@@ -45,7 +45,7 @@ export function eachNucleotideElement(loci: Loci, structureGroup: StructureGroup
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (!Structure.areEquivalent(loci.structure, structure)) return false
+    if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
     const unit = group.units[0]
     if (!Unit.isAtomic(unit)) return false
     const { nucleotideElements, model, elements } = unit

+ 3 - 3
src/mol-repr/structure/visual/util/polymer.ts

@@ -95,7 +95,7 @@ export function eachPolymerElement(loci: Loci, structureGroup: StructureGroup, a
     let changed = false
     if (!StructureElement.isLoci(loci)) return false
     const { structure, group } = structureGroup
-    if (!Structure.areEquivalent(loci.structure, structure)) return false
+    if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
     const { polymerElements, model, elements } = group.units[0]
     const { index, offsets } = model.atomicHierarchy.residueAtomSegments
     const { traceElementIndex } = model.atomicHierarchy.derived.residue
@@ -156,7 +156,7 @@ export function eachPolymerGapElement(loci: Loci, structureGroup: StructureGroup
     let changed = false
     if (Link.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(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)
@@ -170,7 +170,7 @@ export function eachPolymerGapElement(loci: Loci, structureGroup: StructureGroup
         }
     } else if (StructureElement.isLoci(loci)) {
         const { structure, group } = structureGroup
-        if (!Structure.areEquivalent(loci.structure, structure)) return false
+        if (!Structure.areParentsEquivalent(loci.structure, structure)) return false
         const groupCount = group.units[0].gapElements.length
         for (const e of loci.elements) {
             const unitIdx = group.unitIndexMap.get(e.unit.id)