coloring.ts 1.1 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. import { CustomElementProperty } from '../../mol-model-props/common/custom-element-property';
  8. import { Model, ElementIndex } from '../../mol-model/structure';
  9. import { Color } from '../../mol-util/color';
  10. export const StripedResidues = CustomElementProperty.create<number>({
  11. label: 'Residue Stripes',
  12. name: 'basic-wrapper-residue-striping',
  13. getData(model: Model) {
  14. const map = new Map<ElementIndex, number>();
  15. const residueIndex = model.atomicHierarchy.residueAtomSegments.index;
  16. for (let i = 0, _i = model.atomicHierarchy.atoms._rowCount; i < _i; i++) {
  17. map.set(i as ElementIndex, residueIndex[i] % 2);
  18. }
  19. return { value: map };
  20. },
  21. coloring: {
  22. getColor(e) { return e === 0 ? Color(0xff0000) : Color(0x0000ff); },
  23. defaultColor: Color(0x777777)
  24. },
  25. getLabel(e) {
  26. return e === 0 ? 'Odd stripe' : 'Even stripe';
  27. }
  28. });