UNPKG

molstar

Version:

A comprehensive macromolecular library.

109 lines (108 loc) 4.18 kB
"use strict"; /** * Copyright (c) 2019-2026 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityBuilder = void 0; const types_1 = require("../../../mol-model/structure/model/types.js"); const db_1 = require("../../../mol-data/db.js"); const schema_1 = require("../basic/schema.js"); class EntityBuilder { constructor() { this.count = 0; this.ids = []; this.types = []; this.descriptions = []; this.compoundsMap = new Map(); this.seqresMap = new Map(); this.namesMap = new Map(); this.heteroMap = new Map(); this.chainMap = new Map(); this.sequenceMap = new Map(); this.polymerCount = 0; } set(type, description) { this.count += 1; this.ids.push(`${this.count}`); this.types.push(type); this.descriptions.push([description]); } addPolymer(map, key, options) { if (!map.has(key)) { this.polymerCount += 1; this.set('polymer', (options === null || options === void 0 ? void 0 : options.customName) || `Polymer ${this.polymerCount}`); map.set(key, `${this.count}`); } return map.get(key); } addNonPolymer(map, key, moleculeType, options) { if (!map.has(key)) { const type = moleculeType === types_1.MoleculeType.Saccharide ? 'branched' : 'non-polymer'; this.set(type, (options === null || options === void 0 ? void 0 : options.customName) || this.namesMap.get(key) || key); map.set(key, `${this.count}`); } return map.get(key); } getEntityId(compId, moleculeType, chainId, options) { if (moleculeType === types_1.MoleculeType.Water) { if (this.waterId === undefined) { this.set('water', (options === null || options === void 0 ? void 0 : options.customName) || 'Water'); this.waterId = `${this.count}`; } return this.waterId; } else if ((0, types_1.isPolymer)(moleculeType)) { if (this.compoundsMap.has(chainId)) { return this.compoundsMap.get(chainId); } else { if (this.seqresMap.has(chainId)) { const { key, residues } = this.seqresMap.get(chainId); if (residues.has(compId)) { return this.addPolymer(this.sequenceMap, key, options); } } return this.addPolymer(this.chainMap, chainId, options); } } else { if (this.seqresMap.has(chainId)) { const { key, residues } = this.seqresMap.get(chainId); if (residues.has(compId)) { return this.addNonPolymer(this.sequenceMap, key, moleculeType, options); } } return this.addNonPolymer(this.heteroMap, compId, moleculeType, options); } } getEntityTable() { return db_1.Table.ofPartialColumns(schema_1.BasicSchema.entity, { id: db_1.Column.ofStringArray(this.ids), type: db_1.Column.ofStringAliasArray(this.types), pdbx_description: db_1.Column.ofStringListArray(this.descriptions), }, this.count); } setCompounds(compounds) { for (let i = 0, il = compounds.length; i < il; ++i) { const { chains, description } = compounds[i]; this.set('polymer', description); for (let j = 0, jl = chains.length; j < jl; ++j) { this.compoundsMap.set(chains[j], `${this.count}`); } } } setNames(names) { names.forEach(n => this.namesMap.set(n[0], n[1])); } setSeqres(seqresMap) { for (const [chainId, residues] of seqresMap) { this.seqresMap.set(chainId, { key: residues.join('-'), residues: new Set(residues) }); } } } exports.EntityBuilder = EntityBuilder;