MolecularAI / aizynthfinder

A tool for retrosynthetic planning
https://molecularai.github.io/aizynthfinder/
MIT License
571 stars 130 forks source link

AiZynthFinder does not work. #111

Closed okikosuke closed 1 year ago

okikosuke commented 1 year ago

I am trying to install AiZynthFinder from the following site and use it as a GUI on Jupyter Notebook. https://magattaca.hatenablog.com/entry/2020/10/12/005441 https://zenn.dev/retrosynthchan/articles/9283f3e8dd8dac

I get an error when I run the following code in Jupyter Notebook. What is the cause and how can I fix it?

from aizynthfinder.interfaces import AiZynthApp
configfile=r "C:\Users\Oki.Kosuke\aizynthfinder\model\config.yml"
app = AiZynthApp(configfile)
Loading template-based expansion policy model from C:\Users\Oki.Kosuke\aizynthfinder\model\uspto_model.hdf5 to uspto
---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
Cell In[1], line 3
      1 from aizynthfinder.interfaces import AiZynthApp
      2 configfile=r"C:\Users\Oki.Kosuke\aizynthfinder\model\config.yml"
----> 3 app = AiZynthApp(configfile)

File ~\aizynthfinder\aizynthfinder\interfaces\aizynthapp.py:60, in AiZynthApp.__init__(self, configfile, setup)
     57 def __init__(self, configfile: str, setup: bool = True) -> None:
     58     # pylint: disable=used-before-assignment
     59     setup_logger(logging.INFO)
---> 60     self.finder = AiZynthFinder(configfile=configfile)
     61     self._input: StrDict = dict()
     62     self._output: StrDict = dict()

File ~\aizynthfinder\aizynthfinder\aizynthfinder.py:65, in AiZynthFinder.__init__(self, configfile, configdict)
     62 self._logger = logger()
     64 if configfile:
---> 65     self.config = Configuration.from_file(configfile)
     66 elif configdict:
     67     self.config = Configuration.from_dict(configdict)

File ~\aizynthfinder\aizynthfinder\context\config.py:116, in Configuration.from_file(cls, filename)
    114 with open(filename, "r") as fileobj:
    115     _config = yaml.load(fileobj.read(), Loader=yaml.SafeLoader)
--> 116 return Configuration.from_dict(_config)

File ~\aizynthfinder\aizynthfinder\context\config.py:96, in Configuration.from_dict(cls, source)
     93 src_copy = dict(source)  # Make a copy so we can pop items
     94 config_obj._update_from_config(src_copy)
---> 96 config_obj.expansion_policy.load_from_config(**src_copy.get("policy", {}))
     97 config_obj.filter_policy.load_from_config(**src_copy.get("filter", {}))
     98 config_obj.stock.load_from_config(**src_copy.get("stock", {}))

File ~\aizynthfinder\aizynthfinder\context\policy\policies.py:112, in ExpansionPolicy.load_from_config(self, **config)
    110 for key, policy_spec in files_spec.items():
    111     modelfile, templatefile = policy_spec
--> 112     strategy = TemplateBasedExpansionStrategy(
    113         key, self._config, source=modelfile, templatefile=templatefile
    114     )
    115     self.load(strategy)
    117 # Load policies specifying a module and class, e.g. package.module.MyStrategyClass

File ~\aizynthfinder\aizynthfinder\context\policy\expansion_strategies.py:91, in TemplateBasedExpansionStrategy.__init__(self, key, config, **kwargs)
     86 templatefile = kwargs["templatefile"]
     88 self._logger.info(
     89     f"Loading template-based expansion policy model from {source} to {self.key}"
     90 )
---> 91 self.model = load_model(source, self.key, self._config.use_remote_models)
     93 self._logger.info(f"Loading templates from {templatefile} to {self.key}")
     94 if templatefile.endswith(".csv.gz") or templatefile.endswith(".csv"):

File ~\aizynthfinder\aizynthfinder\utils\models.py:72, in load_model(source, key, use_remote_models)
     57 """
     58 Load model from a configuration specification.
     59 
   (...)
     69 :return: a model object with a predict object
     70 """
     71 if not use_remote_models:
---> 72     return LocalKerasModel(source)
     74 try:
     75     return ExternalModelViaGRPC(key)

File ~\aizynthfinder\aizynthfinder\utils\models.py:98, in LocalKerasModel.__init__(self, filename)
     97 def __init__(self, filename: str) -> None:
---> 98     self.model = load_keras_model(filename, custom_objects=CUSTOM_OBJECTS)
     99     try:
    100         self._model_dimensions = int(self.model.input.shape[1])

File ~\Anaconda3\envs\AiZF\lib\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File h5py\_objects.pyx:54, in h5py._objects.with_phil.wrapper()

File h5py\_objects.pyx:55, in h5py._objects.with_phil.wrapper()

File ~\Anaconda3\envs\AiZF\lib\site-packages\h5py\_hl\dataset.py:1046, in Dataset.__array__(self, dtype)
   1043 if numpy.product(self.shape, dtype=numpy.ulonglong) == 0:
   1044     return arr
-> 1046 self.read_direct(arr)
   1047 return arr

File ~\Anaconda3\envs\AiZF\lib\site-packages\h5py\_hl\dataset.py:1007, in Dataset.read_direct(self, dest, source_sel, dest_sel)
   1004     dest_sel = sel.select(dest.shape, dest_sel)
   1006 for mspace in dest_sel.broadcast(source_sel.array_shape):
-> 1007     self.id.read(mspace, fspace, dest, dxpl=self._dxpl)

File h5py\_objects.pyx:54, in h5py._objects.with_phil.wrapper()

File h5py\_objects.pyx:55, in h5py._objects.with_phil.wrapper()

File h5py\h5d.pyx:192, in h5py.h5d.DatasetID.read()

File h5py\_proxy.pyx:112, in h5py._proxy.dset_rw()

File h5py\h5fd.pyx:165, in h5py.h5fd.H5FD_fileobj_read()

MemoryError: bad allocation

Environment

AiZynthFinder was installed in a virtual environment named AiZF. The virtual environment is as follows. This is an excerpt.

The RDKit and Python versions were taken from the following page https://github.com/MolecularAI/aizynthfinder/issues/15

I installed AiZynthFinder with the following code

git clone https://github.com/MolecularAI/aizynthfinder.git
cd aizynthfinder
python -m pip install -e .

Downloaded the data with the following code.

mkdir model
python aizynthfinder/tools/download_public_data.py model

I launched Jupyter Notebook with the following code.

aizynthapp --config model/config.yml

By the way, the folder configuration is as follows.

C:\Users\UserName
 --aizynthfinder
 |-aizynthfinder
 |-tools
 | |-.py There are 4 .py files
 |-model
  |-config.yml
  |- Four .hdf5 files
  |- Two .gz files
SGenheden commented 1 year ago

Hello. It looks like you ran out of memory. The MemoryError exception points to that. How much RAM do you have on your machine?

okikosuke commented 1 year ago

@SGenheden Thank you for your comment.What does “RAM” mean? And how do I check the “RAM”?

okikosuke commented 1 year ago

@SGenheden Somehow, I redid it again and it worked. It is a very good tool and I will use it.