Package schrodinger :: Package application :: Package desmond :: Module mdkey :: Class CfgAtom
[hide private]
[frames] | no frames]

Class CfgAtom

object --+
         |
        CfgAtom


This class represents the "atomic" parameters in a config file. Atomic
parameters do not contain further sub-elements. For example,
'force.type' is an atomic parameter, whereas 'force' is not because it
has sub-elements like 'type', 'gibbs', etc.

Public attributes:
  - validate -  None by default. This attribute can be set to be a
    callable object that assesses whether a given value is legal or not
    for this 'CfgAtom' object. The callable object should be able to
    take one argument -- the value subject to its assessment and returns
     either True (if the value is OK) or False (if the value is illegal).

Properties:
  - val - This is a read-write property for accessing the value of this
    'CfgAtom' object.

Instance Methods [hide private]
 
__init__(self, s)
Constructs a 'CfgAtom' object based on the value 's'.
 
__str__(self)
Converts the value to a string.
 
__ne__(self, rhs)
Returns True if the value of this object does not equal that of 'rhs'.
 
__eq__(self, rhs)
Returns True if the value of this object equals that of 'rhs'.
 
__set_val(self, val)
Sets the value.
 
__get_val(self)
Returns the value.
 
work_val(self, macro_dict)
 
expand_macro(self, macro_dict)
This method will replace all occurences (in the value) of each key (in 'macro_dict') to the corresponding value.
 
recover_macro(self)
This is usually called after an expand_macro call and recovers the value to the original macro-containing form.
 
backup(self)
Internally makes a copy of the current value.
 
isChanged(self)
Compares the value with the internal copy, and returns True if there is difference or False otherwise.
 
rollback(self)
Recovers the value to the internal copy of the value.
 
update(self, val, umarker=None)
Updates the value with 'val', which is exactly the same as setting the value via the 'val' property.
 
clearUmarker(self, umarker)

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]
  val
Readwrite.

Inherited from object: __class__

Method Details [hide private]

__init__(self, s)
(Constructor)

 

Constructs a 'CfgAtom' object based on the value 's'.

Parameters:
  • s - Can be a floating number, an integer number, or a string.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

 

Converts the value to a string. If the value itself is a string, then returns the value flanked with double-quotes (i.e., "<value>").

Overrides: object.__str__

__set_val(self, val)

 

Sets the value.

If the public attribute 'validate' is not None, then after the conversion the value will be sent to the callable object as pointed by the 'validate' attribute for assessment. If the assessment returns True, the value will be set; otherwise it is discarded.

Parameters:
  • val - Can be any object as long as it can be converted to the internal type of the value via the _convert method. If 'val' cannot be converted, it is ignored.

expand_macro(self, macro_dict)

 

This method will replace all occurences (in the value) of each key (in 'macro_dict') to the corresponding value. It has effect only for string type of values.

For example, if the value is '$JOBNAME on $DATE', then with a 'macro_dict' of {'$JOBNAME' : 'my_jobname', '$DATE' : 'Oct. 10, 2007'}, this method will change the value to 'my_jobname on Oct. 10, 2007'.

Parameters:
  • macro_dict - Should be dictionary, e.g., {'$JOBNAME' : 'my_jobname', '$DATE' : 'Oct. 10, 2007'}.

recover_macro(self)

 

This is usually called after an expand_macro call and recovers the value to the original macro-containing form.

For example, if the value is changed (by expand_macro) from '$JOBNAME on $DATE' to 'my_jobname on Oct. 10, 2007', then a call to this function will restore the value to '$JOBNAME on $DATE'.

backup(self)

 

Internally makes a copy of the current value. This internal copy can be used later on to recover the value if the value was changed unwantedly.

rollback(self)

 

Recovers the value to the internal copy of the value. The internal copy of the value was made by the last call to the 'backup' function.

update(self, val, umarker=None)

 

Updates the value with 'val', which is exactly the same as setting the value via the 'val' property.

If the public attribute 'validate' is not None, then after the conversion the value will be sent to the callable object as pointed by the 'validate' attribute for assessment. If the assessment returns True, the value will be set; otherwise it is discarded.

Parameters:
  • val - Can be any object as long as it can be converted to the internal type of the value via the _convert method. If 'val' cannot be converted, it is ignored.

Property Details [hide private]

val

Readwrite. When read, this returns the current value.

Get Method:
__get_val(self) - Returns the value.
Set Method:
__set_val(self, val) - Sets the value.