From f7c573d3bdfd402563873237b6549d002eae71c0 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Wed, 11 Jul 2018 08:58:23 +0200
Subject: [PATCH] Sort sheets in mmCIF export

---
 .../structure/export/categories/secondary-structure.ts     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/mol-model/structure/export/categories/secondary-structure.ts b/src/mol-model/structure/export/categories/secondary-structure.ts
index 35936e165..7d051ddc5 100644
--- a/src/mol-model/structure/export/categories/secondary-structure.ts
+++ b/src/mol-model/structure/export/categories/secondary-structure.ts
@@ -25,7 +25,7 @@ export function _struct_conf(ctx: CifExportContext): CifCategory {
 }
 
 export function _struct_sheet_range(ctx: CifExportContext): CifCategory {
-    const elements = findElements(ctx, 'sheet');
+    const elements = (findElements(ctx, 'sheet') as SSElement<SecondaryStructure.Sheet>[]).sort(compare_ssr);
     return {
         data: elements,
         name: 'struct_sheet_range',
@@ -34,6 +34,11 @@ export function _struct_sheet_range(ctx: CifExportContext): CifCategory {
     };
 }
 
+function compare_ssr(x: SSElement<SecondaryStructure.Sheet>, y: SSElement<SecondaryStructure.Sheet>) {
+    const a = x.element, b = y.element;
+    return a.sheet_id < b.sheet_id ? -1 : a.sheet_id === b.sheet_id ? x.start.element - y.start.element : 1
+};
+
 const struct_conf_fields: CifField[] = [
     CifField.str<number, SSElement<SecondaryStructure.Helix>[]>('conf_type_id', (i, data) => data[i].element.type_id),
     CifField.str<number, SSElement<SecondaryStructure.Helix>[]>('conf_type_id', (i, data, idx) => `${data[i].element.type_id}${idx + 1}`),
-- 
GitLab