jbrowse-plugin-protein3d 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/LaunchProteinViewExtensionPoint/normalizeLaunch.js +7 -0
  2. package/dist/ProteinView/loadStructureData.js +2 -1
  3. package/dist/ProteinView/markProblems.js +4 -2
  4. package/dist/ProteinView/model.js +3 -1
  5. package/dist/ProteinView/residueFilter.js +184 -0
  6. package/dist/ProteinView/sessionHighlights.js +11 -13
  7. package/dist/ProteinView/structureModel.js +8 -0
  8. package/dist/ProteinView/structurePipeline.js +25 -16
  9. package/dist/chunks/{LaunchProteinViewDialog-GDEANZ6O.js → LaunchProteinViewDialog-PC5HYIE3.js} +2 -2
  10. package/dist/chunks/{ProteinView-QALYTNTX.js → ProteinView-56FHBQSV.js} +2 -2
  11. package/dist/chunks/chunk-6B7WZJO7.js +2 -0
  12. package/dist/chunks/chunk-6B7WZJO7.js.map +7 -0
  13. package/dist/chunks/chunk-6OAZLCO5.js +2 -0
  14. package/dist/chunks/chunk-6OAZLCO5.js.map +7 -0
  15. package/dist/chunks/chunk-DFLRALX5.js +2 -0
  16. package/dist/chunks/chunk-DFLRALX5.js.map +7 -0
  17. package/dist/chunks/{chunk-VT5BCVCX.js → chunk-FRK6X72I.js} +2 -2
  18. package/dist/chunks/chunk-NUJCOEJ3.js +2 -0
  19. package/dist/chunks/chunk-NUJCOEJ3.js.map +7 -0
  20. package/dist/chunks/{chunk-KZ76WUQW.js → chunk-WHJFF2WE.js} +2 -2
  21. package/dist/chunks/chunk-WHJFF2WE.js.map +7 -0
  22. package/dist/chunks/{launchAnnotationView-UFCA3T3G.js → launchAnnotationView-XEUIILD5.js} +2 -2
  23. package/dist/chunks/{launchProteinView-S7VBHQK7.js → launchProteinView-XUNPJWEY.js} +2 -2
  24. package/dist/chunks/{launchViewUtils-7XTBTFAV.js → launchViewUtils-JLW2J4TI.js} +2 -2
  25. package/dist/chunks/model-QDSVZCTN.js +2 -0
  26. package/dist/chunks/model-QDSVZCTN.js.map +7 -0
  27. package/dist/jbrowse-plugin-protein3d.esm.js +1 -1
  28. package/dist/jbrowse-plugin-protein3d.esm.js.map +1 -1
  29. package/dist/test_data/molstarPlugin.js +2 -0
  30. package/dist/test_data/molstarStructure.js +23 -1
  31. package/dist/version.js +1 -1
  32. package/package.json +1 -1
  33. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.test.ts +14 -0
  34. package/src/LaunchProteinViewExtensionPoint/normalizeLaunch.ts +13 -0
  35. package/src/ProteinView/loadStructureData.ts +4 -3
  36. package/src/ProteinView/markProblems.test.ts +8 -0
  37. package/src/ProteinView/markProblems.ts +12 -4
  38. package/src/ProteinView/model.test.ts +22 -0
  39. package/src/ProteinView/model.ts +6 -1
  40. package/src/ProteinView/proteinViewSpec.ts +6 -0
  41. package/src/ProteinView/residueFilter.test.ts +97 -0
  42. package/src/ProteinView/residueFilter.ts +250 -0
  43. package/src/ProteinView/sessionHighlights.test.ts +41 -0
  44. package/src/ProteinView/sessionHighlights.ts +16 -13
  45. package/src/ProteinView/structureModel.ts +9 -0
  46. package/src/ProteinView/structurePipeline.test.ts +100 -1
  47. package/src/ProteinView/structurePipeline.ts +36 -18
  48. package/src/test_data/molstarPlugin.ts +11 -1
  49. package/src/test_data/molstarStructure.ts +28 -1
  50. package/src/version.ts +1 -1
  51. package/dist/chunks/chunk-AYS6MD64.js +0 -2
  52. package/dist/chunks/chunk-AYS6MD64.js.map +0 -7
  53. package/dist/chunks/chunk-IW33ITI5.js +0 -2
  54. package/dist/chunks/chunk-IW33ITI5.js.map +0 -7
  55. package/dist/chunks/chunk-KZ76WUQW.js.map +0 -7
  56. package/dist/chunks/chunk-SR54J2GA.js +0 -2
  57. package/dist/chunks/chunk-SR54J2GA.js.map +0 -7
  58. package/dist/chunks/chunk-UEHBHBLB.js +0 -2
  59. package/dist/chunks/chunk-UEHBHBLB.js.map +0 -7
  60. package/dist/chunks/model-P2NVES57.js +0 -2
  61. package/dist/chunks/model-P2NVES57.js.map +0 -7
  62. /package/dist/chunks/{LaunchProteinViewDialog-GDEANZ6O.js.map → LaunchProteinViewDialog-PC5HYIE3.js.map} +0 -0
  63. /package/dist/chunks/{ProteinView-QALYTNTX.js.map → ProteinView-56FHBQSV.js.map} +0 -0
  64. /package/dist/chunks/{chunk-VT5BCVCX.js.map → chunk-FRK6X72I.js.map} +0 -0
  65. /package/dist/chunks/{launchAnnotationView-UFCA3T3G.js.map → launchAnnotationView-XEUIILD5.js.map} +0 -0
  66. /package/dist/chunks/{launchProteinView-S7VBHQK7.js.map → launchProteinView-XUNPJWEY.js.map} +0 -0
  67. /package/dist/chunks/{launchViewUtils-7XTBTFAV.js.map → launchViewUtils-JLW2J4TI.js.map} +0 -0
@@ -13,6 +13,7 @@ const STRUCTURE_KEY_ROLES = {
13
13
  hidden: 'setting',
14
14
  assembly: 'setting',
15
15
  chains: 'setting',
16
+ filter: 'setting',
16
17
  feature: 'launchWide',
17
18
  userProvidedTranscriptSequence: 'launchWide',
18
19
  connectedViewId: 'launchWide',
@@ -44,6 +45,11 @@ function isNumber(value) {
44
45
  function isFeature(value) {
45
46
  return isRecord(value);
46
47
  }
48
+ // the shape only: the view model refuses a predicate that does not read, with
49
+ // the reason, as it does a color
50
+ function isPredicateList(value) {
51
+ return Array.isArray(value) && value.every(isRecord);
52
+ }
47
53
  function isResidueRange(value) {
48
54
  return (isRecord(value) &&
49
55
  typeof value.start === 'number' &&
@@ -126,6 +132,7 @@ function readStructure(fields, at, warnings) {
126
132
  hidden: read('hidden', isBoolean, 'true or false'),
127
133
  assembly: read('assembly', isString, 'a string'),
128
134
  chains: read('chains', isStringArray, 'a list of chain ids'),
135
+ filter: read('filter', isPredicateList, "a list of predicates such as [{ field: 'residue', lte: 184 }]"),
129
136
  feature: read('feature', isFeature, 'a feature object'),
130
137
  userProvidedTranscriptSequence: read('userProvidedTranscriptSequence', isString, 'a string'),
131
138
  connectedViewId: read('connectedViewId', isString, 'a string'),
@@ -68,13 +68,14 @@ function structureAssemblies(model, molstar) {
68
68
  * callers own the decision of whether/where to store the result.
69
69
  */
70
70
  export async function loadStructureData({ structure, plugin, }) {
71
- const { data, url, assembly, chains } = structure;
71
+ const { data, url, assembly, chains, filter } = structure;
72
72
  const { model, structures: molstarStructures, modelIds, } = await loadStructure({
73
73
  plugin,
74
74
  data: data || undefined,
75
75
  url,
76
76
  assembly,
77
77
  chains,
78
+ filter,
78
79
  });
79
80
  const molstar = await loadMolstar();
80
81
  // An experimental entry's B-factors are not confidence: read as pLDDT they
@@ -1,3 +1,4 @@
1
+ import { narrowsChains } from './residueFilter';
1
2
  import { parseSite } from './residueSpec';
2
3
  const MARK_TYPES = ['spheres', 'sticks', 'cartoon'];
3
4
  const HEX_COLOR = /^#[0-9a-f]{6}$/i;
@@ -32,8 +33,8 @@ function siteProblems(where, key, site) {
32
33
  /**
33
34
  * Why `marks` would draw something other than what it says: a site or mark
34
35
  * type that does not parse, a color that is not #rrggbb, or a cartoon over a
35
- * chain the structure already draws. `structures` are the view's, whose
36
- * `chains` say which chains are drawn.
36
+ * chain the structure already draws whole. `structures` are the view's, whose
37
+ * `chains` and `filter` say what is drawn.
37
38
  */
38
39
  export function markProblems(marks, structures = []) {
39
40
  if (marks === undefined) {
@@ -60,6 +61,7 @@ export function markProblems(marks, structures = []) {
60
61
  ...encodingProblems(where, mark),
61
62
  ...(mark.mark === 'cartoon' &&
62
63
  site?.kind === 'chain' &&
64
+ !narrowsChains(structure) &&
63
65
  (!drawn || drawn.includes(site.chain))
64
66
  ? [
65
67
  `${where} draws chain ${site.chain} as a cartoon over the one the structure draws; list the other chains in chains`,
@@ -19,6 +19,7 @@ import { checkedColor, colorOfScheme, resolvedColor } from './proteinColor';
19
19
  import { defaultDisplayName } from './proteinViewSpec';
20
20
  import { removeMolstarStructure } from './removeStructure';
21
21
  import { reportPluginFailure } from './reportPluginFailure';
22
+ import { checkedStructureFilters } from './residueFilter';
22
23
  import { syncResidueMarks } from './residueMarks';
23
24
  import { applySavedCamera } from './savedCamera';
24
25
  import { highlightCameraSnapshot, syncSessionHighlightMarks, } from './sessionHighlights';
@@ -221,7 +222,7 @@ function stateModelFactory() {
221
222
  alignmentAlgorithm: types.optional(types.enumeration('AlignmentAlgorithm', ALIGNMENT_ALGORITHM_VALUES), DEFAULT_ALIGNMENT_ALGORITHM),
222
223
  }))
223
224
  .preProcessSnapshot(({ colorScheme, ...snapshot }) => withStoredSettings({
224
- ...checkedLayers(snapshot, snapshot.structures),
225
+ ...checkedLayers(snapshot, checkedStructureFilters(snapshot.structures)),
225
226
  displayName: snapshot.displayName ??
226
227
  defaultDisplayName(snapshot.structures ?? []),
227
228
  color: checkedColor(snapshot.color ??
@@ -487,6 +488,7 @@ function stateModelFactory() {
487
488
  molstarStructure,
488
489
  marks: s.sessionHighlightMarks,
489
490
  chains: s.chains,
491
+ filter: s.filter,
490
492
  }))
491
493
  : []);
492
494
  const seeded = self.structures.some(s => s.seededSelection);
@@ -0,0 +1,184 @@
1
+ /**
2
+ * The fields a predicate tests, each with the Mol* property it reads and the
3
+ * level Mol* tests it at. `residue` is the author residue number
4
+ * (`auth_seq_id`), the numbering a paper cites and `marks` address; `chain`
5
+ * the author chain id (`auth_asym_id`), the one `chains` lists.
6
+ */
7
+ const FIELDS = {
8
+ residue: {
9
+ property: 'auth_seq_id',
10
+ numeric: true,
11
+ level: 'residue',
12
+ kind: 'a number',
13
+ },
14
+ chain: {
15
+ property: 'auth_asym_id',
16
+ numeric: false,
17
+ level: 'chain',
18
+ kind: 'a string',
19
+ },
20
+ };
21
+ const BOUNDS = ['lt', 'lte', 'gt', 'gte', 'range'];
22
+ const OPERATORS = ['equal', ...BOUNDS, 'oneOf'];
23
+ const EXAMPLE = "{ field: 'residue', lte: 184 }";
24
+ const TAKES = `a predicate takes field and one of ${OPERATORS.join(', ')}`;
25
+ function isRecord(x) {
26
+ return typeof x === 'object' && x !== null && !Array.isArray(x);
27
+ }
28
+ function isField(field) {
29
+ return typeof field === 'string' && Object.hasOwn(FIELDS, field);
30
+ }
31
+ function isNumber(value) {
32
+ return typeof value === 'number' && Number.isFinite(value);
33
+ }
34
+ function isValue(value, field) {
35
+ return FIELDS[field].numeric ? isNumber(value) : typeof value === 'string';
36
+ }
37
+ function rangeProblems(where, range) {
38
+ if (!Array.isArray(range) || range.length !== 2 || !range.every(isNumber)) {
39
+ return [
40
+ `${where}.range is two numbers, the low and high ends, not ${JSON.stringify(range)}`,
41
+ ];
42
+ }
43
+ const [low, high] = range;
44
+ return low <= high
45
+ ? []
46
+ : [`${where}.range runs low to high; ${low} is above ${high}`];
47
+ }
48
+ function operatorProblems(where, field, key, value) {
49
+ if (key === 'range') {
50
+ return rangeProblems(where, value);
51
+ }
52
+ if (key === 'oneOf') {
53
+ return Array.isArray(value) &&
54
+ value.length > 0 &&
55
+ value.every(v => isValue(v, field))
56
+ ? []
57
+ : [
58
+ `${where}.oneOf is a list of ${field === 'residue' ? 'numbers' : 'strings'}, not ${JSON.stringify(value)}`,
59
+ ];
60
+ }
61
+ const expected = key === 'equal' ? FIELDS[field].kind : 'a number';
62
+ return (key === 'equal' ? isValue(value, field) : isNumber(value))
63
+ ? []
64
+ : [`${where}.${key} is ${expected}, not ${JSON.stringify(value)}`];
65
+ }
66
+ /** The lowest and highest number a predicate's bounds admit; an end no bound
67
+ * names is open. */
68
+ function bounds(predicate) {
69
+ const at = (key) => {
70
+ const value = predicate[key];
71
+ return isNumber(value) ? value : undefined;
72
+ };
73
+ const range = Array.isArray(predicate.range) ? predicate.range : [];
74
+ return {
75
+ low: Math.max(at('gt') ?? -Infinity, at('gte') ?? -Infinity, isNumber(range[0]) ? range[0] : -Infinity),
76
+ high: Math.min(at('lt') ?? Infinity, at('lte') ?? Infinity, isNumber(range[1]) ? range[1] : Infinity),
77
+ };
78
+ }
79
+ function predicateProblems(where, predicate) {
80
+ if (!isRecord(predicate)) {
81
+ return [`${where} is an object such as ${EXAMPLE}`];
82
+ }
83
+ const { field, ...tests } = predicate;
84
+ if (!isField(field)) {
85
+ return [
86
+ `${where}.field is ${Object.keys(FIELDS).join(' or ')}, not ${JSON.stringify(field)}`,
87
+ ];
88
+ }
89
+ const named = Object.keys(tests);
90
+ if (named.length === 0) {
91
+ return [`${where} tests nothing: ${TAKES}`];
92
+ }
93
+ const problems = named.flatMap(key => {
94
+ if (!OPERATORS.some(op => op === key)) {
95
+ return [`${where}.${key} is not an operator: ${TAKES}`];
96
+ }
97
+ if (!FIELDS[field].numeric && BOUNDS.some(op => op === key)) {
98
+ return [
99
+ `${where}.${key} is refused: ${field} is ${FIELDS[field].kind}, so it takes equal or oneOf`,
100
+ ];
101
+ }
102
+ return operatorProblems(where, field, key, tests[key]);
103
+ });
104
+ if (problems.length > 0) {
105
+ return problems;
106
+ }
107
+ const { low, high } = bounds(tests);
108
+ return low > high
109
+ ? [`${where} selects nothing: its bounds run from ${low} to ${high}`]
110
+ : [];
111
+ }
112
+ /** What is wrong with a `filter`, one line each; empty when nothing is. */
113
+ export function filterProblems(filter, where = 'filter') {
114
+ if (filter === undefined) {
115
+ return [];
116
+ }
117
+ if (!Array.isArray(filter)) {
118
+ return [`${where} is a list of predicates such as [${EXAMPLE}]`];
119
+ }
120
+ return filter.flatMap((predicate, i) => predicateProblems(`${where}[${i}]`, predicate));
121
+ }
122
+ /**
123
+ * The view's structures, refused with every problem their filters have. A
124
+ * filter that does not read would otherwise draw a structure the session did
125
+ * not ask for — or all of it.
126
+ */
127
+ export function checkedStructureFilters(structures) {
128
+ const given = structures ?? [];
129
+ const problems = given.flatMap((structure, i) => filterProblems(structure.filter, `structures[${i}].filter`));
130
+ if (problems.length > 0) {
131
+ throw new Error(problems.join('; '));
132
+ }
133
+ return given;
134
+ }
135
+ function predicateTests(MS, predicate) {
136
+ const { equal, lt, lte, gt, gte, range, oneOf } = predicate;
137
+ const value = MS.ammp(FIELDS[predicate.field].property);
138
+ return [
139
+ ...(equal === undefined ? [] : [MS.core.rel.eq([value, equal])]),
140
+ ...(lt === undefined ? [] : [MS.core.rel.lt([value, lt])]),
141
+ ...(lte === undefined ? [] : [MS.core.rel.lte([value, lte])]),
142
+ ...(gt === undefined ? [] : [MS.core.rel.gr([value, gt])]),
143
+ ...(gte === undefined ? [] : [MS.core.rel.gre([value, gte])]),
144
+ ...(range === undefined
145
+ ? []
146
+ : [MS.core.rel.inRange([value, range[0], range[1]])]),
147
+ ...(oneOf === undefined
148
+ ? []
149
+ : [MS.core.set.has([MS.set(...oneOf), value])]),
150
+ ];
151
+ }
152
+ function allOf(MS, tests) {
153
+ return tests.length === 0
154
+ ? undefined
155
+ : tests.length === 1
156
+ ? tests[0]
157
+ : MS.core.logic.and(tests);
158
+ }
159
+ /**
160
+ * What a structure draws, as the two MolScript tests an atom selection takes:
161
+ * the chains `chains` lists and every predicate of `filter`, all of them. A
162
+ * field is tested at its own level — a residue number per residue, a chain id
163
+ * per chain — so the two compose into one selection rather than nesting.
164
+ */
165
+ export function drawnTests(MS, drawn) {
166
+ const { chains, filter = [] } = drawn;
167
+ const at = (level) => filter
168
+ .filter(predicate => FIELDS[predicate.field].level === level)
169
+ .flatMap(predicate => predicateTests(MS, predicate));
170
+ return {
171
+ chainTest: allOf(MS, [
172
+ ...(chains?.length
173
+ ? [MS.core.set.has([MS.set(...chains), MS.ammp('auth_asym_id')])]
174
+ : []),
175
+ ...at('chain'),
176
+ ]),
177
+ residueTest: allOf(MS, at('residue')),
178
+ };
179
+ }
180
+ /** Whether a structure leaves out part of what it draws, so a mark over the
181
+ * rest of a chain adds to the picture rather than covering it. */
182
+ export function narrowsChains(structure) {
183
+ return Array.isArray(structure?.filter) && structure.filter.length > 0;
184
+ }
@@ -15,6 +15,7 @@
15
15
  import { colord } from '@jbrowse/core/util/colord';
16
16
  import { SITES_TAG } from './alignmentSites';
17
17
  import loadMolstar from './loadMolstar';
18
+ import { drawnTests } from './residueFilter';
18
19
  import { structureRootCell } from './structureCells';
19
20
  export const SESSION_HIGHLIGHTS_TAG = 'jbrowse-session-highlights';
20
21
  // core's default highlight color, which the genome view's band draws in
@@ -164,27 +165,24 @@ export async function syncSessionHighlightMarks({ plugin, structures, }) {
164
165
  anchors.delete(cell.transform.ref);
165
166
  update.delete(cell.transform.ref);
166
167
  }
167
- for (const { molstarStructure, marks, chains } of structures) {
168
+ for (const { molstarStructure, marks, chains, filter } of structures) {
168
169
  const root = structureRootCell(plugin, molstar, molstarStructure);
169
170
  if (!root) {
170
171
  continue;
171
172
  }
173
+ const { chainTest, residueTest } = drawnTests(MS, { chains, filter });
172
174
  const labelled = [];
173
175
  for (const { entityId, labelSeqIds, label, color } of marks) {
176
+ const marked = MS.core.set.has([
177
+ MS.set(...labelSeqIds),
178
+ MS.ammp('label_seq_id'),
179
+ ]);
174
180
  const expression = MS.struct.generator.atomGroups({
175
181
  'entity-test': MS.core.rel.eq([MS.ammp('label_entity_id'), entityId]),
176
- 'residue-test': MS.core.set.has([
177
- MS.set(...labelSeqIds),
178
- MS.ammp('label_seq_id'),
179
- ]),
180
- ...(chains?.length
181
- ? {
182
- 'chain-test': MS.core.set.has([
183
- MS.set(...chains),
184
- MS.ammp('auth_asym_id'),
185
- ]),
186
- }
187
- : {}),
182
+ 'residue-test': residueTest
183
+ ? MS.core.logic.and([marked, residueTest])
184
+ : marked,
185
+ ...(chainTest ? { 'chain-test': chainTest } : {}),
188
186
  });
189
187
  update
190
188
  .to(root)
@@ -137,6 +137,14 @@ const Structure = types
137
137
  * highlighted but are not drawn. Absent draws every chain.
138
138
  */
139
139
  chains: types.frozen(),
140
+ /**
141
+ * #property
142
+ * Which residues of those chains are drawn, as field predicates on
143
+ * `residue` (`auth_seq_id`) and `chain` (`auth_asym_id`): CCR5's Δ32
144
+ * allele is `[{ field: 'residue', lte: 184 }]`. The rest stay loaded,
145
+ * mapped and highlighted but are not drawn. Absent draws every residue.
146
+ */
147
+ filter: types.frozen(),
140
148
  })
141
149
  .volatile(() => ({
142
150
  /**
@@ -1,6 +1,7 @@
1
1
  import { isBinaryStructureUrl, structureFormatFromContent, structureFormatFromName, } from 'p2s_mapper';
2
2
  import { CRYSTALLIZATION_ADDITIVES } from './crystallizationAdditives';
3
3
  import loadMolstar from './loadMolstar';
4
+ import { drawnTests } from './residueFilter';
4
5
  // Typed as always resolving to a trajectory, but Mol* reverts a parse that
5
6
  // fails and resolves with nothing
6
7
  function parseTrajectory(plugin, raw, format) {
@@ -34,9 +35,12 @@ export async function parseStructureTrajectory({ plugin, data, url, }) {
34
35
  }
35
36
  return trajectory;
36
37
  }
37
- /** The label of a polymer component narrowed to the drawn chains, which
38
+ /** The label of a polymer component narrowed to part of the structure, which
38
39
  * other drawing (the surface) finds it by in place of its static type. */
39
40
  export const DRAWN_CHAINS_POLYMER = 'Polymer, drawn chains';
41
+ function drawsPart({ chains, filter }) {
42
+ return !!chains?.length || !!filter?.length;
43
+ }
40
44
  /** The `assembly` value that builds the deposited model, every chain the file
41
45
  * holds, rather than one of the entry's biological assemblies. */
42
46
  export const DEPOSITED_MODEL = 'deposited';
@@ -87,21 +91,22 @@ async function removeWater(plugin, structures) {
87
91
  * `structure` param: absent, it builds the first assembly. An ensemble builds
88
92
  * each model whole and ignores it.
89
93
  */
90
- async function applyStructurePreset(plugin, trajectory, source, assembly, chains) {
94
+ async function applyStructurePreset(plugin, trajectory, source, assembly, drawn) {
91
95
  const params = { useDefaultIfSingleModel: true, structure: rootStructure(assembly) };
92
- return collectPreset(plugin, source, await plugin.builders.structure.hierarchy.applyPreset(trajectory, 'all-models', params), chains);
96
+ return collectPreset(plugin, source, await plugin.builders.structure.hierarchy.applyPreset(trajectory, 'all-models', params), drawn);
93
97
  }
94
98
  /**
95
- * Narrow the preset's polymer and ligand components to the named author
96
- * chains. The structure itself stays whole, so mapping, highlights and colors
99
+ * Narrow the preset's polymer and ligand components to the residues the spec
100
+ * draws. The structure itself stays whole, so mapping, highlights and colors
97
101
  * address it as before; only what is drawn shrinks.
102
+ *
103
+ * A `filter` narrows the ligand component too: a bound ligand is numbered in
104
+ * the same author series as the polymer, well above its last residue, so a
105
+ * residue bound leaves the ligand out as well.
98
106
  */
99
- async function drawOnlyChains(plugin, structures, chains) {
107
+ async function drawOnlyPart(plugin, structures, drawn) {
100
108
  const { MolScriptBuilder: MS, StateSelection, StateTransforms, } = await loadMolstar();
101
- const chainTest = MS.core.set.has([
102
- MS.set(...chains),
103
- MS.ammp('auth_asym_id'),
104
- ]);
109
+ const { chainTest, residueTest } = drawnTests(MS, drawn);
105
110
  const entityTest = (polymer) => polymer
106
111
  ? MS.core.rel.eq([MS.ammp('entityType'), 'polymer'])
107
112
  : MS.core.logic.and([
@@ -128,7 +133,8 @@ async function drawOnlyChains(plugin, structures, chains) {
128
133
  type: {
129
134
  name: 'expression',
130
135
  params: MS.struct.generator.atomGroups({
131
- 'chain-test': chainTest,
136
+ ...(chainTest ? { 'chain-test': chainTest } : {}),
137
+ ...(residueTest ? { 'residue-test': residueTest } : {}),
132
138
  'entity-test': entityTest(polymer),
133
139
  }),
134
140
  },
@@ -155,11 +161,11 @@ async function drawOnlyChains(plugin, structures, chains) {
155
161
  }
156
162
  await update.commit();
157
163
  }
158
- async function collectPreset(plugin, source, preset, chains) {
164
+ async function collectPreset(plugin, source, preset, drawn) {
159
165
  const { models, structures } = presetOutput(preset);
160
166
  await removeWater(plugin, structures);
161
- if (chains?.length) {
162
- await drawOnlyChains(plugin, structures, chains);
167
+ if (drawsPart(drawn)) {
168
+ await drawOnlyPart(plugin, structures, drawn);
163
169
  }
164
170
  const loaded = structures.flatMap(s => (s.obj ? [s.obj.data] : []));
165
171
  if (loaded.length === 0) {
@@ -172,8 +178,11 @@ async function collectPreset(plugin, source, preset, chains) {
172
178
  };
173
179
  }
174
180
  /** Load a structure from its text or its url, as the view shows one. */
175
- export async function loadStructure({ plugin, data, url, assembly, chains, }) {
181
+ export async function loadStructure({ plugin, data, url, assembly, chains, filter, }) {
176
182
  const trajectory = await parseStructureTrajectory({ plugin, data, url });
177
183
  const source = url ?? 'the structure data';
178
- return applyStructurePreset(plugin, trajectory, source, assembly, chains);
184
+ return applyStructurePreset(plugin, trajectory, source, assembly, {
185
+ chains,
186
+ filter,
187
+ });
179
188
  }