GHeinzelmann / BAT.py

The Binding Affinity Tool (BAT.py) is a fully automated tool for absolute binding free energy calculations on protein-ligand systems, compatible with the AMBER and OpenMM simulation packages.
MIT License
166 stars 45 forks source link

UnboundLocalError: cannot access local variable 'ratio' where it is not associated with a value #31

Closed rez3vil closed 1 year ago

rez3vil commented 1 year ago

After executing

python3 BAT.py -i input-dd.in -s equil

it shows following error

Traceback (most recent call last):
  File "/home/administrator/Documents/BAT_ABFEP/BAT/BAT.py", line 594, in <module>
    build.create_box(comp, hmr, pose, mol, num_waters, water_model, ion_def, neut, buffer_x, buffer_y, buffer_z, stage, ntpr, ntwr, ntwe, ntwx, cut, gamma_ln, barostat, receptor_ff, ligand_ff, dt, dec_method, other_mol)
  File "/home/administrator/Documents/BAT_ABFEP/BAT/lib/build.py", line 1109, in create_box
    box_volume = scripts.box_volume()
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/administrator/Documents/BAT_ABFEP/BAT/lib/scripts.py", line 85, in box_volume
    box_volume=float(ratio * x_axis * y_axis * z_axis)
                     ^^^^^
UnboundLocalError: cannot access local variable 'ratio' where it is not associated with a value
GHeinzelmann commented 1 year ago

Hi, and thanks for your interest in the BAT code. A couple of people have had this same issue recently, so I would very much like to solve it. Could you please send me an email (my address is in the main page), then I will probably ask for some of the files BAT generated in your computer, then we can get to the bottom of this issue and fix it. Thanks!

rez3vil commented 1 year ago

Hi thank you for replying! I did looked at the solved section for the same error, I noticed it's arising from the missing value from protonation in build.pdb (I am guessing?). As commented by others, I am trying new conda environment with openbabel=2.4.1 and see if the error persists.

Update: From #27 I tried creating a fresh conda env with .yml file but the error still persists. Can I provide you any files over here? This is my work computer. I don't have email access.

GHeinzelmann commented 1 year ago

Hm I am not sure, but if there is a way for me to have access to the BAT-generated files, it would be the best way to solve this issue quickly.

rez3vil commented 1 year ago

Hi I will try to reproduce the same error back home today on my personal computer and will update you. I hope you won't close this thread.

GHeinzelmann commented 1 year ago

Don't worry, I also really want to address this problem. Thanks!

rez3vil commented 1 year ago

BAT.zip Hi can you have a look at this? I am attaching the files here.

GHeinzelmann commented 1 year ago

HI, thanks for the files. It seems that the problem was in the parameter generation using antechamber, since the lig.mol2 file was not created. Can you try to go inside the equil/build_files folder and run the command:

antechamber -i lig-h.pdb -fi pdb -o lig.mol2 -fo mol2 -c bcc -s 2 -at gaff -nc 0

Then check if the lig.mol2 file was generated, I tested here and it worked in my computer. Remember that Ambertools has to be in your path, by running a command like:

source ~/amber20/amber.sh

Let me know how that goes. Thanks!

rez3vil commented 1 year ago

Hi, sorry for the delayed reply. You guessed the error right. It wasn't creating lig.mol2. Somehow my amber wasn't being accessed in the first place. The first line code executed properly.

Now the error comes when I run the second command,

python3 BAT.py -i input-dd.in -s fe

The above code is throwing following error.

Setting up pose0
window: c00 weight: 0.0
Traceback (most recent call last):
  File "BAT.py", line 644, in <module>
    anch = build.build_dec(fwin, hmr, mol, pose, comp, win, water_model, ntpr, ntwr, ntwe, ntwx, cut, gamma_ln, barostat, receptor_ff, ligand_ff, dt, sdr_dist, dec_method, l1_x, l1_y, l1_z, l1_range, min_adis, max_adis, ion_def, other_mol, solv_shell)
  File "/home/administrator/Documents/BAT_ABFEP/BAT/lib/build.py", line 621, in build_dec
    shutil.copy('../../build_files/%s.pdb' %mol.lower(), './')
  File "/home/administrator/anaconda3/envs/BAT/lib/python3.7/shutil.py", line 248, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/home/administrator/anaconda3/envs/BAT/lib/python3.7/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '../../build_files/lig.pdb'

I am guessing the script wants to copy the files from newly generated "equil/build_files" folder and not from "/build_files"? I am attaching files here just in case if you need it. BAT.zip

GHeinzelmann commented 1 year ago

Hi. Did you run the equilibrium simulations for each pose using AMBER? You have to run the run-local.bash command for each pose in its respective folder, like so:

source run-local.bash

The fe step is done after running them, and the fe simulations also have to be performed using the respective scripts, like explained in the tutorial.

rez3vil commented 1 year ago

Hi. Did you run the equilibrium simulations for each pose using AMBER? You have to run the run-local.bash command for each pose in its respective folder, like so:

source run-local.bash

The fe step is done after running them, and the fe simulations also have to be performed using the respective scripts, like explained in the tutorial.

Hi sorry, I kind of overlooked the run-local.bash command. I will run and get back to you.

GHeinzelmann commented 1 year ago

No update, will assume everything went well. Closing issue.