ソースを参照

reverted vmd parser and properties to original

yakomaxa 2 年 前
コミット
6a83dc56ba

+ 5 - 104
src/mol-script/transpilers/vmd/parser.ts

@@ -15,37 +15,8 @@ import { keywords } from './keywords';
 import { functions } from './functions';
 import { OperatorList } from '../types';
 import { Transpiler } from '../transpiler';
-//import { AtomGroupArgs } from '../types';
 
-//const slash = P.MonadicParser.string('/');
-
-//function orNull(rule: P.MonadicParser<any>) {
-//    return rule.or(P.MonadicParser.of(null));
-//}
-
-/**function atomSelectionQuery(x: any) {
-   const tests: AtomGroupArgs = {};
-    const props: { [k: string]: any[] } = {};
-
-    for (let k in x) {
-        const ps = properties[k];
-        if (!ps) {
-            throw new Error(`property '${k}' not supported, value '${x[k]}'`);
-        }
-        if (x[k] === null) continue;
-        if (!props[ps.level]) props[ps.level] = [];
-        props[ps.level].push(x[k]);
-    }
-
-    for (let p in props) {
-        tests[p] = h.andExpr(props[p]);
-    }
-
-    return B.struct.generator.atomGroups(tests);
-}
-*/
-
-//const propertiesDict = h.getPropertyRules(properties)
+// const propertiesDict = h.getPropertyRules(properties)
 
 // <, <=, = or ==, >=, >, and !=
 // lt, le, eq, ge, gt, and ne, =~
@@ -148,84 +119,14 @@ const lang = P.MonadicParser.createLanguage({
         ).wrap(P.MonadicParser.string('('), P.MonadicParser.string(')'));
     },
 
-    Expression: function (r : any) {
+    Expression: function (r:any) {
         return P.MonadicParser.alt(
-	    r.Keywords,
-            r.NamedAtomProperties,
-	    r.ValueQuery
+            r.RangeListProperty,
+            r.ValueQuery,
+            r.Keywords,
         );
     },
-    
-//    Expression: function (r:any) {
-//        return P.MonadicParser.alt(
-//	    r.NamedAtomProperties,
-//	    r.AtomSelectionMacro.map(atomSelectionQuery),
-//	    r.Keywords,
- //           r.ValueQuery, 
- //       );
-  //  },
-
-    NamedAtomProperties: function () {
-	return P.MonadicParser.alt(...h.getNamedPropertyRules(properties));                                                                                 
-    },
 
-/*        AtomSelectionMacro: function (r : any) {
-        return P.MonadicParser.alt(
-            slash.then(P.MonadicParser.alt(
-                P.MonadicParser.seq(
-                    orNull(r.ObjectProperty).skip(slash),
-                    orNull(propertiesDict.segi).skip(slash),
-                    orNull(propertiesDict.chain).skip(slash),
-                    orNull(propertiesDict.resi).skip(slash),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { object: x[0], segi: x[1], chain: x[2], resi: x[3], name: x[4] }; }),
-                P.MonadicParser.seq(
-                    orNull(r.ObjectProperty).skip(slash),
-                    orNull(propertiesDict.segi).skip(slash),
-                    orNull(propertiesDict.chain).skip(slash),
-                    orNull(propertiesDict.resi)
-                ).map(x => { return { object: x[0], segi: x[1], chain: x[2], resi: x[3] }; }),
-                P.MonadicParser.seq(
-                    orNull(r.ObjectProperty).skip(slash),
-                    orNull(propertiesDict.segi).skip(slash),
-                    orNull(propertiesDict.chain)
-                ).map(x => { return { object: x[0], segi: x[1], chain: x[2] }; }),
-                P.MonadicParser.seq(
-                    orNull(r.ObjectProperty).skip(slash),
-                    orNull(propertiesDict.segi)
-                ).map(x => { return { object: x[0], segi: x[1] }; }),
-                P.MonadicParser.seq(
-                    orNull(r.ObjectProperty)
-                ).map(x => { return { object: x[0] }; }),
-            )),
-            P.MonadicParser.alt(
-                P.MonadicParser.seq(
-                    orNull(r.ObjectProperty).skip(slash),
-                    orNull(propertiesDict.segi).skip(slash),
-                    orNull(propertiesDict.chain).skip(slash),
-                    orNull(propertiesDict.resi).skip(slash),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { object: x[0], segi: x[1], chain: x[2], resi: x[3], name: x[4] }; }),
-                P.MonadicParser.seq(
-                    orNull(propertiesDict.segi).skip(slash),
-                    orNull(propertiesDict.chain).skip(slash),
-                    orNull(propertiesDict.resi).skip(slash),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { segi: x[0], chain: x[1], resi: x[2], name: x[3] }; }),
-                P.MonadicParser.seq(
-                    orNull(propertiesDict.chain).skip(slash),
-                    orNull(propertiesDict.resi).skip(slash),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { chain: x[0], resi: x[1], name: x[2] }; }),
-                P.MonadicParser.seq(
-                    orNull(propertiesDict.resi).skip(slash),
-                    orNull(propertiesDict.name)
-                ).map(x => { return { resi: x[0], name: x[1] }; }),
-            )
-        );
-    },
-*/
-    
     Keywords: () => P.MonadicParser.alt(...h.getKeywordRules(keywords)),
 
     ValueRange: function (r:any) {

+ 11 - 14
src/mol-script/transpilers/vmd/properties.ts

@@ -13,9 +13,6 @@ const reFloat = /[-+]?[0-9]*\.?[0-9]+/;
 const rePosInt = /[+]?[0-9]+/;
 const reInt = /[-+]?[0-9]+/;
 
-function atomNameListMapVMD(x: string) { return x.split(' ').map(B.atomName); };
-function listMapVMD(x: string) { return x.split(' ').map(x => x.replace(/^["']|["']$/g, '')); }
-
 function str(x: string) { return x; }
 
 export const sstrucDict: { [key: string]: string } = {
@@ -37,7 +34,7 @@ export const properties: PropertyDict = {
     name: {
         '@desc': 'str    atom name',
         '@examples': ['name CA'],
-        regex: /[a-zA-Z0-9 ]+/, map: atomNameListMapVMD ,
+        regex: /[a-zA-Z0-9]+/, map: B.atomName,
         level: 'atom-test', property: B.ammp('label_atom_id')
     },
     type: {
@@ -83,8 +80,8 @@ export const properties: PropertyDict = {
     chain: {
         '@desc': 'str  the one-character chain identifier',
         '@examples': ['chain A'],
-        regex: /[a-zA-Z0-9 ]+/, map :listMapVMD,
-        level: 'chain-test', property: B.ammp('auth_asym_id')
+        regex: /[a-zA-Z0-9]+/, map: str,
+        level: 'residue-test', property: B.ammp('auth_asym_id')
     },
     residue: {
         '@desc': 'num  a set of connected atoms with the same residue number',
@@ -93,13 +90,6 @@ export const properties: PropertyDict = {
         regex: reInt, map: x => parseInt(x),
         level: 'residue-test', property: B.ammp('auth_seq_id')
     },
-    resid: {
-        '@desc': 'num  residue id',
-        '@examples': ['resid 42'],
-        isNumeric: true,
-        regex: reInt, map: x => parseInt(x),
-        level: 'residue-test', property: B.ammp('auth_seq_id')
-    },  
     fragment: {
         '@desc': 'num  a set of connected residues',
         '@examples': ['fragment 42'],
@@ -141,9 +131,16 @@ export const properties: PropertyDict = {
     resname: {
         '@desc': 'str  residue name',
         '@examples': ['resname ALA'],
-        regex: /[a-zA-Z0-9 ]+/, map: atomNameListMapVMD,
+        regex: /[a-zA-Z0-9]+/, map: str,
         level: 'residue-test', property: B.ammp('auth_comp_id')
     },
+    resid: {
+        '@desc': 'num  residue id',
+        '@examples': ['resid 42'],
+        isNumeric: true,
+        regex: reInt, map: x => parseInt(x),
+        level: 'residue-test', property: B.ammp('auth_seq_id')
+    },
     segname: {
         '@desc': 'str  segment name',
         '@examples': ['segname B'],