Package schrodinger :: Package utils :: Module sea :: Class Atom
[hide private]
[frames] | no frames]

Class Atom

object --+    
         |    
       Sea --+
             |
            Atom
Known Subclasses:

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:

Instance Methods [hide private]
 
__init__(self, s=None, type=None, parent=None)
Constructs a 'Atom' object based on the value 's'.
 
__str__(self)
Converts the value to a string.
 
__eq__(self, rhs)
Returns True if the value of this object equals that of 'rhs'.
 
__deepcopy__(self, memo={})
 
__set_val(self, val)
Sets the value.
 
__get_raw_val(self)
Returns the raw value.
 
__get_sval(self)
Used by the sval property, which is to get an Sea object of the value that is represented by this Sea object.
 
__get_bval(self)
Returns a new Sea object, which has all macros expanded and references dereferenced.
 
__get_dval(self)
Returns a new Sea object, which has all references dereferenced, but macros are preserved.
 
__get_val(self)
Returns the value.
 
update(self, val, tag=set([]))
Updates the value with 'val'.
 
_dump_impl(self, tag)

Inherited from Sea: __getstate__, __ne__, __setstate__, add_tag, apply, clear_all_tag, dump, has_tag, parent, pmode, remove_tag, reset_tag, set_parent, set_pmode, tag

Inherited from Sea (private): _add_tag_impl, _remove_tag_impl, _reset_tag_impl

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

Static Methods [hide private]
 
num_wildcard(s)
This function is used to tell about strings like "*.*.keyword".
 
guess_value_type(s)
Guesses the type of the object that 's' represents.

Inherited from Sea (private): _gen_sea, _normalize_tag

Class Variables [hide private]
  WILDCARD_PATTERN = re.compile(r'\* *\.')
  __refmemo = []
Properties [hide private]
  raw_val
Readwrite.
  sval
Readonly.
  bval
Readonly.
  dval
Readonly.
  val
Readwrite.

Inherited from object: __class__

Method Details [hide private]

num_wildcard(s)
Static Method

 

This function is used to tell about strings like "*.*.keyword". It returns a tuple object. The first element is the number of wildcards "*", the second element is the word at the end after the '.' symbol. For example: num_wildcard( "*.*.keyword" ) will yield (2, "keyword"). See more examples in the unit tests below.

guess_value_type(s)
Static Method

 

Guesses the type of the object that 's' represents. A tuple will be returned. The first element is the object of the guessed type, the second element is the type. If 's' is a non-str object of buildin type, 's' and its type will be returned. If 's' is str object, the type of the object that the string represents will be guessed and the string will be converted to an object of the guessed type. Note these strings: "yes", "true", "on", "no", "false", and "off" will be considered as bool type of objects. If 's' is None, (None, None) will be returned. If 's' is of other types than the above, a ValueError exception will be returned.

__init__(self, s=None, type=None, parent=None)
(Constructor)

 

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

Parameters:
  • s - Can be a floating number, a boolean value, an integer number, or a string. If 's' is a string. the function will try to guess the type of object that the string represents and convert the string to the guessed type. 's' cannot be a dict, or tuple, or dict object.
  • type - Supplies a type, instead of using the guessed one. If it is None, the guessed type will be used.
  • parent - Specifies the parent of this 'Atom' object.
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__

__eq__(self, rhs)
(Equality operator)

 

Returns True if the value of this object equals that of 'rhs'. If the values of both this and 'rhs' are floating numbers, the is_equal function (see above) will be used for comparison. If 'rhs' is not an 'Atom' object, False will be returned.

Overrides: Sea.__eq__

__deepcopy__(self, memo={})

 
Overrides: Sea.__deepcopy__

__set_val(self, val)

 

Sets the value.

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, a ValueError exception will be raised.

__get_sval(self)

 

Used by the sval property, which is to get an Sea object of the value that is represented by this Sea object. If the value is a reference, the sval of the referenced Sea object will be returned; otherwise, this object will be returned. This function will raise ValueError if the reference is invalid or if the reference is circular.

__get_val(self)

 

Returns the value. If the raw value is a string, the returned value will have all macros (if any) expanded. If the value is a reference, the actual referenced value will be returned.

update(self, val, tag=set([]))

 

Updates the value with 'val'. If 'val' is a Atom, then this Atom object will be altered to be the same as 'val'. So the type of the value of this object can be altered by the update function. If 'val' is not a Atom, then this function will behave exactly the same as setting the value via the 'val' property.

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.
  • tag - Add the tag to this object.

_dump_impl(self, tag)

 
Overrides: Sea._dump_impl

Property Details [hide private]

raw_val

Readwrite. When read, this returns the raw value.

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

sval

Readonly. Returns the dereferenced `Sea' object.

Get Method:
__get_sval(self) - Used by the sval property, which is to get an Sea object of the value that is represented by this Sea object.

bval

Readonly. Returns a new `Atom' object, which has all macros expanded and references dereferenced.

Get Method:
__get_bval(self) - Returns a new Sea object, which has all macros expanded and references dereferenced.

dval

Readonly. Returns a new `Atom' object with dereferenced value.

Get Method:
__get_dval(self) - Returns a new Sea object, which has all references dereferenced, but macros are preserved.

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.