molstar
Version:
A comprehensive macromolecular library.
127 lines (126 loc) • 5.4 kB
JavaScript
/**
* Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { __awaiter, __generator } from "tslib";
import * as fs from 'fs';
import * as util from 'util';
import { CIF } from '../../../../mol-io/reader/cif';
import { getParam } from '../../../common/util';
import { mmCIF_Schema } from '../../../../mol-io/reader/cif/schema/mmcif';
import { ComponentBond } from '../../../../mol-model-formats/structure/property/bonds/chem_comp';
import { ComponentAtom } from '../../../../mol-model-formats/structure/property/atoms/chem_comp';
import { CCD_Schema } from '../../../../mol-io/reader/cif/schema/ccd';
require('util.promisify').shim();
var readFile = util.promisify(fs.readFile);
export var wwPDB_chemCompBond = function (_a) {
var model = _a.model, params = _a.params;
return __awaiter(void 0, void 0, void 0, function () {
var table, data, entries;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, getChemCompBondTable(getBondTablePath(params))];
case 1:
table = _b.sent();
data = ComponentBond.chemCompBondFromTable(model, table);
entries = ComponentBond.getEntriesFromChemCompBond(data);
return [2 /*return*/, ComponentBond.Provider.set(model, { entries: entries, data: data })];
}
});
});
};
function read(path) {
return __awaiter(this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!path.endsWith('.bcif')) return [3 /*break*/, 2];
_b = Uint8Array.bind;
return [4 /*yield*/, readFile(path)];
case 1:
_a = new (_b.apply(Uint8Array, [void 0, _c.sent()]))();
return [3 /*break*/, 3];
case 2:
_a = readFile(path, 'utf8');
_c.label = 3;
case 3: return [2 /*return*/, _a];
}
});
});
}
var chemCompBondTable;
function getChemCompBondTable(path) {
return __awaiter(this, void 0, void 0, function () {
var parsed, _a, _b, table;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!!chemCompBondTable) return [3 /*break*/, 3];
_b = (_a = CIF).parse;
return [4 /*yield*/, read(path)];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()]).run()];
case 2:
parsed = _c.sent();
if (parsed.isError)
throw new Error(parsed.toString());
table = CIF.toDatabase(mmCIF_Schema, parsed.result.blocks[0]);
chemCompBondTable = table.chem_comp_bond;
_c.label = 3;
case 3: return [2 /*return*/, chemCompBondTable];
}
});
});
}
function getBondTablePath(params) {
var path = getParam(params, 'wwPDB', 'chemCompBondTablePath');
if (!path)
throw new Error("wwPDB 'chemCompBondTablePath' not set!");
return path;
}
export var wwPDB_chemCompAtom = function (_a) {
var model = _a.model, params = _a.params;
return __awaiter(void 0, void 0, void 0, function () {
var table, data, entries;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, getChemCompAtomTable(getAtomTablePath(params))];
case 1:
table = _b.sent();
data = ComponentAtom.chemCompAtomFromTable(model, table);
entries = ComponentAtom.getEntriesFromChemCompAtom(data);
return [2 /*return*/, ComponentAtom.Provider.set(model, { entries: entries, data: data })];
}
});
});
};
var chemCompAtomTable;
function getChemCompAtomTable(path) {
return __awaiter(this, void 0, void 0, function () {
var parsed, _a, _b, table;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!!chemCompAtomTable) return [3 /*break*/, 3];
_b = (_a = CIF).parse;
return [4 /*yield*/, read(path)];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()]).run()];
case 2:
parsed = _c.sent();
if (parsed.isError)
throw new Error(parsed.toString());
table = CIF.toDatabase(CCD_Schema, parsed.result.blocks[0]);
chemCompAtomTable = table.chem_comp_atom;
_c.label = 3;
case 3: return [2 /*return*/, chemCompAtomTable];
}
});
});
}
function getAtomTablePath(params) {
var path = getParam(params, 'wwPDB', 'chemCompAtomTablePath');
if (!path)
throw new Error("wwPDB 'chemCompAtomTablePath' not set!");
return path;
}