lich-uct / molpher-lib

C++/Python Library for Systematic Chemical Space Exploration
https://lich-uct.github.io/molpher-lib/
Other
17 stars 7 forks source link

Cryptic error raised when `max_iters` is specified in algorithm settings #6

Closed martin-sicho closed 6 years ago

martin-sicho commented 6 years ago

When running the classic algorithm example code:

import os
import sys

from molpher.algorithms.classic.run import run
from molpher.algorithms.settings import Settings

def main(args):
    # our source and target molecules
    cocaine = 'CN1[C@H]2CC[C@@H]1[C@@H](C(=O)OC)[C@@H](OC(=O)c1ccccc1)C2'
    procaine = 'O=C(OCCN(CC)CC)c1ccc(N)cc1'

    # path to a directory where results will be stored (read from command line if possible)
    storage_dir = None
    if len(args) == 2:
        storage_dir = os.path.abspath(args[1])
    else:
        storage_dir = 'classic_data'

    # initialize the exploration settings
    settings = Settings(
        cocaine
        , procaine
        , storage_dir
        , max_threads=4
        , max_iters = 10
    )

    run(settings)

if __name__ == "__main__":
    exit(main(sys.argv))

the max_iters = 10 parameter is honored, but a confusing message is raised:

Error message:
Traceback (most recent call last):
  File "small.py", line 39, in <module>
    main(smiles[x],smiles[y], storage_dir='classical_data_'+start_id[x]+'_'+target_id[y]+'_run_'+str(runnum))
  File "small.py", line 32, in main
    run(settings)
  File "/home/isabel/anaconda2/envs/molpher_pseudo_random/lib/python3.6/site-packages/molpher-0.0.0b2-py3.6-linux-x86_64.egg/molpher/algorithms/classic/run.py", line 16, in run
    pathfinder()
  File "/home/isabel/anaconda2/envs/molpher_pseudo_random/lib/python3.6/site-packages/molpher-0.0.0b2-py3.6-linux-x86_64.egg/molpher/algorithms/pathfinders.py", line 46, in __call__
    self.path = find_path(self.tree, self.tree.params['target'])
  File "/home/isabel/anaconda2/envs/molpher_pseudo_random/lib/python3.6/site-packages/molpher-0.0.0b2-py3.6-linux-x86_64.egg/molpher/algorithms/functions.py", line 41, in find_path
    current = tree.fetchMol(end_mol)
  File "/home/isabel/anaconda2/envs/molpher_pseudo_random/lib/python3.6/site-packages/molpher-0.0.0b2-py3.6-linux-x86_64.egg/molpher/core/ExplorationTree.py", line 233, in fetchMol
    ret = super(ExplorationTree, self).fetchMol(canonSMILES)
  File "/home/isabel/anaconda2/envs/molpher_pseudo_random/lib/python3.6/site-packages/molpher-0.0.0b2-py3.6-linux-x86_64.egg/molpher/swig_wrappers/core.py", line 1918, in fetchMol
    return _core.ExplorationTree_fetchMol(self, canonSMILES)
RuntimeError: Molecule (COC1=CC=C(F)C=C1C(C)(C)CC(O)(CC1=CC=CC=C1)C(=O)NC1=CC=C2C(=O)OCC2=C1) is not present in the tree.

It should give a clear message about what went wrong.