浏览代码

VMD parser updated, now math function to value comparison enabled

yakomaxa 2 年之前
父节点
当前提交
57a1184a16
共有 1 个文件被更改,包括 27 次插入24 次删除
  1. 27 24
      src/mol-script/transpilers/vmd/parser.ts

+ 27 - 24
src/mol-script/transpilers/vmd/parser.ts

@@ -57,32 +57,35 @@ const valueOperators: OperatorList = [
         type: h.binaryLeft,
         rule: P.MonadicParser.alt(P.MonadicParser.regexp(/\s*(=~|==|>=|<=|=|!=|>|<)\s*/, 1), P.MonadicParser.whitespace.result('=')),
         map: (op, e1, e2) => {
-            // console.log(op, e1, e2)
+	    console.log(e1.head !== undefined && e2.head !==undefined)
+            console.log(op, e1, e2)
             let expr;
-            if (e1.head.name === 'structure-query.atom-property.macromolecular.secondary-structure-flags') {
-                expr = B.core.flags.hasAny([e1, sstrucMap(e2)]);
-            } else if (e2.head.name === 'structure-query.atom-property.macromolecular.secondary-structure-flags') {
-                expr = B.core.flags.hasAny([e2, sstrucMap(e1)]);
-            } else if (e1.head.name === 'core.type.regex') {
-                expr = B.core.str.match([e1, B.core.type.str([e2])]);
-            } else if (e2.head.name === 'core.type.regex') {
-                expr = B.core.str.match([e2, B.core.type.str([e1])]);
-            } else if (op === '=~') {
-                if (e1.head.name) {
-                    expr = B.core.str.match([
-                        B.core.type.regex([`^${e2}$`, 'i']),
-                        B.core.type.str([e1])
-                    ]);
-                } else {
-                    expr = B.core.str.match([
-                        B.core.type.regex([`^${e1}$`, 'i']),
-                        B.core.type.str([e2])
-                    ]);
-                }
-            }
+	    if (e1.head !== undefined && e2.head !== undefined){
+		if (e1.head.name === 'structure-query.atom-property.macromolecular.secondary-structure-flags') {
+                    expr = B.core.flags.hasAny([e1, sstrucMap(e2)]);
+		} else if (e2.head.name === 'structure-query.atom-property.macromolecular.secondary-structure-flags') {
+                    expr = B.core.flags.hasAny([e2, sstrucMap(e1)]);
+		} else if (e1.head.name === 'core.type.regex') {
+                    expr = B.core.str.match([e1, B.core.type.str([e2])]);
+		} else if (e2.head.name === 'core.type.regex') {
+                    expr = B.core.str.match([e2, B.core.type.str([e1])]);
+		} else if (op === '=~') {
+                    if (e1.head.name) {
+			expr = B.core.str.match([
+                            B.core.type.regex([`^${e2}$`, 'i']),
+                            B.core.type.str([e1])
+			]);
+                    } else {
+			expr = B.core.str.match([
+                            B.core.type.regex([`^${e1}$`, 'i']),
+                            B.core.type.str([e2])
+			]);
+                    }
+		}
+	    }
             if (!expr) {
-                if (e1.head.name) e2 = h.wrapValue(e1, e2);
-                if (e2.head.name) e1 = h.wrapValue(e2, e1);
+                if (e1.head) e2 = h.wrapValue(e1, e2);
+                if (e2.head) e1 = h.wrapValue(e2, e1);
                 switch (op) {
                     case '=':
                     case '==':