Class ScriptEval

All Implemented Interfaces:
JmolScriptEvaluator

public class ScriptEval extends ScriptParam
  • Field Details

    • sm

      public ShapeManager sm
    • isJS

      public boolean isJS
    • historyDisabled

      public boolean historyDisabled
    • tQuiet

      public boolean tQuiet
    • compiler

      public ScriptCompiler compiler
    • outputBuffer

      public SB outputBuffer
    • scriptFileName

      public String scriptFileName
    • functionName

      public String functionName
    • isStateScript

      public boolean isStateScript
    • scriptLevel

      public int scriptLevel
    • CONTEXT_HOLD_QUEUE

      public static final String CONTEXT_HOLD_QUEUE
      See Also:
    • CONTEXT_DELAY

      public static final String CONTEXT_DELAY
      See Also:
    • commandHistoryLevelMax

      public static int commandHistoryLevelMax
    • aatoken

      public T[][] aatoken
    • pc

      public int pc
    • thisCommand

      public String thisCommand
    • fullCommand

      public String fullCommand
    • pcResume

      public int pcResume
    • debugHigh

      public boolean debugHigh
    • privateFuncs

      protected Map<String,ScriptFunction> privateFuncs
    • tempStatement

      protected T[] tempStatement
  • Constructor Details

    • ScriptEval

      public ScriptEval()
  • Method Details

    • getAllowJSThreads

      public boolean getAllowJSThreads()
    • setAllowJSThreads

      public void setAllowJSThreads(boolean b)
    • doReport

      public boolean doReport()
    • isStateScript

      public boolean isStateScript()
    • setStatic

      public int setStatic(int tok, int ival)
      set a static variable, with checking for range
    • getScript

      public String getScript()
    • setViewer

      public ScriptEval setViewer(Viewer vwr)
    • setCompiler

      public void setCompiler()
    • compileScriptString

      public boolean compileScriptString(String script, boolean tQuiet)
    • compileScriptFile

      public boolean compileScriptFile(String filename, boolean tQuiet)
    • evaluateCompiledScript

      public void evaluateCompiledScript(Object[] params, boolean isCmdLine_c_or_C_Option, boolean isCmdLine_C_Option, boolean historyDisabled, boolean listCommands, SB outputBuffer, boolean allowThreads)
    • useThreads

      public boolean useThreads()
    • resumeEval

      public void resumeEval(Object sco)
      From dispatchCommands and JmolThread resumeEval. After throwing a ScriptInterruption, all statements following the current one are lost. When a JavaScript timeout returns from a DELAY, MOVE, MOVETO, or other sleep-requiring command, it is the ScriptContext that contains all have to worry about this, because the current thread is just put to sleep, not stopped, but in JavaScript, where we only have one thread, we need to manage this more carefully. We re-enter the halted script here, using a saved script context. The program counter is incremented to skip the initiating statement, and all parent contexts up the line are set with mustResumeEval = true.
      Parameters:
      sco -
    • runScript

      public void runScript(String script) throws ScriptException
      Throws:
      ScriptException
    • runScriptBuffer

      public void runScriptBuffer(String script, SB outputBuffer, boolean isFuncReturn) throws ScriptException
      runs a script immediately and sends selected output to a provided SB
      Parameters:
      script -
      outputBuffer -
      Throws:
      ScriptException
    • checkScriptSilent

      public ScriptContext checkScriptSilent(String script)
      a method for just checking a script
      Parameters:
      script -
      Returns:
      a ScriptContext that indicates errors and provides a tokenized version of the script that has passed all syntax checking, both in the compiler and the evaluator
    • setDebugging

      public void setDebugging()
    • haltExecution

      public void haltExecution()
    • pauseExecution

      public void pauseExecution(boolean withDelay)
    • stepPausedExecution

      public void stepPausedExecution()
    • resumePausedExecution

      public void resumePausedExecution()
    • isExecuting

      public boolean isExecuting()
    • isPaused

      public boolean isPaused()
    • isStepping

      public boolean isStepping()
    • isStopped

      public boolean isStopped()
    • getNextStatement

      public String getNextStatement()
      when paused, indicates what statement will be next
      Returns:
      a string indicating the statement
    • evaluateExpression

      public Object evaluateExpression(Object expr, boolean asVariable, boolean compileOnly)
      a general-use method to evaluate a "SET" type expression.
      Parameters:
      expr -
      asVariable -
      Returns:
      an object of one of the following types: Boolean, Integer, Float, String, Point3f, BitSet
    • runBufferedSafely

      public void runBufferedSafely(String script, SB outputBuffer)
    • runUserAction

      public static SV runUserAction(String functionName, Object[] params, Viewer vwr)
    • checkSelect

      public boolean checkSelect(Map<String,SV> h, T[] where)
      Check a map for a WHERE phrase
    • getAtomBitSet

      public BS getAtomBitSet(Object atomExpression)
      A general method to evaluate a string representing an atom set. Excepts one atom expression or one per line as "OR". Excepts "()" as "none".
      Parameters:
      atomExpression -
      Returns:
      is a bitset indicating the selected atoms
    • compileScript

      public boolean compileScript(String filename, String strScript, boolean debugCompiler)
    • evalFunctionFloat

      public float evalFunctionFloat(Object func, Object params, float[] values)
    • getUserFunctionResult

      public SV getUserFunctionResult(String name, Lst<SV> params, SV tokenAtom) throws ScriptException
      Throws:
      ScriptException
    • clearDefinedVariableAtomSets

      public void clearDefinedVariableAtomSets()
    • lookupIdentifierValue

      public BS lookupIdentifierValue(String identifier) throws ScriptException
      Throws:
      ScriptException
    • deleteAtomsInVariables

      public void deleteAtomsInVariables(BS bsDeleted)
    • getThisContext

      public ScriptContext getThisContext()
    • pushContextDown

      public void pushContextDown(String why)
    • getScriptContext

      public ScriptContext getScriptContext(String why)
    • restoreScriptContext

      public void restoreScriptContext(ScriptContext context, boolean isPopContext, boolean isFlowCommand, boolean statementOnly)
    • setException

      public void setException(ScriptException sx, String msg, String untranslated)
    • statementAsString

      public static String statementAsString(Viewer vwr, T[] statement, int iTok, boolean doLogMessages)
    • setObjectPropSafe

      public String setObjectPropSafe(String id, int tokCommand)
      called by Viewer in setting up a PyMOL scene.
    • setAtomProp

      protected void setAtomProp(String prop, Object value, BS bs)
    • restrictSelected

      public void restrictSelected(boolean isBond, boolean doInvert)
    • showString

      public void showString(String str)
    • showStringPrint

      public void showStringPrint(String s, boolean mustDo)
      Specified by:
      showStringPrint in class ScriptError
    • report

      public void report(String s, boolean isError)
    • delayScript

      public void delayScript(int millis)
    • evalParallel

      public boolean evalParallel(ScriptContext context, ShapeManager shapeManager)
    • loadFileResourceAsync

      public void loadFileResourceAsync(String fileName) throws ScriptException
      load a static file asynchronously
      Throws:
      ScriptException
    • loadFileAsync

      public String loadFileAsync(String prefix, String filename, int i, boolean doClear) throws ScriptException
      Allows asynchronous file loading from the LOAD or SCRIPT command. Saves the context, initiates a FileLoadThread instance. When the file loading completes, the file data (sans filename) is saved in the FileManager cache under cache://localLoad_xxxxx. Context is resumed at this command in the script, and the file is then retrieved from the cache. Only run from JSmol/HTML5 when vwr.isJS; Incompatibilities: LOAD and SCRIPT commands, load() function only; only one "?" per LOAD command
      Parameters:
      prefix -
      filename - or null if end of LOAD command and now just clearing out cache
      i -
      doClear - ensures only one file is in the cache for a given type
      Returns:
      cached file name if it exists
      Throws:
      ScriptException
    • notifyResumeStatus

      public void notifyResumeStatus()
    • refresh

      public void refresh(boolean doDelay) throws ScriptException
      Refresh the display NOW
      Parameters:
      doDelay -
      Throws:
      ScriptException
    • stopScriptThreads

      public void stopScriptThreads()
    • getErrorLineMessage2

      public String getErrorLineMessage2()
    • getLinenumber

      public int getLinenumber(ScriptContext c)
    • dispatchCommands

      public boolean dispatchCommands(boolean isSpt, boolean fromFunc, boolean isTry) throws ScriptException
      Parameters:
      isSpt -
      fromFunc -
      isTry -
      Returns:
      false only when still working through resumeEval
      Throws:
      ScriptException
    • cmdLoad

      public void cmdLoad() throws ScriptException
      Throws:
      ScriptException
    • checkFileExists

      public String checkFileExists(String prefix, boolean isAsync, String filename, int i, boolean doClear) throws ScriptException
      Throws:
      ScriptException
    • isAtomExpression

      public boolean isAtomExpression(int i)
    • cmdRotate

      public void cmdRotate(boolean isSpin, boolean isSelected) throws ScriptException
      Throws:
      ScriptException
    • cmdScript

      public void cmdScript(int tok, String filename, String theScript, Lst<SV> params) throws ScriptException
      Throws:
      ScriptException
    • cmdUndoRedo

      public void cmdUndoRedo(int tok) throws ScriptException
      Throws:
      ScriptException
    • getPartialCharges

      public void getPartialCharges(BS bs) throws ScriptException
      Throws:
      ScriptException
    • encodeRadiusParameter

      public RadiusData encodeRadiusParameter(int index, boolean isOnly, boolean allowAbsolute) throws ScriptException
      Throws:
      ScriptException
    • expandFloatArray

      public Object expandFloatArray(float[] a, int min, boolean asBS) throws ScriptException
      Accepts a float array and expands [1 -3] to [1 2 3], for example.
      Parameters:
      a -
      min -
      asBS -
      Returns:
      float[] or BS
      Throws:
      ScriptException
    • getColorRange

      public String getColorRange(int i) throws ScriptException
      Throws:
      ScriptException
    • getFullPathName

      public String getFullPathName(boolean withType) throws ScriptException
      Throws:
      ScriptException
    • getObjectCenter

      protected P3 getObjectCenter(String axisID, int index, int modelIndex)
    • getPlaneForObject

      protected P4 getPlaneForObject(String id, V3 vAB)
    • getQuaternionArray

      public Quat[] getQuaternionArray(Object quaternionOrSVData, int itype)
    • getSetAxesTypeMad10

      public int getSetAxesTypeMad10(int index) throws ScriptException
      Throws:
      ScriptException
    • getShapeProperty

      public Object getShapeProperty(int shapeType, String propertyName)
    • getShapePropertyData

      public boolean getShapePropertyData(int shapeType, String propertyName, Object[] data)
    • getTranslucentLevel

      public float getTranslucentLevel(int i) throws ScriptException
      Throws:
      ScriptException
    • setMeshDisplayProperty

      public boolean setMeshDisplayProperty(int shape, int i, int tok) throws ScriptException
      Parameters:
      shape -
      i -
      tok -
      Returns:
      true if successful
      Throws:
      ScriptException
    • setObjectMad10

      public void setObjectMad10(int iShape, String name, int mad10)
    • setObjectProperty

      public String setObjectProperty() throws ScriptException
      Throws:
      ScriptException
    • setShapeNameParameter

      public String setShapeNameParameter(int i) throws ScriptException
      Throws:
      ScriptException
    • setShapeProperty

      public void setShapeProperty(int shapeType, String propertyName, Object propertyValue)
    • setShapePropertyBs

      public void setShapePropertyBs(int iShape, String propertyName, Object propertyValue, BS bs)
    • setShapeSizeBs

      public void setShapeSizeBs(int shapeType, int size, BS bs)
    • setShapeTranslucency

      public void setShapeTranslucency(int shapeType, String prefix, String translucency, float translucentLevel, BS bs)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCurrentModelFileAsString

      public String getCurrentModelFileAsString(String fname)
    • getCmdExt

      public CmdExt getCmdExt()
    • getIsoExt

      public IsoExt getIsoExt()
    • getMathExt

      public MathExt getMathExt()
    • getSmilesExt

      public SmilesExt getSmilesExt()
    • parameterExpressionList

      protected Lst<SV> parameterExpressionList(int pt, int ptAtom, boolean isArrayItem) throws ScriptException
      Throws:
      ScriptException
    • parameterExpressionString

      protected String parameterExpressionString(int pt, int ptMax) throws ScriptException
      Throws:
      ScriptException
    • parameterExpressionBoolean

      protected boolean parameterExpressionBoolean(int pt, int ptMax) throws ScriptException
      Throws:
      ScriptException
    • parameterExpressionToken

      protected SV parameterExpressionToken(int pt) throws ScriptException
      Throws:
      ScriptException
    • parameterExpressionSelect

      protected boolean parameterExpressionSelect(Map<String,SV> h, T[] where) throws ScriptException
      Throws:
      ScriptException
    • atomExpressionAt

      public BS atomExpressionAt(int index) throws ScriptException
      Throws:
      ScriptException
    • atomExpression

      public BS atomExpression(T[] code, int pcStart, int pcStop, boolean allowRefresh, boolean allowUnderflow, Object[] ret, boolean andNotDeleted) throws ScriptException
      Parameters:
      code -
      pcStart -
      pcStop -
      allowRefresh -
      allowUnderflow -
      ret - -- true return value; may not be a BS
      andNotDeleted - IGNORED
      Returns:
      atom bitset
      Throws:
      ScriptException
    • noCopy

      protected boolean noCopy(int i, int dir)
    • getAssocArray

      protected Map<String,Object> getAssocArray(int i) throws ScriptException
      Throws:
      ScriptException
    • listBS

      protected Lst<SV> listBS(BS bs)
    • compareFloatData

      protected BS compareFloatData(int tokWhat, float[] data, int tokOperator, float comparisonFloat)
      Parameters:
      tokWhat -
      data -
      tokOperator -
      comparisonFloat -
      Returns:
      BitSet
    • compareFloat

      protected boolean compareFloat(int tokOperator, float a, float b)
    • getBitsetProperty

      public Object getBitsetProperty(BS bs, Lst<SV> pts, int tok, P3 ptRef, P4 planeRef, Object tokenValue, Object opValue, boolean useAtomMap, int index, boolean asVectorIfAll) throws ScriptException
      Throws:
      ScriptException
    • getAtomBits

      protected BS getAtomBits(int tokType, Object specInfo)
    • getSeqCode

      protected static int getSeqCode(T instruction)
    • setVariable

      protected SV setVariable(int pt, int ptMax, String key, boolean isSet) throws ScriptException
      Parameters:
      pt - starting point in command token sequence
      ptMax - ending point in command token sequenec, possibly -1 for "all"
      key - the variable name to save the result in. This must be a standard user variable, either local or global
      isSet - from Set ... or Var .... or just xxx ....
      Returns:
      a variable or null
      Throws:
      ScriptException
    • setStatement

      protected boolean setStatement(T[] st0, int pt0) throws ScriptException
      provides support for @x and @{....} in statements. The compiler passes on these, because they must be integrated with the statement dynamically.
      Parameters:
      st0 - aaToken[i]
      pt0 -
      Returns:
      a fixed token set -- with possible overrun of unused null tokens
      Throws:
      ScriptException
    • isFunction

      protected boolean isFunction(String sf)
    • addFunction

      protected void addFunction(ScriptFunction f)
    • getFunction

      protected ScriptFunction getFunction(String sf)