UNPKG

molstar

Version:

A comprehensive macromolecular library.

115 lines (114 loc) 4.53 kB
/** * Copyright (c) 2017-2022 Mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { mmCIF_Schema } from '../../../../mol-io/reader/cif/schema/mmcif'; import { CifWriter } from '../../../../mol-io/writer/cif'; import { Table } from '../../../../mol-data/db'; import { FormatPropertyProvider } from '../../common/property'; export var ComponentBond; (function (ComponentBond) { ComponentBond.Descriptor = { name: 'chem_comp_bond', cifExport: { prefix: '', categories: [{ name: 'chem_comp_bond', instance(ctx) { const p = ComponentBond.Provider.get(ctx.firstModel); if (!p) return CifWriter.Category.Empty; const chem_comp_bond = p.data; if (!chem_comp_bond) return CifWriter.Category.Empty; const comp_names = ctx.structures[0].uniqueResidueNames; const { comp_id, _rowCount } = chem_comp_bond; const indices = []; for (let i = 0; i < _rowCount; i++) { if (comp_names.has(comp_id.value(i))) indices[indices.length] = i; } return CifWriter.Category.ofTable(chem_comp_bond, indices); } }] } }; ComponentBond.Provider = FormatPropertyProvider.create(ComponentBond.Descriptor); function chemCompBondFromTable(model, table) { return Table.pick(table, mmCIF_Schema.chem_comp_bond, (i) => { return model.properties.chemicalComponentMap.has(table.comp_id.value(i)); }); } ComponentBond.chemCompBondFromTable = chemCompBondFromTable; function getEntriesFromChemCompBond(data) { const entries = new Map(); function addEntry(id) { // weird behavior when 'PRO' is requested - will report a single bond // between N and H because a later operation would override real content if (entries.has(id)) return entries.get(id); const e = new Entry(id); entries.set(id, e); return e; } const { comp_id, atom_id_1, atom_id_2, value_order, pdbx_aromatic_flag, _rowCount, pdbx_ordinal } = data; let entry = addEntry(comp_id.value(0)); for (let i = 0; i < _rowCount; i++) { const id = comp_id.value(i); const nameA = atom_id_1.value(i); const nameB = atom_id_2.value(i); const order = value_order.value(i); const aromatic = pdbx_aromatic_flag.value(i) === 'y'; const key = pdbx_ordinal.value(i); if (entry.id !== id) { entry = addEntry(id); } let flags = 1 /* BondType.Flag.Covalent */; let ord = 1; if (aromatic) flags |= 16 /* BondType.Flag.Aromatic */; switch (order.toLowerCase()) { case 'delo': flags |= 16 /* BondType.Flag.Aromatic */; break; case 'doub': ord = 2; break; case 'trip': ord = 3; break; case 'quad': ord = 4; break; } entry.add(nameA, nameB, ord, flags, key); } return entries; } ComponentBond.getEntriesFromChemCompBond = getEntriesFromChemCompBond; class Entry { add(a, b, order, flags, key, swap = true) { const e = this.map.get(a); if (e !== void 0) { const f = e.get(b); if (f === void 0) { e.set(b, { order, flags, key }); } } else { const map = new Map(); map.set(b, { order, flags, key }); this.map.set(a, map); } if (swap) this.add(b, a, order, flags, key, false); } constructor(id) { this.id = id; this.map = new Map(); } } ComponentBond.Entry = Entry; })(ComponentBond || (ComponentBond = {}));