UNPKG

molstar

Version:

A comprehensive macromolecular library.

68 lines 2.88 kB
#!/usr/bin/env node "use strict"; /** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Josh McMenemy <josh.mcmenemy@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var argparse = (0, tslib_1.__importStar)(require("argparse")); var path = (0, tslib_1.__importStar)(require("path")); var util_1 = (0, tslib_1.__importDefault)(require("util")); var fs_1 = (0, tslib_1.__importDefault)(require("fs")); require('util.promisify').shim(); var writeFile = util_1.default.promisify(fs_1.default.writeFile); var util_2 = require("./util"); function extractIonNames(ccd) { var ionNames = []; for (var k in ccd) { var chem_comp = ccd[k].chem_comp; if (chem_comp.name.value(0).toUpperCase().includes(' ION')) { ionNames.push(chem_comp.id.value(0)); } } // these are extra ions that don't have ION in their name ionNames.push('NCO', 'OHX'); return ionNames; } function writeIonNamesFile(filePath, ionNames) { var output = "/**\n * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.\n *\n * Code-generated ion names params file. Names extracted from CCD components.\n *\n * @author molstar/chem-comp-dict/create-table cli\n */\n\nexport const IonNames = new Set(" + JSON.stringify(ionNames).replace(/"/g, "'").replace(/,/g, ', ') + ");\n"; writeFile(filePath, output); } function run(out, forceDownload) { if (forceDownload === void 0) { forceDownload = false; } return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var ccd, ionNames; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, util_2.ensureDataAvailable)(forceDownload)]; case 1: _a.sent(); return [4 /*yield*/, (0, util_2.readCCD)()]; case 2: ccd = _a.sent(); ionNames = extractIonNames(ccd); if (!fs_1.default.existsSync(path.dirname(out))) { fs_1.default.mkdirSync(path.dirname(out)); } writeIonNamesFile(out, ionNames); return [2 /*return*/]; } }); }); } var parser = new argparse.ArgumentParser({ add_help: true, description: 'Extract and save IonNames from CCD.' }); parser.add_argument('out', { help: 'Generated file output path.' }); parser.add_argument('--forceDownload', '-f', { action: 'store_true', help: 'Force download of CCD and PVCD.' }); var args = parser.parse_args(); run(args.out, args.forceDownload); //# sourceMappingURL=create-ions.js.map