diff --git a/src/mol-script/transpilers/pymol/properties.ts b/src/mol-script/transpilers/pymol/properties.ts index 106ddf36941358d400190fb3e3bbeebea99ec44a..66279b4818ba0b737d5c6c4b372a4970f3ff0b75 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)]; } }