From 3803181895901b4475583fa25580a96e9ebc00ef Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Wed, 6 Jun 2018 09:32:06 +0200
Subject: [PATCH] Element and Bond loci

---
 src/mol-model/structure/structure.ts          |  5 ++--
 src/mol-model/structure/structure/element.ts  | 15 +++++++++--
 .../structure/structure/unit/bonds.ts         | 26 ++++++++++++++++++-
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/mol-model/structure/structure.ts b/src/mol-model/structure/structure.ts
index c57bb2a47..44a299b2e 100644
--- a/src/mol-model/structure/structure.ts
+++ b/src/mol-model/structure/structure.ts
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  */
@@ -8,5 +8,6 @@ import Element from './structure/element'
 import Structure from './structure/structure'
 import Unit from './structure/unit'
 import StructureSymmetry from './structure/symmetry'
+import { Bond } from './structure/unit/bonds'
 
-export { Element, Structure, Unit, StructureSymmetry }
\ No newline at end of file
+export { Element, Bond, Structure, Unit, StructureSymmetry }
\ No newline at end of file
diff --git a/src/mol-model/structure/structure/element.ts b/src/mol-model/structure/structure/element.ts
index 48e030760..270fdcdf7 100644
--- a/src/mol-model/structure/structure/element.ts
+++ b/src/mol-model/structure/structure/element.ts
@@ -24,7 +24,7 @@ namespace Element {
 
     /** All the information required to access element properties */
     export interface Location { unit: Unit, element: number }
-    export function Location(): Location { return { unit: {} as any, element: 0 }; }
+    export function Location(unit?: Unit, element?: number): Location { return { unit: unit as any, element: element || 0 }; }
     export interface Property<T> { (location: Location): T }
     export interface Predicate extends Property<boolean> { }
 
@@ -37,7 +37,18 @@ namespace Element {
     export function property<T>(p: Property<T>) { return p; }
 
     /** Represents multiple element locations */
-    export type Loci = ReadonlyArray<{ unit: Unit, elements: SortedArray }>
+    export interface Loci {
+        readonly kind: 'element-loci',
+        readonly elements: ReadonlyArray<{ unit: Unit, elements: SortedArray }>
+    }
+
+    export function Loci(elements: ArrayLike<{ unit: Unit, elements: SortedArray }>): Loci {
+        return { kind: 'element-loci', elements: elements as Loci['elements'] };
+    }
+
+    export function isLoci(x: any): x is Loci {
+        return !!x && x.kind === 'element-loci';
+    }
 }
 
 export default Element
\ No newline at end of file
diff --git a/src/mol-model/structure/structure/unit/bonds.ts b/src/mol-model/structure/structure/unit/bonds.ts
index 6316c3eeb..73b6ff8d6 100644
--- a/src/mol-model/structure/structure/unit/bonds.ts
+++ b/src/mol-model/structure/structure/unit/bonds.ts
@@ -4,5 +4,29 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
+import { Element } from '../../structure'
+
 export * from './bonds/intra-data'
-export * from './bonds/intra-compute'
\ No newline at end of file
+export * from './bonds/intra-compute'
+
+interface Bond {
+    readonly a: Readonly<Element.Location>,
+    readonly b: Readonly<Element.Location>
+}
+
+namespace Bond {
+    export interface Loci {
+        readonly kind: 'bond-loci',
+        readonly bonds: ReadonlyArray<Bond>
+    }
+
+    export function Loci(bonds: ArrayLike<Bond>): Loci {
+        return { kind: 'bond-loci', bonds: bonds as Loci['bonds'] };
+    }
+
+    export function isLoci(x: any): x is Loci {
+        return !!x && x.kind === 'bond-loci';
+    }
+}
+
+export { Bond }
\ No newline at end of file
-- 
GitLab