molstar
Version:
A comprehensive macromolecular library.
71 lines (70 loc) • 3.19 kB
JavaScript
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Unit, StructureElement, Structure } from '../../../../mol-model/structure';
import { EmptyLoci } from '../../../../mol-model/loci';
import { LocationIterator } from '../../../../mol-geo/util/location-iterator';
import { getResidueLoci } from './common';
import { eachAtomicUnitTracedElement } from './polymer';
export var NucleotideLocationIterator;
(function (NucleotideLocationIterator) {
function fromGroup(structureGroup) {
var group = structureGroup.group, structure = structureGroup.structure;
var u = group.units[0];
var nucleotideElementIndices = Unit.isAtomic(u) ? u.nucleotideElements : [];
var groupCount = nucleotideElementIndices.length;
var instanceCount = group.units.length;
var location = StructureElement.Location.create(structure);
var getLocation = function (groupIndex, instanceIndex) {
var unit = group.units[instanceIndex];
location.unit = unit;
location.element = nucleotideElementIndices[groupIndex];
return location;
};
return LocationIterator(groupCount, instanceCount, 1, getLocation);
}
NucleotideLocationIterator.fromGroup = fromGroup;
})(NucleotideLocationIterator || (NucleotideLocationIterator = {}));
export function getNucleotideElementLoci(pickingId, structureGroup, id) {
var objectId = pickingId.objectId, instanceId = pickingId.instanceId, groupId = pickingId.groupId;
if (id === objectId) {
var structure = structureGroup.structure, group = structureGroup.group;
var unit = group.units[instanceId];
if (Unit.isAtomic(unit)) {
return getResidueLoci(structure, unit, unit.nucleotideElements[groupId]);
}
}
return EmptyLoci;
}
function selectNuclotideElements(u) { return u.nucleotideElements; }
/**
* Mark a nucleotide element (e.g. part of a cartoon block)
* - mark only when all its residue's elements are in a loci
*/
export function eachNucleotideElement(loci, structureGroup, apply) {
var changed = false;
if (!StructureElement.Loci.is(loci))
return false;
var structure = structureGroup.structure, group = structureGroup.group;
if (!Structure.areEquivalent(loci.structure, structure))
return false;
var unit = group.units[0];
if (!Unit.isAtomic(unit))
return false;
var nucleotideElements = unit.nucleotideElements;
var groupCount = nucleotideElements.length;
for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) {
var e = _a[_i];
if (!Unit.isAtomic(e.unit))
continue;
if (!group.unitIndexMap.has(e.unit.id))
continue;
var intervalOffset = group.unitIndexMap.get(e.unit.id) * groupCount;
if (Unit.isAtomic(e.unit)) {
changed = eachAtomicUnitTracedElement(intervalOffset, groupCount, selectNuclotideElements, apply, e) || changed;
}
}
return changed;
}