3dg.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Model } from '../../mol-model/structure/model';
  7. import { Task } from '../../mol-task';
  8. import { ModelFormat } from './format';
  9. import { Column, Table } from '../../mol-data/db';
  10. import { EntityBuilder } from './common/entity';
  11. import { File3DG } from '../../mol-io/reader/3dg/parser';
  12. import { fillSerial } from '../../mol-util/array';
  13. import { MoleculeType } from '../../mol-model/structure/model/types';
  14. import { BasicSchema, createBasic } from './basic/schema';
  15. import { createModels } from './basic/parser';
  16. function getBasic(table: File3DG['table']) {
  17. const entityIds = new Array<string>(table._rowCount)
  18. const entityBuilder = new EntityBuilder()
  19. const seqIdStarts = table.position.toArray({ array: Uint32Array })
  20. const seqIdEnds = new Uint32Array(table._rowCount)
  21. const stride = seqIdStarts[1] - seqIdStarts[0]
  22. const objectRadius = stride / 3500
  23. for (let i = 0, il = table._rowCount; i < il; ++i) {
  24. const chr = table.chromosome.value(i)
  25. const entityId = entityBuilder.getEntityId(chr, MoleculeType.DNA, chr)
  26. entityIds[i] = entityId
  27. seqIdEnds[i] = seqIdStarts[i] + stride - 1
  28. }
  29. const ihm_sphere_obj_site = Table.ofPartialColumns(BasicSchema.ihm_sphere_obj_site, {
  30. id: Column.ofIntArray(fillSerial(new Uint32Array(table._rowCount))),
  31. entity_id: Column.ofStringArray(entityIds),
  32. seq_id_begin: Column.ofIntArray(seqIdStarts),
  33. seq_id_end: Column.ofIntArray(seqIdEnds),
  34. asym_id: table.chromosome,
  35. Cartn_x: Column.ofFloatArray(Column.mapToArray(table.x, x => x * 10, Float32Array)),
  36. Cartn_y: Column.ofFloatArray(Column.mapToArray(table.y, y => y * 10, Float32Array)),
  37. Cartn_z: Column.ofFloatArray(Column.mapToArray(table.z, z => z * 10, Float32Array)),
  38. object_radius: Column.ofConst(objectRadius, table._rowCount, Column.Schema.float),
  39. rmsf: Column.ofConst(0, table._rowCount, Column.Schema.float),
  40. model_id: Column.ofConst(1, table._rowCount, Column.Schema.int),
  41. }, table._rowCount)
  42. return createBasic({
  43. entity: entityBuilder.getEntityTable(),
  44. ihm_model_list: Table.ofPartialColumns(BasicSchema.ihm_model_list, {
  45. model_id: Column.ofIntArray([1]),
  46. model_name: Column.ofStringArray(['3DG Model']),
  47. }, 1),
  48. ihm_sphere_obj_site
  49. })
  50. }
  51. //
  52. export { Format3dg }
  53. type Format3dg = ModelFormat<File3DG>
  54. namespace Format3dg {
  55. export function is(x: ModelFormat): x is Format3dg {
  56. return x.kind === '3dg'
  57. }
  58. export function from3dg(file3dg: File3DG): Format3dg {
  59. return { kind: '3dg', name: '3DG', data: file3dg };
  60. }
  61. }
  62. export function trajectoryFrom3DG(file3dg: File3DG): Task<Model.Trajectory> {
  63. return Task.create('Parse 3DG', async ctx => {
  64. const format = Format3dg.from3dg(file3dg);
  65. const basic = getBasic(file3dg.table)
  66. return createModels(basic, format, ctx);
  67. })
  68. }