molstar
Version:
A comprehensive macromolecular library.
243 lines • 11.4 kB
JavaScript
/**
* Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMtrix = exports.parseRemark350 = exports.parseCryst1 = void 0;
var cif_1 = require("../../../mol-io/reader/cif");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
function parseCryst1(id, record) {
// COLUMNS DATA TYPE CONTENTS
// --------------------------------------------------------------------------------
// 1 - 6 Record name "CRYST1"
// 7 - 15 Real(9.3) a (Angstroms)
// 16 - 24 Real(9.3) b (Angstroms)
// 25 - 33 Real(9.3) c (Angstroms)
// 34 - 40 Real(7.2) alpha (degrees)
// 41 - 47 Real(7.2) beta (degrees)
// 48 - 54 Real(7.2) gamma (degrees)
// 56 - 66 LString Space group
// 67 - 70 Integer Z value
var get = function (s, l) { return (record.substr(s, l) || '').trim(); };
var cell = {
entry_id: cif_1.CifField.ofString(id),
length_a: cif_1.CifField.ofString(get(6, 9)),
length_b: cif_1.CifField.ofString(get(15, 9)),
length_c: cif_1.CifField.ofString(get(24, 9)),
angle_alpha: cif_1.CifField.ofString(get(33, 7)),
angle_beta: cif_1.CifField.ofString(get(40, 7)),
angle_gamma: cif_1.CifField.ofString(get(47, 7)),
Z_PDB: cif_1.CifField.ofString(get(66, 4)),
pdbx_unique_axis: cif_1.CifField.ofString('?')
};
var symmetry = {
entry_id: cif_1.CifField.ofString(id),
'space_group_name_H-M': cif_1.CifField.ofString(get(55, 11)),
Int_Tables_number: cif_1.CifField.ofString('?'),
cell_setting: cif_1.CifField.ofString('?'),
space_group_name_Hall: cif_1.CifField.ofString('?')
};
return [cif_1.CifCategory.ofFields('cell', cell), cif_1.CifCategory.ofFields('symmetry', symmetry)];
}
exports.parseCryst1 = parseCryst1;
function PdbAssembly(id, details) {
return { id: id, details: details, groups: [] };
}
function parseRemark350(lines, lineStart, lineEnd) {
var assemblies = [];
// Read the assemblies
var current, group, matrix, operId = 1, asmId = 1;
var getLine = function (n) { return lines.data.substring(lines.indices[2 * n], lines.indices[2 * n + 1]); };
for (var i = lineStart; i < lineEnd; i++) {
var line = getLine(i);
if (line.substr(11, 12) === 'BIOMOLECULE:') {
var id = line.substr(23).trim();
var details = "Biomolecule " + id;
line = getLine(i + 1);
if (line.substr(11, 30) !== 'APPLY THE FOLLOWING TO CHAINS:') {
i++;
details = line.substr(11).trim();
}
current = PdbAssembly(id, details);
assemblies.push(current);
}
else if (line.substr(13, 5) === 'BIOMT') {
var biomt = line.split(/\s+/);
var row = parseInt(line[18]) - 1;
if (row === 0) {
matrix = linear_algebra_1.Mat4.identity();
group.operators.push({ id: operId++, matrix: matrix });
}
linear_algebra_1.Mat4.setValue(matrix, row, 0, parseFloat(biomt[4]));
linear_algebra_1.Mat4.setValue(matrix, row, 1, parseFloat(biomt[5]));
linear_algebra_1.Mat4.setValue(matrix, row, 2, parseFloat(biomt[6]));
linear_algebra_1.Mat4.setValue(matrix, row, 3, parseFloat(biomt[7]));
}
else if (line.substr(11, 30) === 'APPLY THE FOLLOWING TO CHAINS:' ||
line.substr(11, 30) === ' AND CHAINS:') {
if (line.substr(11, 5) === 'APPLY') {
group = { chains: [], operators: [] };
current.groups.push(group);
}
var chainList = line.substr(41, 30).split(',');
for (var j = 0, jl = chainList.length; j < jl; ++j) {
var c = chainList[j].trim();
if (c)
group.chains.push(c);
}
}
else if (line.substr(11, 33) === 'APPLYING THE FOLLOWING TO CHAINS:') {
// variant in older PDB format version
current = PdbAssembly("" + asmId, "Biomolecule " + asmId);
assemblies.push(current);
asmId += 1;
group = { chains: [], operators: [] };
current.groups.push(group);
i++;
line = getLine(i);
var chainList = line.substr(11, 69).split(',');
for (var j = 0, jl = chainList.length; j < jl; ++j) {
var c = chainList[j].trim();
if (c)
group.chains.push(c);
}
}
}
if (assemblies.length === 0)
return [];
// Generate CIF
// pdbx_struct_assembly
var pdbx_struct_assembly = {
id: cif_1.CifField.ofStrings(assemblies.map(function (a) { return a.id; })),
details: cif_1.CifField.ofStrings(assemblies.map(function (a) { return a.details; }))
};
// pdbx_struct_assembly_gen
var pdbx_struct_assembly_gen_rows = [];
for (var _i = 0, assemblies_1 = assemblies; _i < assemblies_1.length; _i++) {
var asm = assemblies_1[_i];
for (var _a = 0, _b = asm.groups; _a < _b.length; _a++) {
var group_1 = _b[_a];
pdbx_struct_assembly_gen_rows.push({
assembly_id: asm.id,
oper_expression: group_1.operators.map(function (o) { return o.id; }).join(','),
asym_id_list: group_1.chains.join(',')
});
}
}
var pdbx_struct_assembly_gen = {
assembly_id: cif_1.CifField.ofStrings(pdbx_struct_assembly_gen_rows.map(function (r) { return r.assembly_id; })),
oper_expression: cif_1.CifField.ofStrings(pdbx_struct_assembly_gen_rows.map(function (r) { return r.oper_expression; })),
asym_id_list: cif_1.CifField.ofStrings(pdbx_struct_assembly_gen_rows.map(function (r) { return r.asym_id_list; }))
};
// pdbx_struct_oper_list
var pdbx_struct_oper_list_rows = [];
for (var _c = 0, assemblies_2 = assemblies; _c < assemblies_2.length; _c++) {
var asm = assemblies_2[_c];
for (var _d = 0, _e = asm.groups; _d < _e.length; _d++) {
var group_2 = _e[_d];
for (var _f = 0, _g = group_2.operators; _f < _g.length; _f++) {
var oper = _g[_f];
var row = {
id: '' + oper.id,
type: '?',
name: '?',
symmetry_operation: '?'
};
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
row["matrix[" + (i + 1) + "][" + (j + 1) + "]"] = '' + linear_algebra_1.Mat4.getValue(oper.matrix, i, j);
}
row["vector[" + (i + 1) + "]"] = '' + linear_algebra_1.Mat4.getValue(oper.matrix, i, 3);
}
pdbx_struct_oper_list_rows.push(row);
}
}
}
var pdbx_struct_oper_list = {
id: cif_1.CifField.ofStrings(pdbx_struct_oper_list_rows.map(function (r) { return r.id; })),
type: cif_1.CifField.ofStrings(pdbx_struct_oper_list_rows.map(function (r) { return r.type; })),
name: cif_1.CifField.ofStrings(pdbx_struct_oper_list_rows.map(function (r) { return r.name; })),
symmetry_operation: cif_1.CifField.ofStrings(pdbx_struct_oper_list_rows.map(function (r) { return r.symmetry_operation; }))
};
var _loop_1 = function (i) {
var _loop_2 = function (j) {
var k_1 = "matrix[" + (i + 1) + "][" + (j + 1) + "]";
pdbx_struct_oper_list[k_1] = cif_1.CifField.ofStrings(pdbx_struct_oper_list_rows.map(function (r) { return r[k_1]; }));
};
for (var j = 0; j < 3; j++) {
_loop_2(j);
}
var k = "vector[" + (i + 1) + "]";
pdbx_struct_oper_list[k] = cif_1.CifField.ofStrings(pdbx_struct_oper_list_rows.map(function (r) { return r[k]; }));
};
for (var i = 0; i < 3; i++) {
_loop_1(i);
}
return [
cif_1.CifCategory.ofFields('pdbx_struct_assembly', pdbx_struct_assembly),
cif_1.CifCategory.ofFields('pdbx_struct_assembly_gen', pdbx_struct_assembly_gen),
cif_1.CifCategory.ofFields('pdbx_struct_oper_list', pdbx_struct_oper_list)
];
}
exports.parseRemark350 = parseRemark350;
function parseMtrix(lines, lineStart, lineEnd) {
var matrices = [];
var matrix;
var getLine = function (n) { return lines.data.substring(lines.indices[2 * n], lines.indices[2 * n + 1]); };
for (var i = lineStart; i < lineEnd; i++) {
var line = getLine(i);
var ncs = line.split(/\s+/);
var row = parseInt(line[5]) - 1;
if (row === 0) {
matrix = linear_algebra_1.Mat4.identity();
matrices.push(matrix);
}
linear_algebra_1.Mat4.setValue(matrix, row, 0, parseFloat(ncs[2]));
linear_algebra_1.Mat4.setValue(matrix, row, 1, parseFloat(ncs[3]));
linear_algebra_1.Mat4.setValue(matrix, row, 2, parseFloat(ncs[4]));
linear_algebra_1.Mat4.setValue(matrix, row, 3, parseFloat(ncs[5]));
}
if (matrices.length === 0)
return [];
var struct_ncs_oper_rows = [];
var id = 1;
for (var _i = 0, matrices_1 = matrices; _i < matrices_1.length; _i++) {
var oper = matrices_1[_i];
var row = {
id: 'ncsop' + (id++),
code: '.',
details: '.'
};
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
row["matrix[" + (i + 1) + "][" + (j + 1) + "]"] = '' + linear_algebra_1.Mat4.getValue(oper, i, j);
}
row["vector[" + (i + 1) + "]"] = '' + linear_algebra_1.Mat4.getValue(oper, i, 3);
}
struct_ncs_oper_rows.push(row);
}
var struct_ncs_oper = {
id: cif_1.CifField.ofStrings(struct_ncs_oper_rows.map(function (r) { return r.id; })),
code: cif_1.CifField.ofStrings(struct_ncs_oper_rows.map(function (r) { return r.code; })),
details: cif_1.CifField.ofStrings(struct_ncs_oper_rows.map(function (r) { return r.details; })),
};
var _loop_3 = function (i) {
var _loop_4 = function (j) {
var k_2 = "matrix[" + (i + 1) + "][" + (j + 1) + "]";
struct_ncs_oper[k_2] = cif_1.CifField.ofStrings(struct_ncs_oper_rows.map(function (r) { return r[k_2]; }));
};
for (var j = 0; j < 3; j++) {
_loop_4(j);
}
var k = "vector[" + (i + 1) + "]";
struct_ncs_oper[k] = cif_1.CifField.ofStrings(struct_ncs_oper_rows.map(function (r) { return r[k]; }));
};
for (var i = 0; i < 3; i++) {
_loop_3(i);
}
return [cif_1.CifCategory.ofFields('struct_ncs_oper', struct_ncs_oper)];
}
exports.parseMtrix = parseMtrix;
//# sourceMappingURL=assembly.js.map
;