pack.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * Taken/adapted from DensityServer (https://github.com/dsehnal/DensityServer)
  5. *
  6. * @author David Sehnal <david.sehnal@gmail.com>
  7. */
  8. import pack from './pack/main'
  9. import VERSION from './pack/version'
  10. let config = {
  11. input: <{ name: string, filename: string }[]>[],
  12. isPeriodic: false,
  13. outputFilename: '',
  14. blockSize: 96
  15. };
  16. function printHelp() {
  17. let help = [
  18. `VolumeServer Packer ${VERSION}, (c) 2016 - now, David Sehnal`,
  19. ``,
  20. `The input data must be CCP4/MAP mode 2 (32-bit floats) files.`,
  21. ``,
  22. `Usage: `,
  23. ``,
  24. ` node pack -v`,
  25. ` Print version.`,
  26. ``,
  27. ` node pack -xray main.ccp4 diff.ccp4 output.mdb [-blockSize 96]`,
  28. ` Pack main and diff density into a single block file.`,
  29. ` Optionally specify maximum block size.`,
  30. ``,
  31. ` node pack -em density.map output.mdb [-blockSize 96]`,
  32. ` Pack single density into a block file.`,
  33. ` Optionally specify maximum block size.`
  34. ];
  35. console.log(help.join('\n'));
  36. }
  37. function parseInput() {
  38. let input = false;
  39. if (process.argv.length <= 2) {
  40. printHelp();
  41. process.exit();
  42. return false;
  43. }
  44. for (let i = 2; i < process.argv.length; i++) {
  45. switch (process.argv[i].toLowerCase()) {
  46. case '-blocksize':
  47. config.blockSize = +process.argv[++i];
  48. break;
  49. case '-xray':
  50. input = true;
  51. config.input = [
  52. { name: '2Fo-Fc', filename: process.argv[++i] },
  53. { name: 'Fo-Fc', filename: process.argv[++i] }
  54. ];
  55. config.isPeriodic = true;
  56. config.outputFilename = process.argv[++i];
  57. break;
  58. case '-em':
  59. input = true;
  60. config.input = [
  61. { name: 'em', filename: process.argv[++i] }
  62. ];
  63. config.outputFilename = process.argv[++i];
  64. break;
  65. case '-v':
  66. console.log(VERSION);
  67. process.exit();
  68. return false;
  69. default:
  70. printHelp();
  71. process.exit();
  72. return false;
  73. }
  74. }
  75. return input;
  76. }
  77. if (parseInput()) {
  78. pack(config.input, config.blockSize, config.isPeriodic, config.outputFilename);
  79. }