Example #1
0
    def _f_process(self, x):

        __doc___ = """
        returns the squared sum of residuals
        objective function is the free energy
        """

        self._f[:] = 0.
        if self.anal_grad:
            self._g[:] = 0.

            ### &PyArray_Type, &target,
            ### &PyArray_Type, &source,
            ### &PyArray_Type, &assign,
            ### &PyArray_Type, &factor,
            ### &PyArray_Type, &assign_factor

            ### Calculate DDG_comp - DDG_exp
            if self.pairs:
                _f = merge_casedata_ext(self._calc_data, self.ind_case, self.w,
                                        self.ind_rec)
                self._f[:] += pair_difference_ext(_f, self.pairidx) + x[-1]

                for i in range(self.parms - 1):
                    _g = merge_casedata_ext(self._gradients[:,
                                                            i], self.ind_case,
                                            self.w, self.ind_rec)
                    self._g[:, i] += pair_difference_ext(_g, self.pairidx)
                self._g[:, -1] = 1

            else:
                self._f[:] += merge_casedata_ext(self._calc_data,
                                                 self.ind_case, self.w,
                                                 self.ind_rec)

                for i in range(self.parms):
                    self._g[:,
                            i] += merge_casedata_ext(self._gradients[:, i],
                                                     self.ind_case, self.w,
                                                     self.ind_rec)

        else:

            ### &PyArray_Type, &target,
            ### &PyArray_Type, &source,
            ### &PyArray_Type, &assign,
            ### &PyArray_Type, &factor,
            ### &PyArray_Type, &assign_factor

            if self.pairs:
                _f = merge_casedata_ext(self._calc_data, self.ind_case, self.w,
                                        self.ind_rec)
                self._f[:] += pair_difference_ext(_f, self.pairidx) + x[-1]

            else:
                self._f[:] += merge_casedata_ext(self._calc_data,
                                                 self.ind_case, self.w,
                                                 self.ind_rec)
Example #2
0
    def set_functional(self):

        if self.parms == 6:
            self._gist_functional_ext = gist_functional_6p_ext
        elif self.parms == 5:
            self._gist_functional_ext = gist_functional_5p_ext
        elif self.parms == 4:
            self._gist_functional_ext = gist_functional_4p_ext

        else:
            parms_error(self.parms, self._parms)

        ### Note, all arrays which are passed to the functionals (such as
        ### gist_functional_6p_ext), must be DOUBLE (i.e. 32bit floating
        ### point type in C). This will not checked within the C routine
        ### (but should be implemented at some point ...).

        if self.pairs:
            self._exp_data = pair_difference_ext(self.dg.astype(DOUBLE),
                                                 self.pairidx)
            self._f = np.zeros(self.N_pairs, dtype=DOUBLE)
            self._g = np.zeros((self.N_pairs, self._parms), dtype=DOUBLE)
        else:
            self._exp_data = np.copy(self.dg.astype(DOUBLE))
            self._f = np.zeros(self.N_case, dtype=DOUBLE)
            self._g = np.zeros((self.N_case, self._parms), dtype=DOUBLE)

        self._gradients = np.zeros((self.N_pos, self.parms), dtype=DOUBLE)
        self._calc_data = np.zeros(self.N_pos, dtype=DOUBLE)
        self._dx = 0.00000001
Example #3
0
    def _f_process(self, x):

        __doc___ = """
        returns the squared sum of residuals
        objective function is the free energy
        """

        self.gist_functional(x)

        ### x[0] = E_aff
        ### x[1] = e_co
        ### x[2] = S_aff
        ### x[3] = s_co
        ### x[4] = g_co (Rec)
        ### x[5] = g_co (Cplx)
        ### x[6] = g_co (Lig)
        ### x[7] = C_E
        ### x[8] = C_S

        self._f[:] = 0.
        if self.anal_grad:
            self._g[:] = 0.
            ### Complex and Ligand contributions

            ### &PyArray_Type, &source,
            ### &PyArray_Type, &assign,
            ### &PyArray_Type, &factor,
            ### &PyArray_Type, &assign_factor

            if self.pairs:
                _f = merge_casedata_ext(self._calc_data_cplx[:, 0],
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:, 0],
                                         self.ind_case_lig, self.w_lig,
                                         self.ind_case_lig)
                self._f[:, 0] += pair_difference_ext(_f, self.pairidx)
                _f = merge_casedata_ext(self._calc_data_cplx[:, 1],
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:, 1],
                                         self.ind_case_lig, self.w_lig,
                                         self.ind_case_lig)
                self._f[:, 1] += pair_difference_ext(_f, self.pairidx)

                for i in range(self.parms - 2):
                    _g = merge_casedata_ext(self._gradients_cplx[:, i, 0],
                                            self.ind_case_cplx, self.w_cplx,
                                            self.ind_case_cplx)
                    _g -= merge_casedata_ext(self._gradients_lig[:, i, 0],
                                             self.ind_case_lig, self.w_lig,
                                             self.ind_case_lig)
                    self._g[:, i, 0] += pair_difference_ext(_g, self.pairidx)
                    _g = merge_casedata_ext(self._gradients_cplx[:, i, 1],
                                            self.ind_case_cplx, self.w_cplx,
                                            self.ind_case_cplx)
                    _g -= merge_casedata_ext(self._gradients_lig[:, i, 1],
                                             self.ind_case_lig, self.w_lig,
                                             self.ind_case_lig)
                    self._g[:, i, 1] += pair_difference_ext(_g, self.pairidx)
                _g = merge_casedata_ext(self._gradients_cplx[:, -3, 0],
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                self._g[:, -4, 0] += pair_difference_ext(_g, self.pairidx)
                _g = merge_casedata_ext(self._gradients_lig[:, -3, 0],
                                        self.ind_case_lig, self.w_lig,
                                        self.ind_case_lig)
                self._g[:, -3, 0] -= pair_difference_ext(_g, self.pairidx)
                _g = merge_casedata_ext(self._gradients_cplx[:, -3, 1],
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                self._g[:, -4, 1] += pair_difference_ext(_g, self.pairidx)
                _g = merge_casedata_ext(self._gradients_lig[:, -3, 1],
                                        self.ind_case_lig, self.w_lig,
                                        self.ind_case_lig)
                self._g[:, -3, 1] -= pair_difference_ext(_g, self.pairidx)

            else:
                self._f[:, 0] = merge_casedata_ext(self._calc_data_cplx[:, 0],
                                                   self.ind_case_cplx,
                                                   self.w_cplx,
                                                   self.ind_case_cplx)
                self._f[:, 0] -= merge_casedata_ext(self._calc_data[:, 0],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
                self._f[:,
                        0] -= merge_casedata_ext(self._calc_data_lig[:, 0],
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)
                self._f[:, 1] = merge_casedata_ext(self._calc_data_cplx[:, 1],
                                                   self.ind_case_cplx,
                                                   self.w_cplx,
                                                   self.ind_case_cplx)
                self._f[:, 1] -= merge_casedata_ext(self._calc_data[:, 1],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
                self._f[:,
                        1] -= merge_casedata_ext(self._calc_data_lig[:, 1],
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)

                for i in range(self.parms - 2):
                    self._g[:, i, 0] = merge_casedata_ext(
                        self._gradients_cplx[:, i, 0], self.ind_case_cplx,
                        self.w_cplx, self.ind_case_cplx)
                    self._g[:, i,
                            0] -= merge_casedata_ext(self._gradients[:, i, 0],
                                                     self.ind_case, self.w,
                                                     self.ind_rec)
                    self._g[:, i, 0] -= merge_casedata_ext(
                        self._gradients_lig[:, i, 0], self.ind_case_lig,
                        self.w_lig, self.ind_case_lig)
                    self._g[:, i, 1] = merge_casedata_ext(
                        self._gradients_cplx[:, i, 1], self.ind_case_cplx,
                        self.w_cplx, self.ind_case_cplx)
                    self._g[:, i,
                            1] -= merge_casedata_ext(self._gradients[:, i, 1],
                                                     self.ind_case, self.w,
                                                     self.ind_rec)
                    self._g[:, i, 1] -= merge_casedata_ext(
                        self._gradients_lig[:, i, 1], self.ind_case_lig,
                        self.w_lig, self.ind_case_lig)

                self._g[:, -4, 0] += merge_casedata_ext(
                    self._gradients_cplx[:, -3, 0], self.ind_case_cplx,
                    self.w_cplx, self.ind_case_cplx)
                self._g[:, -5,
                        0] -= merge_casedata_ext(self._gradients[:, -3, 0],
                                                 self.ind_case, self.w,
                                                 self.ind_rec)
                self._g[:, -3,
                        0] -= merge_casedata_ext(self._gradients_lig[:, -3, 0],
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)
                self._g[:, -4, 1] += merge_casedata_ext(
                    self._gradients_cplx[:, -3, 1], self.ind_case_cplx,
                    self.w_cplx, self.ind_case_cplx)
                self._g[:, -5,
                        1] -= merge_casedata_ext(self._gradients[:, -3, 1],
                                                 self.ind_case, self.w,
                                                 self.ind_rec)
                self._g[:, -3,
                        1] -= merge_casedata_ext(self._gradients_lig[:, -3, 1],
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)

            self._f[:, 0] += x[-2]
            self._f[:, 1] += x[-1]

            self._g[:, -2, 0] = 1
            self._g[:, -2, 1] = 0
            self._g[:, -1, 0] = 0
            self._g[:, -1, 1] = 1

        else:

            if self.pairs:
                _f = merge_casedata_ext(self._calc_data_cplx[:, 0],
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:, 0],
                                         self.ind_case_lig, self.w_lig,
                                         self.ind_case_lig)
                self._f[:, 0] += pair_difference_ext(_f, self.pairidx)
                _f = merge_casedata_ext(self._calc_data_cplx[:, 1],
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:, 1],
                                         self.ind_case_lig, self.w_lig,
                                         self.ind_case_lig)
                self._f[:, 1] += pair_difference_ext(_f, self.pairidx)

            else:
                self._f[:, 0] = merge_casedata_ext(self._calc_data_cplx[:, 0],
                                                   self.ind_case_cplx,
                                                   self.w_cplx,
                                                   self.ind_case_cplx)
                self._f[:, 0] -= merge_casedata_ext(self._calc_data[:, 0],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
                self._f[:,
                        0] -= merge_casedata_ext(self._calc_data_lig[:, 0],
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)
                self._f[:, 1] = merge_casedata_ext(self._calc_data_cplx[:, 1],
                                                   self.ind_case_cplx,
                                                   self.w_cplx,
                                                   self.ind_case_cplx)
                self._f[:, 1] -= merge_casedata_ext(self._calc_data[:, 1],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
                self._f[:,
                        1] -= merge_casedata_ext(self._calc_data_lig[:, 1],
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)

            self._f[:, 0] += x[-2]
            self._f[:, 1] += x[-1]
Example #4
0
    def _f_process(self, x):

        __doc__ = """
        returns the squared sum of residuals using
        multiobjective function optimization with linear
        scaling.
        objective funtions are energy and entropy
        """
        self.gist_functional(x)

        self._f[:] = 0.
        if self.anal_grad:
            self._g[:] = 0.

            if self.pairs:
                _f = merge_casedata_ext(self._calc_data[:, 0], self.ind_case,
                                        self.w, self.ind_rec)
                self._f[:, 0] += pair_difference_ext(_f, self.pairidx) + x[-2]
                _f = merge_casedata_ext(self._calc_data[:, 1], self.ind_case,
                                        self.w, self.ind_rec)
                self._f[:, 1] += pair_difference_ext(_f, self.pairidx) + x[-1]

                for i in range(self.parms - 1):
                    _g = merge_casedata_ext(self._gradients[:, i,
                                                            0], self.ind_case,
                                            self.w, self.ind_rec)
                    self._g[:, i, 0] += pair_difference_ext(_g, self.pairidx)
                    _g = merge_casedata_ext(self._gradients[:, i,
                                                            1], self.ind_case,
                                            self.w, self.ind_rec)
                    self._g[:, i, 1] += pair_difference_ext(_g, self.pairidx)
                self._g[:, -2, 0] = 1
                self._g[:, -2, 1] = 0
                self._g[:, -1, 0] = 0
                self._g[:, -1, 1] = 1

            else:
                self._f[:, 0] += merge_casedata_ext(self._calc_data[:, 0],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
                self._f[:, 1] += merge_casedata_ext(self._calc_data[:, 1],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)

                for i in range(self.parms + 1):
                    self._g[:, i,
                            0] += merge_casedata_ext(self._gradients[:, i, 0],
                                                     self.ind_case, self.w,
                                                     self.ind_rec)
                    self._g[:, i,
                            1] += merge_casedata_ext(self._gradients[:, i, 1],
                                                     self.ind_case, self.w,
                                                     self.ind_rec)

        else:

            if self.pairs:
                _f = merge_casedata_ext(self._calc_data[:, 0], self.ind_case,
                                        self.w, self.ind_rec)
                self._f[:, 0] += pair_difference_ext(_f, self.pairidx) + x[-2]
                _f = merge_casedata_ext(self._calc_data[:, 1], self.ind_case,
                                        self.w, self.ind_rec)
                self._f[:, 1] += pair_difference_ext(_f, self.pairidx) + x[-1]

            else:
                self._f[:, 0] += merge_casedata_ext(self._calc_data[:, 0],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
                self._f[:, 1] += merge_casedata_ext(self._calc_data[:, 1],
                                                    self.ind_case, self.w,
                                                    self.ind_rec)
Example #5
0
    def _f_process(self, x):

        __doc___ = """
        returns the squared sum of residuals
        objective function is the free energy
        """

        self.gist_functional(x)

        self._f[:] = 0.
        if self.anal_grad:
            self._g[:] = 0.
            ### Complex and Ligand contributions

            ### &PyArray_Type, &source,
            ### &PyArray_Type, &assign,
            ### &PyArray_Type, &factor,
            ### &PyArray_Type, &assign_factor

            if self.pairs:
                _f = merge_casedata_ext(self._calc_data_cplx,
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig,
                                         self.ind_case_lig, self.w_lig,
                                         self.ind_case_lig)
                self._f[:] += pair_difference_ext(_f, self.pairidx)

                for i in range(self.parms - 1):
                    _g = merge_casedata_ext(self._gradients_cplx[:, i],
                                            self.ind_case_cplx, self.w_cplx,
                                            self.ind_case_cplx)
                    _g -= merge_casedata_ext(self._gradients_lig[:, i],
                                             self.ind_case_lig, self.w_lig,
                                             self.ind_case_lig)
                    self._g[:, i] += pair_difference_ext(_g, self.pairidx)

            else:
                self._f[:] = merge_casedata_ext(self._calc_data_cplx,
                                                self.ind_case_cplx,
                                                self.w_cplx,
                                                self.ind_case_cplx)
                self._f[:] -= merge_casedata_ext(self._calc_data,
                                                 self.ind_case, self.w,
                                                 self.ind_rec)
                self._f[:] -= merge_casedata_ext(self._calc_data_lig,
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)

                for i in range(self.parms):
                    self._g[:,
                            i] = merge_casedata_ext(self._gradients_cplx[:, i],
                                                    self.ind_case_cplx,
                                                    self.w_cplx,
                                                    self.ind_case_cplx)
                    self._g[:,
                            i] -= merge_casedata_ext(self._gradients[:, i],
                                                     self.ind_case, self.w,
                                                     self.ind_rec)
                    self._g[:,
                            i] -= merge_casedata_ext(self._gradients_lig[:, i],
                                                     self.ind_case_lig,
                                                     self.w_lig,
                                                     self.ind_case_lig)

            self._f[:] += x[-1]
            self._g[:, -1] = 1

        else:

            if self.pairs:
                ### Complex and Ligand contributions
                _f = merge_casedata_ext(self._calc_data_cplx,
                                        self.ind_case_cplx, self.w_cplx,
                                        self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig,
                                         self.ind_case_lig, self.w_lig,
                                         self.ind_case_lig)
                self._f[:] += pair_difference_ext(_f, self.pairidx)

            else:
                ### Receptor contributions
                self._f[:] = merge_casedata_ext(self._calc_data_cplx,
                                                self.ind_case_cplx,
                                                self.w_cplx,
                                                self.ind_case_cplx)
                self._f[:] -= merge_casedata_ext(self._calc_data,
                                                 self.ind_case, self.w,
                                                 self.ind_rec)
                self._f[:] -= merge_casedata_ext(self._calc_data_lig,
                                                 self.ind_case_lig, self.w_lig,
                                                 self.ind_case_lig)

            self._f[:] += x[-1]
Example #6
0
    def _f_process(self, x):

        __doc___= """
        returns the squared sum of residuals
        objective function is the free energy
        """

        self.gist_functional(x)

        self._f[:] = 0.
        if self.anal_grad:
            self._g[:] = 0.

            if self.pairs:
                _f  = merge_casedata_ext(self._calc_data_cplx[:,0], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:,0],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                self._f[:,0] += pair_difference_ext(_f, self.pairidx)
                _f  = merge_casedata_ext(self._calc_data_cplx[:,1], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:,1],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                self._f[:,1] += pair_difference_ext(_f, self.pairidx)

                for i in range(self.parms-1):
                    _g              = merge_casedata_ext(self._gradients_cplx[:,i,0], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                    _g             -= merge_casedata_ext(self._gradients_lig[:, i,0], self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                    self._g[:,i,0] += pair_difference_ext(_g, self.pairidx)
                    _g              = merge_casedata_ext(self._gradients_cplx[:,i,1], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                    _g             -= merge_casedata_ext(self._gradients_lig[:, i,1], self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                    self._g[:,i,1] += pair_difference_ext(_g, self.pairidx)

            else:
                self._f[:,0]  = merge_casedata_ext(self._calc_data_cplx[:,0], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                self._f[:,0] -= merge_casedata_ext(self._calc_data[:,0], self.ind_case, self.w, self.ind_rec)
                self._f[:,0] -= merge_casedata_ext(self._calc_data_lig[:,0],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                self._f[:,1]  = merge_casedata_ext(self._calc_data_cplx[:,1], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                self._f[:,1] -= merge_casedata_ext(self._calc_data[:,1], self.ind_case, self.w, self.ind_rec)
                self._f[:,1] -= merge_casedata_ext(self._calc_data_lig[:,1],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)

                for i in range(self.parms+1):
                    self._g[:,i,0]  = merge_casedata_ext(self._gradients_cplx[:,i,0], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                    self._g[:,i,0] -= merge_casedata_ext(self._gradients[:,i,0], self.ind_case, self.w, self.ind_rec)
                    self._g[:,i,0] -= merge_casedata_ext(self._gradients_lig[:, i,0], self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                    self._g[:,i,1]  = merge_casedata_ext(self._gradients_cplx[:,i,1], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                    self._g[:,i,1] -= merge_casedata_ext(self._gradients[:,i,1], self.ind_case, self.w, self.ind_rec)
                    self._g[:,i,1] -= merge_casedata_ext(self._gradients_lig[:, i,1], self.ind_case_lig,  self.w_lig,  self.ind_case_lig)

            self._f[:,0]   += x[-2]
            self._f[:,1]   += x[-1]

            self._g[:,-2,0] = 1
            self._g[:,-2,1] = 0
            self._g[:,-1,0] = 0
            self._g[:,-1,1] = 1

        else:

            if self.pairs:
                _f  = merge_casedata_ext(self._calc_data_cplx[:,0], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:,0],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                self._f[:,0] += pair_difference_ext(_f, self.pairidx)
                _f  = merge_casedata_ext(self._calc_data_cplx[:,1], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                _f -= merge_casedata_ext(self._calc_data_lig[:,1],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                self._f[:,1] += pair_difference_ext(_f, self.pairidx)

            else:
                self._f[:,0]  = merge_casedata_ext(self._calc_data_cplx[:,0], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                self._f[:,0] -= merge_casedata_ext(self._calc_data[:,0], self.ind_case, self.w, self.ind_rec)
                self._f[:,0] -= merge_casedata_ext(self._calc_data_lig[:,0],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)
                self._f[:,1]  = merge_casedata_ext(self._calc_data_cplx[:,1], self.ind_case_cplx, self.w_cplx, self.ind_case_cplx)
                self._f[:,1] -= merge_casedata_ext(self._calc_data[:,1], self.ind_case, self.w, self.ind_rec)
                self._f[:,1] -= merge_casedata_ext(self._calc_data_lig[:,1],  self.ind_case_lig,  self.w_lig,  self.ind_case_lig)

            self._f[:,0] += x[-2]
            self._f[:,1] += x[-1]