From dd6dcddabad88e971b64fadbc6ce9cc9b8a26e2b Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Sat, 9 Jun 2018 12:41:27 +0200 Subject: [PATCH] Update Structure construction from Model --- src/apps/structure-info/model.ts | 2 +- .../structure/structure/structure.ts | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/apps/structure-info/model.ts b/src/apps/structure-info/model.ts index c06c66e4e..6a8ce6309 100644 --- a/src/apps/structure-info/model.ts +++ b/src/apps/structure-info/model.ts @@ -196,7 +196,7 @@ async function run(mmcif: mmCIF_Database) { //printIHMModels(models[0]); printUnits(structure); //printRings(structure); - printLinks(structure, true, true); + //printLinks(structure, true, true); //printModRes(models[0]); //printSecStructure(models[0]); } diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts index 22666fb13..78ef1b470 100644 --- a/src/mol-model/structure/structure/structure.ts +++ b/src/mol-model/structure/structure/structure.ts @@ -94,25 +94,27 @@ namespace Structure { export function create(units: ReadonlyArray<Unit>): Structure { return new Structure(units); } + /** + * Construct a Structure from a model. + * + * Generally, a single unit corresponds to a single chain, with the exception + * of consecutive "single atom chains". + */ export function ofModel(model: Model): Structure { const chains = model.atomicHierarchy.chainSegments; const builder = new StructureBuilder(); - const { residueSegments: { segmentMap: residueIndex } } = model.atomicHierarchy; - for (let c = 0; c < chains.count; c++) { const start = chains.segments[c]; - let end = chains.segments[c + 1]; - let rStart = residueIndex[start], rEnd = residueIndex[end - 1]; - while (rEnd - rStart <= 1 && c + 1 < chains.count) { + // merge all consecutive "single atom chains" + while (c + 1 < chains.count + && chains.segments[c + 1] - chains.segments[c] === 1 + && chains.segments[c + 2] - chains.segments[c + 1] === 1) { c++; - end = chains.segments[c + 1]; - rStart = rEnd; - rEnd = residueIndex[end - 1]; } - const elements = SortedArray.ofBounds(start, end); + const elements = SortedArray.ofBounds(start, chains.segments[c + 1]); builder.addUnit(Unit.Kind.Atomic, model, SymmetryOperator.Default, elements); } -- GitLab