Exemplo n.º 1
0
class DockingParameter42FileMaker:
    """Accept a <ligand>.pdbqt and <receptor>.pdbqt and create
    <ligand>_<receptor>42.dpf
    """
    def __init__(self, verbose=None):
        self.verbose = verbose
        self.dpo = DockingParameters()

    def getTypes(self, molecule):
        if not len(molecule.allAtoms.bonds[0]):
            molecule.buildBondsByDistance()
        ad4_typer = AutoDock4_AtomTyper(verbose=self.verbose)
        ad4_typer.setAutoDockElements(molecule)
        dict = {}
        for a in molecule.allAtoms:
            dict[a.autodock_element] = 1
        d_types = dict.keys()
        d_types.sort()
        mol_types = d_types[0]
        for t in d_types[1:]:
            mol_types = mol_types + " " + t
        if self.verbose:
            print "end of getTypes: types=", mol_types, ' class=', mol_types.__class__
        return mol_types

    def set_write_all(self, value):
        verbose = self.verbose
        self.dpo['write_all_flag']['value'] = True
        if verbose:
            print "set write_all_flag to", self.dpo['write_all_flag']['value']

    def set_ligand(self, ligand_filename):
        verbose = self.verbose
        self.ligand_filename = os.path.basename(ligand_filename)
        if verbose: print "set ligand_filename to", self.ligand_filename
        self.dpo.set_ligand(ligand_filename)
        #expect a filename like ind.out.pdbq: get 'ind' from it
        self.ligand_stem = string.split(self.ligand_filename, '.')[0]
        if verbose: print "set ligand_stem to", self.ligand_stem
        self.ligand = Read(ligand_filename)[0]
        if self.ligand == None:
            print 'ERROR reading: ', ligand_filename
            return
        if verbose: print "read ", self.ligand.name
        #set dpo:
        #move
        self.dpo['move']['value'] = self.ligand_filename
        if verbose: print "set move to ", self.dpo['move']['value']
        #ndihe
        #assumes ligand has torTree
        self.dpo['ndihe']['value'] = self.ligand.parser.keys.count("BRANCH")
        #self.dpo['ndihe']['value'] = len(self.ligand.torTree.torsionMap)
        if verbose: print "set ndihe to ", self.dpo['ndihe']['value']
        #torsdof
        #caution dpo['torsdof4']['value'] is a list [ndihe, 0.274]
        try:
            self.dpo['torsdof4']['value'][0] = self.ligand.TORSDOF
        except:
            print 'setting torsdof to ligand.ndihe=', self.ligand.ndihe
            self.dpo['torsdof4']['value'][0] = self.ligand.ndihe
        if verbose: print "set torsdof4 to ", self.dpo['torsdof4']['value']
        #types
        self.ligand.types = self.getTypes(self.ligand)
        self.dpo['ligand_types']['value'] = self.ligand.types
        if verbose: print "set types to ", self.dpo['ligand_types']['value']
        #about
        self.ligand.getCenter()
        cen = self.ligand.center
        self.dpo['about']['value'] =  [round(cen[0],4), round(cen[1],4),\
                                        round(cen[2],4)]
        if verbose: print "set about to ", self.dpo['about']['value']

    def set_receptor(self, receptor_filename):
        self.receptor_filename = os.path.basename(receptor_filename)
        self.receptor_stem = string.split(self.receptor_filename, '.')[0]
        self.dpo.set_receptor(receptor_filename)

    def set_flexres(self, flexres_filename):
        flexmol = Read(flexres_filename)[0]
        flexres_filename = os.path.basename(flexres_filename)
        self.dpo['flexres_flag']['value'] = True
        self.dpo['flexres']['value'] = flexres_filename
        #make sure each atom type in flexres molecule is in ligand_types
        d = {}
        current_types = self.dpo['ligand_types']['value'].split()
        for t in current_types:
            d[t] = 1
        for a in flexmol.allAtoms:
            d[a.autodock_element] = 1
        self.dpo['ligand_types']['value'] = string.join(d.keys())

    def set_docking_parameters(self, **kw):
        """Any docking parameters should be set here
        """
        # like this:
        # newdict = {'ga_num_evals':1750000, 'ga_pop_size':150,
        #            'ga_run':20, 'rmstol':2.0}
        # self.mv.dpo['<parameter>']['value'] = <new value>
        for parm, newvalue in kw.items():
            self.dpo[parm]['value'] = newvalue
            if parm == 'set_sw1':
                self.dpo['set_psw1']['value'] = not newvalue
            if parm == 'set_psw1':
                self.dpo['set_sw1']['value'] = not newvalue
            if parm == 'flexres':
                self.set_flexres(newvalue)
            if parm == 'write_all':
                self.set_write_all(newvalue)

    def write_dpf(self,
                  dpf_filename,
                  parm_list=genetic_algorithm_local_search_list4_2,
                  pop_seed=False):
        if not dpf_filename:
            dpf_filename = "%s%s%s%s" % \
                           (self.ligand_stem, "_",
                            self.receptor_stem, ".dpf")
        # now that we have a filename...
        # set initial conformation
        if pop_seed:
            self.dpo['tran0']['value'] = self.dpo['about']['value']
            self.dpo['axisangle0']['value'] = '0 0 0 0'
            #self.dpo['quat0']['value'] = '1.0 0. 0. 0.'
            dihe0 = '0. ' * self.dpo['ndihe']['value']
            dihe0.rstrip()
            self.dpo['dihe0']['value'] = dihe0
        if self.verbose:
            print "writing ", dpf_filename
        self.dpo.write42(dpf_filename, parm_list)
Exemplo n.º 2
0
 def __init__(self, verbose=None):
     self.verbose = verbose
     self.dpo = DockingParameters()
Exemplo n.º 3
0
class DockingParameterFileMaker:
    """Accept a <ligand>.pdbq and <receptor>.pdbqs and create
    <ligand>_<receptor>.dpf
    """

    def __init__(self, verbose = None):
        self.verbose = verbose
        self.dpo = DockingParameters()


    def set_ligand(self, ligand_filename): 
        self.ligand_filename = os.path.basename(ligand_filename)
        if verbose:
            print "set ligand_filename to", self.ligand_filename
        self.dpo.set_ligand(ligand_filename)
        #expect a filename like ind.out.pdbq: get 'ind' from it
        self.ligand_stem = string.split(self.ligand_filename,'.')[0]
        if verbose: print "set ligand_stem to", self.ligand_stem
        self.ligand = Read(ligand_filename)[0]
        if self.ligand==None:
            print 'ERROR reading: ', ligand_filename
            return 
        if verbose: 
            print "read ", self.ligand.name
        #set dpo:
        #move
        self.dpo['move']['value'] = self.ligand_filename
        if verbose: print "set move to ", self.dpo['move']['value']
        #ndihe
        #assumes ligand has torTree
        self.dpo['ndihe']['value'] = self.ligand.parser.keys.count("BRANCH")
        #self.dpo['ndihe']['value'] = len(self.ligand.torTree.torsionMap)
        if verbose: print "set ndihe to ", self.dpo['ndihe']['value']
        #torsdof
        #caution dpo['torsdof']['value'] is a list [ndihe, 0.3113]
        self.dpo['torsdof']['value'][0] = self.ligand.TORSDOF
        if verbose: print "set torsdof to ", self.dpo['torsdof']['value']
        #types
        d = {}
        for a in self.ligand.allAtoms:
            d[a.autodock_element] = 1
        sortKeyList =  ['C','A','N','O','S','H','P','n','f','F','c','b','I','M']
        lig_types = ""
        for t in sortKeyList:
            if t in d.keys():
                lig_types = lig_types + t
        self.ligand.types = lig_types
        self.dpo['types']['value'] = self.ligand.types
        if verbose: print "set types to ", self.dpo['types']['value']
        #about
        self.ligand.getCenter()
        cen = self.ligand.center
        self.dpo['about']['value'] =  [round(cen[0],4), round(cen[1],4),\
                                        round(cen[2],4)]
        if verbose: print "set about to ", self.dpo['about']['value']
        

    def set_receptor(self, receptor_filename):
        self.receptor_filename = os.path.basename(receptor_filename)
        self.receptor_stem = string.split(self.receptor_filename, '.')[0]
        self.dpo.set_receptor(receptor_filename)


    #def set_docking_parameters(self, newdict={}):
    def set_docking_parameters(self, **kw):
        """Any docking paramters should be set here
        """
        # like this: 
        # newdict = {'ga_num_evals':1750000, 'ga_pop_size':150,
        #            'ga_run':20, 'rmstol':2.0}
        # self.dpo['<parameter>']['value'] = <new value>
        # eg self.dpo['rmstol']['value'] = 2.0
        for parm, newvalue in kw.items():
            #print "parm=", parm, ' newvalue=', newvalue
            self.dpo[parm]['value'] = newvalue
            if parm=='set_sw1':
                self.dpo['set_psw1']['value'] = not newvalue
            if parm=='set_psw1':
                self.dpo['set_sw1']['value'] = not newvalue


    def write_dpf(self, dpf_filename,
              parm_list = genetic_algorithm_local_search_list):
        if not dpf_filename:
            dpf_filename = "%s%s%s%s" % \
                           (self.ligand_stem, "_",
                            self.receptor_stem, ".dpf")
        # now that we have a filename...
        if self.verbose:
            print "writing ", dpf_filename
        self.dpo.write(dpf_filename, parm_list)
Exemplo n.º 4
0
 def __init__(self, verbose = None):
     self.verbose = verbose
     self.dpo = DockingParameters()
Exemplo n.º 5
0
 def _buildDpo(self, lines):
     dpo = DockingParameters()
     dpo._parse(lines)
     return dpo
Exemplo n.º 6
0
        print("dpf3_to_dpf4: using default receptor_filename:",
              receptor_filename)
    if not dpf3_filename:
        print(
            'dpf3_to_dpf4: no dpf3_filename specified using GridParameter defaults'
        )

    parms = {}
    parms['simulated_annealing_list4'] = simulated_annealing_list4
    parms['genetic_algorithm_list4'] = genetic_algorithm_list4
    parms[
        'genetic_algorithm_local_search_list4'] = genetic_algorithm_local_search_list4
    parms['local_search_list4'] = local_search_list4

    #what about nucleic acids???
    DPO4 = DockingParameters()
    print("default: ligand_types=", DPO4['ligand_types']['value'])
    orig_compute_unbound_extended_flag = DPO4['compute_unbound_extended_flag'][
        'value']
    if dpf3_filename:
        DPO4.read(dpf3_filename)
        if verbose: print('read ', dpf3_filename)
        DPO4['compute_unbound_extended_flag'][
            'value'] = orig_compute_unbound_extended_flag
    else:
        if verbose: print('using dpo defaults')
    DPO4.set_ligand(ligand_filename)
    DPO4.set_version("4.1")
    DPO4['set_sw1']['value'] = 0
    DPO4['set_sw1_flag']['value'] = 0
    DPO4['set_psw1']['value'] = 1
Exemplo n.º 7
0
class DockingParameterFileMaker:
    """Accept a <ligand>.pdbq and <receptor>.pdbqs and create
    <ligand>_<receptor>.dpf
    """
    def __init__(self, verbose=None):
        self.verbose = verbose
        self.dpo = DockingParameters()

    def set_ligand(self, ligand_filename):
        self.ligand_filename = os.path.basename(ligand_filename)
        if verbose:
            print "set ligand_filename to", self.ligand_filename
        self.dpo.set_ligand(ligand_filename)
        #expect a filename like ind.out.pdbq: get 'ind' from it
        self.ligand_stem = string.split(self.ligand_filename, '.')[0]
        if verbose: print "set ligand_stem to", self.ligand_stem
        self.ligand = Read(ligand_filename)[0]
        if self.ligand == None:
            print 'ERROR reading: ', ligand_filename
            return
        if verbose:
            print "read ", self.ligand.name
        #set dpo:
        #move
        self.dpo['move']['value'] = self.ligand_filename
        if verbose: print "set move to ", self.dpo['move']['value']
        #ndihe
        #assumes ligand has torTree
        self.dpo['ndihe']['value'] = self.ligand.parser.keys.count("BRANCH")
        #self.dpo['ndihe']['value'] = len(self.ligand.torTree.torsionMap)
        if verbose: print "set ndihe to ", self.dpo['ndihe']['value']
        #torsdof
        #caution dpo['torsdof']['value'] is a list [ndihe, 0.3113]
        self.dpo['torsdof']['value'][0] = self.ligand.TORSDOF
        if verbose: print "set torsdof to ", self.dpo['torsdof']['value']
        #types
        d = {}
        for a in self.ligand.allAtoms:
            d[a.autodock_element] = 1
        sortKeyList = [
            'C', 'A', 'N', 'O', 'S', 'H', 'P', 'n', 'f', 'F', 'c', 'b', 'I',
            'M'
        ]
        lig_types = ""
        for t in sortKeyList:
            if t in d.keys():
                lig_types = lig_types + t
        self.ligand.types = lig_types
        self.dpo['types']['value'] = self.ligand.types
        if verbose: print "set types to ", self.dpo['types']['value']
        #about
        self.ligand.getCenter()
        cen = self.ligand.center
        self.dpo['about']['value'] =  [round(cen[0],4), round(cen[1],4),\
                                        round(cen[2],4)]
        if verbose: print "set about to ", self.dpo['about']['value']

    def set_receptor(self, receptor_filename):
        self.receptor_filename = os.path.basename(receptor_filename)
        self.receptor_stem = string.split(self.receptor_filename, '.')[0]
        self.dpo.set_receptor(receptor_filename)

    #def set_docking_parameters(self, newdict={}):
    def set_docking_parameters(self, **kw):
        """Any docking paramters should be set here
        """
        # like this:
        # newdict = {'ga_num_evals':1750000, 'ga_pop_size':150,
        #            'ga_run':20, 'rmstol':2.0}
        # self.dpo['<parameter>']['value'] = <new value>
        # eg self.dpo['rmstol']['value'] = 2.0
        for parm, newvalue in kw.items():
            #print "parm=", parm, ' newvalue=', newvalue
            self.dpo[parm]['value'] = newvalue
            if parm == 'set_sw1':
                self.dpo['set_psw1']['value'] = not newvalue
            if parm == 'set_psw1':
                self.dpo['set_sw1']['value'] = not newvalue

    def write_dpf(self,
                  dpf_filename,
                  parm_list=genetic_algorithm_local_search_list):
        if not dpf_filename:
            dpf_filename = "%s%s%s%s" % \
                           (self.ligand_stem, "_",
                            self.receptor_stem, ".dpf")
        # now that we have a filename...
        if self.verbose:
            print "writing ", dpf_filename
        self.dpo.write(dpf_filename, parm_list)
Exemplo n.º 8
0
class DockingParameter4FileMaker:
    """Accept a <ligand>.pdbqt and <receptor>.pdbqt and create
    <ligand>_<receptor>4.dpf
    """

    def __init__(self, verbose = None):
        self.verbose = verbose
        self.dpo = DockingParameters()


    def getTypes(self, molecule):
        if not len(molecule.allAtoms.bonds[0]):
            molecule.buildBondsByDistance()
        ad4_typer = AutoDock4_AtomTyper(verbose=self.verbose)
        ad4_typer.setAutoDockElements(molecule)
        dict = {}
        for a in molecule.allAtoms:
            dict[a.autodock_element] = 1
        d_types = dict.keys()
        d_types.sort()
        mol_types = d_types[0]
        for t in d_types[1:]:
            mol_types = mol_types + " " + t
        if self.verbose: print "end of getTypes: types=", mol_types, ' class=', mol_types.__class__
        return mol_types


    def set_write_all(self, value):
        verbose = self.verbose
        self.dpo['write_all_flag']['value'] = True
        if verbose: print "set write_all_flag to", self.dpo['write_all_flag']['value']


    def set_ligand(self, ligand_filename): 
        verbose = self.verbose
        self.ligand_filename = os.path.basename(ligand_filename)
        if verbose: print "set ligand_filename to", self.ligand_filename
        self.dpo.set_ligand(ligand_filename)
        #expect a filename like ind.out.pdbq: get 'ind' from it
        self.ligand_stem = string.split(self.ligand_filename,'.')[0]
        if verbose: print "set ligand_stem to", self.ligand_stem
        self.ligand = Read(ligand_filename)[0]
        if self.ligand==None:
            print 'ERROR reading: ', ligand_filename
            return 
        if verbose: print "read ", self.ligand.name
        #set dpo:
        #move
        self.dpo['move']['value'] = self.ligand_filename
        if verbose: print "set move to ", self.dpo['move']['value']
        #ndihe
        #assumes ligand has torTree
        self.dpo['ndihe']['value'] = self.ligand.parser.keys.count("BRANCH")
        #self.dpo['ndihe']['value'] = len(self.ligand.torTree.torsionMap)
        if verbose: print "set ndihe to ", self.dpo['ndihe']['value']
        #torsdof
        #caution dpo['torsdof4']['value'] is a list [ndihe, 0.274]
        try:
            self.dpo['torsdof4']['value'][0] = self.ligand.TORSDOF
        except:
            print 'setting torsdof to ligand.ndihe=', self.ligand.ndihe
            self.dpo['torsdof4']['value'][0] = self.ligand.ndihe
        if verbose: print "set torsdof4 to ", self.dpo['torsdof4']['value']
        #types
        self.ligand.types = self.getTypes(self.ligand)
        self.dpo['ligand_types']['value'] = self.ligand.types
        if verbose: print "set types to ", self.dpo['ligand_types']['value']
        #about
        self.ligand.getCenter()
        cen = self.ligand.center
        self.dpo['about']['value'] =  [round(cen[0],4), round(cen[1],4),\
                                        round(cen[2],4)]
        if verbose: print "set about to ", self.dpo['about']['value']
        

    def set_receptor(self, receptor_filename):
        self.receptor_filename = os.path.basename(receptor_filename)
        self.receptor_stem = string.split(self.receptor_filename, '.')[0]
        self.dpo.set_receptor(receptor_filename)


    def set_flexres(self, flexres_filename):
        flexmol = Read(flexres_filename)[0]
        flexres_filename = os.path.basename(flexres_filename)
        self.dpo['flexres_flag']['value'] = True
        self.dpo['flexres']['value'] = flexres_filename
        #make sure each atom type in flexres molecule is in ligand_types
        d = {}
        current_types = self.dpo['ligand_types']['value'].split()
        for t in current_types:
            d[t] = 1
        for a in flexmol.allAtoms:
            d[a.autodock_element] = 1
        self.dpo['ligand_types']['value'] = string.join(d.keys())


    def set_docking_parameters(self, **kw):
        """Any docking parameters should be set here
        """
        # like this: 
        # newdict = {'ga_num_evals':1750000, 'ga_pop_size':150,
        #            'ga_run':20, 'rmstol':2.0}
        # self.mv.dpo['<parameter>']['value'] = <new value>
        for parm, newvalue in kw.items():
            self.dpo[parm]['value'] = newvalue
            if parm=='set_sw1':
                self.dpo['set_psw1']['value'] = not newvalue
            if parm=='set_psw1':
                self.dpo['set_sw1']['value'] = not newvalue
            if parm=='flexres':
                self.set_flexres(newvalue) 
            if parm=='write_all':
                self.set_write_all(newvalue) 


    def write_dpf(self, dpf_filename,
              parm_list = genetic_algorithm_local_search_list4, 
              pop_seed = False):
        if not dpf_filename:
            dpf_filename = "%s%s%s%s" % \
                           (self.ligand_stem, "_",
                            self.receptor_stem, ".dpf")
        # now that we have a filename...
        # set initial conformation
        if pop_seed:
            self.dpo['tran0']['value'] = self.dpo['about']['value']
            self.dpo['axisangle0']['value'] = '0 0 0 0'
            #self.dpo['quat0']['value'] = '1.0 0. 0. 0.'
            dihe0 = '0. '*self.dpo['ndihe']['value']
            dihe0.rstrip()
            self.dpo['dihe0']['value'] = dihe0 
        if self.verbose:
            print "writing ", dpf_filename
        self.dpo.write4(dpf_filename, parm_list)
    # @@ ASSUMPTIONS: WCG conventions for dpf and gpf names @@
    # @@ from docking directory name                        @@
    dpf_pathname = os.path.join(docking_pathname, docking_name) + ".dpf"
    dpf_filename = os.path.basename(dpf_pathname)
    # remove "faahNNNN_ from docking name
    gpf_pathname = os.path.join(docking_pathname, docking_name[9:]) + ".gpf"
    gpf_filename = os.path.basename(gpf_pathname)

    #
    # get filenames from the dpf and gpf
    #
    from AutoDockTools.DockingParameters import DockingParameters
    from AutoDockTools.GridParameters import GridParameters

    dpo = DockingParameters()
    log.info("reading dpf: %s" % dpf_pathname)
    dpo.read(dpf_pathname)
    ligand_filename = dpo["move"]["value"]
    ligand_pathname = os.path.join(docking_pathname, ligand_filename)
    log.info("ligand_filename: %s" % ligand_filename)
    log.debug("ligand_pathname: %s" % ligand_pathname)

    gpo = GridParameters()
    log.info("reading gpf: %s" % gpf_pathname)
    gpo.read(gpf_pathname)
    receptor_filename = gpo["receptor"]["value"]
    receptor_pathname = os.path.join(docking_pathname, receptor_filename)
    log.info("receptor_filename: %s" % receptor_filename)
    log.debug("receptor_pathname: %s" % receptor_pathname)
Exemplo n.º 10
0
        usage()
        sys.exit()
    if not receptor_filename:
        receptor_filename = dpf3_stem + '.pdbqt'
        print "dpf3_to_dpf4: using default receptor_filename:", receptor_filename
    if not dpf3_filename:
        print 'dpf3_to_dpf4: no dpf3_filename specified using GridParameter defaults'

    parms= {}
    parms['simulated_annealing_list4'] =  simulated_annealing_list4
    parms['genetic_algorithm_list4'] = genetic_algorithm_list4
    parms['genetic_algorithm_local_search_list4'] = genetic_algorithm_local_search_list4
    parms['local_search_list4'] = local_search_list4 

    #what about nucleic acids???
    DPO4 = DockingParameters()
    print "default: ligand_types=", DPO4['ligand_types']['value']
    orig_compute_unbound_extended_flag = DPO4['compute_unbound_extended_flag']['value']
    if dpf3_filename:
        DPO4.read(dpf3_filename)
        if verbose: print 'read ', dpf3_filename
        DPO4['compute_unbound_extended_flag']['value'] = orig_compute_unbound_extended_flag
    else:
        if verbose: print 'using dpo defaults'
    DPO4.set_ligand(ligand_filename)
    DPO4.set_version("4.1")
    DPO4['set_sw1']['value'] = 0
    DPO4['set_sw1_flag']['value'] = 0
    DPO4['set_psw1']['value'] = 1
    DPO4['set_psw1_flag']['value'] = 1
    res = DPO4.set_ligand_types_from_filename(ligand_filename)
Exemplo n.º 11
0
class LibraryDpfWriter:


    def __init__(self, dpffile, extension='pdbq', \
                    err_file="write_lib_dpf_errors",
                    prefix='', verbose=0):
        self.verbose = verbose
        if verbose: print("self.verbose = ", verbose)
        self.prefix = prefix
        self.setup(dpffile)
        self.parm_list_dict = {}
        self.parm_list_dict['GALS'] = genetic_algorithm_local_search_list
        self.parm_list_dict['GA'] = genetic_algorithm_list
        self.parm_list_dict['LS'] = local_search_list
        self.parm_list_dict['SA'] = simulated_annealing_list
        self.ligandfilenames = []
        self.extension = extension
        self.error_file = open(err_file, 'w')


    def setup(self, dpffile):
        self.dpffile = dpffile
        self.dpo = DockingParameters()
        self.dpo.read(dpffile)


    def getligands(self, extension, name=''):
        typeDict = {}
        key = name + '*.' + extension
        self.ligandfilenames = glob.glob(key)
        return self.ligandfilenames


    def write(self, dpo, style='GALS'):
        #one file per ligand
        dpffiles = []
        receptor_stem = self.dpo.receptor_stem
        parm_list = self.parm_list_dict[style]
        if not len(self.ligandfilenames):
            self.getligands(self.extension)
        #print "len(self.ligandfilenames)=", len(self.ligandfilenames)
        for ligand_file in self.ligandfilenames:
            #get the types
            typeDict = {}
            m = Read(ligand_file)[0]
            for a in m.allAtoms:
                typeDict[a.autodock_element] = 1
            type_list = list(typeDict.keys())
            #check that there is a map for each type
            ok = 1
            for t in type_list:
                mapfile = receptor_stem + '.' + t + '.map'
                try:
                    assert os.path.exists(mapfile)
                except:
                    ok = 0
                    ostr = ligand_file + " missing map " + t + "\n"
                    self.error_file.write(ostr)
                    break  #try to continue 'for' statement with next filename
            #update dpo with ligand specific values
            if not ok:
                if self.verbose:
                    print("problem with ", ligand_file)
                continue
            types = string.join(type_list,'')
            self.dpo['move']['value'] = ligand_file
            if self.verbose: print("set types to ", types)
            self.dpo['types']['value'] = types
            #CAUTION: dpo['torsdof']['value'] is [0,0.3113]
            self.dpo['torsdof']['value'][0] = m.TORSDOF
            if hasattr(m, 'ndihe'):
                ndihe = m.ndihe
            elif hasattr(m, 'torscount'):
                ndihe = m.torscount
            elif hasattr(m, 'torTree'):
                ndihe = len(m.torTree.torsionMap)
            else:
                msg = ligand_file + " is not properly formatted: no torsions!"
                raise AttributeError(msg)
            self.dpo['ndihe']['value'] = ndihe
            outputfilename = self.prefix + m.name + "_" + style + ".dpf"
            if self.verbose: print("writing ", outputfilename)
            self.dpo.write(outputfilename, parm_list)
            dpffiles.append(outputfilename)
        return dpffiles
Exemplo n.º 12
0
 def setup(self, dpffile):
     self.dpffile = dpffile
     self.dpo = DockingParameters()
     self.dpo.read(dpffile)
    
    # @@ ASSUMPTIONS: WCG conventions for dpf and gpf names @@
    # @@ from docking directory name                        @@
    dpf_pathname = os.path.join(docking_pathname, docking_name) + ".dpf"
    dpf_filename = os.path.basename(dpf_pathname)
    # remove "faahNNNN_ from docking name
    gpf_pathname = os.path.join(docking_pathname, docking_name[9:]) + ".gpf"
    gpf_filename = os.path.basename(gpf_pathname)

    #
    # get filenames from the dpf and gpf
    #
    from AutoDockTools.DockingParameters import DockingParameters
    from AutoDockTools.GridParameters import GridParameters

    dpo = DockingParameters()
    log.info("reading dpf: %s" % dpf_pathname)
    dpo.read(dpf_pathname)
    ligand_filename = dpo["move"]["value"]
    ligand_pathname = os.path.join(docking_pathname, ligand_filename)
    log.info ("ligand_filename: %s" % ligand_filename)
    log.debug("ligand_pathname: %s" % ligand_pathname)

    gpo = GridParameters()
    log.info("reading gpf: %s" % gpf_pathname)
    gpo.read(gpf_pathname)
    receptor_filename = gpo["receptor"]["value"]
    receptor_pathname = os.path.join(docking_pathname, receptor_filename)
    log.info ("receptor_filename: %s" % receptor_filename)
    log.debug("receptor_pathname: %s" % receptor_pathname)
class LibraryDpfWriter:


    def __init__(self, dpffile, extension='pdbq', \
                    err_file="write_lib_dpf_errors", 
                    prefix='', verbose=0):
        self.verbose = verbose
        if verbose: print "self.verbose = ", verbose
        self.prefix = prefix
        self.setup(dpffile)
        self.parm_list_dict = {}
        self.parm_list_dict['GALS'] = genetic_algorithm_local_search_list
        self.parm_list_dict['GA'] = genetic_algorithm_list
        self.parm_list_dict['LS'] = local_search_list
        self.parm_list_dict['SA'] = simulated_annealing_list
        self.ligandfilenames = []
        self.extension = extension
        self.error_file = open(err_file, 'w')


    def setup(self, dpffile):
        self.dpffile = dpffile
        self.dpo = DockingParameters() 
        self.dpo.read(dpffile)


    def getligands(self, extension, name=''):
        typeDict = {}
        key = name + '*.' + extension
        self.ligandfilenames = glob.glob(key)
        return self.ligandfilenames


    def write(self, dpo, style='GALS'):
        #one file per ligand
        dpffiles = []
        receptor_stem = self.dpo.receptor_stem
        parm_list = self.parm_list_dict[style]
        if not len(self.ligandfilenames):
            self.getligands(self.extension)
        #print "len(self.ligandfilenames)=", len(self.ligandfilenames)
        for ligand_file in self.ligandfilenames:
            #get the types 
            typeDict = {}
            m = Read(ligand_file)[0]
            for a in m.allAtoms:
                typeDict[a.autodock_element] = 1
            type_list = typeDict.keys()
            #check that there is a map for each type
            ok = 1
            for t in type_list:
                mapfile = receptor_stem + '.' + t + '.map'
                try:
                    assert os.path.exists(mapfile)
                except:
                    ok = 0
                    ostr = ligand_file + " missing map " + t + "\n"
                    self.error_file.write(ostr)
                    break  #try to continue 'for' statement with next filename
            #update dpo with ligand specific values
            if not ok:
                if self.verbose:
                    print "problem with ", ligand_file
                continue
            types = string.join(type_list,'')
            self.dpo['move']['value'] = ligand_file
            if self.verbose: print "set types to ", types
            self.dpo['types']['value'] = types
            #CAUTION: dpo['torsdof']['value'] is [0,0.3113]
            self.dpo['torsdof']['value'][0] = m.TORSDOF
            if hasattr(m, 'ndihe'):
                ndihe = m.ndihe
            elif hasattr(m, 'torscount'):
                ndihe = m.torscount
            elif hasattr(m, 'torTree'):
                ndihe = len(m.torTree.torsionMap)
            else:
                msg = ligand_file + " is not properly formatted: no torsions!"
                raise AttributeError, msg
            self.dpo['ndihe']['value'] = ndihe
            outputfilename = self.prefix + m.name + "_" + style + ".dpf"
            if self.verbose: print "writing ", outputfilename
            self.dpo.write(outputfilename, parm_list)
            dpffiles.append(outputfilename)
        return dpffiles
 def setup(self, dpffile):
     self.dpffile = dpffile
     self.dpo = DockingParameters() 
     self.dpo.read(dpffile)