atomic-derived.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { AtomicData } from '../atomic';
  7. import { ChemicalComponentMap } from '../chemical-component';
  8. import { AtomicIndex, AtomicDerivedData } from '../atomic/hierarchy';
  9. import { ElementIndex, ResidueIndex } from '../../indexing';
  10. import { MoleculeType, getMoleculeType, getComponentType } from '../../types';
  11. import { getAtomIdForAtomRole } from 'mol-model/structure/util';
  12. export function getAtomicDerivedData(data: AtomicData, index: AtomicIndex, chemicalComponentMap: ChemicalComponentMap): AtomicDerivedData {
  13. const { label_comp_id, _rowCount: n } = data.residues
  14. const traceElementIndex = new Uint32Array(n)
  15. const directionElementIndex = new Uint32Array(n)
  16. const moleculeType = new Uint8Array(n)
  17. const moleculeTypeMap = new Map<string, MoleculeType>()
  18. for (let i = 0; i < n; ++i) {
  19. const compId = label_comp_id.value(i)
  20. const chemCompMap = chemicalComponentMap
  21. const cc = chemCompMap.get(compId)
  22. let molType: MoleculeType
  23. if (cc) {
  24. molType = cc.moleculeType
  25. } else if (moleculeTypeMap.has(compId)){
  26. molType = moleculeTypeMap.get(compId)!
  27. } else {
  28. molType = getMoleculeType(getComponentType(compId), compId)
  29. // TODO if unknown molecule type, use atom names to guess molecule type
  30. moleculeTypeMap.set(compId, molType)
  31. }
  32. moleculeType[i] = molType
  33. const traceAtomId = getAtomIdForAtomRole(molType, 'trace')
  34. traceElementIndex[i] = index.findAtomOnResidue(i as ResidueIndex, traceAtomId)
  35. const directionAtomId = getAtomIdForAtomRole(molType, 'direction')
  36. directionElementIndex[i] = index.findAtomOnResidue(i as ResidueIndex, directionAtomId)
  37. }
  38. return {
  39. residue: {
  40. traceElementIndex: traceElementIndex as unknown as ArrayLike<ElementIndex>,
  41. directionElementIndex: directionElementIndex as unknown as ArrayLike<ElementIndex>,
  42. moleculeType: moleculeType as unknown as ArrayLike<MoleculeType>,
  43. }
  44. }
  45. }