schrodinger / pymol-open-source

Open-source foundation of the user-sponsored PyMOL molecular visualization system.
https://pymol.org/
Other
1.2k stars 281 forks source link

ModuleNotFoundError: No module named 'requests' #249

Closed MarcAmil30 closed 1 year ago

MarcAmil30 commented 2 years ago

Hello :)

When running a python script (shown below called mutation.py) with PyMOL, I get a ModuleNotFoundError: No module named 'requests' when running it through the terminal with $ pymol mutation.py. However, I get no error when running it through the GUI and using the Run Script option.

Both give the same output but one (terminal option) also outputs an error.

Q: I wanted to ask why this is the case?

The code, which is not mine, is shown below:

prot_list = [['1shr', 'A']] # example [['1nzp', 'A'], ['4oxn', 'B']] # how many proteins do you want
residues_list = [36, 37, 38] # example [3, 35, 100] # only 3 residues
aminoacid = 'ALA' # only one

for prot in prot_list:
    #Initialize
    # fetch protein by PDB code
    cmd.fetch(prot[0])
    # mutagenesis mode
    cmd.wizard("mutagenesis")
    cmd.do("refresh_wizard")

    # create 7 object 
    for obj in range(1,8):
        cmd.create('obj_%s' % obj, prot[0])
    # Mutate
    cmd.get_wizard().set_mode(aminoacid)

    #for obj_1 (mutation in all residues)   
    cmd.get_wizard().do_select("/obj_1//%s/%d" % (prot[1], residues_list[0]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.get_wizard().do_select("/obj_1//%s/%d" % (prot[1], residues_list[1]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.get_wizard().do_select("/obj_1//%s/%d" % (prot[1], residues_list[2]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[0], residues_list[1], residues_list[2], aminoacid),'obj_1')

    #for obj_2 (mutation in residue # 1 and 2)
    cmd.get_wizard().do_select("/obj_2//%s/%d" % (prot[1], residues_list[0]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.get_wizard().do_select("/obj_2//%s/%d" % (prot[1], residues_list[1]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[0], residues_list[2], aminoacid),'obj_2')

    #for obj_3 (mutation in residue # 1 and 3)
    cmd.get_wizard().do_select("/obj_3//%s/%d" % (prot[1], residues_list[0]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.get_wizard().do_select("/obj_3//%s/%d" % (prot[1], residues_list[2]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[0], residues_list[2], aminoacid),'obj_3')

    #for obj_4 (mutation in residue # 2 and 3)
    cmd.get_wizard().do_select("/obj_4//%s/%d" % (prot[1], residues_list[1]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.get_wizard().do_select("/obj_4//%s/%d" % (prot[1], residues_list[2]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[1], residues_list[2], aminoacid),'obj_4')

    #for obj_5 (mutation in residue # 1)
    cmd.get_wizard().do_select("/obj_5//%s/%d" % (prot[1], residues_list[0]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[0], aminoacid),'obj_5')
    #for obj_6 (mutation in residue # 2)
    cmd.get_wizard().do_select("/obj_6//%s/%d" % (prot[1], residues_list[1]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[1], aminoacid),'obj_6')
    #for obj_7 (mutation in residue # 3)
    cmd.get_wizard().do_select("/obj_7//%s/%d" % (prot[1], residues_list[2]))
    cmd.frame(1)
    cmd.get_wizard().apply()
    cmd.save("%s_%s_%s_x_%s.pdb" % (prot[0], prot[1], residues_list[2], aminoacid),'obj_7')

    # Done
    cmd.set_wizard()
    if len(prot_list) == 1:
        continue
    else:
        cmd.reinitialize()  
JarrettSJohnson commented 2 years ago

I cannot reproduce what you're observing but I can perhaps guess the underlying issue:

The pymol application that is ran by default in the terminal may be different than the PyMOL application that you're running by GUI. By chance might you have another version of PyMOL installed somewhere? Perhaps the output of which pymol in the terminal can shed some light. We only package and import the request library for the incentive version but not for open-source; so that's probably where I'd start.

JarrettSJohnson commented 1 year ago

Closing after about a year of inactivity. Please reopen if you still need assistance with this.