Browse Source

give pymol the ability to deal with negatively indexed residue numbering

yakomaxa 2 years ago
parent
commit
93e107f333
1 changed files with 45 additions and 11 deletions
  1. 45 11
      src/mol-script/transpilers/pymol/properties.ts

+ 45 - 11
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)];
     }
 }