UNPKG

molstar

Version:

A comprehensive macromolecular library.

322 lines 15.1 kB
#!/usr/bin/env node /** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator } from "tslib"; import * as argparse from 'argparse'; require('util.promisify').shim(); import { Structure, StructureElement, Unit, StructureProperties, UnitRing } from '../../mol-model/structure'; // import { Run, Progress } from '../../mol-task' import { OrderedSet } from '../../mol-data/int'; import { openCif, downloadCif } from './helpers'; import { Vec3 } from '../../mol-math/linear-algebra'; import { trajectoryFromMmCIF } from '../../mol-model-formats/structure/mmcif'; import { Sequence } from '../../mol-model/sequence'; import { ModelSecondaryStructure } from '../../mol-model-formats/structure/property/secondary-structure'; import { ModelSymmetry } from '../../mol-model-formats/structure/property/symmetry'; import { Task } from '../../mol-task'; function downloadFromPdb(pdb) { return __awaiter(this, void 0, void 0, function () { var parsed; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, downloadCif("http://www.ebi.ac.uk/pdbe/static/entry/" + pdb + "_updated.cif", false)]; case 1: parsed = _a.sent(); return [2 /*return*/, parsed.blocks[0]]; } }); }); } export function readCifFile(path) { return __awaiter(this, void 0, void 0, function () { var parsed; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, openCif(path)]; case 1: parsed = _a.sent(); return [2 /*return*/, parsed.blocks[0]]; } }); }); } export function atomLabel(model, aI) { var _a = model.atomicHierarchy, atoms = _a.atoms, residues = _a.residues, chains = _a.chains, residueAtomSegments = _a.residueAtomSegments, chainAtomSegments = _a.chainAtomSegments; var label_atom_id = atoms.label_atom_id, label_comp_id = atoms.label_comp_id; var label_seq_id = residues.label_seq_id; var label_asym_id = chains.label_asym_id; var rI = residueAtomSegments.index[aI]; var cI = chainAtomSegments.index[aI]; return label_asym_id.value(cI) + " " + label_comp_id.value(aI) + " " + label_seq_id.value(rI) + " " + label_atom_id.value(aI); } export function residueLabel(model, rI) { var _a = model.atomicHierarchy, atoms = _a.atoms, residues = _a.residues, chains = _a.chains, residueAtomSegments = _a.residueAtomSegments, chainAtomSegments = _a.chainAtomSegments; var label_comp_id = atoms.label_comp_id; var label_seq_id = residues.label_seq_id; var label_asym_id = chains.label_asym_id; var aI = residueAtomSegments.offsets[rI]; var cI = chainAtomSegments.index[aI]; return label_asym_id.value(cI) + " " + label_comp_id.value(aI) + " " + label_seq_id.value(rI); } export function printSecStructure(model) { console.log('\nSecondary Structure\n============='); var residues = model.atomicHierarchy.residues; var secondaryStructure = ModelSecondaryStructure.Provider.get(model); if (!secondaryStructure) return; var key = secondaryStructure.key, elements = secondaryStructure.elements; var count = residues._rowCount; var rI = 0; while (rI < count) { var start = rI; while (rI < count && key[start] === key[rI]) rI++; rI--; var e = elements[key[start]]; if (e.kind !== 'none') console.log(e.kind + ": " + residueLabel(model, start) + " - " + residueLabel(model, rI)); rI++; } } export function printBonds(structure, showIntra, showInter) { if (showIntra) { console.log('\nIntra Unit Bonds\n============='); for (var _a = 0, _b = structure.units; _a < _b.length; _a++) { var unit = _b[_a]; if (!Unit.isAtomic(unit)) continue; var elements = unit.elements; var _c = unit.bonds, a = _c.a, b = _c.b, edgeCount = _c.edgeCount; var model = unit.model; if (!edgeCount) continue; for (var bI = 0, _bI = edgeCount * 2; bI < _bI; bI++) { var x = a[bI], y = b[bI]; if (x >= y) continue; console.log(atomLabel(model, elements[x]) + " -- " + atomLabel(model, elements[y])); } } } if (showInter) { console.log('\nInter Unit Bonds\n============='); var bonds = structure.interUnitBonds; for (var _d = 0, _e = structure.units; _d < _e.length; _d++) { var unit = _e[_d]; if (!Unit.isAtomic(unit)) continue; for (var _f = 0, _g = bonds.getConnectedUnits(unit.id); _f < _g.length; _f++) { var pairBonds = _g[_f]; if (!pairBonds.areUnitsOrdered || pairBonds.edgeCount === 0) continue; var unitA = pairBonds.unitA, unitB = pairBonds.unitB, edgeCount = pairBonds.edgeCount; var uA = structure.unitMap.get(unitA); var uB = structure.unitMap.get(unitB); console.log(unitA + " - " + unitB + ": " + edgeCount + " bond(s)"); for (var _h = 0, _k = pairBonds.connectedIndices; _h < _k.length; _h++) { var aI = _k[_h]; for (var _l = 0, _m = pairBonds.getEdges(aI); _l < _m.length; _l++) { var bond = _m[_l]; console.log(atomLabel(uA.model, uA.elements[aI]) + " -- " + atomLabel(uB.model, uB.elements[bond.indexB])); } } } } } } export function printSequence(model) { console.log('\nSequence\n============='); var byEntityKey = model.sequence.byEntityKey; for (var _a = 0, _b = Object.keys(byEntityKey); _a < _b.length; _a++) { var key = _b[_a]; var _c = byEntityKey[+key], sequence = _c.sequence, entityId = _c.entityId; var seqId = sequence.seqId, compId = sequence.compId; console.log(entityId + " (" + sequence.kind + " " + seqId.value(0) + ", " + seqId.value(seqId.rowCount - 1) + ") (" + compId.value(0) + ", " + compId.value(compId.rowCount - 1) + ")"); console.log("" + Sequence.getSequenceString(sequence)); } console.log(); } export function printRings(structure) { console.log('\nRings\n============='); for (var _a = 0, _b = structure.units; _a < _b.length; _a++) { var unit = _b[_a]; if (!Unit.isAtomic(unit)) continue; var _c = unit.rings, all = _c.all, byFingerprint = _c.byFingerprint; var fps = []; for (var i = 0, _i = Math.min(5, all.length); i < _i; i++) { fps[fps.length] = UnitRing.fingerprint(unit, all[i]); } if (all.length > 5) fps.push('...'); console.log("Unit " + unit.id + ", " + all.length + " ring(s), " + byFingerprint.size + " different fingerprint(s).\n " + fps.join(', ')); } console.log(); } export function printUnits(structure) { console.log('\nUnits\n============='); var l = StructureElement.Location.create(structure); for (var _a = 0, _b = structure.units; _a < _b.length; _a++) { var unit = _b[_a]; l.unit = unit; var elements = unit.elements; var size = OrderedSet.size(elements); if (Unit.isAtomic(l.unit)) { console.log("Atomic unit " + unit.id + " " + unit.conformation.operator.name + ": " + size + " elements"); } else if (Unit.isCoarse(l.unit)) { console.log("Coarse unit " + unit.id + " " + unit.conformation.operator.name + " (" + (Unit.isSpheres(l.unit) ? 'spheres' : 'gaussians') + "): " + size + " elements."); var props = StructureProperties.coarse; var modelSeq = l.unit.model.sequence; for (var j = 0, _j = Math.min(size, 3); j < _j; j++) { l.element = OrderedSet.getAt(elements, j); var residues = []; var start = props.seq_id_begin(l), end = props.seq_id_end(l); var compId = modelSeq.byEntityKey[props.entityKey(l)].sequence.compId.value; for (var e = start; e <= end; e++) residues.push(compId(e)); console.log(props.asym_id(l) + ":" + start + "-" + end + " (" + residues.join('-') + ") " + props.asym_id(l) + " [" + props.x(l).toFixed(2) + ", " + props.y(l).toFixed(2) + ", " + props.z(l).toFixed(2) + "]"); } if (size > 3) console.log("..."); } } } export function printSymmetryInfo(model) { console.log('\nSymmetry Info\n============='); var symmetry = ModelSymmetry.Provider.get(model); if (!symmetry) return; var _a = symmetry.spacegroup.cell, size = _a.size, anglesInRadians = _a.anglesInRadians; console.log("Spacegroup: " + symmetry.spacegroup.name + " size: " + Vec3.toString(size) + " angles: " + Vec3.toString(anglesInRadians)); console.log("Assembly names: " + symmetry.assemblies.map(function (a) { return a.id; }).join(', ')); // NCS example: 1auy console.log("NCS operators: " + (symmetry.ncsOperators && symmetry.ncsOperators.map(function (a) { return a.name; }).join(', '))); } export function printModelStats(models) { return __awaiter(this, void 0, void 0, function () { var i, m; return __generator(this, function (_a) { switch (_a.label) { case 0: console.log('\nModels\n============='); i = 0; _a.label = 1; case 1: if (!(i < models.frameCount)) return [3 /*break*/, 4]; return [4 /*yield*/, Task.resolveInContext(models.getFrameAtIndex(i))]; case 2: m = _a.sent(); if (m.coarseHierarchy.isDefined) { console.log(m.label + " " + m.modelNum + ": " + m.atomicHierarchy.atoms._rowCount + " atom(s), " + m.coarseHierarchy.spheres.count + " sphere(s), " + m.coarseHierarchy.gaussians.count + " gaussian(s)"); } else { console.log(m.label + " " + m.modelNum + ": " + m.atomicHierarchy.atoms._rowCount + " atom(s)"); } _a.label = 3; case 3: i++; return [3 /*break*/, 1]; case 4: console.log(); return [2 /*return*/]; } }); }); } export function getModelsAndStructure(frame) { return __awaiter(this, void 0, void 0, function () { var models, structure; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, trajectoryFromMmCIF(frame).run()]; case 1: models = _a.sent(); structure = Structure.ofModel(models.representative); return [2 /*return*/, { models: models, structure: structure }]; } }); }); } function run(frame, args) { return __awaiter(this, void 0, void 0, function () { var _a, models, structure; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, getModelsAndStructure(frame)]; case 1: _a = _b.sent(), models = _a.models, structure = _a.structure; if (args.models) printModelStats(models); if (args.seq) printSequence(models.representative); if (args.units) printUnits(structure); if (args.sym) printSymmetryInfo(models.representative); if (args.rings) printRings(structure); if (args.intraBonds) printBonds(structure, true, false); if (args.interBonds) printBonds(structure, false, true); if (args.sec) printSecStructure(models.representative); return [2 /*return*/]; } }); }); } function runDL(pdb, args) { return __awaiter(this, void 0, void 0, function () { var mmcif; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, downloadFromPdb(pdb)]; case 1: mmcif = _a.sent(); run(mmcif, args); return [2 /*return*/]; } }); }); } function runFile(filename, args) { return __awaiter(this, void 0, void 0, function () { var mmcif; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, readCifFile(filename)]; case 1: mmcif = _a.sent(); run(mmcif, args); return [2 /*return*/]; } }); }); } var parser = new argparse.ArgumentParser({ add_help: true, description: 'Print info about a structure, mainly to test and showcase the mol-model module' }); parser.add_argument('--download', '-d', { help: 'Pdb entry id' }); parser.add_argument('--file', '-f', { help: 'filename' }); parser.add_argument('--models', { help: 'print models info', action: 'store_true' }); parser.add_argument('--seq', { help: 'print sequence', action: 'store_true' }); parser.add_argument('--units', { help: 'print units', action: 'store_true' }); parser.add_argument('--sym', { help: 'print symmetry', action: 'store_true' }); parser.add_argument('--rings', { help: 'print rings', action: 'store_true' }); parser.add_argument('--intraBonds', { help: 'print intra unit bonds', action: 'store_true' }); parser.add_argument('--interBonds', { help: 'print inter unit bonds', action: 'store_true' }); parser.add_argument('--mod', { help: 'print modified residues', action: 'store_true' }); parser.add_argument('--sec', { help: 'print secoundary structure', action: 'store_true' }); var args = parser.parse_args(); if (args.download) runDL(args.download, args); else if (args.file) runFile(args.file, args); //# sourceMappingURL=model.js.map