WinslowFan Claude Opus 5.5 commited on
Commit
c77380d
·
1 Parent(s): 4e1ae88

Draw the alternative semi-transparent in the superposed view

Browse files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

frontend/src/components/StructureDiff.tsx CHANGED
@@ -15,20 +15,20 @@ export const DIFF_COLORS: Record<CompareClass, string> = {
15
  missing: 'transparent',
16
  };
17
 
18
- /* In the superposed "both" view the alternative is drawn in one colour so it stands apart from this chain. */
19
- export const ALT_COLOR = '#9b7fd4';
20
 
21
  type Show = 'both' | 'A' | 'B';
22
 
23
- function runsFor(residues: StructureCompare['residues'], chain: 'A' | 'B', uniform?: string): ResidueColorRun[] {
24
  const absent: CompareClass = chain === 'A' ? 'only_b' : 'only_a';
25
  const runs: ResidueColorRun[] = [];
26
  for (const r of residues) {
27
  if (r.class === absent || r.class === 'missing') continue;
28
- const color = uniform ?? DIFF_COLORS[r.class];
29
  const last = runs[runs.length - 1];
30
  if (last && last.color === color && last.end === r.pos - 1) last.end = r.pos;
31
- else runs.push({ chain, start: r.pos, end: r.pos, color });
32
  }
33
  return runs;
34
  }
@@ -64,7 +64,7 @@ export function StructureDiff({
64
 
65
  const runs = useMemo(() => {
66
  if (!d) return [];
67
- if (show === 'both') return [...runsFor(d.residues, 'A'), ...runsFor(d.residues, 'B', ALT_COLOR)];
68
  return runsFor(d.residues, show);
69
  }, [d, show]);
70
 
@@ -91,7 +91,7 @@ export function StructureDiff({
91
  ]}
92
  />
93
  <p className="muted small sdiff__stats">
94
- {show === 'both' ? <>{la} is coloured by deviation; {lb} is violet. </> : null}
95
  {lb} superposed onto {la} on their largest rigid core: {fmtInt(d.counts.low)} of {fmtInt(d.n_common)} shared
96
  residues within {t.low} Å (core RMSD {fmtNum(d.rmsd_core, 2)} Å), maximum deviation {fmtNum(d.max_dev, 1)} Å.
97
  </p>
@@ -105,7 +105,11 @@ export function StructureDiff({
105
  <ul className="legend sdiff__legend">
106
  {show === 'both' && (
107
  <li>
108
- <Swatch color={ALT_COLOR} /> {lb} (alternative, superposed)
 
 
 
 
109
  </li>
110
  )}
111
  <li>
 
15
  missing: 'transparent',
16
  };
17
 
18
+ /* In the superposed "both" view the alternative keeps the same colours but is drawn semi-transparent. */
19
+ export const ALT_OPACITY = 0.35;
20
 
21
  type Show = 'both' | 'A' | 'B';
22
 
23
+ function runsFor(residues: StructureCompare['residues'], chain: 'A' | 'B', opacity?: number): ResidueColorRun[] {
24
  const absent: CompareClass = chain === 'A' ? 'only_b' : 'only_a';
25
  const runs: ResidueColorRun[] = [];
26
  for (const r of residues) {
27
  if (r.class === absent || r.class === 'missing') continue;
28
+ const color = DIFF_COLORS[r.class];
29
  const last = runs[runs.length - 1];
30
  if (last && last.color === color && last.end === r.pos - 1) last.end = r.pos;
31
+ else runs.push({ chain, start: r.pos, end: r.pos, color, opacity });
32
  }
33
  return runs;
34
  }
 
64
 
65
  const runs = useMemo(() => {
66
  if (!d) return [];
67
+ if (show === 'both') return [...runsFor(d.residues, 'A'), ...runsFor(d.residues, 'B', ALT_OPACITY)];
68
  return runsFor(d.residues, show);
69
  }, [d, show]);
70
 
 
91
  ]}
92
  />
93
  <p className="muted small sdiff__stats">
94
+ {show === 'both' ? <>{la} is solid and {lb} semi-transparent, both coloured by deviation. </> : null}
95
  {lb} superposed onto {la} on their largest rigid core: {fmtInt(d.counts.low)} of {fmtInt(d.n_common)} shared
96
  residues within {t.low} Å (core RMSD {fmtNum(d.rmsd_core, 2)} Å), maximum deviation {fmtNum(d.max_dev, 1)} Å.
97
  </p>
 
105
  <ul className="legend sdiff__legend">
106
  {show === 'both' && (
107
  <li>
108
+ <Swatch color={DIFF_COLORS.low} /> solid: {la}
109
+ <span style={{ opacity: ALT_OPACITY + 0.15 }}>
110
+ <Swatch color={DIFF_COLORS.low} />
111
+ </span>{' '}
112
+ faded: {lb}
113
  </li>
114
  )}
115
  <li>
frontend/src/components/StructureViewer.tsx CHANGED
@@ -140,6 +140,8 @@ export interface ResidueColorRun {
140
  start: number;
141
  end: number;
142
  color: string;
 
 
143
  }
144
 
145
  /**
@@ -175,6 +177,7 @@ export function CustomStructureViewer({
175
  beg_auth_seq_id: r.start,
176
  end_auth_seq_id: r.end,
177
  color: hexToRgb(r.color),
 
178
  }));
179
  loadMolstar()
180
  .then(() => {
 
140
  start: number;
141
  end: number;
142
  color: string;
143
+ /** 0–1; below 1 draws the run semi-transparent */
144
+ opacity?: number;
145
  }
146
 
147
  /**
 
177
  beg_auth_seq_id: r.start,
178
  end_auth_seq_id: r.end,
179
  color: hexToRgb(r.color),
180
+ ...(r.opacity != null && r.opacity < 1 ? { opacity: r.opacity } : {}),
181
  }));
182
  loadMolstar()
183
  .then(() => {