Explorar el Código

developing rasmol residue-range selector WIP

yakomaxa hace 2 años
padre
commit
2ccce0beaf

+ 54 - 3
src/mol-script/transpilers/rasmol/parser.ts

@@ -11,7 +11,8 @@ import * as P from '../../../mol-util/monadic-parser';
 import * as h from '../helper';
 import { MolScriptBuilder } from '../../../mol-script/language/builder';
 const B = MolScriptBuilder;
-import { properties, structureMap } from './properties';
+import { properties, structureMap, structureDict } from './properties';
+import { special } from './special';
 import { operators } from './operators';
 import { keywords } from './keywords';
 import { AtomGroupArgs } from '../types';
@@ -125,7 +126,8 @@ const lang = P.MonadicParser.createLanguage({
 
     Expression: function (r: any) {
         return P.MonadicParser.alt(
-//	    r.NamedAtomProperties,
+	    //	    r.NamedAtomProperties,
+	    r.RangeListProperty,
 	    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])
@@ -147,6 +149,51 @@ const lang = P.MonadicParser.createLanguage({
         return P.MonadicParser.alt(...h.getNamedPropertyRules(properties));
     },
 
+        ValueRange: function (r: any) {
+        return P.MonadicParser.seq(
+            r.Value
+                .skip(P.MonadicParser.regexp(/-/i)),
+            r.Value
+        ).map(x => ({ range: x }));
+    },
+
+    RangeListProperty: function (r: any) {
+        return P.MonadicParser.seq(
+            P.MonadicParser.alt(...h.getPropertyNameRules(special, /\s/))
+                .skip(P.MonadicParser.whitespace),
+            P.MonadicParser.alt(
+                r.ValueRange,
+                r.Value
+            ).sepBy1(P.MonadicParser.comma)
+        ).map(x => {
+            const [property, values] = x;
+            const listValues: (string | number)[] = [];
+            const rangeValues: any[] = [];
+
+            values.forEach((v: any) => {
+                if (v.range) {
+                    rangeValues.push(
+                        B.core.rel.inRange([property, v.range[0], v.range[1]])
+                    );
+                } else {
+                    listValues.push(h.wrapValue(property, v, structureDict));
+                }
+            });
+
+            const rangeTest = h.orExpr(rangeValues);
+            const listTest = h.valuesTest(property, listValues);
+
+            let test;
+            if (rangeTest && listTest) {
+                test = B.core.logic.or([rangeTest, listTest]);
+            } else {
+                test = rangeTest ? rangeTest : listTest;
+            }
+
+	    return B.struct.generator.atomGroups({ [h.testLevel(property)]: test });
+        });
+    },
+
     Operator: function (r: any) {
         return h.combineOperators(operators, P.MonadicParser.alt(r.Parens, r.Expression));
     },
@@ -155,9 +202,12 @@ 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.Resno.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)),
+//		r.Chainname2.or(P.MonadicParser.of(null)),
                 r.Atomname.or(P.MonadicParser.of(null)),
                 r.Altloc.or(P.MonadicParser.of(null)),
                 r.Model.or(P.MonadicParser.of(null))),
@@ -166,12 +216,13 @@ const lang = P.MonadicParser.createLanguage({
 
     AtomPrefix: () => P.MonadicParser.regexp(/[0-9:^%/.]/).desc('atom-prefix'),
     Chainname: () => P.MonadicParser.regexp(/:([A-Za-z]{1,3})/, 1).desc('chainname'),
+//    Chainname2: () => P.MonadicParser.regexp(/\*([A-Za-z]{1,3})/, 1).desc('chainname'),
     Model: () => P.MonadicParser.regexp(/\/([0-9]+)/, 1).map(Number).desc('model'),
     Element: () => P.MonadicParser.regexp(/_([A-Za-z]{1,3})/, 1).desc('element'),
     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'),
-    Resno2: (r: any) => r.split(',').Integer.desc('resno'),
+//    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'),
 

+ 16 - 1
src/mol-script/transpilers/rasmol/properties.ts

@@ -16,7 +16,14 @@ const rePosInt = /[0-9]+/;
 
 function str(x: string) { return x; }
 
-const structureDict: {[key: string]: string} = {
+export function sstrucMap(x: string) {
+    return B.struct.type.secondaryStructureFlags(
+        [structureDict[x.toUpperCase()] || 'none']
+    );
+}
+
+
+export const structureDict: {[key: string]: string} = {
     none: 'none',
     turn: 'turn',
     sheet: 'beta',
@@ -446,6 +453,14 @@ export const properties: PropertyDict = {
         regex: /-?[0-9]+/, map: x => parseInt(x),
         level: 'residue-test', property: B.ammp('auth_seq_id')
     },
+    hoge: {
+        '@desc': 'PDB residue number, not including insertion code (see also seqcode, below)',
+        '@examples': ['resno = 100'],
+//        isNumeric: true,
+        regex: /-?[0-9]+/, map: x => parseInt(x),
+        level: 'residue-test', property: B.ammp('auth_seq_id')
+
+    },
     selected: {
         '@desc': '1.0 if atom is selected; 0.0 if not',
         '@examples': [''],

+ 64 - 0
src/mol-script/transpilers/rasmol/special.ts

@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ * @author Panagiotis Tourlas <panagiot_tourlov@hotmail.com>
+ *
+ * @author Koya Sakuma
+ * This module was taken from jmol transpiler from MolQL and modified in similar manner as pymol and vmd tranpilers.                                             \
+*/
+
+import { MolScriptBuilder } from '../../../mol-script/language/builder';
+const B = MolScriptBuilder;
+import { PropertyDict } from '../types';
+
+const reFloat = /[-+]?[0-9]*\.?[0-9]+/;
+const rePosInt = /[0-9]+/;
+
+function str(x: string) { return x; }
+
+export function sstrucMap(x: string) {
+    return B.struct.type.secondaryStructureFlags(
+        [structureDict[x.toUpperCase()] || 'none']
+    );
+}
+
+
+export const structureDict: {[key: string]: string} = {
+    none: 'none',
+    turn: 'turn',
+    sheet: 'beta',
+    helix: 'helix',
+    dna: 'dna',
+    rna: 'rna',
+
+    0: 'none',
+    1: 'turn',
+    2: 'beta',
+    3: 'helix',
+    4: 'dna',
+    5: 'rna',
+    6: 'carbohydrate',
+    7: '3-10',
+    8: 'alpha',
+    9: 'pi',
+};
+export function structureMap(x: any) {
+    if (x.head && x.head === 'core.type.regex') x = x.args[0].replace(/^\^|\$$/g, '');
+    x = structureDict[x.toString().toLowerCase()] || 'none';
+    if (['dna', 'rna', 'carbohydrate'].indexOf(x) !== -1) {
+        throw new Error("values 'dna', 'rna', 'carbohydrate' not yet supported for 'structure' property");
+    } else {
+        return B.struct.type.secondaryStructureFlags([x]);
+    }
+}
+
+export const special: PropertyDict = {
+    hoge: {
+        '@desc': 'PDB residue number, not including insertion code (see also seqcode, below)',
+        '@examples': ['resno = 100'],
+//        isNumeric: true,
+        regex: /-?[0-9]+/, map: x => parseInt(x),
+        level: 'residue-test', property: B.ammp('auth_seq_id')
+    },
+};
+

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 546 - 0
src/mol-script/transpilers/rasmol/special.ts~


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

@@ -470,6 +470,7 @@ 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');

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio