Skip to content
Snippets Groups Projects
Select Git revision
  • 53c8ba549fe1af07a33e5524ba68efc93564f5d9
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

builders.ts

Blame
  • builders.ts 2.86 KiB
    /**
     * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { StructureElement, Structure } from '../../structure';
    import { StructureSelection } from '../selection';
    import { HashSet } from 'mol-data/generic';
    import { structureUnion } from './structure-set';
    import { StructureSubsetBuilder } from '../../structure/util/subset-builder';
    import { ElementIndex } from '../../model';
    
    export class UniqueStructuresBuilder {
        private set = HashSet(Structure.hashCode, Structure.areUnitAndIndicesEqual);
        private structures: Structure[] = [];
        private allSingletons = true;
    
        add(s: Structure) {
            if (!s.elementCount) return;
            if (s.elementCount !== 1) this.allSingletons = false;
            if (this.set.add(s)) {
                this.structures[this.structures.length] = s;
            }
        }
    
        getSelection() {
            if (this.allSingletons) return StructureSelection.Singletons(this.source, structureUnion(this.source, this.structures));
            return StructureSelection.Sequence(this.source, this.structures);
        }
    
        constructor(private source: Structure) {
        }
    }
    
    export class LinearGroupingBuilder {
        private builders: StructureSubsetBuilder[] = [];
        private builderMap = new Map<string, StructureSubsetBuilder>();
    
        add(key: any, unit: number, element: ElementIndex) {
            let b = this.builderMap.get(key);
            if (!b) {
                b = this.source.subsetBuilder(true);
                this.builders[this.builders.length] = b;
                this.builderMap.set(key, b);
            }
            b.addToUnit(unit, element);
        }
    
        private allSingletons() {
            for (let i = 0, _i = this.builders.length; i < _i; i++) {
                if (this.builders[i].elementCount > 1) return false;
            }
            return true;
        }
    
        private singletonSelection(): StructureSelection {
            const builder = this.source.subsetBuilder(true);
            const loc = StructureElement.create();
            for (let i = 0, _i = this.builders.length; i < _i; i++) {
                this.builders[i].setSingletonLocation(loc);
                builder.addToUnit(loc.unit.id, loc.element);
            }
            return StructureSelection.Singletons(this.source, builder.getStructure());
        }
    
        private fullSelection() {
            const structures: Structure[] = new Array(this.builders.length);
            for (let i = 0, _i = this.builders.length; i < _i; i++) {
                structures[i] = this.builders[i].getStructure();