-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #897 from fredludlow/colordata
Colordata addition
- Loading branch information
Showing
7 changed files
with
125 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** Demonstration of structuredata colormaker, coloring atoms by numeric property passed | ||
* in as colorData.atomData | ||
*/ | ||
stage.loadFile('data://1lee.pdb').then(function (c) { | ||
// We might be colouring by some calculated/predicted property (e.g. ML model which outputs | ||
// scores/quantities for individual atoms) | ||
|
||
// For our example, we'll generate some random "scores" for the ligand atoms in PDB entry 1lee | ||
// (Ligand has hetcode R36), leaving all the protein atoms unscored | ||
|
||
var structure = c.structure | ||
var scores = [] | ||
|
||
var ligandView = structure.getView(new NGL.Selection('R36')) | ||
|
||
ligandView.eachAtom(ap => { | ||
// We only populate scores for some of the atoms (those in the R36 residue), | ||
// For non-ligand atoms scores[i] will be undefined, and color will fallback to color value | ||
scores[ap.index] = Math.random() | ||
}) | ||
|
||
c.addRepresentation('licorice', { | ||
color: 'structuredata', | ||
colorData: {atomData: scores}, | ||
colorDomain: [0.0, 1.0], // This is the default domain | ||
colorScale: 'rainbow', // Any of the normal color scales are available | ||
colorValue: '#888' // Fallback color for atoms without data | ||
}) | ||
c.autoView('R36') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Use of structuredata-colormaker with bonding info. | ||
*/ | ||
|
||
stage.loadFile('data://adrenalin.mol2').then(function (o) { | ||
var s = o.structure | ||
var bondData = [] | ||
// Here the data is randomly generated, but could be a bond-specific | ||
// property from an external source (e.g. estimated bond enthalpy) | ||
s.eachBond(b => { | ||
bondData.push(Math.random()) | ||
}) | ||
|
||
o.addRepresentation('ball+stick', { | ||
colorScheme: 'structuredata', | ||
colorData: { bondData: bondData }, | ||
colorValue: 'grey' // As colorData.atomData is not defined, the atom colors fall back to colorValue. | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @file Colordata Colormaker | ||
* @author Fred Ludlow <[email protected]> | ||
* @private | ||
*/ | ||
|
||
import { ColormakerRegistry } from '../globals' | ||
import Colormaker, { ColorData, ColormakerScale, manageColor, StuctureColormakerParams } from './colormaker' | ||
import AtomProxy from '../proxy/atom-proxy' | ||
import BondProxy from '../proxy/bond-proxy' | ||
|
||
|
||
class StructuredataColormaker extends Colormaker { | ||
atomData?: ColorData['atomData'] | ||
bondData?: ColorData['bondData'] | ||
scale: ColormakerScale | ||
|
||
constructor(params: StuctureColormakerParams) { | ||
super(params) | ||
if (!params.scale) { | ||
this.parameters.scale = 'rwb' | ||
} | ||
this.atomData = this.parameters.data?.atomData | ||
this.bondData = this.parameters.data?.bondData | ||
this.scale = this.getScale(this.parameters) | ||
} | ||
|
||
@manageColor | ||
atomColor(a: AtomProxy) { | ||
const val = this.atomData?.[a.index] | ||
return (val !== undefined) ? this.scale(val) : this.parameters.value | ||
} | ||
|
||
@manageColor | ||
bondColor(bond: BondProxy, fromTo: boolean) { | ||
const val = this.bondData?.[bond.index] | ||
|
||
// Explicit bond data? | ||
if (val !== undefined) return this.scale(val) | ||
|
||
|
||
if (this.atomProxy) { | ||
this.atomProxy.index = fromTo ? bond.atomIndex1 : bond.atomIndex2 | ||
return this.atomColor(this.atomProxy) | ||
} | ||
|
||
// Fallback | ||
return this.parameters.value | ||
} | ||
} | ||
|
||
ColormakerRegistry.add('structuredata', StructuredataColormaker) | ||
|
||
export default StructuredataColormaker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters