ccsb-scripps / AutoDock-Vina

AutoDock Vina
http://vina.scripps.edu
Apache License 2.0
596 stars 209 forks source link

Ligand(s) was(ere) not initialized. #271

Closed YvetteJxy closed 8 months ago

YvetteJxy commented 8 months ago

I encountered some issues when performing batch Vina calculations, but I'm not sure of the specific reasons.

Here is my code:

from vina import Vina
import os
docking_0_999_list = []
ligand_path = '/hy-tmp/ligand_16415/'
for i in range(1000):   # 0-999
    v = Vina(cpu=8)
    for j in range(21):   # 0-20
        pdbqt_file = '{}.pdbqt'.format(i)
        pdbqt_path = os.path.join(ligand_path, pdbqt_file)
        if not os.path.exists(pdbqt_path):
            print(f'不存在{pdbqt_file}')
        else:
            v.set_ligand_from_file(pdbqt_path)   
            print(pdbqt_path)
            v.set_receptor(rigid_pdbqt_filename=f"/hy-tmp/0_999/{i}_{j}.pdbqt")
            # print(2)
            v.compute_vina_maps(center=[0., 0., 0.], box_size=[30, 30, 30])
            # print(3)
            # print(v.score())
            print(v.optimize())
            v.dock(exhaustiveness=32)
            energy_minimized = v.optimize()
            temp = [i, j, energy_minimized[0]]
            docking_0_999_list.append(temp)

Below is the error message:

RuntimeError Traceback (most recent call last) Cell In[5], line 20 17 v.compute_vina_maps(center=[0., 0., 0.], box_size=[30, 30, 30]) 18 # print(3) 19 # print(v.score()) ---> 20 print(v.optimize()) 21 v.dock(exhaustiveness=32) 22 energy_minimized = v.optimize()

File /usr/local/miniconda3/lib/python3.8/site-packages/vina/vina.py:453, in Vina.optimize(self, max_steps) 449 raise ValueError('Error: max_steps cannot be negative.') 451 # It does not make sense to report energies with a precision higher than 3 452 # since the coordinates precision is 3. --> 453 energies = np.around(self._vina.optimize(max_steps), decimals=3) 454 return energies

File /usr/local/miniconda3/lib/python3.8/site-packages/vina/vina_wrapper.py:737, in Vina.optimize(self, max_steps) 736 def optimize(self, max_steps=0): --> 737 return _vina_wrapper.Vina_optimize(self, max_steps)

RuntimeError:

Vina runtime error: Cannot do the optimization. Ligand(s) was(ere) not initialized.

However, when I attempted to run AutoDock calculations using the first set of data directly, there were no errors.

v = Vina(cpu= 8)

v.set_receptor(rigid_pdbqt_filename='/hy-tmp/0_999/0_0.pdbqt')
v.set_ligand_from_file('/hy-tmp/ligand_16415/0.pdbqt')

v.compute_vina_maps(center=[0., 0., 0.], box_size=[30, 30, 30])
print(v.score())
print(v.optimize())
v.dock(exhaustiveness=32)
rwxayheee commented 8 months ago

Hi @YvetteJxy, Not sure if this will work but in your loop codes, could you try loading receptor before ligand, that is, moving

v.set_ligand_from_file(pdbqt_path)

after

v.set_receptor(rigid_pdbqt_filename=f"/hy-tmp/0_999/{i}_{j}.pdbqt")

This was just a thought according to: https://github.com/ccsb-scripps/AutoDock-Vina/blob/d13f9e93e253573b01ffbb28cfd1e2dd26ff9002/src/lib/vina.cpp#L88

YvetteJxy commented 8 months ago

Hi @YvetteJxy, Not sure if this will work but in your loop codes, could you try loading receptor before ligand, that is, moving

v.set_ligand_from_file(pdbqt_path)

after

v.set_receptor(rigid_pdbqt_filename=f"/hy-tmp/0_999/{i}_{j}.pdbqt")

This was just a thought according to:

https://github.com/ccsb-scripps/AutoDock-Vina/blob/d13f9e93e253573b01ffbb28cfd1e2dd26ff9002/src/lib/vina.cpp#L88

You are right. Now my codes can run. Thank you very much. All Best

diogomart commented 8 months ago

Good catch @rwxayheee, thank you!