@@ -10,7 +10,7 @@ declare global {
1010}
1111
1212export 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
1515interface 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