3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TSUBAMEでAiZynthFinder用のConda環境を構築したい

Last updated at Posted at 2021-11-09

本記事の概要

また環境構築ログ.Qiitaのことコードをかけるメモ帳だと思ってるから許して欲しい

やったこと

環境構築

Conda環境に必要なパッケージをぶち込む

conda create --name aizynthfinder python=3.7
conda activate aizynthfinder
conda install -c rdkit "rdkit=>2019.09.1" -y
conda install -c anaconda "tensorflow>=2.1.0" -y
conda install -c anaconda graphviz -y
python -m pip install https://github.com/MolecularAI/aizynthfinder/archive/v3.0.0.tar.gz

まあまあ時間がかかる.

実行に必要なファイルのダウンロード

リポジトリのクローンと,実行に使うらしいファイルのダウンロード

git clone https://github.com/MolecularAI/aizynthfinder.git
cd aizynthfinder
mkdir model
python aizynthfinder/tools/download_public_data.py model

実行用スクリプト類の作成

試しに逆合成してみる化合物のSMILES

smiles.txt
C1=C(N=C(C(=O)N1)C(=O)N)F

逆合成し,その結果をoutput.hdf5として出力するジョブスクリプト(tsubameに投げるやつ)

aizynth_test.sh
#!/bin/bash
#$ -cwd
#$ -N Aizynth_test
#$ -l f_node=1
#$ -l h_rt=0:10:0
#$ -V


. /etc/profile.d/modules.sh
module load cuda/11.2.146 cudnn/8.1

source  ~/.bashrc
conda activate aizynthfinder
export PYTHONPATH="/home/0/{学籍番号}/aizynthfinder:$PYTHONPATH"

aizynthcli --config /home/0/{学籍番号}/aizynthfinder/model/config.yml --smiles /home/0/{学籍番号}/aizynthfinder/smiles.txt

hdf5ファイルを可視化するコード

gen_image.py
import pandas as pd
from aizynthfinder.reactiontree import ReactionTree

data = pd.read_hdf("output.hdf5", "table")
all_trees = data.trees.values
trees_for_first_target = all_trees[0]

for itree, tree in enumerate(trees_for_first_target):
    imagefile = f"route{itree:03d}.png"
    ReactionTree.from_dict(tree).to_image().save(imagefile)

上のコードを走らせるジョブスクリプト.
うまくいくとカレントディレクトリにroute000.pngroute001.png,...というのがいくつかできる

view_smiles.sh
#!/bin/bash
#$ -cwd
#$ -N View_smiles
#$ -l q_core=1
#$ -l h_rt=0:10:0
#$ -V


. /etc/profile.d/modules.sh
module load cuda/11.2.146 cudnn/8.1

source  ~/.bashrc
conda activate aizynthfinder
export PYTHONPATH="/home/0/{学籍番号}/aizynthfinder:$PYTHONPATH"

python3 /home/0/18B03528/aizynthfinder/gen_image.py                                  

そのほか有用そうな情報

  • aizynthcliするときのオプションに--output hogefuga.hdf5をつけるとファイル名がhogefuga.hdf5として保存されるらしい

複数のSMILESを一気に走らせたい

準備

cd aizynthfinder
mkdir SMILES
mkdir OUTPUTS
make_scripts.py
## 目標は,'/home/0/{学籍番号}/aizynthfinder/SMILES'内に複数あるSMILES_(id).txtに対し,output_(id).hdf5を作ってくれるよう>なスクリプトの自動生成

import os

DIR='/home/0/{学籍番号}/aizynthfinder'

with open(DIR+'/auto_script.sh', mode='w') as sh:
    sh.write('#!/bin/bash\n')
    sh.write('#$ -cwd\n')
    sh.write('#$ -N Auto_test\n')
    sh.write('#$ -l f_node=1\n')
    sh.write('#$ -l h_rt=0:10:0\n')
    sh.write('#$ -V\n')
    sh.write('\n')
    sh.write('. /etc/profile.d/modules.sh\n')
    sh.write('module load cuda/11.2.146 cudnn/8.1\n')
    sh.write('\n')
    sh.write('source  ~/.bashrc\n')
    sh.write('conda activate aizynthfinder\n')
    sh.write('export PYTHONPATH="/home/0/{学籍番号}/aizynthfinder:$PYTHONPATH"\n')

    for filename in os.listdir(DIR+'/SMILES'):
        sh.write(f'ayzinthcli --config {DIR}/model/config.yml --output {DIR}/OUTPUTS/{filename}.hdf5 --smiles {DIR}/{filename}\n')
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?