molstar
Version:
A comprehensive macromolecular library.
102 lines • 4.58 kB
JavaScript
/**
* Copyright (c) 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 argparse from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import fetch from 'node-fetch';
import { UniqueArray } from '../../mol-data/generic';
var LIPIDS_DIR = path.resolve(__dirname, '../../../../build/lipids/');
var MARTINI_LIPIDS_PATH = path.resolve(LIPIDS_DIR, 'martini_lipids.itp');
var MARTINI_LIPIDS_URL = 'http://www.cgmartini.nl/images/parameters/lipids/Collections/martini_v2.0_lipids_all_201506.itp';
function ensureAvailable(path, url) {
return __awaiter(this, void 0, void 0, function () {
var name_1, data, _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!(FORCE_DOWNLOAD || !fs.existsSync(path))) return [3 /*break*/, 3];
name_1 = url.substr(url.lastIndexOf('/') + 1);
console.log("downloading " + name_1 + "...");
return [4 /*yield*/, fetch(url)];
case 1:
data = _d.sent();
if (!fs.existsSync(LIPIDS_DIR)) {
fs.mkdirSync(LIPIDS_DIR);
}
_b = (_a = fs).writeFileSync;
_c = [path];
return [4 /*yield*/, data.text()];
case 2:
_b.apply(_a, _c.concat([_d.sent()]));
console.log("done downloading " + name_1);
_d.label = 3;
case 3: return [2 /*return*/];
}
});
});
}
function ensureLipidsAvailable() {
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ensureAvailable(MARTINI_LIPIDS_PATH, MARTINI_LIPIDS_URL)];
case 1:
_a.sent();
return [2 /*return*/];
}
}); });
}
var extraLipids = ['DMPC'];
function run(out) {
return __awaiter(this, void 0, void 0, function () {
var lipidsItpStr, lipids, reLipid, m, v, _i, extraLipids_1, v, lipidNames, output;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ensureLipidsAvailable()];
case 1:
_a.sent();
lipidsItpStr = fs.readFileSync(MARTINI_LIPIDS_PATH, 'utf8');
lipids = UniqueArray.create();
reLipid = /\[moleculetype\]\n; molname nrexcl\n +([a-zA-Z]{3,5})/g;
while ((m = reLipid.exec(lipidsItpStr)) !== null) {
v = m[0].substr(m[0].lastIndexOf(' ') + 1);
UniqueArray.add(lipids, v, v);
}
for (_i = 0, extraLipids_1 = extraLipids; _i < extraLipids_1.length; _i++) {
v = extraLipids_1[_i];
UniqueArray.add(lipids, v, v);
}
lipidNames = JSON.stringify(lipids.array);
if (out) {
output = "/**\n * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.\n *\n * Code-generated lipid params file. Names extracted from Martini FF lipids itp.\n *\n * @author molstar/lipid-params cli\n */\n\nexport const LipidNames = new Set(" + lipidNames.replace(/"/g, "'").replace(/,/g, ', ') + ");\n";
fs.writeFileSync(out, output);
}
else {
console.log(lipidNames);
}
return [2 /*return*/];
}
});
});
}
var parser = new argparse.ArgumentParser({
add_help: true,
description: 'Create lipid params (from martini lipids itp)'
});
parser.add_argument('--out', '-o', {
help: 'Generated lipid params output path, if not given printed to stdout'
});
parser.add_argument('--forceDownload', '-f', {
action: 'store_true',
help: 'Force download of martini lipids itp'
});
var args = parser.parse_args();
var FORCE_DOWNLOAD = args.forceDownload;
run(args.out || '').catch(function (e) {
console.error(e);
});
//# sourceMappingURL=index.js.map