test.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { resolveJob } from './server/query';
  2. import * as fs from 'fs'
  3. import * as path from 'path'
  4. import { StructureCache } from './server/structure-wrapper';
  5. import { createJob } from './server/jobs';
  6. function wrapFile(fn: string) {
  7. const w = {
  8. open(this: any) {
  9. if (this.opened) return;
  10. this.file = fs.openSync(fn, 'w');
  11. this.opened = true;
  12. },
  13. writeBinary(this: any, data: Uint8Array) {
  14. this.open();
  15. fs.writeSync(this.file, new Buffer(data));
  16. return true;
  17. },
  18. writeString(this: any, data: string) {
  19. this.open();
  20. fs.writeSync(this.file, data);
  21. return true;
  22. },
  23. end(this: any) {
  24. if (!this.opened || this.ended) return;
  25. fs.close(this.file, function () { });
  26. this.ended = true;
  27. },
  28. file: 0,
  29. ended: false,
  30. opened: false
  31. };
  32. return w;
  33. }
  34. export const basePath = path.join(__dirname, '..', '..', '..', '..')
  35. export const examplesPath = path.join(basePath, 'examples')
  36. export const outPath = path.join(basePath, 'build', 'test')
  37. if (!fs.existsSync(outPath)) fs.mkdirSync(outPath);
  38. async function run() {
  39. try {
  40. // const testFile = '1crn.cif'
  41. // const testFile = '1grm_updated.cif'
  42. // const testFile = 'C:/Projects/mol-star/molstar-proto/build/test/in/1grm_updated.cif'
  43. // const request = createJob({
  44. // entryId: testFile,
  45. // queryName: 'full',
  46. // queryParams: { },
  47. // });
  48. const testFile = '1cbs_updated.cif'
  49. const request = createJob({
  50. entryId: path.join(examplesPath, testFile),
  51. queryName: 'full',
  52. queryParams: { }
  53. });
  54. // const request = createJob({
  55. // entryId: path.join(examplesPath, testFile),
  56. // queryName: 'atoms',
  57. // queryParams: {
  58. // atom_site: { label_comp_id: 'ALA' }
  59. // }
  60. // });
  61. // const request = createJob({
  62. // entryId: path.join(examplesPath, testFile),
  63. // queryName: 'residueInteraction',
  64. // queryParams: {
  65. // atom_site: { label_comp_id: 'REA' },
  66. // radius: 5
  67. // }
  68. // });
  69. const encoder = await resolveJob(request);
  70. const writer = wrapFile(path.join(outPath, testFile));
  71. // const writer = wrapFile(path.join(outPath, '1grm_test.cif'));
  72. encoder.writeTo(writer);
  73. writer.end();
  74. } catch (e) {
  75. console.error(e)
  76. } finally {
  77. StructureCache.expireAll();
  78. }
  79. }
  80. run();