<commit_before>#!/usr/bin/env node

var fs = require('fs'),
	cluster = require('cluster');
if (cluster.isMaster) {
	// Allocate arrays to hold ligand properties
	var num_ligands = 17224424,
		mwt = new Float32Array(num_ligands),
		lgp = new Float32Array(num_ligands),
		ads = new Float32Array(num_ligands),
		pds = new Float32Array(num_ligands),
		hbd = new Int16Array(num_ligands),
		hba = new Int16Array(num_ligands),
		psa = new Int16Array(num_ligands),
		chg = new Int16Array(num_ligands),
		nrb = new Int16Array(num_ligands);
	// Parse ligand properties
	var prop = 'idock/16_prop.bin.gz';
	console.log('Parsing %s', prop);
	var start = Date.now();
	fs.readFile(prop, function(err, data) {
		if (err) throw err;
		require('zlib').gunzip(data, function(err, buf) {
			if (err) throw err;
			for (i = 0, o = 0; i < num_ligands; ++i, o += 26) {
				mwt[i] = buf.readFloatLE(o +  0);
				lgp[i] = buf.readFloatLE(o +  4);
				ads[i] = buf.readFloatLE(o +  8);
				pds[i] = buf.readFloatLE(o + 12);
				hbd[i] = buf.readInt16LE(o + 16);
				hba[i] = buf.readInt16LE(o + 18);
				psa[i] = buf.readInt16LE(o + 20);
				chg[i] = buf.readInt16LE(o + 22);
				nrb[i] = buf.readInt16LE(o + 24);
			}
			console.log('Parsed %d ligands within %d seconds', num_ligands, Date.now() - start);
			// Fork worker processes with cluster
			var numCPUs = require('os').cpus().length;
			console.log('Forking %d worker processes', numCPUs);
			var msg = function(m) {
				if (m.query == '/idock/ligands') {
					var ligands = 0;
					for (var i = 0; i < num_ligands; ++i) {
						if ((m.mwt_lb <= mwt[i]) && (mwt[i] <= m.mwt_ub) && (m.lgp_lb <= lgp[i]) && (lgp[i] <= m.lgp_ub) && (m.ads_lb <= ads[i]) && (ads[i] <= m.ads_ub) && (m.pds_lb <= pds[i]) && (pds[i] <= m.pds_ub) && (m.hbd_lb <= hbd[i]) && (hbd[i] <= m.hbd_ub) && (m.hba_lb <= hba[i]) && (hba[i] <= m.hba_ub) && (m.psa_lb <= psa[i]) && (psa[i] <= m.psa_ub) && (m.chg_lb <= chg[i]) && (chg[i] <= m.chg_ub) && (m.nrb_lb <= nrb[i]) && (nrb[i] <= m.nrb_ub)) ++ligands;
					}
					this.send({ligands: ligands});
				}
			}
			for (var i = 0; i < numCPUs; i++) {
				cluster.fork().on('message', msg);
			}
			cluster.on('death', function(worker) {
				console.log('Worker process %d died. Restarting...', worker.pid);
				cluster.fork().on('message', msg);
			});
		});
	});
} else {
	// Connect to MongoDB
	var mongodb = require('mongodb');
	new mongodb.MongoClient(new mongodb.Server(process.argv[2], 27017), {db: {native_parser: true}}).open(function(err, mongoClient) {
		if (err) throw err;
		var db = mongoClient.db('istar');
		db.authenticate(process.argv[3], process.argv[4], function(err, authenticated) {
			if (err) throw err;
			var idock = db.collection('idock');
			var igrep = db.collection('igrep');
			// Configure express server
			var express = require('express');
			var app = express();
			app.configure(function() {
				app.use(express.compress());
				app.use(express.bodyParser());
				app.use(app.router);
				app.use(function(req, res, next) {
					if (req.headers['user-agent'] && req.headers['user-agent'].indexOf('MSIE') > -1) {
						res.setHeader('X-UA-Compatible', 'IE=Edge');
					}
					next();
				});
			});
			app.configure('development', function() {
				app.use(express.static(__dirname + '/public'));
				app.use(express.static('/home/hjli/nfs/hjli/istar/public'));
				app.use(express.favicon(__dirname + '/public'));
				app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
			});
			app.configure('production', function() {
				var oneYear = 31557600000; // 1000 * 60 * 60 * 24 * 365.25
				app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
				app.use(express.static('/home/hjli/nfs/hjli/istar/public', { maxAge: oneYear }));
				app.use(express.favicon(__dirname + '/public', { maxAge: oneYear }));
				app.use(express.errorHandler());<commit_msg>Replaced express.bodyParser() by express.json() and express.urlencoded() in web.js<commit_after>#!/usr/bin/env node

var fs = require('fs'),
	cluster = require('cluster');
if (cluster.isMaster) {
	// Allocate arrays to hold ligand properties
	var num_ligands = 17224424,
		mwt = new Float32Array(num_ligands),
		lgp = new Float32Array(num_ligands),
		ads = new Float32Array(num_ligands),
		pds = new Float32Array(num_ligands),
		hbd = new Int16Array(num_ligands),
		hba = new Int16Array(num_ligands),
		psa = new Int16Array(num_ligands),
		chg = new Int16Array(num_ligands),
		nrb = new Int16Array(num_ligands);
	// Parse ligand properties
	var prop = 'idock/16_prop.bin.gz';
	console.log('Parsing %s', prop);
	var start = Date.now();
	fs.readFile(prop, function(err, data) {
		if (err) throw err;
		require('zlib').gunzip(data, function(err, buf) {
			if (err) throw err;
			for (i = 0, o = 0; i < num_ligands; ++i, o += 26) {
				mwt[i] = buf.readFloatLE(o +  0);
				lgp[i] = buf.readFloatLE(o +  4);
				ads[i] = buf.readFloatLE(o +  8);
				pds[i] = buf.readFloatLE(o + 12);
				hbd[i] = buf.readInt16LE(o + 16);
				hba[i] = buf.readInt16LE(o + 18);
				psa[i] = buf.readInt16LE(o + 20);
				chg[i] = buf.readInt16LE(o + 22);
				nrb[i] = buf.readInt16LE(o + 24);
			}
			console.log('Parsed %d ligands within %d seconds', num_ligands, Date.now() - start);
			// Fork worker processes with cluster
			var numCPUs = require('os').cpus().length;
			console.log('Forking %d worker processes', numCPUs);
			var msg = function(m) {
				if (m.query == '/idock/ligands') {
					var ligands = 0;
					for (var i = 0; i < num_ligands; ++i) {
						if ((m.mwt_lb <= mwt[i]) && (mwt[i] <= m.mwt_ub) && (m.lgp_lb <= lgp[i]) && (lgp[i] <= m.lgp_ub) && (m.ads_lb <= ads[i]) && (ads[i] <= m.ads_ub) && (m.pds_lb <= pds[i]) && (pds[i] <= m.pds_ub) && (m.hbd_lb <= hbd[i]) && (hbd[i] <= m.hbd_ub) && (m.hba_lb <= hba[i]) && (hba[i] <= m.hba_ub) && (m.psa_lb <= psa[i]) && (psa[i] <= m.psa_ub) && (m.chg_lb <= chg[i]) && (chg[i] <= m.chg_ub) && (m.nrb_lb <= nrb[i]) && (nrb[i] <= m.nrb_ub)) ++ligands;
					}
					this.send({ligands: ligands});
				}
			}
			for (var i = 0; i < numCPUs; i++) {
				cluster.fork().on('message', msg);
			}
			cluster.on('death', function(worker) {
				console.log('Worker process %d died. Restarting...', worker.pid);
				cluster.fork().on('message', msg);
			});
		});
	});
} else {
	// Connect to MongoDB
	var mongodb = require('mongodb');
	new mongodb.MongoClient(new mongodb.Server(process.argv[2], 27017), {db: {native_parser: true}}).open(function(err, mongoClient) {
		if (err) throw err;
		var db = mongoClient.db('istar');
		db.authenticate(process.argv[3], process.argv[4], function(err, authenticated) {
			if (err) throw err;
			var idock = db.collection('idock');
			var igrep = db.collection('igrep');
			// Configure express server
			var express = require('express');
			var app = express();
			app.configure(function() {
				app.use(express.compress());
				app.use(express.json());
				app.use(express.urlencoded());
				app.use(app.router);
				app.use(function(req, res, next) {
					if (req.headers['user-agent'] && req.headers['user-agent'].indexOf('MSIE') > -1) {
						res.setHeader('X-UA-Compatible', 'IE=Edge');
					}
					next();
				});
			});
			app.configure('development', function() {
				app.use(express.static(__dirname + '/public'));
				app.use(express.static('/home/hjli/nfs/hjli/istar/public'));
				app.use(express.favicon(__dirname + '/public'));
				app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
			});
			app.configure('production', function() {
				var oneYear = 31557600000; // 1000 * 60 * 60 * 24 * 365.25
				app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
				app.use(express.static('/home/hjli/nfs/hjli/istar/public', { maxAge: oneYear }));
				app.use(express.favicon(__dirname + '/public', { maxAge: oneYear }));
				app.use(express.errorHandler());
{'fraction_non_alphanumeric': 0.20288191787809232, 'fraction_numerical': 0.024228513134404488, 'mean_word_length': 3.57851722124927, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3879914', 'n_tokens_mistral': 3574, 'n_tokens_neox': 3041, 'n_words': 603}