Trees | Indices | Help |
|
---|
|
Functionality for "ark" file format handling. 'sea' stands for Schrodinger Enhanced Ark. The syntax of the ark format can be found elsewhere (e.g., Desmond User Manual). Below is an example, demonstrating the most basic usage of this module. Say we have a file called 'config.cfg' with the following content: ------start of the content------ fep = { lambda = "default:12" i_window = ? output = { name = "$JOBNAME$[_replica$REPLICA$].dE" first = 0.0 interval = 1.2 } } temperature = [300.0 310.0 320.0] ------end of the content------ We can parse it with a code like this: import schrodinger.utils.sea as sea cfg = sea.Map( open( "config.cfg", "r" ).read() ) In fact, the code does much more than merely parsing the content. But the important thing here is that at the end we get an 'Map' object that enables us to easily manipulate settings for the file as shown below: assert( cfg.fep.lambda_ .val == "default:12" ) assert( cfg.fep.i_window .val == None ) assert( cfg.output.first .val == 0.0 ) assert( cfg.output.interval.val == 1.2 ) assert( cfg.output.name.raw_val == "$JOBNAME$[_replica$REPLICA$].dE" ) assert( cfg.temperature[0].val == 300.0 ) assert( cfg.temperature[1].val == 310.0 ) assert( cfg.temperature[2].val == 320.0 ) assert( cfg.temperature .val == [300.0, 310.0, 320.0] # Another way to access the data: assert( cfg["fep"]["lambda" ].val == "default:12" ) assert( cfg["fep"]["i_window"].val == None ) cfg.output.first.val = 1.0 assert( cfg.output.first.val == 1.0 ) cfg.output.i_window.val = 1 assert( cfg.output.first.val == 1 ) cfg.fep.lambda_.val = "a different string" assert( cfg.fep.lambda_.val == "a different string" ) cfg.temperature[0].val = 20.0 assert( cfg.temperature[0].val == 20.0 ) # Adds a new key-value pair. cfg["new_key"] = 1 # Deletes an existing key-value pair. del cfg.fep["interval"] print str( cfg ) #Result: #fep = { # i_window = 1 # lambda = "a different string" # new_key = 1 # output = { # name = "$JOBNAME$[_replica$REPLICA$].dE" # first = 1.0 # } #} #temperature = [20.0 310.0 320.0] Some explanations of the code: - The ".val" is in fact a python 'property' for reading and mutating the value of the parameter. - In the file, we have a parameter named "lambda", but in the code, we access it as "lambda_". The reason that we have to use "lambda_" is because 'lambda' is a python keyword. - The value '?' in the file will correspond to 'None' in python code. - The ".raw_val" is similar to the ".val". The different is that the latter will give a value where the macro's are expanded, whereas the former will give the original string. More information regarding macros is beyond the scope of this docstring, please refere to the document. - Notice an expression like: 'temperature[0].val' returns the value of the 0-th element of the list, while 'temperature.val' returns a buildin 'list' object for the entire list. Copyright Schrodinger, LLC. All rights reserved.
|
|||
Sea This is the base class the 'Atom', 'List', and 'Map' classes. |
|||
Atom This class represents the "atomic" parameters in a config file. |
|||
Hydrogen | |||
List This class represents the "list" parameters in a config file. |
|||
Key An instance of this class will be used as the key of the Map class (see below). |
|||
Map This class represents the "map" parameters in a config file. |
|||
_Evalor This is the evaluator class for checking validity of parameters. |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
__CHECK_SEA_DEBUG = False hash(x) |
|||
__debug_str_buf =
|
|||
macro_dict =
|
|||
_STRIP_BRACKET_PATTERN = re.compile(r'\x00\[
|
|||
__OP = {"*": __op_mul, "==": __op_eq, "<": __op_lt, "<=": __op
|
|||
__TYPE = {"str": str, "str1":(str, [1, 1000000000],), "float":
|
|||
__CONVERTIBLE_TO =
|
|||
__xcheck = {"power2": _xchk_power2, "file_exists": _xchk_file_
|
|||
__package__ =
|
|
Returns True if the string 's' is one of the following: 'true', 'yes', and 'on', or False if it is one of the following: 'false', 'no', and 'off'. Case difference will be ignored. Raises a ValueError exception if 's' is none of the above strings. |
Prints out some information for debugging purposes.
|
Filters a given value 'val' and returns a new 'Sea' (or its derivatives) object representing the value.
|
Returns a 'List' object for the given list of objects. Usually, we do not need to call this function directly. Call '_val_filter' instead.
|
This function is needed by the 'expand_macro' function below. It replaces dollar char '$' as in the following cases: $$, $[, $] in a string with the ' ' char. The results for these cases will be the following: , [, ] respectively. |
This function is needed by the 'expand_macro' function below. It replaces dollar char '$' as in the following cases: $$, $[, $] in a string with the ' ' char. The results for these cases will be the following: , [, ] respectively. |
Mutates a given string 's' by following the following rules: 1. If there is a dollar sign '$' within a fragment of string that is delimited by ' [' and ' ]', the entire fragment including the ' [' and ' ]' delimiters will be removed. 2. If there is no dollar sign within the fragment, then the fragment will be retained, and only the delimiters will be removed. Examples: _strip_bracket( "desmond [_$JOBNAME ]" ) # Returns "desmond" _strip_bracket( "desmond [_jobname ]" ) # Returns "desmond_jobname" This function is usually used together with the '_escape_dollar' function in the 'expand_macro' function (see below). |
Mutates a given string 's' by following the following rules: 1. If there is a dollar sign '$' within a fragment of string that is delimited by ' [' and ' ]', the entire fragment including the ' [' and ' ]' delimiters will be removed. 2. If there is no dollar sign within the fragment, then the fragment will be retained, and only the delimiters will be removed. Examples: _strip_bracket( "desmond [_$JOBNAME ]" ) # Returns "desmond" _strip_bracket( "desmond [_jobname ]" ) # Returns "desmond_jobname" This function is usually used together with the '_escape_dollar' function in the 'expand_macro' function (see below). |
Replaces the macros in the string 's' using the values given by the macro dictionary 'macro_dict'. The expanded string will be returned. Rules or conventions about macros and expansion:
|
Replaces the macros in the string 's' using the values given by the macro dictionary 'macro_dict'. The expanded string will be returned. Rules or conventions about macros and expansion:
|
Returns the difference between 'x' and 'reference'. Both 'x' and 'reference' must be 'Map' objects. The difference is a 4-tuple: The first element is a 'Map' object containing the changed values in 'x', the second element is a 'Map' object containing the changed value in 'reference', the third element is a 'Map' object containing keys in x but not in 'reference', the forth element is a 'Map' object containing keys in 'reference' but not in 'x'. |
Extracts a subset of keys from the 'Map' object 'x' that has the tag. And returns a new 'Map' object containing the extracted keys. |
expand_sea return an expanded string of a sea obj. For instance, after calling expand_sea_string, eneseq ={ name = foo.ene first = 0 } is converted into eneseq.name = "foo.ene" eneseq.first = 0 |
Evaluates the "multiplication" expression and returns product of the arg[0], arg[1], arg[3], ...
|
Evaluates the "equal" expression and returns True the arg[0] and arg[1] are equal or False otherwise.
|
Evaluates the "less than" expression and returns True the arg[0] is less than arg[1] or False otherwise.
|
Evaluates the "less or equal" expression and returns True the arg[0] is less than or equal to arg[1] or False otherwise.
|
Evaluates the "greater than" expression and returns True the arg[0] is greater than arg[1] or False otherwise.
|
Evaluates the "greater or equal" expression and returns True the arg[0] is greater than or equal to arg[1] or False otherwise.
|
Evaluates the "logic and" expression and returns True if both arg[0] and arg[1] are true.
|
Evaluates the "logic or" expression and returns True if either arg[0] or arg[1] is true.
|
Evaluates the "logic not" expression and returns True if arg[0] is false or False if arg[0] is true.
|
Evaluates the "at" expression and returns the referenced value.
|
Evaluates the "minus" expression and returns arithmatic result (the difference between two values, or the negative value).
|
Contatenate two strings and returns the result.
|
Evaluates the "less than" expression and returns True the arg[0] is less than arg[1] or False otherwise.
|
This is an external checker. It checks whether an integer value is power of 2 or not.
|
This is an external checker. It checks whether a file (not a dir) exists.
|
This is an external checker. It checks whether a dir (not a file) exists.
|
Evaluates the expression and returns the results.
|
Registers external checker.
|
Similiar to the 'check_map' function (see above), but no need to provide a '_Evalor' object. A new '_Evalor' object will be created and returned. |
|
_STRIP_BRACKET_PATTERN
|
__OP
|
__TYPE
|
__CONVERTIBLE_TO
|
__xcheck
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Aug 6 04:50:22 2015 | http://epydoc.sourceforge.net |