molstar
Version:
A comprehensive macromolecular library.
123 lines • 5.54 kB
JavaScript
/**
* Copyright (c) 2019-2020 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.topologyFromPsf = exports.PsfFormat = void 0;
var tslib_1 = require("tslib");
var db_1 = require("../../mol-data/db");
var types_1 = require("../../mol-model/structure/model/types");
var topology_1 = require("../../mol-model/structure/topology/topology");
var mol_task_1 = require("../../mol-task");
var schema_1 = require("./basic/schema");
var component_1 = require("./common/component");
var entity_1 = require("./common/entity");
var util_1 = require("./common/util");
var util_2 = require("./util");
function getBasic(atoms) {
var entityIds = new Array(atoms.count);
var asymIds = new Array(atoms.count);
var seqIds = new Uint32Array(atoms.count);
var ids = new Uint32Array(atoms.count);
var entityBuilder = new entity_1.EntityBuilder();
var componentBuilder = new component_1.ComponentBuilder(atoms.residueId, atoms.atomName);
var currentEntityId = '';
var currentAsymIndex = 0;
var currentAsymId = '';
var currentSeqId = 0;
var currentSegmentName = atoms.segmentName.value(0), segmentChanged = false;
var prevMoleculeType = 0 /* Unknown */;
var prevResidueNumber = -1;
for (var i = 0, il = atoms.count; i < il; ++i) {
var residueNumber = atoms.residueId.value(i);
var segmentName = atoms.segmentName.value(i);
if (currentSegmentName !== segmentName) {
currentAsymId = (0, util_1.getChainId)(currentAsymIndex);
currentAsymIndex += 1;
currentSeqId = 0;
segmentChanged = true;
currentSegmentName = segmentName;
}
else {
segmentChanged = false;
}
if (segmentChanged || residueNumber !== prevResidueNumber) {
var compId = atoms.residueName.value(i);
var moleculeType = (0, types_1.getMoleculeType)(componentBuilder.add(compId, i).type, compId);
if (!segmentChanged && (moleculeType !== prevMoleculeType || residueNumber !== prevResidueNumber + 1)) {
currentAsymId = (0, util_1.getChainId)(currentAsymIndex);
currentAsymIndex += 1;
currentSeqId = 0;
}
currentEntityId = entityBuilder.getEntityId(compId, moleculeType, currentAsymId);
currentSeqId += 1;
prevResidueNumber = residueNumber;
prevMoleculeType = moleculeType;
}
entityIds[i] = currentEntityId;
asymIds[i] = currentAsymId;
seqIds[i] = currentSeqId;
ids[i] = i;
}
var atom_site = db_1.Table.ofPartialColumns(schema_1.BasicSchema.atom_site, {
auth_asym_id: atoms.segmentName,
auth_atom_id: atoms.atomName,
auth_comp_id: atoms.residueName,
auth_seq_id: atoms.residueId,
id: db_1.Column.ofIntArray(ids),
label_asym_id: db_1.Column.ofStringArray(asymIds),
label_atom_id: atoms.atomName,
label_comp_id: atoms.residueName,
label_seq_id: db_1.Column.ofIntArray(seqIds),
label_entity_id: db_1.Column.ofStringArray(entityIds),
occupancy: db_1.Column.ofConst(1, atoms.count, db_1.Column.Schema.float),
type_symbol: db_1.Column.ofStringArray(db_1.Column.mapToArray(atoms.atomName, function (s) { return (0, util_2.guessElementSymbolString)(s); })),
pdbx_PDB_model_num: db_1.Column.ofConst(1, atoms.count, db_1.Column.Schema.int),
}, atoms.count);
return (0, schema_1.createBasic)({
entity: entityBuilder.getEntityTable(),
chem_comp: componentBuilder.getChemCompTable(),
atom_site: atom_site
});
}
var PsfFormat;
(function (PsfFormat) {
function is(x) {
return (x === null || x === void 0 ? void 0 : x.kind) === 'psf';
}
PsfFormat.is = is;
function fromPsf(psf) {
return { kind: 'psf', name: psf.id, data: psf };
}
PsfFormat.fromPsf = fromPsf;
})(PsfFormat || (PsfFormat = {}));
exports.PsfFormat = PsfFormat;
function topologyFromPsf(psf) {
var _this = this;
return mol_task_1.Task.create('Parse PSF', function (ctx) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
var format, basic, _a, atomIdA, atomIdB, bonds;
return (0, tslib_1.__generator)(this, function (_b) {
format = PsfFormat.fromPsf(psf);
basic = getBasic(psf.atoms);
_a = psf.bonds, atomIdA = _a.atomIdA, atomIdB = _a.atomIdB;
bonds = {
indexA: db_1.Column.ofLambda({
value: function (row) { return atomIdA.value(row) - 1; },
rowCount: atomIdA.rowCount,
schema: atomIdA.schema,
}),
indexB: db_1.Column.ofLambda({
value: function (row) { return atomIdB.value(row) - 1; },
rowCount: atomIdB.rowCount,
schema: atomIdB.schema,
}),
order: db_1.Column.ofConst(1, psf.bonds.count, db_1.Column.Schema.int)
};
return [2 /*return*/, topology_1.Topology.create(psf.id, basic, bonds, format)];
});
}); });
}
exports.topologyFromPsf = topologyFromPsf;
//# sourceMappingURL=psf.js.map
;