Browse Source

Rasmol parser WIP 4

yakomaxa 2 years ago
parent
commit
8a5cebd635

+ 21 - 1
src/mol-script/transpilers/pymol/properties.ts

@@ -19,8 +19,28 @@ function rangeMap(x: string) {
     return { min, max };
 }
 function listOrRangeMap(x: string) {
-    return x.includes('-') ? rangeMap(x) : listMap(x).map(x => parseInt(x));
+    if (x.includes('-') && x.includes('+')){
+        const pSplit = x.split('+').map(x => x.replace(/^["']|["']$/g, ''));
+        const res : number[] =[];
+        pSplit.forEach( x => {
+            if (x.includes('-')){
+                const [min, max] = x.split('-').map(x=>parseInt(x));
+                for (var i = min;  i <= max;  i++){
+                    res.push(i);
+                }
+            }else{
+                res.push(parseInt(x));
+            }
+        });
+        console.log(res)
+        return res;
+    }else if(x.includes('-') && !x.includes('+')){
+        return rangeMap(x)
+    }else if(!x.includes('-') && x.includes('+')){
+        return listMap(x)
+    }
 }
+
 function elementListMap(x: string) {
     return x.split('+').map(B.struct.type.elementSymbol);
 }

+ 1 - 1
src/mol-script/transpilers/rasmol/operators.ts

@@ -38,7 +38,7 @@ export const operators: OperatorList = [
         '@examples': ['ASP or GLU'],
         name: 'or',
         type: h.binaryLeft,
-        rule: h.infixOp(/OR|\|/i),
+        rule: h.infixOp(/OR|\||\|\|/i),
         map: (op, s1, s2) => B.struct.combinator.merge([s1, s2])
     }
 ];

+ 60 - 49
src/mol-script/transpilers/rasmol/parser.ts

@@ -32,8 +32,8 @@ const dot = P.MonadicParser.string('.');
 const colon = P.MonadicParser.string(':');
 const comma = P.MonadicParser.string(',');
 const star = P.MonadicParser.string('*');
-const bra = P.MonadicParser.string('[');
-const ket = P.MonadicParser.string(']');
+const bra = P.MonadicParser.string('(');
+const ket = P.MonadicParser.string(')');
 const numbers = P.MonadicParser.regexp(/[0-9]/);
 
 /* is Parser -> MonadicParser substitution correct? */
@@ -167,21 +167,26 @@ const lang = P.MonadicParser.createLanguage({
 
     Expression: function (r: any) {
         return P.MonadicParser.alt(
-	    //	    r.NamedAtomProperties,
-//	    r.AtomExpression.map(atomExpressionQuery),
-	    r.AtomSelectionMacro.map(atomSelectionQuery2),
-//	    r.AtomSelectionMacroResi.map(atomSelectionQuery2),
 //	    r.Keywords,
-//            r.Resno.lookahead(P.MonadicParser.regexp(/\s*(?!(LIKE|>=|<=|!=|[:^%/.=><]))/i)).map((x: any) => B.struct.generator.atomGroups({
-//                'residue-test': B.core.rel.eq([B.ammp('auth_seq_id'), x])
+//	    r.ValueQuery,
+	    r.AtomSelectionMacro.map(atomSelectionQuery2),
+	    r.AtomSelectionMacroResi.map(atomSelectionQuery2),
+//	    r.NamedAtomProperties,
+  
+
+  //          r.Resno.lookahead(P.MonadicParser.regexp(/\s*(?!(LIKE|>=|<=|!=|[:^%/.=><]))/i)).map((x: any) => B.struct.generator.atomGroups({	
+  //              'residue-test': B.core.rel.eq([B.ammp('auth_seq_id'), x])		
+//            })),
+//	    r.Atomno.lookahead(P.MonadicParser.regexp(/\s*(?!(LIKE|>=|<=|!=|[:^%/.=><]))/i)).map((x: any) => B.struct.generator.atomGroups({	
+  //              'atom-test': B.core.rel.eq([B.ammp('id'), x])		
 //            })),
-//            r.ValueQuery,
-  //          r.Element.map((x: string) => B.struct.generator.atomGroups({
+
+//            r.Element.map((x: string) => B.struct.generator.atomGroups({
 //                'atom-test': B.core.rel.eq([B.acp('elementSymbol'), B.struct.type.elementSymbol(x)])
-  //          })),
-  //          r.Resname.map((x: string) => B.struct.generator.atomGroups({
-    //            'residue-test': B.core.rel.eq([B.ammp('label_comp_id'), x])
-      //      })),
+//            })),
+//            r.Resname.map((x: string) => B.struct.generator.atomGroups({
+//		'residue-test': B.core.rel.eq([B.ammp('label_comp_id'), x])
+//            })),	  
         );
     },
 
@@ -215,40 +220,44 @@ const lang = P.MonadicParser.createLanguage({
                 ).map(x => { return {name: x[0] }; }),
             )),
 	    // 1-100 lys:a.ca lys:a lys lys.ca
-//	    numbers.then(P.MonadicParser.alt(
-//		P.MonadicParser.alt(
-//		    P.MonadicParser.seq(
-//			orNull(propertiesDict.resi),
-//		    ).map(x => { return { resi: x[0] };})
-//		))),
-            P.MonadicParser.alt(
-                P.MonadicParser.seq(
-                    orNull(propertiesDict.resn).skip(colon),
-                    orNull(propertiesDict.chain).skip(dot),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { resn: x[0], chain: x[1], name: x[2] }; }),
-		P.MonadicParser.seq(
-                    orNull(propertiesDict.resn).skip(star),
-                    orNull(propertiesDict.chain).skip(dot),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { resn: x[0], chain: x[1], name: x[2] }; }),
-                P.MonadicParser.seq(
-                    orNull(propertiesDict.resn).skip(colon),
-                    orNull(propertiesDict.chain),
-                ).map(x => { return { resn: x[0], chain: x[1] }; }),
-		P.MonadicParser.seq(
-                    orNull(propertiesDict.resn).skip(star),
-                    orNull(propertiesDict.chain),
-                ).map(x => { return { resn: x[0], chain: x[1] }; }),
-		P.MonadicParser.seq(
-                    orNull(propertiesDict.resn).skip(dot),
-                    orNull(propertiesDict.name),
-                ).map(x => { return { resn: x[0], name: x[1] }; }),
-		P.MonadicParser.seq(
-                    orNull(propertiesDict.resn),
-		).map(x => {  return { resn: x[0] };}),
-	    ),
-        );
+	    bra.then(P.MonadicParser.alt(
+		P.MonadicParser.alt(
+		    P.MonadicParser.seq(
+			orNull(propertiesDict.resi).skip(ket),
+		    ).map(x => { return { resi: x[0] };})
+		))),
+	    P.MonadicParser.alt(
+		P.MonadicParser.alt(
+                    P.MonadicParser.seq(
+			orNull(propertiesDict.resn).skip(colon),
+			orNull(propertiesDict.chain).skip(dot),
+			orNull(propertiesDict.name)
+                    ).map(x => { return { resn: x[0], chain: x[1], name: x[2] }; }),
+		    P.MonadicParser.seq(
+			orNull(propertiesDict.resn).skip(star),
+			orNull(propertiesDict.chain).skip(dot),
+			orNull(propertiesDict.name)
+                    ).map(x => { return { resn: x[0], chain: x[1], name: x[2] }; }),
+                    P.MonadicParser.seq(
+			orNull(propertiesDict.resn).skip(colon),
+			orNull(propertiesDict.chain),
+                    ).map(x => { return { resn: x[0], chain: x[1] }; }),
+		    P.MonadicParser.seq(
+			orNull(propertiesDict.resn).skip(star),
+			orNull(propertiesDict.chain),
+                    ).map(x => { return { resn: x[0], chain: x[1] }; }),
+		    P.MonadicParser.seq(
+			orNull(propertiesDict.resn).skip(dot),
+			orNull(propertiesDict.name),
+                    ).map(x => { return { resn: x[0], name: x[1] }; }),
+		    P.MonadicParser.seq(
+			orNull(propertiesDict.resn),
+		    ).map(x => {  return { resn: x[0] };}),
+		)
+	    )		  
+	    
+	)
+		    
     },
 
     AtomSelectionMacroResi: function (r: any) {
@@ -330,8 +339,9 @@ const lang = P.MonadicParser.createLanguage({
         return P.MonadicParser.seq(
             P.MonadicParser.lookahead(r.AtomPrefix),
             P.MonadicParser.seq(
-		r.ResnoRange.or(P.MonadicParser.of(null)),
+//		r.ResnoRange.or(P.MonadicParser.of(null)),
                 r.Resno.or(P.MonadicParser.of(null)),
+		r.Atomno.or(P.MonadicParser.of(null)),
 //		r.Resno2.or(P.MonadicParser.of(null)),
                 r.Inscode.or(P.MonadicParser.of(null)),
                 r.Chainname.or(P.MonadicParser.of(null)),
@@ -350,6 +360,7 @@ const lang = P.MonadicParser.createLanguage({
     Atomname: () => P.MonadicParser.regexp(/\.([a-zA-Z0-9]{1,4})/, 1).map(B.atomName).desc('atomname'),
     Resname: () => P.MonadicParser.regexp(/[a-zA-Z0-9]{1,4}/).desc('resname'),
     Resno: (r: any) => r.Integer.desc('resno'),
+    Atomno: (r: any) => r.Integer.desc('atomno'),
 //    Resno2: (r: any) => r.split(',').Integer.desc('resno'),
     Altloc: () => P.MonadicParser.regexp(/%([a-zA-Z0-9])/, 1).desc('altloc'),
     Inscode: () => P.MonadicParser.regexp(/\^([a-zA-Z0-9])/, 1).desc('inscode'),

+ 20 - 1
src/mol-script/transpilers/rasmol/special_properties.ts

@@ -19,7 +19,26 @@ function rangeMap(x: string) {
     return { min, max };
 }
 function listOrRangeMap(x: string) {
-    return x.includes('-') ? rangeMap(x) : listMap(x).map(x => parseInt(x));
+    if (x.includes('-') && x.includes('+')){
+	const pSplit = x.split('+').map(x => x.replace(/^["']|["']$/g, ''));
+	const res : number[] =[];
+	pSplit.forEach( x => {
+	    if (x.includes('-')){
+		const [min, max] = x.split('-').map(x=>parseInt(x));
+		for (var i = min;  i <= max;  i++){
+		    res.push(i);
+		}		 
+	    }else{
+		res.push(parseInt(x));
+	    }
+	});
+	console.log(res)
+	return res;		    	
+    }else if(x.includes('-') && !x.includes('+')){
+	return rangeMap(x)
+    }else if(!x.includes('-') && x.includes('+')){
+	return listMap(x)
+    }
 }
 function elementListMap(x: string) {
     return x.split('+').map(B.struct.type.elementSymbol);

+ 0 - 1
src/mol-util/monadic-parser.ts

@@ -470,7 +470,6 @@ export namespace MonadicParser {
     export const letters = regexp(/[a-z]*/i).desc('optional letters');
     export const optWhitespace = regexp(/\s*/).desc('optional whitespace');
     export const whitespace = regexp(/\s+/).desc('whitespace');
-    export const comma = regexp(/,/).desc('comma');
     export const cr = string('\r');
     export const lf = string('\n');
     export const crlf = string('\r\n');