Package schrodinger :: Package application :: Package matsci :: Module enumeration :: Class Alchemist
[hide private]
[frames] | no frames]

Class Alchemist

object --+
         |
        Alchemist
Known Subclasses:

Class that mutates the element of an atom in a structure

Instance Methods [hide private]
 
__init__(self, master, targets, new_items, child=None)
Create an Alchemist object.
type(data)
performTransmutation(self, data, index, item)
Perform a transmutation on a copy of data at index.
 
allTransmutationsCompleted(self, mydata, myused)
Perform whatever action is required when all transmutations have been performed on the mydata object
 
runTransmutations(self, data, used=None)
Begin transmutations.

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, master, targets, new_items, child=None)
(Constructor)

 

Create an Alchemist object. Alchemists modify an object by changing a
target item to new item.  For instance, an Alchemist:
    - Might transmute the element of a particular atom
    - Might change the item of a list to a new value
For enumeration, a series of Alchemists will work together to perform
all necessary mutations, each alchemist passing their mutated structures
on to another (child) alchemist. The general workflow looks like:
    receive mutated_object from parent alchemist
    for target in targets:
        for new_item in new_items:
            make a copy_of_mutated_object
            change item at target in copy_of_mutated_object to new_item
            pass copy_of_mutated_object to child alchemist

@type master: object
@param master: The master for this object. Can be a panel or other
object that has methods that get called by Alchemist methods. By
default, the Alchemist class calls master.transmutationCompleted with
each fully transmuted object.

@type targets: list
@param targets: list of possible positions for this Alchemist to mutate

@type new_items: list
@param new_items: list of items to change each target to.

@type child: L{Alchemist}
@param child: The Alchemist to call each time this Alchemist transmutes
an atom.  If child is None, than this Alchemist is the last in the line.

Overrides: object.__init__

performTransmutation(self, data, index, item)

 

Perform a transmutation on a copy of data at index. It is very important that this happen on a copy of data, not data itself.

Parameters:
  • data - The object to transmute a copy of
  • index - An index that tells what part of data to transmute
  • item - The object to mutate data[index] to
Returns: type(data)
A COPY of data, transmuted at index

allTransmutationsCompleted(self, mydata, myused)

 

Perform whatever action is required when all transmutations have been performed on the mydata object

Parameters:
  • mydata - The object that is fully transmuted
  • myused (list) - List of indexes that have been transmuted in mydata

runTransmutations(self, data, used=None)

 

Begin transmutations.

This Alchemist will determine what targets to transmute based on its set of original targets minus those targets that have been used by previous Alchemists. Each time this Alchemist transmutes an item, it calls its child Alchemist to do its mutations (which calls its child Alchemist each time it transmutes an item, and so on). Thus is the iterative process of transmutating all possible combinations achieved.

If this Alchemist does not have any children, than it is the last in the Alchemist line and it should call allTransmutationsCompleted when it is done with a transmutation.

Parameters:
  • data (object) - The object to be transmuted
  • used (list of int) - The indexes in data of the transmutations performed by parent Alchemists. The last item in this list is used to ensure that this Alchemist does not mutate any target already covered by parent Alchemists.