diff --git a/src/mol-repr/structure/complex-representation.ts b/src/mol-repr/structure/complex-representation.ts index ee4fb95d0d02c57e8368122fb8643a47fe31c292..bdd23b1ae20f49fd3d60785b78a7f4eb8e9c2b0b 100644 --- a/src/mol-repr/structure/complex-representation.ts +++ b/src/mol-repr/structure/complex-representation.ts @@ -8,7 +8,7 @@ import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { StructureParams, ComplexVisual, StructureRepresentation, StructureRepresentationStateBuilder, StructureRepresentationState } from './representation'; import { RepresentationContext, RepresentationParamsGetter } from '../representation'; -import { Structure } from '../../mol-model/structure'; +import { Structure, StructureElement, Link } from '../../mol-model/structure'; import { Subject } from 'rxjs'; import { getNextMaterialId, GraphicsRenderObject } from '../../mol-gl/render-object'; import { createEmptyTheme, Theme } from '../../mol-theme/theme'; @@ -55,6 +55,14 @@ export function ComplexRepresentation<P extends StructureParams>(label: string, } function mark(loci: Loci, action: MarkerAction) { + if (!_structure) return false + if (!StructureElement.isLoci(loci) && !Link.isLoci(loci)) return false + if (!Structure.areParentsEquivalent(loci.structure, _structure)) return false + if (StructureElement.isLoci(loci)) { + loci = StructureElement.Loci.remap(loci, _structure) + } else if (Link.isLoci(loci)) { + loci = Link.remapLoci(loci, _structure) + } return visual ? visual.mark(loci, action) : false } diff --git a/src/mol-repr/structure/units-representation.ts b/src/mol-repr/structure/units-representation.ts index 2a731d88898a2218dacdd058967c86e57ae1956c..cbc6eb0004feb8353e6273224624dbea0d96d2ca 100644 --- a/src/mol-repr/structure/units-representation.ts +++ b/src/mol-repr/structure/units-representation.ts @@ -11,7 +11,7 @@ import { UnitKind, UnitKindOptions } from './visual/util/common'; import { Visual } from '../visual'; import { StructureGroup } from './units-visual'; import { RepresentationContext, RepresentationParamsGetter } from '../representation'; -import { Structure, Unit } from '../../mol-model/structure'; +import { Structure, Unit, StructureElement, Link } from '../../mol-model/structure'; import { Subject } from 'rxjs'; import { getNextMaterialId, GraphicsRenderObject } from '../../mol-gl/render-object'; import { createEmptyTheme, Theme } from '../../mol-theme/theme'; @@ -164,6 +164,14 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: R function mark(loci: Loci, action: MarkerAction) { let changed = false + if (!_structure) return false + if (!StructureElement.isLoci(loci) && !Link.isLoci(loci)) return false + if (!Structure.areParentsEquivalent(loci.structure, _structure)) return false + if (StructureElement.isLoci(loci)) { + loci = StructureElement.Loci.remap(loci, _structure) + } else if (Link.isLoci(loci)) { + loci = Link.remapLoci(loci, _structure) + } visuals.forEach(({ visual }) => { changed = visual.mark(loci, action) || changed }) diff --git a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts index 711e98eb429477d22f20cc1ce97e8212823dfe26..094aef3eefdaaf8e9ca0ab45c9188b4f6bc8f93f 100644 --- a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts @@ -119,8 +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.areParentsEquivalent(loci.structure, structure)) return false - loci = Link.remapLoci(loci, structure) + if (!Structure.areEquivalent(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]) @@ -129,8 +128,7 @@ function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval } } } else if (StructureElement.isLoci(loci)) { - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(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) { diff --git a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts index b5adcfe5c757b0c2cfa0c53f962283722c7e1492..db874c3fd941b8318f9bd7f96ecbf08a87ae2e82 100644 --- a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts +++ b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts @@ -196,8 +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.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(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` diff --git a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts index b540d9d49a79f89f98d0d1f3ff0e7bd24a66d467..460343df6f8c056173bf89cc6ad09d507356252c 100644 --- a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts @@ -133,8 +133,7 @@ function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: In const { getTerminalLinkIndex } = structure.carbohydrates let changed = false if (Link.isLoci(loci)) { - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = Link.remapLoci(loci, structure) + if (!Structure.areEquivalent(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) { @@ -142,8 +141,7 @@ function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: In } } } else if (StructureElement.isLoci(loci)) { - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(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) { diff --git a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts index b90daa355fa7a586ed872f7d689db3cc334318d5..1971a36e4be76ace3231728529e93fa25ccfdd15 100644 --- a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts +++ b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts @@ -107,8 +107,7 @@ function eachCrossLink(loci: Loci, structure: Structure, apply: (interval: Inter const crossLinks = structure.crossLinkRestraints let changed = false if (Link.isLoci(loci)) { - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = Link.remapLoci(loci, structure) + if (!Structure.areEquivalent(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) { diff --git a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts index 204015f873524fc7e1d8a6f83fd264ca189a2a6b..775534ce9864a7887a2c30974f27367407627ec7 100644 --- a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts @@ -97,8 +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.areParentsEquivalent(loci.structure, structure)) return false - loci = Link.remapLoci(loci, structure) + if (!Structure.areEquivalent(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) { @@ -106,8 +105,7 @@ function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval) } } } else if (StructureElement.isLoci(loci)) { - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(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 => { diff --git a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts index 55fe6843a1468b8be77a3b04168ad96e43e38d62..a881695b133cd20e6cc7276fbeb2785d35e8186c 100644 --- a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts @@ -121,8 +121,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval: let changed = false if (Link.isLoci(loci)) { const { structure, group } = structureGroup - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = Link.remapLoci(loci, structure) + if (!Structure.areEquivalent(loci.structure, structure)) return false const unit = group.units[0] if (!Unit.isAtomic(unit)) return false const groupCount = unit.links.edgeCount * 2 @@ -137,8 +136,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval: } } else if (StructureElement.isLoci(loci)) { const { structure, group } = structureGroup - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(loci.structure, structure)) return false const unit = group.units[0] if (!Unit.isAtomic(unit)) return false const groupCount = unit.links.edgeCount * 2 diff --git a/src/mol-repr/structure/visual/util/element.ts b/src/mol-repr/structure/visual/util/element.ts index e492772ed8429eb1c37bf32a7265ebda46f3345a..d70dc06a3b71b61f1bcf6c4b8b0d35c14b8deeb3 100644 --- a/src/mol-repr/structure/visual/util/element.ts +++ b/src/mol-repr/structure/visual/util/element.ts @@ -72,8 +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.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(loci.structure, structure)) return false const elementCount = group.elements.length for (const e of loci.elements) { const unitIdx = group.unitIndexMap.get(e.unit.id) diff --git a/src/mol-repr/structure/visual/util/nucleotide.ts b/src/mol-repr/structure/visual/util/nucleotide.ts index 5406facc48d095ae677a67a8642349011c59acb2..e3d968dea150cd69f235c9075c308792f9e0cb25 100644 --- a/src/mol-repr/structure/visual/util/nucleotide.ts +++ b/src/mol-repr/structure/visual/util/nucleotide.ts @@ -45,8 +45,7 @@ export function eachNucleotideElement(loci: Loci, structureGroup: StructureGroup let changed = false if (!StructureElement.isLoci(loci)) return false const { structure, group } = structureGroup - if (!Structure.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(loci.structure, structure)) return false const unit = group.units[0] if (!Unit.isAtomic(unit)) return false const { nucleotideElements, model, elements } = unit diff --git a/src/mol-repr/structure/visual/util/polymer.ts b/src/mol-repr/structure/visual/util/polymer.ts index b185f488350c3ea99ec4eacd04e32d1f1cb39419..401626df03ae2bbeb6b5def9eb02c0c108c8915d 100644 --- a/src/mol-repr/structure/visual/util/polymer.ts +++ b/src/mol-repr/structure/visual/util/polymer.ts @@ -95,8 +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.areParentsEquivalent(loci.structure, structure)) return false - loci = StructureElement.Loci.remap(loci, structure) + if (!Structure.areEquivalent(loci.structure, structure)) return false const { polymerElements, model, elements } = group.units[0] const { index, offsets } = model.atomicHierarchy.residueAtomSegments const { traceElementIndex } = model.atomicHierarchy.derived.residue