Browse Source

rename IndexPairBonds mapping field from id to key

Alexander Rose 3 years ago
parent
commit
73be238ac4

+ 1 - 1
CHANGELOG.md

@@ -10,7 +10,7 @@ Note that since we don't clearly distinguish between a public and private interf
 - Move Viewer APP to a separate file to allow use without importing light theme & index.html
 - Add symmetry support for mol2 files (only spacegroup setting 1)
 - Improve bond assignment from ``IndexPairBonds``
-    - Add ``id`` for mapping to source data
+    - Add ``key`` field for mapping to source data
     - Fix assignment of bonds with unphysical length
 - Fix label/stats of single atom selection in multi-chain units
 

+ 2 - 2
src/mol-model-formats/structure/mol2.ts

@@ -77,7 +77,7 @@ async function getModels(mol2: Mol2File, ctx: RuntimeContext) {
         if (_models.frameCount > 0) {
             const indexA = Column.ofIntArray(Column.mapToArray(bonds.origin_atom_id, x => x - 1, Int32Array));
             const indexB = Column.ofIntArray(Column.mapToArray(bonds.target_atom_id, x => x - 1, Int32Array));
-            const id = bonds.bond_id;
+            const key = bonds.bond_id;
             const order = Column.ofIntArray(Column.mapToArray(bonds.bond_type, x => {
                 switch (x) {
                     case 'ar': // aromatic
@@ -104,7 +104,7 @@ async function getModels(mol2: Mol2File, ctx: RuntimeContext) {
                         return BondType.Flag.Covalent;
                 }
             }, Int8Array));
-            const pairBonds = IndexPairBonds.fromData({ pairs: { id, indexA, indexB, order, flag }, count: atoms.count });
+            const pairBonds = IndexPairBonds.fromData({ pairs: { key, indexA, indexB, order, flag }, count: atoms.count });
 
             const first = _models.representative;
             IndexPairBonds.Provider.set(first, pairBonds);

+ 7 - 7
src/mol-model-formats/structure/property/bonds/index-pair.ts

@@ -12,7 +12,7 @@ import { BondType } from '../../../../mol-model/structure/model/types';
 import { ElementIndex } from '../../../../mol-model/structure';
 
 export type IndexPairsProps = {
-    readonly id: ArrayLike<number>
+    readonly key: ArrayLike<number>
     readonly order: ArrayLike<number>
     readonly distance: ArrayLike<number>
     readonly flag: ArrayLike<BondType.Flag>
@@ -22,19 +22,19 @@ export type IndexPairBonds = { bonds: IndexPairs, maxDistance: number }
 
 function getGraph(indexA: ArrayLike<ElementIndex>, indexB: ArrayLike<ElementIndex>, props: Partial<IndexPairsProps>, count: number): IndexPairs {
     const builder = new IntAdjacencyGraph.EdgeBuilder(count, indexA, indexB);
-    const id = new Int32Array(builder.slotCount);
+    const key = new Int32Array(builder.slotCount);
     const order = new Int8Array(builder.slotCount);
     const distance = new Array(builder.slotCount);
     const flag = new Array(builder.slotCount);
     for (let i = 0, _i = builder.edgeCount; i < _i; i++) {
         builder.addNextEdge();
-        builder.assignProperty(id, props.id ? props.id[i] : -1);
+        builder.assignProperty(key, props.key ? props.key[i] : -1);
         builder.assignProperty(order, props.order ? props.order[i] : 1);
         builder.assignProperty(distance, props.distance ? props.distance[i] : -1);
         builder.assignProperty(flag, props.flag ? props.flag[i] : BondType.Flag.Covalent);
     }
 
-    return builder.createGraph({ id, order, distance, flag });
+    return builder.createGraph({ key, order, distance, flag });
 }
 
 export namespace IndexPairBonds {
@@ -48,7 +48,7 @@ export namespace IndexPairBonds {
         pairs: {
             indexA: Column<number>,
             indexB: Column<number>,
-            id?: Column<number>,
+            key?: Column<number>,
             order?: Column<number>,
             /**
              * Useful for bonds in periodic cells. That is, only bonds within the given
@@ -77,12 +77,12 @@ export namespace IndexPairBonds {
         const { pairs, count } = data;
         const indexA = pairs.indexA.toArray() as ArrayLike<ElementIndex>;
         const indexB = pairs.indexB.toArray() as ArrayLike<ElementIndex>;
-        const id = pairs.id && pairs.id.toArray();
+        const key = pairs.key && pairs.key.toArray();
         const order = pairs.order && pairs.order.toArray();
         const distance = pairs.distance && pairs.distance.toArray();
         const flag = pairs.flag && pairs.flag.toArray();
         return {
-            bonds: getGraph(indexA, indexB, { id, order, distance, flag }, count),
+            bonds: getGraph(indexA, indexB, { key, order, distance, flag }, count),
             maxDistance: p.maxDistance
         };
     }