From c5e64b39dbe6d3e52c5746411c63d9bbf6250473 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Sun, 27 Oct 2019 11:53:37 +0100
Subject: [PATCH] mol-model-formats: mmCIF substitute undefined
 atom_site.label_* with auth_* columns (and vice versa)

---
 .../structure/mmcif/atomic.ts                  | 18 ++++++++++++++++++
 src/mol-plugin/ui/sequence/sequence.tsx        |  5 +----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/mol-model-formats/structure/mmcif/atomic.ts b/src/mol-model-formats/structure/mmcif/atomic.ts
index ba2356112..85f28233d 100644
--- a/src/mol-model-formats/structure/mmcif/atomic.ts
+++ b/src/mol-model-formats/structure/mmcif/atomic.ts
@@ -42,6 +42,15 @@ function findHierarchyOffsets(atom_site: AtomSite) {
     return { residues, chains };
 }
 
+function substUndefinedColumn<T extends Table<any>>(table: T, a: keyof T, b: keyof T) {
+    if (!(table as any)[a].isDefined) {
+        (table as any)[a] = (table as any)[b];
+    }
+    if (!(table as any)[b].isDefined) {
+        (table as any)[b] = (table as any)[a];
+    }
+}
+
 function createHierarchyData(atom_site: AtomSite, sourceIndex: Column<number>, offsets: { residues: ArrayLike<number>, chains: ArrayLike<number> }): AtomicData {
     const atoms = Table.ofColumns(AtomsSchema, {
         type_symbol: Column.ofArray({ array: Column.mapToArray(atom_site.type_symbol, ElementSymbol), schema: Column.Schema.Aliased<ElementSymbol>(Column.Schema.str) }),
@@ -51,11 +60,20 @@ function createHierarchyData(atom_site: AtomSite, sourceIndex: Column<number>, o
         pdbx_formal_charge: atom_site.pdbx_formal_charge,
         sourceIndex
     });
+
     const residues = Table.view(atom_site, ResiduesSchema, offsets.residues);
     // Optimize the numeric columns
     Table.columnToArray(residues, 'label_seq_id', Int32Array);
     Table.columnToArray(residues, 'auth_seq_id', Int32Array);
+
     const chains = Table.view(atom_site, ChainsSchema, offsets.chains);
+
+    // Fix possibly missing auth_/label_ columns
+    substUndefinedColumn(residues, 'label_seq_id', 'auth_seq_id');
+    substUndefinedColumn(atoms, 'label_atom_id', 'auth_atom_id');
+    substUndefinedColumn(residues, 'label_comp_id', 'auth_comp_id');
+    substUndefinedColumn(chains, 'label_asym_id', 'auth_asym_id');
+
     return { atoms, residues, chains };
 }
 
diff --git a/src/mol-plugin/ui/sequence/sequence.tsx b/src/mol-plugin/ui/sequence/sequence.tsx
index 1a76915e1..065337366 100644
--- a/src/mol-plugin/ui/sequence/sequence.tsx
+++ b/src/mol-plugin/ui/sequence/sequence.tsx
@@ -132,10 +132,7 @@ export class Sequence<P extends SequenceProps> extends PluginUIComponent<P> {
         const l = StructureElement.Loci.getFirstLocation(loci, this.location);
         if (l) {
             if (Unit.isAtomic(l.unit)) {
-                const { residues } = l.unit.model.atomicHierarchy
-                const seqId = residues.auth_seq_id.isDefined
-                    ? StructureProperties.residue.auth_seq_id(l)
-                    : StructureProperties.residue.label_seq_id(l)
+                const seqId = StructureProperties.residue.auth_seq_id(l)
                 const insCode = StructureProperties.residue.pdbx_PDB_ins_code(l)
                 sequenceNumber = `${seqId}${insCode ? insCode : ''}`
             } else if (Unit.isCoarse(l.unit)) {
-- 
GitLab