Skip to content

Commit 871c29c

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
feat: add bio-coloring pack (hydrophobicity, b-factor, charge)
1 parent e8d90ba commit 871c29c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/components/Controls.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ export const Controls: React.FC<ControlsProps> = ({
335335
<option value="element">Element</option>
336336
<option value="resname">Residue</option>
337337
<option value="structure">Structure</option>
338+
<option value="hydrophobicity">Hydrophobicity</option>
339+
<option value="bfactor">B-Factor (Flexibility)</option>
340+
<option value="charge">Charge (+/-)</option>
338341
</select>
339342
</div>
340343
</div>

src/components/ProteinViewer.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare global {
1010
}
1111

1212
export type RepresentationType = 'cartoon' | 'licorice' | 'backbone' | 'spacefill' | 'surface' | 'ribbon';
13-
export type ColoringType = 'chainid' | 'element' | 'residue' | 'secondary' | 'hydrophobicity' | 'structure';
13+
export type ColoringType = 'chainid' | 'element' | 'residue' | 'secondary' | 'hydrophobicity' | 'structure' | 'bfactor' | 'charge';
1414

1515
interface ProteinViewerProps {
1616
pdbId?: string;
@@ -502,7 +502,7 @@ export const ProteinViewer = forwardRef<ProteinViewerRef, ProteinViewerProps>(({
502502
// For simple coloring modes (chainid, element), we use a purely manual scheme
503503
// This ensures that "base" colors are identical whether a custom rule exists or not.
504504

505-
if (currentColoring === 'chainid' || currentColoring === 'element') {
505+
if (currentColoring === 'chainid' || currentColoring === 'element' || currentColoring === 'charge') {
506506
const schemeId = `unified-scheme-${Date.now()}`;
507507

508508
// Pre-calculate custom colors for fast lookup
@@ -528,7 +528,18 @@ export const ProteinViewer = forwardRef<ProteinViewerRef, ProteinViewerProps>(({
528528
return customColorMap.get(atom.index);
529529
}
530530

531-
// 2. Base Coloring (Stable)
531+
// 2. Charge Coloring
532+
if (currentColoring === 'charge') {
533+
const resName = atom.resname;
534+
// Positive: Blue
535+
if (['ARG', 'LYS', 'HIS'].includes(resName)) return 0x0000FF;
536+
// Negative: Red
537+
if (['ASP', 'GLU'].includes(resName)) return 0xFF0000;
538+
// Neutral: White/Grey
539+
return 0xCCCCCC;
540+
}
541+
542+
// 3. Base Coloring (Stable)
532543
if (currentColoring === 'element') {
533544
return ELEMENT_COLORS[atom.element] || ELEMENT_COLORS['DEFAULT'];
534545
}

0 commit comments

Comments
 (0)