From ee43a971b308cad5eff4cb002439b6cc2c5f7ee0 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Fri, 22 Jun 2018 16:21:24 -0700
Subject: [PATCH] added model.properties.asymIdSerialMap

---
 .../structure/model/formats/mmcif.ts          | 26 ++++++++++++++++---
 src/mol-model/structure/model/model.ts        |  5 ++--
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/mol-model/structure/model/formats/mmcif.ts b/src/mol-model/structure/model/formats/mmcif.ts
index abd3a7a59..6bb1c3566 100644
--- a/src/mol-model/structure/model/formats/mmcif.ts
+++ b/src/mol-model/structure/model/formats/mmcif.ts
@@ -135,7 +135,7 @@ function isHierarchyDataEqual(a: AtomicData, b: AtomicData) {
         && Table.areEqual(a.atoms as Table<AtomsSchema>, b.atoms as Table<AtomsSchema>)
 }
 
-function modResMap(format: mmCIF_Format) {
+function getModifiedResidueNameMap(format: mmCIF_Format) {
     const data = format.data.pdbx_struct_mod_residue;
     const map = new Map<string, string>();
     const comp_id = data.label_comp_id.isDefined ? data.label_comp_id : data.auth_comp_id;
@@ -148,6 +148,24 @@ function modResMap(format: mmCIF_Format) {
     return map;
 }
 
+function getAsymIdSerialMap(format: mmCIF_Format) {
+    const data = format.data.struct_asym;
+    const map = new Map<string, number>();
+    let serial = 0
+
+    const id = data.id
+    const count = data._rowCount
+    for (let i = 0; i < count; ++i) {
+        const _id = id.value(i)
+        if (!map.has(_id)) {
+            map.set(_id, serial)
+            serial += 1
+        }
+    }
+
+    return map;
+}
+
 function createModel(format: mmCIF_Format, atom_site: AtomSite, previous?: Model): Model {
     const hierarchyOffsets = findHierarchyOffsets(atom_site);
     const hierarchyData = createHierarchyData(atom_site, hierarchyOffsets);
@@ -176,7 +194,8 @@ function createModel(format: mmCIF_Format, atom_site: AtomSite, previous?: Model
         ? format.data.entry.id.value(0)
         : format.data._name;
 
-    const modifiedResidueNameMap = modResMap(format);
+    const modifiedResidueNameMap = getModifiedResidueNameMap(format);
+    const asymIdSerialMap = getAsymIdSerialMap(format)
 
     return {
         id: UUID.create(),
@@ -191,7 +210,8 @@ function createModel(format: mmCIF_Format, atom_site: AtomSite, previous?: Model
         coarseConformation: coarse.conformation,
         properties: {
             secondaryStructure: getSecondaryStructureMmCif(format.data, atomicHierarchy),
-            modifiedResidueNameMap
+            modifiedResidueNameMap,
+            asymIdSerialMap
         },
         symmetry: getSymmetry(format)
     };
diff --git a/src/mol-model/structure/model/model.ts b/src/mol-model/structure/model/model.ts
index 6ade4fe45..48a16e133 100644
--- a/src/mol-model/structure/model/model.ts
+++ b/src/mol-model/structure/model/model.ts
@@ -13,7 +13,7 @@ import { CoarseHierarchy, CoarseConformation } from './properties/coarse'
 import { Entities } from './properties/common';
 import { SecondaryStructure } from './properties/seconday-structure';
 
-//import from_gro from './formats/gro'
+// import from_gro from './formats/gro'
 import from_mmCIF from './formats/mmcif'
 /**
  * Interface to the "source data" of the molecule.
@@ -40,6 +40,7 @@ interface Model extends Readonly<{
         readonly secondaryStructure: SecondaryStructure,
         // maps modified residue name to its parent
         readonly modifiedResidueNameMap: Map<string, string>,
+        readonly asymIdSerialMap: Map<string, number>,
         [customName: string]: any
     },
 
@@ -54,7 +55,7 @@ interface Model extends Readonly<{
 namespace Model {
     export function create(format: Format) {
         switch (format.kind) {
-            //case 'gro': return from_gro(format);
+            // case 'gro': return from_gro(format);
             case 'mmCIF': return from_mmCIF(format);
         }
     }
-- 
GitLab