From cad44a07f00865f831f59b7b297f969c3ca3b478 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Tue, 11 Sep 2018 00:14:25 +0200
Subject: [PATCH] Fixed inter-unit bond computation for transformed units

---
 .../model/formats/mmcif/bonds/struct_conn.ts         | 12 ++++++------
 .../structure/structure/unit/links/inter-compute.ts  |  4 +++-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/mol-model/structure/model/formats/mmcif/bonds/struct_conn.ts b/src/mol-model/structure/model/formats/mmcif/bonds/struct_conn.ts
index 75a4afa89..3296debca 100644
--- a/src/mol-model/structure/model/formats/mmcif/bonds/struct_conn.ts
+++ b/src/mol-model/structure/model/formats/mmcif/bonds/struct_conn.ts
@@ -14,11 +14,11 @@ import { ModelPropertyDescriptor } from '../../../properties/custom';
 import { mmCIF_Database, mmCIF_Schema } from 'mol-io/reader/cif/schema/mmcif';
 import { SortedArray } from 'mol-data/int';
 import { CifWriter } from 'mol-io/writer/cif'
-import { ElementIndex } from '../../../indexing';
+import { ElementIndex, ResidueIndex } from '../../../indexing';
 
 export interface StructConn {
-    getResidueEntries(residueAIndex: number, residueBIndex: number): ReadonlyArray<StructConn.Entry>,
-    getAtomEntries(atomIndex: number): ReadonlyArray<StructConn.Entry>,
+    getResidueEntries(residueAIndex: ResidueIndex, residueBIndex: ResidueIndex): ReadonlyArray<StructConn.Entry>,
+    getAtomEntries(atomIndex: ElementIndex): ReadonlyArray<StructConn.Entry>,
     readonly entries: ReadonlyArray<StructConn.Entry>
 }
 
@@ -117,11 +117,11 @@ export namespace StructConn {
         }
 
 
-        getResidueEntries(residueAIndex: number, residueBIndex: number): ReadonlyArray<StructConn.Entry> {
+        getResidueEntries(residueAIndex: ResidueIndex, residueBIndex: ResidueIndex): ReadonlyArray<StructConn.Entry> {
             return this.getResiduePairIndex().get(_resKey(residueAIndex, residueBIndex)) || _emptyEntry;
         }
 
-        getAtomEntries(atomIndex: number): ReadonlyArray<StructConn.Entry> {
+        getAtomEntries(atomIndex: ElementIndex): ReadonlyArray<StructConn.Entry> {
             return this.getAtomIndex().get(atomIndex) || _emptyEntry;
         }
 
@@ -134,7 +134,7 @@ export namespace StructConn {
         distance: number,
         order: number,
         flags: number,
-        partners: { residueIndex: number, atomIndex: ElementIndex, symmetry: string }[]
+        partners: { residueIndex: ResidueIndex, atomIndex: ElementIndex, symmetry: string }[]
     }
 
     type StructConnType = typeof mmCIF_Schema.struct_conn.conn_type_id.T
diff --git a/src/mol-model/structure/structure/unit/links/inter-compute.ts b/src/mol-model/structure/structure/unit/links/inter-compute.ts
index cd8e37397..56c354a52 100644
--- a/src/mol-model/structure/structure/unit/links/inter-compute.ts
+++ b/src/mol-model/structure/structure/unit/links/inter-compute.ts
@@ -153,11 +153,13 @@ function findLinks(structure: Structure, params: LinkComputationParameters) {
     if (!structure.units.some(u => Unit.isAtomic(u))) return new InterUnitBonds(map);
 
     const lookup = structure.lookup3d;
+    const imageCenter = Vec3.zero();
     for (const unit of structure.units) {
         if (!Unit.isAtomic(unit)) continue;
 
         const bs = unit.lookup3d.boundary.sphere;
-        const closeUnits = lookup.findUnitIndices(bs.center[0], bs.center[1], bs.center[2], bs.radius + MAX_RADIUS);
+        Vec3.transformMat4(imageCenter, bs.center, unit.conformation.operator.matrix);
+        const closeUnits = lookup.findUnitIndices(imageCenter[0], imageCenter[1], imageCenter[2], bs.radius + MAX_RADIUS);
         for (let i = 0; i < closeUnits.count; i++) {
             const other = structure.units[closeUnits.indices[i]];
             if (!Unit.isAtomic(other) || unit.id >= other.id) continue;
-- 
GitLab