1.1.1.3.1.1.1.3. ExplorationTree¶
- class molpher.swig_wrappers.core.ExplorationTree(*args, **kwargs)[source]¶
Represents an
exploration treeand facilitates the most basic interaction with it. It is a tight wrapper around the C++ implementation. Themolpher.core.ExplorationTreeclass extends upon this implementation and provides a more user-friendly version of this class.Attention
This class does not define a constructor. Use the
create()factory method to spawn instances.- static create(*args)¶
Returns an
ExplorationTreeinstance using a suppliedExplorationData, tree snapshot or SMILES strings of the source molecule and the target molecule.- Parameters
*args (
ExplorationDataorstr) – anExplorationDatainstance, path to a tree snapshot or a source molecule and a target molecule as two arguments.- Returns
ExplorationTreeinstance created from the supplied snapshot- Return type
- save(filename)[source]¶
Saves the tree to a snapshot file. The filename should end with either
.xmlor.snp.- Parameters
filename (
str) – path to the new snapshot file
- runOperation(operation)[source]¶
Takes a
TreeOperationinstance and attempts to run it by attaching itself to it and calling its__call__()method.See also
Note
Doing this will also automatically attach the given
TreeOperationinstance to thisExplorationTreeobject.- Parameters
operation (
TreeOperation) – aTreeOperationinstance to run
- fetchLeaves(increase_dist_improve_counter=False)[source]¶
Gives a
tupleofMolpherMolinstances that represent the leaves of thisExplorationTree.- Returns
tupleofMolpherMolinstances representing the leaves of this tree- Return type
- fetchMol(canonSMILES)[source]¶
Attempts to fetch a molecule (represented by its canonical SMILES string) from the current tree. If the molecule exists, it returns an appropriate
MolpherMolinstance. Otherewise, it raises aRuntimeError.- Parameters
canonSMILES (
str) – astrrepresenting SMILES of the molecule being searched for- Returns
MolpherMolrepresenting the looked up molecule- Return type
- Raises
RuntimeErrorif the molecule specified could not be found in the tree
- hasMol(canonSMILES)[source]¶
Returns
TrueorFalseto indicate the presence of a molecule in the current tree.
- deleteSubtree(canonSMILES, descendents_only=False)[source]¶
Deletes a specified molecule from the tree and all of its descendents.
- generateMorphs(*args)[source]¶
Generates mew candidate morphs using the current exploration parameters and saves them (see
ExplorationDatafor details).The generated compounds can be retrieved using the
getCandidateMorphsmethod.Note
All morphs already present in the tree are filtered out automatically.
- sortMorphs()[source]¶
Sorts the candidate morphs according to their distances from the target molecule.
Warning
When morphs are generated the distance to the current target is saved for each morph. This distance is not updated if the target of the tree changes afterwards.
- filterMorphs(*args)[source]¶
Filters the candidate morphs according to the supplied filtering options (see the table below for a listing of the available filters). The filtering options can be easily combined and passed to the method using the
|operator. For example, the method can be called like this:tree.filterMorphs(FilterMorphsOper.SYNTHESIS | FilterMorphsOper.PROBABILITY). If no filter information is passed, all filters are used automatically (equal to passingFilterMorphsOper.ALL).Table 1.5 Filtering options and their descriptions.¶ Option
Description
Filter the
candidate morphsaccording to probability based on their position inExplorationTree.candidates.Remove molecules that do not satisfy the weight constraints.
The inbuilt synthetic feasibility filter.
Maximum number of morphs derived from one molecule.
Remove candidates that are already in the tree (always on).
Remove candidates that have already been tried by their parents.
Use all of the above filters.
The results of the filtering can be observed using the
getCandidateMorphsMaskmethod.See also
- Parameters
*args (
FilterMorphsOperoptions) – one or more filtering options combined using the|operator
- extend()[source]¶
Attach all candidate morphs that have not been filtered out to the tree. In other words, make them the new leaves.
Note
By calling this method a
morphing iterationis committed.
- prune()[source]¶
Perform the pruning of the tree according to the rules specified by current exploration parameters (see
ExplorationDatafor details).
- getThreadCount()[source]¶
Returns the number of threads this particular
ExplorationTreewill use. The value of 0 indicates that the same number of threads as the number of available cores will be used.
- asData()[source]¶
Can be used to obtain the current exploration parameters.
- Returns
instance of
ExplorationData, which holds the current configuration options for the computations on the tree- Return type
- getCandidateMorphs()[source]¶
Gives a
tupleofMolpherMolinstances that represent thecandidate morphsof thisExplorationTreeinstance.- Returns
tupleofMolpherMolinstances representing thecandidate morphs- Return type
- getCandidateMorphsMask()[source]¶
Returns a mask for the
tuplereturned bygetCandidateMorphs. The filtered out morphs are denoted byFalseat the respective position in the mask.Morphs filtered out in this way will not be attached to the tree when
extend()is called.- Returns
tupleofboolinstances which shows what candidate morphs were filtered out- Return type
- getGenerationCount()[source]¶
Returns the number of morph generations in the tree. Basically the number of morphing iterations performed so far.
- Returns
number of morphing iterations performed so far
- Return type
- setThreadCount(threadCnt)[source]¶
Sets the maximum number of threads used by this instance. The value of 0 indicates that the same number of threads as the number of available cores will be used.
- update(data)[source]¶
Change the current exploration parameters for this instance. If the supplied
ExplorationDatainstance contains a tree topology, it is ignored and only the parameters are taken into account.Warning
This may invalidate some data in the tree (such as the distances from the target molecule computed so far).
- Parameters
param (
ExplorationData) – an instance ofExplorationData, which represents the new exploration parameters for this instance
- setCandidateMorphsMask(mask)[source]¶
Sets the morphs’ mask of this instance to a custom value. If the length of the new mask does not correspond to the number of candidate morphs in the tree, a
RuntimeErrorwill be raised.- Parameters
mask (
tuple) –tupleofboolinstances which shows what candidate morphs will be filtered out (not attached to the tree whenextend()is called)- Raises
RuntimeErrorif the length of the new mask does not correspond to the number of candidate morphs in the tree
- traverse(*args)[source]¶
Traverses the tree and calls the
()of the callback on each morph in it. A SMILES string of a root of a subtree can be specified before the callback in order to traverse just the subtree.- Parameters
*args (
TraverseCallbackorstrandTraverseCallback) – either an instance of a class derived fromTraverseCallbackor both SMILES of the root of a subtree and aTraverseCallback