From 1d765bfb4ea9967832cb7243deee7dd98ad7c134 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Tue, 31 Oct 2017 15:48:24 +0100
Subject: [PATCH] date model part ?? + 1 of ???

---
 src/mol-data/model.ts                         |   8 +-
 src/mol-data/model/builders/mmcif.ts          |   2 +-
 src/mol-data/model/constants.ts               | 317 ++++++++++++++++++
 .../model/data/secondary-structure.ts         | 128 -------
 src/mol-data/model/properties/computed.ts     |   7 +
 .../{data => properties}/conformation.ts      |  11 +-
 .../keys.ts => properties/format-specific.ts} |   2 +
 .../hierarchy.ts}                             |  35 +-
 .../model/{data => properties}/transforms.ts  |   0
 src/mol-data/model/utils/hierarchy-keys.ts    |  14 +
 src/mol-data/structure/atom.ts                |  16 +
 src/mol-io/reader/cif/schema/mmcif.ts         |   2 +-
 12 files changed, 393 insertions(+), 149 deletions(-)
 create mode 100644 src/mol-data/model/constants.ts
 delete mode 100644 src/mol-data/model/data/secondary-structure.ts
 create mode 100644 src/mol-data/model/properties/computed.ts
 rename src/mol-data/model/{data => properties}/conformation.ts (62%)
 rename src/mol-data/model/{common/keys.ts => properties/format-specific.ts} (75%)
 rename src/mol-data/model/{data/macromolecule.ts => properties/hierarchy.ts} (65%)
 rename src/mol-data/model/{data => properties}/transforms.ts (100%)
 create mode 100644 src/mol-data/model/utils/hierarchy-keys.ts

diff --git a/src/mol-data/model.ts b/src/mol-data/model.ts
index db02acf8a..a6177c117 100644
--- a/src/mol-data/model.ts
+++ b/src/mol-data/model.ts
@@ -5,8 +5,8 @@
  */
 
 import * as Formats from './model/formats'
-import MacromoleculeData from './model/data/macromolecule'
-import ConformationData from './model/data/conformation'
+import HierarchyProperties from './model/properties/hierarchy'
+import ConformationProperties from './model/properties/conformation'
 import Segmentation from '../mol-base/collections/integer/segmentation'
 
 /**
@@ -21,8 +21,8 @@ interface Model extends Readonly<{
 
     sourceData: Formats.RawData,
 
-    macromolecule: MacromoleculeData,
-    conformation: ConformationData,
+    hierarchy: HierarchyProperties,
+    conformation: ConformationProperties,
 
     // used for diffing.
     version: {
diff --git a/src/mol-data/model/builders/mmcif.ts b/src/mol-data/model/builders/mmcif.ts
index 24ad91e49..b3dad75ba 100644
--- a/src/mol-data/model/builders/mmcif.ts
+++ b/src/mol-data/model/builders/mmcif.ts
@@ -48,7 +48,7 @@ function createModel(raw: RawData, data: mmCIF, bounds: Interval): Model {
         sourceData: raw,
         model_num: 0, // TODO: fix
         //common: 0 as any,
-        macromolecule: 0 as any,
+        hierarchy: 0 as any,
         conformation: 0 as any,
         version: { data: 0, conformation: 0 },
         atomCount: Interval.size(bounds),
diff --git a/src/mol-data/model/constants.ts b/src/mol-data/model/constants.ts
new file mode 100644
index 000000000..5db57c733
--- /dev/null
+++ b/src/mol-data/model/constants.ts
@@ -0,0 +1,317 @@
+/**
+ * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ * @author David Sehnal <david.sehnal@gmail.com>
+ */
+
+import BitFlags from '../../mol-base/utils/bit-flags'
+
+export const enum EntityType {
+    Unknown = 'unknown',
+    Polymer = 'polymer',
+    NonPolymer = 'non-polymer',
+    Macrolide = 'macrolide',
+    Water = 'water'
+}
+
+export const enum MoleculeType {
+    Unknown,
+    Water,
+    Ion,
+    Protein,
+    RNA,
+    DNA,
+    Saccharide
+}
+
+export const enum BackboneType {
+    Unknown,
+    Protein,
+    RNA,
+    DNA,
+    CgProtein,
+    CgRNA,
+    CgDNA
+}
+
+const _chemCompNonPolymer = ['NON-POLYMER'];
+const _chemCompOther = ['OTHER'];
+const _chemCompSaccharide = [
+    'D-SACCHARIDE', 'D-SACCHARIDE 1,4 AND 1,4 LINKING', 'D-SACCHARIDE 1,4 AND 1,6 LINKING',
+    'L-SACCHARIDE', 'L-SACCHARIDE 1,4 AND 1,4 LINKING', 'L-SACCHARIDE 1,4 AND 1,6 LINKING',
+    'SACCHARIDE'
+];
+
+export const ChemComp = {
+    Protein: [
+        'D-BETA-PEPTIDE, C-GAMMA LINKING', 'D-GAMMA-PEPTIDE, C-DELTA LINKING',
+        'D-PEPTIDE COOH CARBOXY TERMINUS', 'D-PEPTIDE NH3 AMINO TERMINUS', 'D-PEPTIDE LINKING',
+        'L-BETA-PEPTIDE, C-GAMMA LINKING', 'L-GAMMA-PEPTIDE, C-DELTA LINKING',
+        'L-PEPTIDE COOH CARBOXY TERMINUS', 'L-PEPTIDE NH3 AMINO TERMINUS', 'L-PEPTIDE LINKING',
+        'PEPTIDE LINKING', 'PEPTIDE-LIKE'
+    ],
+    RNA: [
+        'RNA OH 3 PRIME TERMINUS', 'RNA OH 5 PRIME TERMINUS', 'RNA LINKING'
+    ],
+    DNA: [
+        'DNA OH 3 PRIME TERMINUS', 'DNA OH 5 PRIME TERMINUS', 'DNA LINKING',
+        'L-DNA LINKING', 'L-RNA LINKING'
+    ],
+    Saccharide: _chemCompSaccharide,
+    Other: _chemCompOther,
+    NonPolymer: _chemCompNonPolymer,
+    Hetero: _chemCompNonPolymer.concat(_chemCompOther, _chemCompSaccharide)
+}
+
+export interface SecondaryStructureType extends BitFlags<SecondaryStructureType.Flag> { }
+export namespace SecondaryStructureType {
+    export const Helix = ['h', 'g', 'i']
+    export const Sheet = ['e', 'b']
+    export const Turn = ['s', 't', 'l', '']
+
+    export const is: (ss: SecondaryStructureType, f: Flag) => boolean = BitFlags.has
+
+    export const enum Flag {
+        None = 0x0,
+
+        // category
+        DoubleHelix = 0x1,
+        Helix = 0x2,
+        Beta = 0x4,
+        Turn = 0x8,
+
+        // category variant
+        LeftHanded = 0x10,  // helix
+        RightHanded = 0x20,
+
+        ClassicTurn = 0x40,  // turn
+        InverseTurn = 0x80,
+
+        // sub-category
+        HelixOther = 0x100,  // protein
+        Helix27 = 0x200,
+        Helix3Ten = 0x400,
+        HelixAlpha = 0x800,
+        HelixGamma = 0x1000,
+        HelixOmega = 0x2000,
+        HelixPi = 0x4000,
+        HelixPolyproline = 0x8000,
+
+        DoubleHelixOther = 0x10000,  // nucleic
+        DoubleHelixZ = 0x20000,
+        DoubleHelixA = 0x40000,
+        DoubleHelixB = 0x80000,
+
+        BetaOther = 0x100000,  // protein
+        BetaStrand = 0x200000,  // single strand
+        BetaSheet = 0x400000,  // multiple hydrogen bonded strands
+        BetaBarell = 0x800000,  // closed series of sheets
+
+        TurnOther = 0x1000000,  // protein
+        Turn1 = 0x2000000,
+        Turn2 = 0x4000000,
+        Turn3 = 0x8000000,
+
+        NA = 0x10000000,  // not applicable/available
+    }
+
+    export const SecondaryStructureMmcif: { [value: string]: number } = {
+        HELX_LH_27_P: Flag.Helix | Flag.LeftHanded | Flag.Helix27,  // left-handed 2-7 helix (protein)
+        HELX_LH_3T_P: Flag.Helix | Flag.LeftHanded | Flag.Helix3Ten,  // left-handed 3-10 helix (protein)
+        HELX_LH_AL_P: Flag.Helix | Flag.LeftHanded | Flag.HelixAlpha,  // left-handed alpha helix (protein)
+        HELX_LH_A_N: Flag.DoubleHelix | Flag.LeftHanded | Flag.DoubleHelixA,  // left-handed A helix (nucleic acid)
+        HELX_LH_B_N: Flag.DoubleHelix | Flag.LeftHanded | Flag.DoubleHelixB,  // left-handed B helix (nucleic acid)
+        HELX_LH_GA_P: Flag.Helix | Flag.LeftHanded | Flag.HelixGamma,  // left-handed gamma helix (protein)
+        HELX_LH_N: Flag.DoubleHelix | Flag.LeftHanded,  // left-handed helix with type not specified (nucleic acid)
+        HELX_LH_OM_P: Flag.Helix | Flag.LeftHanded | Flag.HelixOmega,  // left-handed omega helix (protein)
+        HELX_LH_OT_N: Flag.DoubleHelix | Flag.LeftHanded | Flag.DoubleHelixOther,  // left-handed helix with type that does not conform to an accepted category (nucleic acid)
+        HELX_LH_OT_P: Flag.Helix | Flag.LeftHanded | Flag.HelixOther,  // left-handed helix with type that does not conform to an accepted category (protein)
+        HELX_LH_P: Flag.Helix | Flag.LeftHanded,  // left-handed helix with type not specified (protein)
+        HELX_LH_PI_P: Flag.Helix | Flag.LeftHanded | Flag.HelixPi,  // left-handed pi helix (protein)
+        HELX_LH_PP_P: Flag.Helix | Flag.LeftHanded | Flag.HelixPolyproline,  // left-handed polyproline helix (protein)
+        HELX_LH_Z_N: Flag.DoubleHelix | Flag.LeftHanded | Flag.DoubleHelixZ,  // left-handed Z helix (nucleic acid)
+        HELX_N: Flag.DoubleHelix,  // helix with handedness and type not specified (nucleic acid)
+        HELX_OT_N: Flag.DoubleHelix,  // helix with handedness and type that do not conform to an accepted category (nucleic acid)
+        HELX_OT_P: Flag.Helix,  // helix with handedness and type that do not conform to an accepted category (protein)
+        HELX_P: Flag.Helix,  // helix with handedness and type not specified (protein)
+        HELX_RH_27_P: Flag.Helix | Flag.RightHanded | Flag.Helix27,  // right-handed 2-7 helix (protein)
+        HELX_RH_3T_P: Flag.Helix | Flag.RightHanded | Flag.Helix3Ten,  // right-handed 3-10 helix (protein)
+        HELX_RH_AL_P: Flag.Helix | Flag.RightHanded | Flag.HelixAlpha,  // right-handed alpha helix (protein)
+        HELX_RH_A_N: Flag.DoubleHelix | Flag.RightHanded | Flag.DoubleHelixA,  // right-handed A helix (nucleic acid)
+        HELX_RH_B_N: Flag.DoubleHelix | Flag.RightHanded | Flag.DoubleHelixB,  // right-handed B helix (nucleic acid)
+        HELX_RH_GA_P: Flag.Helix | Flag.RightHanded | Flag.HelixGamma,  // right-handed gamma helix (protein)
+        HELX_RH_N: Flag.DoubleHelix | Flag.RightHanded,  // right-handed helix with type not specified (nucleic acid)
+        HELX_RH_OM_P: Flag.Helix | Flag.RightHanded | Flag.HelixOmega,  // right-handed omega helix (protein)
+        HELX_RH_OT_N: Flag.DoubleHelix | Flag.RightHanded | Flag.DoubleHelixOther,  // right-handed helix with type that does not conform to an accepted category (nucleic acid)
+        HELX_RH_OT_P: Flag.Helix | Flag.RightHanded | Flag.HelixOther,  // right-handed helix with type that does not conform to an accepted category (protein)
+        HELX_RH_P: Flag.Helix | Flag.RightHanded,  // right-handed helix with type not specified (protein)
+        HELX_RH_PI_P: Flag.Helix | Flag.RightHanded | Flag.HelixPi,  // right-handed pi helix (protein)
+        HELX_RH_PP_P: Flag.Helix | Flag.RightHanded | Flag.HelixPolyproline,  // right-handed polyproline helix (protein)
+        HELX_RH_Z_N: Flag.DoubleHelix | Flag.RightHanded | Flag.DoubleHelixZ,  // right-handed Z helix (nucleic acid)
+        STRN: Flag.Beta | Flag.BetaStrand,  // beta strand (protein)
+        TURN_OT_P: Flag.Turn | Flag.TurnOther,  // turn with type that does not conform to an accepted category (protein)
+        TURN_P: Flag.Turn,  // turn with type not specified (protein)
+        TURN_TY1P_P: Flag.Turn | Flag.InverseTurn | Flag.Turn1,  // type I prime turn (protein)
+        TURN_TY1_P: Flag.Turn | Flag.ClassicTurn | Flag.Turn1,  // type I turn (protein)
+        TURN_TY2P_P: Flag.Turn | Flag.InverseTurn | Flag.Turn2,  // type II prime turn (protein)
+        TURN_TY2_P: Flag.Turn | Flag.ClassicTurn | Flag.Turn2,  // type II turn (protein)
+        TURN_TY3P_P: Flag.Turn | Flag.InverseTurn | Flag.Turn3,  // type III prime turn (protein)
+        TURN_TY3_P: Flag.Turn | Flag.ClassicTurn | Flag.Turn3,  // type III turn (protein)
+    }
+
+    export const SecondaryStructurePdb: { [value: string]: number } = {
+        1: Flag.Helix | Flag.RightHanded | Flag.HelixAlpha,  // Right-handed alpha (default)
+        2: Flag.Helix | Flag.RightHanded | Flag.HelixOmega,  // Right-handed omega
+        3: Flag.Helix | Flag.RightHanded | Flag.HelixPi,  // Right-handed pi
+        4: Flag.Helix | Flag.RightHanded | Flag.HelixGamma,  // Right-handed gamma
+        5: Flag.Helix | Flag.RightHanded | Flag.Helix3Ten,  // Right-handed 310
+        6: Flag.Helix | Flag.LeftHanded | Flag.HelixAlpha,  // Left-handed alpha
+        7: Flag.Helix | Flag.LeftHanded | Flag.HelixOmega,  // Left-handed omega
+        8: Flag.Helix | Flag.LeftHanded | Flag.HelixGamma,  // Left-handed gamma
+        9: Flag.Helix | Flag.Helix27,  // 27 ribbon/helix
+        10: Flag.Helix | Flag.HelixPolyproline,  // Polyproline
+    }
+
+    export const SecondaryStructureStride: { [value: string]: number } = {
+        H: Flag.Helix | Flag.HelixAlpha,  // Alpha helix
+        G: Flag.Helix | Flag.Helix3Ten,  // 3-10 helix
+        I: Flag.Helix | Flag.HelixPi,  // PI-helix
+        E: Flag.Beta | Flag.BetaSheet,  // Extended conformation
+        B: Flag.Beta | Flag.BetaStrand,  // Isolated bridge
+        b: Flag.Beta | Flag.BetaStrand,  // Isolated bridge
+        T: Flag.Turn,  // Turn
+        C: Flag.NA,  // Coil (none of the above)
+    }
+
+    export const SecondaryStructureDssp: { [value: string]: number } = {
+        H: Flag.Helix | Flag.HelixAlpha,  // alpha-helix
+        B: Flag.Beta | Flag.BetaStrand,  // residue in isolated beta-bridge
+        E: Flag.Beta | Flag.BetaSheet,  // extended strand, participates in beta ladder
+        G: Flag.Helix | Flag.Helix3Ten,  // 3-helix (310 helix)
+        I: Flag.Helix | Flag.HelixPi,  // 5 helix (pi-helix)
+        T: Flag.Turn,  // hydrogen bonded turn
+        S: Flag.Turn,  // bend
+    }
+}
+
+export const VdwRadii = {
+    'H': 1.1,
+    'HE': 1.4,
+    'LI': 1.81,
+    'BE': 1.53,
+    'B': 1.92,
+    'C': 1.7,
+    'N': 1.55,
+    'O': 1.52,
+    'F': 1.47,
+    'NE': 1.54,
+    'NA': 2.27,
+    'MG': 1.73,
+    'AL': 1.84,
+    'SI': 2.1,
+    'P': 1.8,
+    'S': 1.8,
+    'CL': 1.75,
+    'AR': 1.88,
+    'K': 2.75,
+    'CA': 2.31,
+    'SC': 2.3,
+    'TI': 2.15,
+    'V': 2.05,
+    'CR': 2.05,
+    'MN': 2.05,
+    'FE': 2.05,
+    'CO': 2.0,
+    'NI': 2.0,
+    'CU': 2.0,
+    'ZN': 2.1,
+    'GA': 1.87,
+    'GE': 2.11,
+    'AS': 1.85,
+    'SE': 1.9,
+    'BR': 1.83,
+    'KR': 2.02,
+    'RB': 3.03,
+    'SR': 2.49,
+    'Y': 2.4,
+    'ZR': 2.3,
+    'NB': 2.15,
+    'MO': 2.1,
+    'TC': 2.05,
+    'RU': 2.05,
+    'RH': 2.0,
+    'PD': 2.05,
+    'AG': 2.1,
+    'CD': 2.2,
+    'IN': 2.2,
+    'SN': 1.93,
+    'SB': 2.17,
+    'TE': 2.06,
+    'I': 1.98,
+    'XE': 2.16,
+    'CS': 3.43,
+    'BA': 2.68,
+    'LA': 2.5,
+    'CE': 2.48,
+    'PR': 2.47,
+    'ND': 2.45,
+    'PM': 2.43,
+    'SM': 2.42,
+    'EU': 2.4,
+    'GD': 2.38,
+    'TB': 2.37,
+    'DY': 2.35,
+    'HO': 2.33,
+    'ER': 2.32,
+    'TM': 2.3,
+    'YB': 2.28,
+    'LU': 2.27,
+    'HF': 2.25,
+    'TA': 2.2,
+    'W': 2.1,
+    'RE': 2.05,
+    'OS': 2.0,
+    'IR': 2.0,
+    'PT': 2.05,
+    'AU': 2.1,
+    'HG': 2.05,
+    'TL': 1.96,
+    'PB': 2.02,
+    'BI': 2.07,
+    'PO': 1.97,
+    'AT': 2.02,
+    'RN': 2.2,
+    'FR': 3.48,
+    'RA': 2.83,
+    'AC': 2.0,
+    'TH': 2.4,
+    'PA': 2.0,
+    'U': 2.3,
+    'NP': 2.0,
+    'PU': 2.0,
+    'AM': 2.0,
+    'CM': 2.0,
+    'BK': 2.0,
+    'CF': 2.0,
+    'ES': 2.0,
+    'FM': 2.0,
+    'MD': 2.0,
+    'NO': 2.0,
+    'LR': 2.0,
+    'RF': 2.0,
+    'DB': 2.0,
+    'SG': 2.0,
+    'BH': 2.0,
+    'HS': 2.0,
+    'MT': 2.0,
+    'DS': 2.0,
+    'RG': 2.0,
+    'CN': 2.0,
+    'UUT': 2.0,
+    'FL': 2.0,
+    'UUP': 2.0,
+    'LV': 2.0,
+    'UUH': 2.0
+}
+export const DefaultVdwRadius = 2.0
\ No newline at end of file
diff --git a/src/mol-data/model/data/secondary-structure.ts b/src/mol-data/model/data/secondary-structure.ts
deleted file mode 100644
index 75d1f4b89..000000000
--- a/src/mol-data/model/data/secondary-structure.ts
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @author Alexander Rose <alexander.rose@weirdbyte.de>
- */
-
-const enum SSF {
-    None = 0x0,
-
-    // category
-    DoubleHelix = 0x1,
-    Helix = 0x2,
-    Beta = 0x4,
-    Turn = 0x8,
-
-    // category variant
-    LeftHanded = 0x10,  // helix
-    RightHanded = 0x20,
-
-    ClassicTurn = 0x40,  // turn
-    InverseTurn = 0x80,
-
-    // sub-category
-    HelixOther = 0x100,  // protein
-    Helix27 = 0x200,
-    Helix3Ten = 0x400,
-    HelixAlpha = 0x800,
-    HelixGamma = 0x1000,
-    HelixOmega = 0x2000,
-    HelixPi = 0x4000,
-    HelixPolyproline = 0x8000,
-
-    DoubleHelixOther = 0x10000,  // nucleic
-    DoubleHelixZ = 0x20000,
-    DoubleHelixA = 0x40000,
-    DoubleHelixB = 0x80000,
-
-    BetaOther = 0x100000,  // protein
-    BetaStrand = 0x200000,  // single strand
-    BetaSheet = 0x400000,  // multiple hydrogen bonded strands
-    BetaBarell = 0x800000,  // closed series of sheets
-
-    TurnOther = 0x1000000,  // protein
-    Turn1 = 0x2000000,
-    Turn2 = 0x4000000,
-    Turn3 = 0x8000000,
-
-    NA = 0x10000000,  // not applicable/available
-}
-export { SSF as SecondaryStructureFlag }
-
-export const SecondaryStructureMmcif: { [value: string]: number } = {
-    HELX_LH_27_P: SSF.Helix | SSF.LeftHanded | SSF.Helix27,  // left-handed 2-7 helix (protein)
-    HELX_LH_3T_P: SSF.Helix | SSF.LeftHanded | SSF.Helix3Ten,  // left-handed 3-10 helix (protein)
-    HELX_LH_AL_P: SSF.Helix | SSF.LeftHanded | SSF.HelixAlpha,  // left-handed alpha helix (protein)
-    HELX_LH_A_N: SSF.DoubleHelix | SSF.LeftHanded | SSF.DoubleHelixA,  // left-handed A helix (nucleic acid)
-    HELX_LH_B_N: SSF.DoubleHelix | SSF.LeftHanded | SSF.DoubleHelixB,  // left-handed B helix (nucleic acid)
-    HELX_LH_GA_P: SSF.Helix | SSF.LeftHanded | SSF.HelixGamma,  // left-handed gamma helix (protein)
-    HELX_LH_N: SSF.DoubleHelix | SSF.LeftHanded,  // left-handed helix with type not specified (nucleic acid)
-    HELX_LH_OM_P: SSF.Helix | SSF.LeftHanded | SSF.HelixOmega,  // left-handed omega helix (protein)
-    HELX_LH_OT_N: SSF.DoubleHelix | SSF.LeftHanded | SSF.DoubleHelixOther,  // left-handed helix with type that does not conform to an accepted category (nucleic acid)
-    HELX_LH_OT_P: SSF.Helix | SSF.LeftHanded | SSF.HelixOther,  // left-handed helix with type that does not conform to an accepted category (protein)
-    HELX_LH_P: SSF.Helix | SSF.LeftHanded,  // left-handed helix with type not specified (protein)
-    HELX_LH_PI_P: SSF.Helix | SSF.LeftHanded | SSF.HelixPi,  // left-handed pi helix (protein)
-    HELX_LH_PP_P: SSF.Helix | SSF.LeftHanded | SSF.HelixPolyproline,  // left-handed polyproline helix (protein)
-    HELX_LH_Z_N: SSF.DoubleHelix | SSF.LeftHanded | SSF.DoubleHelixZ,  // left-handed Z helix (nucleic acid)
-    HELX_N: SSF.DoubleHelix,  // helix with handedness and type not specified (nucleic acid)
-    HELX_OT_N: SSF.DoubleHelix,  // helix with handedness and type that do not conform to an accepted category (nucleic acid)
-    HELX_OT_P: SSF.Helix,  // helix with handedness and type that do not conform to an accepted category (protein)
-    HELX_P: SSF.Helix,  // helix with handedness and type not specified (protein)
-    HELX_RH_27_P: SSF.Helix | SSF.RightHanded | SSF.Helix27,  // right-handed 2-7 helix (protein)
-    HELX_RH_3T_P: SSF.Helix | SSF.RightHanded | SSF.Helix3Ten,  // right-handed 3-10 helix (protein)
-    HELX_RH_AL_P: SSF.Helix | SSF.RightHanded | SSF.HelixAlpha,  // right-handed alpha helix (protein)
-    HELX_RH_A_N: SSF.DoubleHelix | SSF.RightHanded | SSF.DoubleHelixA,  // right-handed A helix (nucleic acid)
-    HELX_RH_B_N: SSF.DoubleHelix | SSF.RightHanded | SSF.DoubleHelixB,  // right-handed B helix (nucleic acid)
-    HELX_RH_GA_P: SSF.Helix | SSF.RightHanded | SSF.HelixGamma,  // right-handed gamma helix (protein)
-    HELX_RH_N: SSF.DoubleHelix | SSF.RightHanded,  // right-handed helix with type not specified (nucleic acid)
-    HELX_RH_OM_P: SSF.Helix | SSF.RightHanded | SSF.HelixOmega,  // right-handed omega helix (protein)
-    HELX_RH_OT_N: SSF.DoubleHelix | SSF.RightHanded | SSF.DoubleHelixOther,  // right-handed helix with type that does not conform to an accepted category (nucleic acid)
-    HELX_RH_OT_P: SSF.Helix | SSF.RightHanded | SSF.HelixOther,  // right-handed helix with type that does not conform to an accepted category (protein)
-    HELX_RH_P: SSF.Helix | SSF.RightHanded,  // right-handed helix with type not specified (protein)
-    HELX_RH_PI_P: SSF.Helix | SSF.RightHanded | SSF.HelixPi,  // right-handed pi helix (protein)
-    HELX_RH_PP_P: SSF.Helix | SSF.RightHanded | SSF.HelixPolyproline,  // right-handed polyproline helix (protein)
-    HELX_RH_Z_N: SSF.DoubleHelix | SSF.RightHanded | SSF.DoubleHelixZ,  // right-handed Z helix (nucleic acid)
-    STRN: SSF.Beta | SSF.BetaStrand,  // beta strand (protein)
-    TURN_OT_P: SSF.Turn | SSF.TurnOther,  // turn with type that does not conform to an accepted category (protein)
-    TURN_P: SSF.Turn,  // turn with type not specified (protein)
-    TURN_TY1P_P: SSF.Turn | SSF.InverseTurn | SSF.Turn1,  // type I prime turn (protein)
-    TURN_TY1_P: SSF.Turn | SSF.ClassicTurn | SSF.Turn1,  // type I turn (protein)
-    TURN_TY2P_P: SSF.Turn | SSF.InverseTurn | SSF.Turn2,  // type II prime turn (protein)
-    TURN_TY2_P: SSF.Turn | SSF.ClassicTurn | SSF.Turn2,  // type II turn (protein)
-    TURN_TY3P_P: SSF.Turn | SSF.InverseTurn | SSF.Turn3,  // type III prime turn (protein)
-    TURN_TY3_P: SSF.Turn | SSF.ClassicTurn | SSF.Turn3,  // type III turn (protein)
-}
-
-export const SecondaryStructurePdb: { [value: string]: number } = {
-    1: SSF.Helix | SSF.RightHanded | SSF.HelixAlpha,  // Right-handed alpha (default)
-    2: SSF.Helix | SSF.RightHanded | SSF.HelixOmega,  // Right-handed omega
-    3: SSF.Helix | SSF.RightHanded | SSF.HelixPi,  // Right-handed pi
-    4: SSF.Helix | SSF.RightHanded | SSF.HelixGamma,  // Right-handed gamma
-    5: SSF.Helix | SSF.RightHanded | SSF.Helix3Ten,  // Right-handed 310
-    6: SSF.Helix | SSF.LeftHanded | SSF.HelixAlpha,  // Left-handed alpha
-    7: SSF.Helix | SSF.LeftHanded | SSF.HelixOmega,  // Left-handed omega
-    8: SSF.Helix | SSF.LeftHanded | SSF.HelixGamma,  // Left-handed gamma
-    9: SSF.Helix | SSF.Helix27,  // 27 ribbon/helix
-    10: SSF.Helix | SSF.HelixPolyproline,  // Polyproline
-}
-
-export const SecondaryStructureStride: { [value: string]: number } = {
-    H: SSF.Helix | SSF.HelixAlpha,  // Alpha helix
-    G: SSF.Helix | SSF.Helix3Ten,  // 3-10 helix
-    I: SSF.Helix | SSF.HelixPi,  // PI-helix
-    E: SSF.Beta | SSF.BetaSheet,  // Extended conformation
-    B: SSF.Beta | SSF.BetaStrand,  // Isolated bridge
-    b: SSF.Beta | SSF.BetaStrand,  // Isolated bridge
-    T: SSF.Turn,  // Turn
-    C: SSF.NA,  // Coil (none of the above)
-}
-
-export const SecondaryStructureDssp: { [value: string]: number } = {
-    H: SSF.Helix | SSF.HelixAlpha,  // alpha-helix
-    B: SSF.Beta | SSF.BetaStrand,  // residue in isolated beta-bridge
-    E: SSF.Beta | SSF.BetaSheet,  // extended strand, participates in beta ladder
-    G: SSF.Helix | SSF.Helix3Ten,  // 3-helix (310 helix)
-    I: SSF.Helix | SSF.HelixPi,  // 5 helix (pi-helix)
-    T: SSF.Turn,  // hydrogen bonded turn
-    S: SSF.Turn,  // bend
-}
\ No newline at end of file
diff --git a/src/mol-data/model/properties/computed.ts b/src/mol-data/model/properties/computed.ts
new file mode 100644
index 000000000..ad7120fc0
--- /dev/null
+++ b/src/mol-data/model/properties/computed.ts
@@ -0,0 +1,7 @@
+/**
+ * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author David Sehnal <david.sehnal@gmail.com>
+ */
+
+// TODO: stuff like "residue type/flags", isRingAtom, rings, bonds??, wrap these in a computation?
\ No newline at end of file
diff --git a/src/mol-data/model/data/conformation.ts b/src/mol-data/model/properties/conformation.ts
similarity index 62%
rename from src/mol-data/model/data/conformation.ts
rename to src/mol-data/model/properties/conformation.ts
index ac90abac4..5cec094ae 100644
--- a/src/mol-data/model/data/conformation.ts
+++ b/src/mol-data/model/properties/conformation.ts
@@ -4,8 +4,7 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
-import { SecondaryStructureFlag as SSF } from './secondary-structure'
-import BitFlags from '../../../mol-base/utils/bit-flags'
+import { SecondaryStructureType } from '../constants'
 import Segmentation from '../../../mol-base/collections/integer/segmentation'
 
 interface Positions {
@@ -15,14 +14,14 @@ interface Positions {
 }
 
 interface SecondaryStructure {
-    ofResidue: ArrayLike<BitFlags<SSF>>,
-    // atom segmentation
+    ofResidue: ArrayLike<SecondaryStructureType>,
+    // atom segmentation??
     segments: Segmentation
 }
 
 interface Conformation {
     positions: Positions,
-    secondaryStructureType: SecondaryStructure
+    secondaryStructure: SecondaryStructure
 }
 
-export default Conformation
+export default Conformation
\ No newline at end of file
diff --git a/src/mol-data/model/common/keys.ts b/src/mol-data/model/properties/format-specific.ts
similarity index 75%
rename from src/mol-data/model/common/keys.ts
rename to src/mol-data/model/properties/format-specific.ts
index 1a7b5e35b..2a7bb4398 100644
--- a/src/mol-data/model/common/keys.ts
+++ b/src/mol-data/model/properties/format-specific.ts
@@ -3,3 +3,5 @@
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  */
+
+// TODO add access to things like MOL2 charge ...
\ No newline at end of file
diff --git a/src/mol-data/model/data/macromolecule.ts b/src/mol-data/model/properties/hierarchy.ts
similarity index 65%
rename from src/mol-data/model/data/macromolecule.ts
rename to src/mol-data/model/properties/hierarchy.ts
index f96f45163..1e7cfd5ef 100644
--- a/src/mol-data/model/data/macromolecule.ts
+++ b/src/mol-data/model/properties/hierarchy.ts
@@ -32,9 +32,7 @@ export const ResiduesSchema = {
     auth_comp_id: mmCIF.atom_site.auth_comp_id,
     label_seq_id: mmCIF.atom_site.label_seq_id,
     auth_seq_id: mmCIF.atom_site.auth_seq_id,
-    pdbx_PDB_ins_code: mmCIF.atom_site.pdbx_PDB_ins_code,
-
-    key: Column.Type.int
+    pdbx_PDB_ins_code: mmCIF.atom_site.pdbx_PDB_ins_code
 };
 
 export interface Residues extends Table<typeof AtomsSchema> { }
@@ -44,10 +42,7 @@ export const ChainsSchema = {
     auth_asym_id: mmCIF.atom_site.auth_asym_id,
     auth_comp_id: mmCIF.atom_site.auth_comp_id,
     label_entity_id: mmCIF.atom_site.label_entity_id,
-    pdbx_PDB_model_num: mmCIF.atom_site.pdbx_PDB_model_num,
-
-    key: Column.Type.int,
-    entityIndex: Column.Type.int
+    pdbx_PDB_model_num: mmCIF.atom_site.pdbx_PDB_model_num
 }
 
 export interface Chains extends Table<typeof ChainsSchema> { }
@@ -55,11 +50,33 @@ export interface Chains extends Table<typeof ChainsSchema> { }
 export const EntitySchema = mmCIF['entity']
 export interface Entities extends Table<typeof EntitySchema> { }
 
-export interface Macromolecule {
+export interface HierarchyData {
     atoms: Atoms,
     residues: Residues,
     chains: Chains,
     entities: Entities
 }
 
-export default Macromolecule
\ No newline at end of file
+export interface HierarchyKeys {
+    // indicate whether the keys form an increasing sequence (in other words, the residues are sorted).
+    // monotonous sequences enable for example faster secodnary structure assignment.
+    isMonotonous: number,
+
+    // assign a key to each residue index.
+    residue: ArrayLike<number>,
+    // assign a key to each chain index
+    chain: ArrayLike<number>,
+    // assigne a key to each chain index
+    // also index to the Entities table.
+    entity: ArrayLike<number>,
+
+    findEntity(id: string): number,
+    findChain(entityId: string, label_asym_id: string): number,
+    findResidue(entityId: string, label_asym_id: string, label_comp_id: string, label_seq_id: number, pdbx_PDB_ins_code: string): number
+}
+
+export interface Hierarchy extends HierarchyData {
+    keys: HierarchyKeys
+}
+
+export default Hierarchy
\ No newline at end of file
diff --git a/src/mol-data/model/data/transforms.ts b/src/mol-data/model/properties/transforms.ts
similarity index 100%
rename from src/mol-data/model/data/transforms.ts
rename to src/mol-data/model/properties/transforms.ts
diff --git a/src/mol-data/model/utils/hierarchy-keys.ts b/src/mol-data/model/utils/hierarchy-keys.ts
new file mode 100644
index 000000000..f65eb69ab
--- /dev/null
+++ b/src/mol-data/model/utils/hierarchy-keys.ts
@@ -0,0 +1,14 @@
+/**
+ * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author David Sehnal <david.sehnal@gmail.com>
+ */
+
+import { HierarchyData, HierarchyKeys } from '../properties/hierarchy'
+
+function create(data: HierarchyData): HierarchyKeys {
+
+    return 0 as any;
+}
+
+export default create;
\ No newline at end of file
diff --git a/src/mol-data/structure/atom.ts b/src/mol-data/structure/atom.ts
index 7a6ef43aa..a15da5213 100644
--- a/src/mol-data/structure/atom.ts
+++ b/src/mol-data/structure/atom.ts
@@ -5,6 +5,9 @@
  */
 
 import Tuple from '../../mol-base/collections/integer/tuple'
+import Structure from '../structure'
+import Unit from './unit'
+import Model from '../model'
 
 /** Atom pointer */
 interface Atom { '@type': Tuple['@type'] }
@@ -17,6 +20,19 @@ namespace Atom {
     export const index: (a: Atom) => number = Tuple.snd;
     export const areEqual: (a: Atom, b: Atom) => boolean = Tuple.areEqual;
     export const hashCode: (a: Atom) => number = Tuple.hashCode;
+
+    /** All the information required to access atom properties */
+    export interface Location {
+        structure: Structure,
+        unit: Unit,
+        model: Model,
+        atomIndex: number,
+        residueIndex: number,
+        chainIndex: number
+    }
+
+    export interface Property<T> { (location: Atom): T }
+    export interface Predicate extends Property<boolean> { }
 }
 
 export default Atom
\ No newline at end of file
diff --git a/src/mol-io/reader/cif/schema/mmcif.ts b/src/mol-io/reader/cif/schema/mmcif.ts
index 839ee23e8..f9b7b9a6c 100644
--- a/src/mol-io/reader/cif/schema/mmcif.ts
+++ b/src/mol-io/reader/cif/schema/mmcif.ts
@@ -14,7 +14,7 @@ const entry = {
     id: str
 }
 
-type EntityType = 'polymer' | 'non-polymer' | 'water'
+type EntityType = 'polymer' | 'non-polymer' | 'water' | 'macrolide'
 
 const entity = {
     id: str,
-- 
GitLab