molstar
Version:
A comprehensive macromolecular library.
71 lines (70 loc) • 2.86 kB
JavaScript
/**
* 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>
*/
import { __awaiter, __generator } from "tslib";
import * as argparse from 'argparse';
import * as path from 'path';
import util from 'util';
import fs from 'fs';
require('util.promisify').shim();
var writeFile = util.promisify(fs.writeFile);
import { DefaultDataOptions, ensureDataAvailable, readCCD } from './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 = DefaultDataOptions; }
return __awaiter(this, void 0, void 0, function () {
var ccd, ionNames;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ensureDataAvailable(options)];
case 1:
_a.sent();
return [4 /*yield*/, readCCD()];
case 2:
ccd = _a.sent();
ionNames = extractIonNames(ccd);
if (!fs.existsSync(path.dirname(out))) {
fs.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 });