UNPKG

molstar

Version:

A comprehensive macromolecular library.

161 lines (160 loc) 8.31 kB
/** * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Michal Malý <michal.maly@ibt.cas.cz> * @author Jiří Černý <jiri.cerny@ibt.cas.cz> */ import { __assign, __awaiter, __generator } from "tslib"; import { Column } from '../../../mol-data/db'; import { toTable } from '../../../mol-io/reader/cif/schema'; import { CustomPropertyDescriptor } from '../../../mol-model/custom-property'; import { CustomModelProperty } from '../../../mol-model-props/common/custom-model-property'; import { PropertyWrapper } from '../../../mol-model-props/common/wrapper'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { MmcifFormat } from '../../../mol-model-formats/structure/mmcif'; export var ConfalPyramids; (function (ConfalPyramids) { ConfalPyramids.Schema = { ndb_struct_ntc_step: { id: Column.Schema.int, name: Column.Schema.str, PDB_model_number: Column.Schema.int, label_entity_id_1: Column.Schema.int, label_asym_id_1: Column.Schema.str, label_seq_id_1: Column.Schema.int, label_comp_id_1: Column.Schema.str, label_alt_id_1: Column.Schema.str, label_entity_id_2: Column.Schema.int, label_asym_id_2: Column.Schema.str, label_seq_id_2: Column.Schema.int, label_comp_id_2: Column.Schema.str, label_alt_id_2: Column.Schema.str, auth_asym_id_1: Column.Schema.str, auth_seq_id_1: Column.Schema.int, auth_asym_id_2: Column.Schema.str, auth_seq_id_2: Column.Schema.int, PDB_ins_code_1: Column.Schema.str, PDB_ins_code_2: Column.Schema.str, }, ndb_struct_ntc_step_summary: { step_id: Column.Schema.int, assigned_CANA: Column.Schema.str, assigned_NtC: Column.Schema.str, confal_score: Column.Schema.int, euclidean_distance_NtC_ideal: Column.Schema.float, cartesian_rmsd_closest_NtC_representative: Column.Schema.float, closest_CANA: Column.Schema.str, closest_NtC: Column.Schema.str, closest_step_golden: Column.Schema.str } }; function fromCif(ctx, model, props) { return __awaiter(this, void 0, void 0, function () { var info, data, fromCif; return __generator(this, function (_a) { info = PropertyWrapper.createInfo(); data = getCifData(model); if (data === undefined) return [2 /*return*/, { value: { info: info, data: undefined } }]; fromCif = createPyramidsFromCif(model, data.steps, data.stepsSummary); return [2 /*return*/, { value: { info: info, data: fromCif } }]; }); }); } ConfalPyramids.fromCif = fromCif; function getCifData(model) { if (!MmcifFormat.is(model.sourceData)) throw new Error('Data format must be mmCIF'); if (!hasNdbStructNtcCategories(model)) return undefined; return { steps: toTable(ConfalPyramids.Schema.ndb_struct_ntc_step, model.sourceData.data.frame.categories.ndb_struct_ntc_step), stepsSummary: toTable(ConfalPyramids.Schema.ndb_struct_ntc_step_summary, model.sourceData.data.frame.categories.ndb_struct_ntc_step_summary) }; } function hasNdbStructNtcCategories(model) { if (!MmcifFormat.is(model.sourceData)) return false; var names = (model.sourceData).data.frame.categoryNames; return names.includes('ndb_struct_ntc_step') && names.includes('ndb_struct_ntc_step_summary'); } function isApplicable(model) { return !!model && hasNdbStructNtcCategories(model); } ConfalPyramids.isApplicable = isApplicable; })(ConfalPyramids || (ConfalPyramids = {})); export var ConfalPyramidsParams = {}; export var ConfalPyramidsProvider = CustomModelProperty.createProvider({ label: 'Confal Pyramids', descriptor: CustomPropertyDescriptor({ name: 'confal_pyramids', }), type: 'static', defaultParams: ConfalPyramidsParams, getParams: function (data) { return ConfalPyramidsParams; }, isApplicable: function (data) { return ConfalPyramids.isApplicable(data); }, obtain: function (ctx, data, props) { return __awaiter(void 0, void 0, void 0, function () { var p; return __generator(this, function (_a) { p = __assign(__assign({}, PD.getDefaultValues(ConfalPyramidsParams)), props); return [2 /*return*/, ConfalPyramids.fromCif(ctx, data, p)]; }); }); } }); function createPyramidsFromCif(model, cifSteps, stepsSummary) { var _a, _b; var steps = new Array(); var mapping = new Array(); var id = cifSteps.id, PDB_model_number = cifSteps.PDB_model_number, name = cifSteps.name, auth_asym_id_1 = cifSteps.auth_asym_id_1, auth_seq_id_1 = cifSteps.auth_seq_id_1, label_comp_id_1 = cifSteps.label_comp_id_1, label_alt_id_1 = cifSteps.label_alt_id_1, PDB_ins_code_1 = cifSteps.PDB_ins_code_1, auth_asym_id_2 = cifSteps.auth_asym_id_2, auth_seq_id_2 = cifSteps.auth_seq_id_2, label_comp_id_2 = cifSteps.label_comp_id_2, label_alt_id_2 = cifSteps.label_alt_id_2, PDB_ins_code_2 = cifSteps.PDB_ins_code_2, _rowCount = cifSteps._rowCount; if (_rowCount !== stepsSummary._rowCount) throw new Error('Inconsistent mmCIF data'); for (var i = 0; i < _rowCount; i++) { var _c = getSummaryData(id.value(i), i, stepsSummary), NtC = _c.NtC, confal_score = _c.confal_score, rmsd = _c.rmsd; var modelNum = PDB_model_number.value(i); var chainId = auth_asym_id_1.value(i); var seqId = auth_seq_id_1.value(i); var modelIdx = modelNum - 1; if (mapping.length <= modelIdx || !mapping[modelIdx]) mapping[modelIdx] = new Map(); var step = { PDB_model_number: modelNum, name: name.value(i), auth_asym_id_1: chainId, auth_seq_id_1: seqId, label_comp_id_1: label_comp_id_1.value(i), label_alt_id_1: label_alt_id_1.value(i), PDB_ins_code_1: PDB_ins_code_1.value(i), auth_asym_id_2: auth_asym_id_2.value(i), auth_seq_id_2: auth_seq_id_2.value(i), label_comp_id_2: label_comp_id_2.value(i), label_alt_id_2: label_alt_id_2.value(i), PDB_ins_code_2: PDB_ins_code_2.value(i), confal_score: confal_score, NtC: NtC, rmsd: rmsd, }; steps.push(step); var mappedChains = mapping[modelIdx]; var residuesOnChain = (_a = mappedChains.get(chainId)) !== null && _a !== void 0 ? _a : new Map(); var stepsForResidue = (_b = residuesOnChain.get(seqId)) !== null && _b !== void 0 ? _b : []; stepsForResidue.push(steps.length - 1); residuesOnChain.set(seqId, stepsForResidue); mappedChains.set(chainId, residuesOnChain); mapping[modelIdx] = mappedChains; } return { steps: steps, mapping: mapping }; } function getSummaryData(id, i, stepsSummary) { var step_id = stepsSummary.step_id, confal_score = stepsSummary.confal_score, assigned_NtC = stepsSummary.assigned_NtC, cartesian_rmsd_closest_NtC_representative = stepsSummary.cartesian_rmsd_closest_NtC_representative; // Assume that step_ids in ntc_step_summary are in the same order as steps in ntc_step for (var j = i; j < stepsSummary._rowCount; j++) { if (id === step_id.value(j)) return { NtC: assigned_NtC.value(j), confal_score: confal_score.value(j), rmsd: cartesian_rmsd_closest_NtC_representative.value(j) }; } // Safety net for cases where the previous assumption is not met for (var j = 0; j < i; j++) { if (id === step_id.value(j)) return { NtC: assigned_NtC.value(j), confal_score: confal_score.value(j), rmsd: cartesian_rmsd_closest_NtC_representative.value(j) }; } throw new Error('Inconsistent mmCIF data'); }