From 93e107f33333f9cba5bbafedf852af3c9137ce19 Mon Sep 17 00:00:00 2001 From: yakomaxa <47655565+yakomaxa@users.noreply.github.com> Date: Sun, 21 Aug 2022 19:32:45 +0900 Subject: [PATCH] give pymol the ability to deal with negatively indexed residue numbering --- .../transpilers/pymol/properties.ts | 56 +++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/mol-script/transpilers/pymol/properties.ts b/src/mol-script/transpilers/pymol/properties.ts index 106ddf369..66279b481 100644 --- a/src/mol-script/transpilers/pymol/properties.ts +++ b/src/mol-script/transpilers/pymol/properties.ts @@ -14,31 +14,65 @@ const reFloat = /[-+]?[0-9]*\.?[0-9]+/; function atomNameListMap(x: string) { return x.split('+').map(B.atomName); } function listMap(x: string) { return x.split('+').map(x => x.replace(/^["']|["']$/g, '')); } -function rangeMap(x: string) { - const [min, max] = x.split('-').map(x => parseInt(x)); - return { min, max }; -} + function listOrRangeMap(x: string) { + // cases if (x.includes('-') && x.includes('+')) { const pSplit = x.split('+').map(x => x.replace(/^["']|["']$/g, '')); const res: number[] = []; pSplit.forEach(x => { - if (x.includes('-')) { + if (x.includes('-') && !x.startsWith("-")) { const [min, max] = x.split('-').map(x=>parseInt(x)); for (let i = min; i <= max; i++) { - res.push(i); + res.push(i); } - } else { + }else if (x.includes('-') && x.startsWith("-") && x.match(/[0-9]+-[-0-9]+/)) { + const min = -parseInt(x.split('-')[1]); + var max ; + if (x.includes('--')) { + max = -parseInt(x.split('-')[3]) + }else{ + max = parseInt(x.split('-')[2]) + } + for (let i = min; i <= max; i++) { + res.push(i); + } + }else if (x.includes('-') && x.startsWith("-") && !x.match(/[0-9]+-[0-9]+/)) { + res.push(parseInt(x)); + }else{ res.push(parseInt(x)); - } + } }); return res; } else if (x.includes('-') && !x.includes('+')) { - return rangeMap(x); + const res: number[] = []; + if (!x.startsWith("-")) { + const [min, max] = x.split('-').map(x=>parseInt(x)); + for (let i = min; i <= max; i++) { + res.push(i); + } + }else if (x.startsWith("-") && x.match(/[0-9]+-[-0-9]+/)) { + const min = -parseInt(x.split('-')[1]); + console.log(min) + var max ; + if (x.includes('--')) { + max = -parseInt(x.split('-')[3]) + }else{ + max = parseInt(x.split('-')[2]) + } + for (let i = min; i <= max; i++) { + res.push(i); + } + }else if (x.startsWith("-") && !x.match(/[0-9]+-[0-9]+/)) { + res.push(parseInt(x)); + }else{ + res.push(parseInt(x)); + } + return res; } else if (!x.includes('-') && x.includes('+')) { - return listMap(x).map(x => parseInt(x)); + return listMap(x).map(x => parseInt(x)); } else { - return listMap(x).map(x => parseInt(x)); + return [parseInt(x)]; } } -- GitLab