Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For AiZynthFinder Scoring Function's Exception #69

Open
cliecy opened this issue Dec 12, 2024 · 4 comments
Open

For AiZynthFinder Scoring Function's Exception #69

cliecy opened this issue Dec 12, 2024 · 4 comments

Comments

@cliecy
Copy link

cliecy commented Dec 12, 2024

Maybe there are some bug with the AiZynthFinder Scoring Function.

{
  "task": "AiZynthScore",
  "output_dir": "./",
  "load_from_previous": false,
  "logging": false,
  "monitor_app": false,
  "termination_exit": false,
  "scoring_functions": [
    {
      "name": "AiZynthFinder",
      "run": true,
      "parameters": {
        "prefix": "AiZynth",
        "policy": "full_uspto_rollout_policy",
        "templates": "full_uspto_unique_templates",
        "filter_policy": "None",
        "stock": "zinc_stock",
        "n_jobs": 1,
        "iteration_limit": 100,
        "return_first": false,
        "time_limit": 120,
        "C": 1.4,
        "cutoff_cumulative": 0.995,
        "cutoff_number": 50,
        "max_transforms": 6,
        "exclude_target_from_stock": false,
        "use_rdchiral": true,
        "env_engine": "mamba"
      }
    }
  ],
  "scoring": {
    "metrics": [
      {
        "name": "AiZynth_top_score",
        "filter": false,
        "weight": 1.0,
        "modifier": "raw",
        "parameters": {}
      }
    ],
    "method": "single"
  },
  "diversity_filter": {
    "run": false
  }
}

I use this json as my config file.
And I got this exception

(molscore) (base) cliecy@cliecyserver:~/myproject/toCompute$ /home/cliecy/miniforge3/envs/molscore/bin/python /home/cliecy/myproject/toCompute/testMolScore.py
/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/moleval/metrics/posecheck/utils/constants.py:26: UserWarning: reduce not found and posecheck may not work properly: Install with "conda install -c bioconda reduce"
  warnings.warn(
/bin/sh: 1: {self.engine}: not found
Failed to identify aizynth-env, attempting to create it automatically (this may take several minutes)
aizynth-env successfully created
Traceback (most recent call last):
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/scoring_functions/aizynthfinder.py", line 108, in try_resources
    with resources.path(
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/importlib/resources.py", line 175, in _path_from_reader
    opener_reader = reader.open_resource(norm_resource)
  File "<frozen importlib._bootstrap_external>", line 1055, in open_resource
FileNotFoundError: [Errno 2] No such file or directory: '/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/data/models/aizynth/full_uspto_rollout_policy.hdf5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/cliecy/myproject/toCompute/testMolScore.py", line 76, in <module>
    ms = MolScore(model_name='bvae_random', task_config='./AiZynthScore.json')
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/manager.py", line 196, in __init__
    self._set_objective(
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/manager.py", line 276, in _set_objective
    self.scoring_functions.append(fclass(**fconfig["parameters"]))
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/scoring_functions/aizynthfinder.py", line 137, in __init__
    "my_policy": [try_resources(policy), try_resources(templates)]
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/scoring_functions/aizynthfinder.py", line 117, in try_resources
    raise FileNotFoundError(
FileNotFoundError: File not found for full_uspto_rollout_policy, please specify.

So I download these files
image
and move them to the /home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/data/models/aizynth/.But I still get this exception.

Traceback (most recent call last):
  File "/home/cliecy/miniforge3/envs/aizynth-env/bin/aizynthcli", line 8, in <module>
    sys.exit(main())
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/interfaces/aizynthcli.py", line 375, in main
    finder = AiZynthFinder(configfile=args.config)
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/aizynthfinder.py", line 71, in __init__
    self.config = Configuration.from_file(configfile)
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/context/config.py", line 141, in from_file
    return Configuration.from_dict(_config)
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/context/config.py", line 111, in from_dict
    config_obj.filter_policy.load_from_config(**filter_config)
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/context/policy/policies.py", line 223, in load_from_config
    obj = cls(key, self._config, **kwargs)
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/context/policy/filter_strategies.py", line 112, in __init__
    super().__init__(key, config, **kwargs)
  File "/home/cliecy/miniforge3/envs/aizynth-env/lib/python3.9/site-packages/aizynthfinder/context/policy/filter_strategies.py", line 47, in __init__
    raise PolicyException(
aizynthfinder.utils.exceptions.PolicyException: A QuickKerasFilter class needs to be initiated with keyword arguments: model
Traceback (most recent call last):
  File "/home/cliecy/myproject/toCompute/testMolScore.py", line 77, in <module>
    bvae_scores = ms.score(bvae_products)
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/manager.py", line 947, in score
    self.run_scoring_functions(
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/manager.py", line 455, in run_scoring_functions
    results = function(
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/scoring_functions/aizynthfinder.py", line 250, in __call__
    return self.score(smiles=smiles, directory=directory)
  File "/home/cliecy/miniforge3/envs/molscore/lib/python3.9/site-packages/molscore/scoring_functions/aizynthfinder.py", line 224, in score
    with open(output_file, "rt") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/cliecy/myproject/toCompute/2024_12_12_bvae_random_AiZynthScore_05_56_13/aizynth_out.json'

I think maybe the AiZynthFinder doesn't get its config is the reason.But I don't know how to solve it.

@MorganCThomas
Copy link
Owner

Thanks for raising this issue, the data files are too big to be included in this python package so perhaps I'll change the API and include an automatic download of the data if I can. I've looked at the code and you should be able to specify them in the config file as absolute paths e.g.,

...
"parameters": {
        "prefix": "AiZynth",
        "policy": "/path/to/full_uspto_rollout_policy.hdf5",
        "templates": "/path/to/full_uspto_unique_templates.hdf5",
        "filter_policy": "None",
        "stock": "/path/to/zinc_stock.hdf5",
...

I can't remember if they are all .hdf5 format but use the appropriate extension.

Please try this and let me know.

@cliecy
Copy link
Author

cliecy commented Dec 12, 2024

I have tried this config.And I got a exception which said self.filter_policy is none.

I think there are some bugs with code here(MolScore/molscore/scoring_functions/aizynthfinder.py:line 220)
The subprocess doen's ouput the output file normally and the program will be down.
image

@MorganCThomas
Copy link
Owner

MorganCThomas commented Dec 12, 2024

It could be that the AiZynthFinder API has changed, I've not used or tested this code in a long time (because it's quite slow as a scoring function), so I'll write some tests and debug ASAP.

In the meantime I can recommend you the rascore_xgb.py scoring function which predicts the solvability of AiZynthFinder, it's much faster to run and I've used this in my research.

@cliecy
Copy link
Author

cliecy commented Dec 12, 2024

Thank you for your advice.Maybe I can try rascore.Hoping you can fix the bugs.

By the way,recently I am just starting to use this framework and it is pretty helpful for me.Thanks for your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants