leandroradusky / pyfoldx

pyFoldX: python bindings for FoldX.
37 stars 4 forks source link

Problems with pyFoldX in jupyter notebook using WSL #6

Closed EmilioKolo closed 9 months ago

EmilioKolo commented 1 year ago

I'm trying to run pyFoldX using Windows Subsystem for Linux, and have encountered two different problems that may or may not have to do with running it on WSL. I made sure to include the path to foldx in the .bashrc file. I wasn't sure if I needed to put the path to the folder or to the file, but I tried both and it didn't change any of the error messages.

The code I'm running is getting a structure from PDB and trying to run getTotalEnergy() on it, and I get two different error messages, one on the command line and a different one in jupyter.

Using the Ubuntu command line, it throws back an index out of range error.

>>> from pyfoldx.structure import Structure
>>> st=Structure("3rkq");
>>> st.getTotalEnergy();
Computing total energy for structure...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/emilio/.local/lib/python3.8/site-packages/pyfoldx/structure/structure.py", line 215, in getTotalEnergy
    foldxHandler.getTotalEnergy(self, consider_waters=consider_waters)[terms].loc[self.code]
  File "/home/emilio/.local/lib/python3.8/site-packages/pyfoldx/foldx/foldxHandler.py", line 101, in getTotalEnergy
    dfData = st_lines[0].split("\t")[1:-1]
IndexError: list index out of range

Using jupyter, the code is a bit longer but it seems to not get the FOLDX_LOCATION variable, which ends up being None.

Computing total energy for structure...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 4
      1 ### Pruebas de pyfoldx
      3 st=Structure("3rkq"); 
----> 4 st.getTotalEnergy(); 
      6 print('fin')

File ~/.local/lib/python3.8/site-packages/pyfoldx/structure/structure.py:215, in Structure.getTotalEnergy(self, terms, consider_waters)
    212     self.totalEnergy = pd.DataFrame(columns=foldxHandler.ENERGY_TERMS)
    213     terms=foldxHandler.ENERGY_TERMS
--> 215 foldxHandler.getTotalEnergy(self, consider_waters=consider_waters)[terms].loc[self.code]
    218 print( "Energy computed." )
    219 return self.totalEnergy

File ~/.local/lib/python3.8/site-packages/pyfoldx/foldx/foldxHandler.py:87, in getTotalEnergy(st, consider_waters, other_parameters)
     84 st.toPdbFile(TMP_FOLDER+"tmp.pdb")
     86 # Run FoldX
---> 87 runFoldX(command          = "Stability", 
     88          working_folder   = TMP_FOLDER, 
     89          pdb              = "tmp.pdb",
     90          other_parameters = other_parameters,
     91          consider_waters  = consider_waters )
     93 # Read files
     94 st_lines = FileHandler.getLines(TMP_FOLDER+"tmp_0_ST.fxout")

File ~/.local/lib/python3.8/site-packages/pyfoldx/foldx/foldxHandler.py:47, in runFoldX(command, working_folder, pdb, other_parameters, working_with_rna, silent, consider_waters)
     44     out = open(working_folder+"./tmp.pdb","r")
     46 with out: 
---> 47     checkFoldx()
     50     c="cd "+working_folder+"; "
     51     c+=FOLDX_LOCATION+" --command="+command+" --pdb="+pdb

File ~/.local/lib/python3.8/site-packages/pyfoldx/foldx/foldxHandler.py:31, in checkFoldx()
     30 def checkFoldx():
---> 31     if not FileHandler.fileExists(FOLDX_LOCATION):
     32         print("FoldX executable not found, please set the variable FOLDX_LOCATION")
     33         exit(0)

File ~/.local/lib/python3.8/site-packages/pyfoldx/handlers/fileHandler.py:30, in FileHandler.fileExists(path)
     23 '''
     24 Check if a file exists.
     25 
     26 :param path: The file or folder to check if exists.
     27 :return: True if the file or folder exists. 
     28 '''
     29 try:
---> 30     with open(path): return True
     31 except IOError:
     32     return False

TypeError: expected str, bytes or os.PathLike object, not NoneType

I'm not sure if I set up something wrong or if this is a WSL problem.

Thanks in advance.

ascusf commented 1 year ago

Download FoldX Suite 5.0 fixed the problem so far. I downloaded FoldX Suite 4.0 first and ran into those issues. I have to type: source ~/.bashrc each time before entering spyder to run pyfoldx.

and I used

Load a protein PDB file from the internet

st = Structure("2ci2","/to_path/2ci2.pdb")

Append and turn horizontal both dataframes

combinedDf = seqEnergyOriginal.T._append(seqRepaired.T)

leandroradusky commented 9 months ago

As said above, this problem is due to the inability of pyFoldx to run with Foldx4.

Closing this issue.