UNPKG

molstar

Version:

A comprehensive macromolecular library.

73 lines (72 loc) 3.06 kB
#!/usr/bin/env node "use strict"; /** * Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Josh McMenemy <josh.mcmenemy@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var argparse = tslib_1.__importStar(require("argparse")); var path = tslib_1.__importStar(require("path")); var util_1 = tslib_1.__importDefault(require("util")); var fs_1 = 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-2022 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-ions cli\n */\n\nexport const IonNames = new Set(".concat(JSON.stringify(ionNames).replace(/"/g, "'").replace(/,/g, ', '), ");\n"); writeFile(filePath, output); } function run(out, options) { if (options === void 0) { options = util_2.DefaultDataOptions; } return tslib_1.__awaiter(this, void 0, void 0, function () { var ccd, ionNames; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, util_2.ensureDataAvailable)(options)]; 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.' }); parser.add_argument('--ccdUrl', '-c', { help: 'Fetch the CCD from a custom URL. This forces download of the CCD.', required: false }); var args = parser.parse_args(); run(args.out, { forceDownload: args.forceDownload, ccdUrl: args.ccdUrl });