11import { loadMVS } from 'molstar/lib/extensions/mvs/load' ;
22import { MVSData , Snapshot } from 'molstar/lib/extensions/mvs/mvs-data' ;
3- import Builder from 'molstar/lib/extensions/mvs/tree/mvs/mvs-builder' ;
4- import { MVSNodeParams } from 'molstar/lib/extensions/mvs/tree/mvs/mvs-tree' ;
5- import { ComponentExpressionT , HexColorT } from 'molstar/lib/extensions/mvs/tree/mvs/param-types' ;
6- import { PluginContext } from 'molstar/lib/mol-plugin/context' ;
7- import { Color } from 'molstar/lib/mol-util/color' ;
8- import { normalizeColor } from '../../helpers' ;
9- import { PisaAssembliesData , PisaAssemblyRecord , PisaInterfaceData , PisaTransform } from './types' ;
3+ import type Builder from 'molstar/lib/extensions/mvs/tree/mvs/mvs-builder' ;
4+ import type { MVSNodeParams } from 'molstar/lib/extensions/mvs/tree/mvs/mvs-tree' ;
5+ import type { ComponentExpressionT , HexColorT } from 'molstar/lib/extensions/mvs/tree/mvs/param-types' ;
6+ import type { PluginContext } from 'molstar/lib/mol-plugin/context' ;
7+ import type { PisaAssembliesData , PisaAssemblyRecord , PisaInterfaceData , PisaTransform } from './types' ;
108
119
1210const COMPONENT_COLORS : HexColorT [ ] = [
@@ -19,6 +17,14 @@ const COMPONENT_COLORS: HexColorT[] = [
1917 // '#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494',
2018] ;
2119const DEFAULT_COMPONENT_COLOR : HexColorT = '#999999' ;
20+ const BULK_COLOR_LIGHTNESS_ADJUSTMENT = 0.4 ;
21+ const INTERFACE_COLOR_LIGHTNESS_ADJUSTMENT = - 0.3 ;
22+ function bulkColorFn ( baseColor : HexColorT ) : HexColorT {
23+ return adjustLightnessRelative ( baseColor , BULK_COLOR_LIGHTNESS_ADJUSTMENT ) ;
24+ }
25+ function interfaceColorFn ( baseColor : HexColorT ) : HexColorT {
26+ return adjustLightnessRelative ( baseColor , INTERFACE_COLOR_LIGHTNESS_ADJUSTMENT ) ;
27+ }
2228
2329async function getAssembliesData ( pdbId : string ) : Promise < PisaAssembliesData > {
2430 return await ( await fetch ( `/tmp/pisa/${ pdbId } /assembly.json` ) ) . json ( ) ;
@@ -31,48 +37,10 @@ async function getInterfaceData(pdbId: string, interfaceId: string): Promise<Pis
3137 return await ( await fetch ( `/tmp/pisa/${ pdbId } /interfaces/interface_${ interfaceId } .json` ) ) . json ( ) ;
3238}
3339function loadStructureData ( builder : Builder . Root , pdbId : string ) {
34- // return builder.download({ url: ' https://www.ebi.ac.uk/pdbe/entry-files/download/3gcb_updated .cif' }).parse({ format: 'mmcif' });
35- return builder . download ( { url : ' https://www.ebi.ac.uk/pdbe/entry-files/download/pdb3gcb .ent' } ) . parse ( { format : 'pdb' } ) ;
40+ // return builder.download({ url: ` https://www.ebi.ac.uk/pdbe/entry-files/download/${pdbId}_updated .cif` }).parse({ format: 'mmcif' });
41+ return builder . download ( { url : ` https://www.ebi.ac.uk/pdbe/entry-files/download/pdb ${ pdbId } .ent` } ) . parse ( { format : 'pdb' } ) ;
3642}
3743
38- /** Positive values for lighter interfaces, negative values for darker interfaces. */
39- const INTERFACE_COLOR_CHANGE_STRENGTH = - 1 ;
40- function bulkColorFn ( baseColor : HexColorT ) : HexColorT {
41- return Color . toHexStyle ( Color . darken ( normalizeColor ( baseColor ) , INTERFACE_COLOR_CHANGE_STRENGTH ) ) as HexColorT ;
42- }
43- function interfaceColorFn ( baseColor : HexColorT ) : HexColorT {
44- return Color . toHexStyle ( Color . lighten ( normalizeColor ( baseColor ) , INTERFACE_COLOR_CHANGE_STRENGTH ) ) as HexColorT ;
45- }
46- // const BULK_COLOR_CHANGE_AMOUNT = 0.3;
47- // const INTERFACE_COLOR_CHANGE_AMOUNT = -0.3;
48- // function bulkColorFn(baseColor: HexColorT): HexColorT {
49- // return lighten(baseColor, BULK_COLOR_CHANGE_AMOUNT);
50- // }
51- // function interfaceColorFn(baseColor: HexColorT): HexColorT {
52- // return lighten(baseColor, INTERFACE_COLOR_CHANGE_AMOUNT);
53- // }
54- // function hexColorToRgb(hex: HexColorT): [number, number, number] {
55- // const hexNum = parseInt(hex.replace('#', '0x'));
56- // return [hexNum >> 16 & 255, hexNum >> 8 & 255, hexNum & 255];
57- // }
58- // function rgbToHexColor(rgb: [number, number, number]): HexColorT {
59- // const hexNum = (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
60- // return '#' + ('000000' + hexNum.toString(16)).slice(-6) as HexColorT;
61- // }
62- // function lighten(color: HexColorT, amount: number): HexColorT {
63- // const rgb = hexColorToRgb(color);
64- // amount = Math.min(1, Math.max(-1, amount));
65- // if (amount > 0) {
66- // rgb[0] = Math.round(rgb[0] * (1 - amount)) + 255 * amount;
67- // rgb[1] = Math.round(rgb[1] * (1 - amount)) + 255 * amount;
68- // rgb[2] = Math.round(rgb[2] * (1 - amount)) + 255 * amount;
69- // } else if (amount < 0) {
70- // rgb[0] = Math.round(rgb[0] * (1 + amount));
71- // rgb[1] = Math.round(rgb[1] * (1 + amount));
72- // rgb[2] = Math.round(rgb[2] * (1 + amount));
73- // }
74- // return rgbToHexColor(rgb);
75- // }
7644
7745export async function pisaDemo ( plugin : PluginContext ) {
7846 const pdbId = '3gcb' ;
@@ -99,7 +67,7 @@ export async function pisaDemo(plugin: PluginContext) {
9967 snapshots . push ( await pisaInterfaceView ( pdbId , interfaceId , { detailMolecules : [ 0 , 1 ] } ) ) ;
10068 }
10169 const mvs = MVSData . createMultistate ( snapshots ) ;
102- console . log ( MVSData . toMVSJ ( mvs ) )
70+ // console.log(MVSData.toMVSJ(mvs))
10371 await loadMVS ( plugin , mvs ) ;
10472
10573 // Comments:
@@ -343,4 +311,30 @@ function decodeChainId(pisaChainId: string): { chainId: string, compId: string |
343311 } else {
344312 return { chainId : pisaChainId , compId : undefined , seqId : undefined , isLigand : false } ;
345313 }
346- }
314+ }
315+
316+ /** Increase/decrease "lightness" of a color (where lightness -1 = black, lightness 1 = white) */
317+ function adjustLightnessRelative ( color : HexColorT , lightnessDiff : number ) : HexColorT {
318+ let [ r , g , b ] = hexColorToNormRgb ( color ) ;
319+ const x = Math . min ( r , g , b ) ;
320+ const z = Math . max ( r , g , b ) ;
321+ const w = x + z - 1 ;
322+ // Compute corresponding color with lightness 0:
323+ const c0 = ( Math . abs ( w ) === 1 ) ? ( ) => 0.5 : ( c : number ) => ( c - Math . max ( w , 0 ) ) / ( 1 - Math . abs ( w ) ) ;
324+ const r0 = c0 ( r ) , g0 = c0 ( g ) , b0 = c0 ( b ) ;
325+ // Compute output color:
326+ const wNew = Math . max ( - 1 , Math . min ( 1 , w + lightnessDiff ) ) ;
327+ const cNew = ( c : number ) => c * ( 1 - Math . abs ( wNew ) ) + Math . max ( wNew , 0 ) ;
328+ const rNew = cNew ( r0 ) , gNew = cNew ( g0 ) , bNew = cNew ( b0 ) ;
329+ return normRgbToHexColor ( rNew , gNew , bNew ) ;
330+ }
331+ /** Convert hex color string to normalized RGB ([0-1, 0-1, 0-1]), e.g. '#0080ff' -> [0, 0.5, 1] */
332+ function hexColorToNormRgb ( hex : HexColorT ) : [ number , number , number ] {
333+ const hexNum = parseInt ( hex . replace ( '#' , '0x' ) ) ;
334+ return [ ( hexNum >> 16 & 255 ) / 255 , ( hexNum >> 8 & 255 ) / 255 , ( hexNum & 255 ) / 255 ] ;
335+ }
336+ /** Convert normalized RGB ([0-1, 0-1, 0-1]) to hex color string, e.g. [0, 0.5, 1] -> '#0080ff' */
337+ function normRgbToHexColor ( r : number , g : number , b : number ) : HexColorT {
338+ const hexNum = ( Math . round ( 255 * r ) << 16 ) | ( Math . round ( 255 * g ) << 8 ) | Math . round ( 255 * b ) ;
339+ return '#' + ( '000000' + hexNum . toString ( 16 ) ) . slice ( - 6 ) as HexColorT ;
340+ }
0 commit comments