Package MolKit :: Module tree :: Class TreeNode
[hide private]
[frames] | no frames]

Class TreeNode

source code

Known Subclasses:
molecule.Molecule, molecule.Atom, protein.SecondaryStructure, molecule.MolecularSystem

Base class for node that can be used to build trees. Every node is by definition a list of its children.mol. a leaf is an empty list. a root has no parent.

Instance Methods [hide private]
  __str__(self)
  __init__(self, name='NoName', parent=None, elementType=None, objects=None, childrenName=None, setClass=<class MolKit.tree.TreeNodeSet at 0xb7c793bc>, childrenSetClass=<class MolKit.tree.TreeNodeSet at 0xb7c793bc>, top=None, childIndex=None, assignUniqIndex=1)
TreeNode constructor.
  deleteSubTree(self)
Function to actually delete all the reference to a TreeNode to Free the memory !!!!
  adopt(self, child, index=None, assignUniqIndex=1, setChildrenTop=0)
Have a parent node adopt a child node
  makeNameUniq(self, aliasList=None)
None <- makeNameUniq() checks that each name in self.children is unique.
  assignUniqIndex(self)
  remove(self, child, assignUniqIndex=1, cleanup=0)
remove a child
  __eq__(self, other)
compare 2 tree nodes by comparing their address in memory
  __ne__(self, other)
compare 2 tree nodes by comparing their address in memory
  __cmp__(self, other)
compare 2 tree nodes by comparing their address in memory
  __hash__(self)
return a hash value for this object
  compare(self, one, other)
compare 2 tree nodes
  __repr__(self)
  getRoot(self)
returns the root of the tree this node belongs to
  getParentOfType(self, what)
return first parent of a givent type
  findLevels(self, lastLevel=None)
goes down the tree until the children member is empty and return the class type of objects in children
  findType(self, _what, uniq=0)
go down the tree until we find Nodes of the given type
  isAbove(self, Klass)
go down the tree until we find Nodes of the given type return the number of level above self at which we find Klass, else 0 is retuned
  isBelow(self, Klass)
go up the tree until we find Nodes of the given type return the number of level above self at which we find Klass, else 0 is retuned
  get(self, function)
select elements among the children of that node using a lambda function
  dump(self)
print out all members and their values
  full_name(self)
Build the node's name by concatenating all names up to the root
  NodesFromName(self, name)
retrieves nodes using a name.
  getPrevious(self)
Get the previous TreeNode in a TreeNodeSet
  getNext(self)
Gets the next TreeNode in a TreeNodeSet
  merge(self, right)
Merges two tree objects by creating a new object that is a copy of the first object but has the children of both of the merged objects as its children.
  _copyNode(self, node, copyDict, nameExt)
  split(self, nodes, nameExt='_copy1')

Class Variables [hide private]
  _numberOfDeletedNodes = 0

Method Details [hide private]

__str__(self)
(Informal representation operator)

source code 
None

__init__(self, name='NoName', parent=None, elementType=None, objects=None, childrenName=None, setClass=<class MolKit.tree.TreeNodeSet at 0xb7c793bc>, childrenSetClass=<class MolKit.tree.TreeNodeSet at 0xb7c793bc>, top=None, childIndex=None, assignUniqIndex=1)
(Constructor)

source code 
TreeNode constructor.
Arguments:
optional objects (list)
optional name (string)
optional parent (instance of a TreeNode)
optional elementType (instance of class inheriting from TreeNode)
         represents the type of the children of that node
optional childrenName (string) alias for children attribute
optional setClass (class type) type of object used for selections
         sets of such nodes
optional childrenSetClass (class type) type of object used for
         a selection of children of that node
optional top (TreeNode) root of the tree

deleteSubTree(self)

source code 
Function to actually delete all the reference to a TreeNode to Free the memory !!!!

adopt(self, child, index=None, assignUniqIndex=1, setChildrenTop=0)

source code 
Have a parent node adopt a child node

makeNameUniq(self, aliasList=None)

source code 
None <- makeNameUniq() checks that each name in self.children is unique. concatenates _uniqIndex to name when identical names are found

assignUniqIndex(self)

source code 
None

remove(self, child, assignUniqIndex=1, cleanup=0)

source code 
remove a child

__eq__(self, other)
(Equality operator)

source code 
compare 2 tree nodes by comparing their address in memory

__ne__(self, other)

source code 
compare 2 tree nodes by comparing their address in memory

__cmp__(self, other)
(Comparison operator)

source code 
compare 2 tree nodes by comparing their address in memory

__hash__(self)
(Hashing function)

source code 
return a hash value for this object

compare(self, one, other)

source code 
compare 2 tree nodes

__repr__(self)
(Representation operator)

source code 
None

getRoot(self)

source code 
returns the root of the tree this node belongs to

getParentOfType(self, what)

source code 
return first parent of a givent type

findLevels(self, lastLevel=None)

source code 
goes down the tree until the children member is empty and return the class type of objects in children

findType(self, _what, uniq=0)

source code 
go down the tree until we find Nodes of the given type

isAbove(self, Klass)

source code 
go down the tree until we find Nodes of the given type return the number of level above self at which we find Klass, else 0 is retuned

isBelow(self, Klass)

source code 
go up the tree until we find Nodes of the given type return the number of level above self at which we find Klass, else 0 is retuned

get(self, function)

source code 
select elements among the children of that node using a lambda function

dump(self)

source code 
print out all members and their values

full_name(self)

source code 
Build the node's name by concatenating all names up to the root

NodesFromName(self, name)

source code 
retrieves nodes using a name. Name is a string as produced by full_name() i.e. node names separated by ':' going from root to leaf

getPrevious(self)

source code 
Get the previous TreeNode in a TreeNodeSet

getNext(self)

source code 
Gets the next TreeNode in a TreeNodeSet

merge(self, right)

source code 
Merges two tree objects by creating a new object that is a copy of the first object but has the children of both of the merged objects as its children.

_copyNode(self, node, copyDict, nameExt)

source code 
None

split(self, nodes, nameExt='_copy1')

source code 
None

Class Variable Details [hide private]

_numberOfDeletedNodes

None
Value:
0