Browse Source

mol-model-formats: mmCIF substitute undefined atom_site.label_* with auth_* columns (and vice versa)

David Sehnal 5 years ago
parent
commit
c5e64b39db

+ 18 - 0
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 };
 }
 

+ 1 - 4
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)) {