NGL@1.0.0-beta.7 Home Manual Reference Source Gallery

src/color/hydrophobicity-colormaker.js

  1. /**
  2. * @file Hydrophobicity Colormaker
  3. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  4. * @private
  5. */
  6.  
  7. import { ColormakerRegistry } from '../globals.js'
  8. import Colormaker from './colormaker.js'
  9.  
  10. import {
  11. ResidueHydrophobicity, DefaultResidueHydrophobicity
  12. } from '../structure/structure-constants.js'
  13.  
  14. /**
  15. * Color by hydrophobicity
  16. */
  17. class HydrophobicityColormaker extends Colormaker {
  18. constructor (params) {
  19. super(params)
  20.  
  21. if (!params.scale) {
  22. this.scale = 'RdYlGn'
  23. }
  24.  
  25. var name
  26. var idx = 0 // 0: DGwif, 1: DGwoct, 2: Oct-IF
  27.  
  28. var resHF = {}
  29. for (name in ResidueHydrophobicity) {
  30. resHF[ name ] = ResidueHydrophobicity[ name ][ idx ]
  31. }
  32.  
  33. if (!params.domain) {
  34. var val
  35. var min = Infinity
  36. var max = -Infinity
  37.  
  38. for (name in resHF) {
  39. val = resHF[ name ]
  40. min = Math.min(min, val)
  41. max = Math.max(max, val)
  42. }
  43.  
  44. this.domain = [ min, 0, max ]
  45. }
  46.  
  47. var hfScale = this.getScale()
  48.  
  49. this.atomColor = function (a) {
  50. return hfScale(resHF[ a.resname ] || DefaultResidueHydrophobicity)
  51. }
  52. }
  53. }
  54.  
  55. ColormakerRegistry.add('hydrophobicity', HydrophobicityColormaker)
  56.  
  57. export default HydrophobicityColormaker