Miscellaneous PilotScript Functions

The following miscellaneous functions are available for PilotScript components.

Miscellaneous Function Name/Prototype Description Example

BinaryAnd

Integer BinaryAnd(Integer a, Integer b)
Perform a binary AND operation on the two arguments taken as 32-bit integers.
#and := BinaryAnd(#a, #b);

Take the binary AND of two integers.

BinaryNot

Integer BinaryNot(Integer a)
Perform a binary XOR operation of the argument taken as a 32-bit integer.
#not := BinaryNot(#a);

Take the binary NOT of the integer.

BinaryOr

Integer BinaryOr(Integer a, Integer b)
Perform a binary OR operation on the two arguments taken as 32-bit integers.
#or := BinaryOr(#a, #b);

Take the binary OR of two integers.

BinaryXOr

Integer BinaryXOr(Integer a, Integer b)
Perform a binary XOR operation on the two arguments taken as 32-bit integers.
#xor := BinaryXOr(#a, #b);

Take the binary XOR of two integers.

Calculate

None Calculate(String propertyName|Property prop|Array arr[, ...])
More efficient than calculating properties individually. Properties you can create are also called this way (for example, models created by a learner component). Calculate() always uses the latest version of a component, while an inline property calculator acts as a copy of it. If a component changes, a protocol with an inline calculator does not change its behavior (relevant for models you create). Use Calculate() to ensure you have the latest version of your model. You can limit the search for a calculator to a given subset of component database. Prepend the property name with a tab name (for example, your "User Name", Components, or Protocols), followed by a forward slash " / ". Only that tab is searched. (Further restrict the search by following the tab name with folders on the tab.)
/* Calculate a set of molecular properties */
   
Calculate('num_atoms', 'num_bonds', 'c_count', 'h_count');

Calculate('canonical_smiles');

CanCalculate

Boolean CanCalculate(String propname)
Provides a way to test whether the given property is calculated using the Calculate() function. CanCalculate(var) is most efficient if given a literal string as its argument, because it can test for the existence of the property once, at first use. You can use a global or local property to test the existence of the property with each execution of the script. (As with Calculate, you can limit the search for the component to a particular tab or folder.)
IF (CanCalculate('my_alogp'))
 THEN
   Calculate('my_alogp');

END IF;

CanCalculateNames

Array CanCalculateNames(String propname)
Similar to CanCalculate, returns an array of component names (the list of all components that can calculate that property). If no components are found, then a zero-length array is returned.
CanCalculateNames('alogp')

Returns "Components/Chemistry/Property Calculators/Physicochemical/ALogP"

CreateGUID

String CreateGUID()
Creates a new GUID (globally unique identifier), which is always a different value for each request.
#randomId := CreateGUID();

Eval

String Eval(String script)
Compiles and executes the supplied PilotScript for each invocation of the function. The script must be supplied as a string. When used as a value for an assignment, the value of the last statement of the script is returned.
Eval('#val := 3; sqrt(#val);')

Returns 1.73205

ISupports

Boolean ISupports(String iname)
Returns True if the current data record supports the given named interface. Current legal values for iname are "IMolecule" and "IDataRecord", plus any root node name. To view these names, use the Data Tree Viewer component.
Isupports('IMolecule');

Returns True if the current data record has a molecule

IsValidPilotScript

Boolean IsValidPilotScript(String str)
Returns True if the string argument is parsed as a valid PilotScript expression. Useful when setting up validation scripts that prompt users if the script is not valid.
IsValidPilotScript('#a := power(2.3, 2)');

Returns True

IsValidPilotScript('#b := 2.3^2');

Returns False

Occurrence

Number Occurrence(String var[, Boolean caseSens])
Wraps around an internal hash table, keeping track of the number of times the value of var is seen. If the second parameter is True, then the comparison is case-sensitive. Otherwise (and by default) the comparison is case-insensitive. /* Filter out duplicate molecules */
Occurrence(canonical_smiles, True) = 1;

/* Filter out records with duplicate cas number */

Occurrence(cas_rn) = 1;

/* Filter out molecules with duplicate names. Case is ignored */

Occurrence(Name, FALSE) = 1;

Parameter

String Parameter(String name)
Returns the value of the component parameter with the given name. If the parameter does not exist, an error is raised. To check if the parameter is defined before using its value, use the IS DEFINED operator. You cannot assign a value to the parameter.
IF Parameter('Size') IS DEFINED
 THEN
     #size := Parameter('Size');
 
ELSE 
    #size := 0;

END IF;

If Size is defined, retrieves the value for this parameter and stores it in the #size local property. If Size contains more than one value, then #size is an array containing those values.

Sleep

None Sleep(Number millisecs)
Pauses the system for the given number of milliseconds.
/* Sleep for 5 seconds */

Sleep(5000);