helpers.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Structure } from '../../../mol-model/structure';
  7. import { ComputedSecondaryStructure } from '../../../mol-model-props/computed/secondary-structure';
  8. import { PluginStateObject } from '../objects';
  9. import { DistanceData } from '../../../mol-repr/shape/loci/distance';
  10. import { LabelData } from '../../../mol-repr/shape/loci/label';
  11. import { OrientationData } from '../../../mol-repr/shape/loci/orientation';
  12. import { AngleData } from '../../../mol-repr/shape/loci/angle';
  13. import { DihedralData } from '../../../mol-repr/shape/loci/dihedral';
  14. /**
  15. * Attaches ComputedSecondaryStructure property when unavailable in sourceData and
  16. * when not an archival file (i.e. no database_2.database_id field)
  17. */
  18. export async function ensureSecondaryStructure(s: Structure) {
  19. if (s.models.length === 1 && s.model && s.model.sourceData.kind === 'mmCIF') {
  20. if (!s.model.sourceData.data.struct_conf.id.isDefined && !s.model.sourceData.data.struct_sheet_range.id.isDefined &&
  21. !s.model.sourceData.data.database_2.database_id.isDefined
  22. ) {
  23. await ComputedSecondaryStructure.attachFromCifOrCompute(s)
  24. }
  25. }
  26. }
  27. export function getDistanceDataFromStructureSelections(s: ReadonlyArray<PluginStateObject.Molecule.Structure.SelectionEntry>): DistanceData {
  28. const lociA = s[0].loci
  29. const lociB = s[1].loci
  30. return { pairs: [{ lociA, lociB }] }
  31. }
  32. export function getAngleDataFromStructureSelections(s: ReadonlyArray<PluginStateObject.Molecule.Structure.SelectionEntry>): AngleData {
  33. const lociA = s[0].loci
  34. const lociB = s[1].loci
  35. const lociC = s[2].loci
  36. return { triples: [{ lociA, lociB, lociC }] }
  37. }
  38. export function getDihedralDataFromStructureSelections(s: ReadonlyArray<PluginStateObject.Molecule.Structure.SelectionEntry>): DihedralData {
  39. const lociA = s[0].loci
  40. const lociB = s[1].loci
  41. const lociC = s[2].loci
  42. const lociD = s[3].loci
  43. return { quads: [{ lociA, lociB, lociC, lociD }] }
  44. }
  45. export function getLabelDataFromStructureSelections(s: ReadonlyArray<PluginStateObject.Molecule.Structure.SelectionEntry>): LabelData {
  46. const loci = s[0].loci
  47. return { infos: [{ loci }] }
  48. }
  49. export function getOrientationDataFromStructureSelections(s: ReadonlyArray<PluginStateObject.Molecule.Structure.SelectionEntry>): OrientationData {
  50. const loci = s[0].loci
  51. return { loci }
  52. }