molstar
Version:
A comprehensive macromolecular library.
95 lines (94 loc) • 4.05 kB
JavaScript
/**
* Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { StructureProperties } from '../../../structure/properties';
var ResidueSet = /** @class */ (function () {
function ResidueSet(options) {
var _a;
this.index = new Map();
this.checkOperator = false;
this.checkOperator = (_a = options === null || options === void 0 ? void 0 : options.checkOperator) !== null && _a !== void 0 ? _a : false;
}
ResidueSet.prototype.add = function (entry) {
var root = this.index.get(entry.label_asym_id);
if (!root) {
root = new Map();
this.index.set(entry.label_asym_id, root);
}
var entries = root.get(entry.label_seq_id);
if (!entries) {
entries = [];
root.set(entry.label_seq_id, entries);
}
var exists = this._find(entry, entries);
if (!exists) {
entries.push(entry);
return true;
}
return false;
};
ResidueSet.prototype.hasLabelAsymId = function (asym_id) {
return this.index.has(asym_id);
};
ResidueSet.prototype.has = function (loc) {
var _a, _b;
var asym_id = _asym_id(loc);
if (!this.index.has(asym_id))
return;
var root = this.index.get(asym_id);
var seq_id = _seq_id(loc);
if (!root.has(seq_id))
return;
var entries = root.get(seq_id);
var comp_id = _comp_id(loc);
var alt_id = _alt_id(loc);
var ins_code = _ins_code(loc);
var op_name = (_a = _op_name(loc)) !== null && _a !== void 0 ? _a : '1_555';
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
var e = entries_1[_i];
if (e.label_comp_id !== comp_id || e.label_alt_id !== alt_id || e.ins_code !== ins_code)
continue;
if (this.checkOperator && ((_b = e.operator_name) !== null && _b !== void 0 ? _b : '1_555') !== op_name)
continue;
return e;
}
};
ResidueSet.getLabel = function (entry, checkOperator) {
var _a;
if (checkOperator === void 0) { checkOperator = false; }
return "".concat(entry.label_asym_id, " ").concat(entry.label_comp_id, " ").concat(entry.label_seq_id, ":").concat(entry.ins_code, ":").concat(entry.label_alt_id).concat(checkOperator ? ' ' + ((_a = entry.operator_name) !== null && _a !== void 0 ? _a : '1_555') : '');
};
ResidueSet.getEntryFromLocation = function (loc) {
var _a;
return {
label_asym_id: _asym_id(loc),
label_comp_id: _comp_id(loc),
label_seq_id: _seq_id(loc),
label_alt_id: _alt_id(loc),
ins_code: _ins_code(loc),
operator_name: (_a = _op_name(loc)) !== null && _a !== void 0 ? _a : '1_555'
};
};
ResidueSet.prototype._find = function (entry, xs) {
var _a, _b;
for (var _i = 0, xs_1 = xs; _i < xs_1.length; _i++) {
var e = xs_1[_i];
if (e.label_comp_id !== entry.label_comp_id || e.label_alt_id !== entry.label_alt_id || e.ins_code !== entry.ins_code)
continue;
if (this.checkOperator && ((_a = e.operator_name) !== null && _a !== void 0 ? _a : '1_555') !== ((_b = entry.operator_name) !== null && _b !== void 0 ? _b : '1_555'))
continue;
return true;
}
return false;
};
return ResidueSet;
}());
export { ResidueSet };
var _asym_id = StructureProperties.chain.label_asym_id;
var _seq_id = StructureProperties.residue.label_seq_id;
var _comp_id = StructureProperties.atom.label_comp_id;
var _alt_id = StructureProperties.atom.label_alt_id;
var _ins_code = StructureProperties.residue.pdbx_PDB_ins_code;
var _op_name = StructureProperties.unit.operator_name;