예제 #1
0
    def _calBiasingForce(self, coord_x, coord_y, d):

        if self.p["abfCheckFlag"] == "yes":
            bsForce = copy.deepcopy(self.colvars_FreeE)

            if self.p["ndims"] == 1:
                bsForce = np.diff(bsForce)
                bsForce = np.append(bsForce,
                                    bsForce[-1])  # padding to the right legnth
                bsForce = (bsForce / self.binw)
                return bsForce[getIndices(coord_x, self.bins)]

            if self.p["ndims"] == 2:

                if d == 0:
                    bsForce = np.diff(bsForce,
                                      axis=0)  # axis=0 for x; axis=1 for y
                    bsForce = np.append(bsForce, [bsForce[-1, :]],
                                        axis=0)  # padding to the right length
                    bsForce = (bsForce / self.binw)

                elif d == 1:
                    bsForce = np.diff(bsForce, axis=1)
                    bsForce = np.append(bsForce,
                                        bsForce[:, -1][:, np.newaxis],
                                        axis=1)  # padding to the right length
                    bsForce = (bsForce / self.binw)

                return bsForce[getIndices(coord_x, self.bins)][getIndices(
                    coord_y, self.bins)]

        else:
            return 0
예제 #2
0
    def _calBiasingForce(self, coord_x, coord_y, d):

        if (self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"]
                == "no") or (self.p["abfCheckFlag"] == "yes"
                             and self.p["nnCheckFlag"] == "yes"
                             and self.criteriaFEBool == 0):
            if self.p["ndims"] == 1:
                if self.colvars_count[getIndices(coord_x, self.bins)] == 0:
                    return 0
                else:
                    return -(
                        (self.colvars_force[getIndices(coord_x, self.bins)] /
                         self.colvars_count[getIndices(coord_x, self.bins)] +
                         self._entropicCorrection()) * self._inverseGradient())

            if self.p["ndims"] == 2:
                if self.colvars_count[d][getIndices(coord_x,
                                                    self.bins)][getIndices(
                                                        coord_y,
                                                        self.bins)] == 0:
                    return 0
                else:
                    return -((self.colvars_force[d][getIndices(coord_x, self.bins)][getIndices(coord_y, self.bins)] / self.colvars_count[d][getIndices(coord_x, self.bins)][getIndices(coord_y, self.bins)] +\
                            self._entropicCorrection()) * self._inverseGradient())

        if (self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"]
                == "yes") and self.criteriaFEBool > 0:
            if self.p["ndims"] == 1:
                return -self.colvars_force_NN[getIndices(coord_x, self.bins)]
            if self.p["ndims"] == 2:
                return -self.colvars_force_NN[d][getIndices(
                    coord_x, self.bins)][getIndices(coord_y, self.bins)]
예제 #3
0
    def _forceHistDistrRecord(self, coord_x, coord_y, d):

        if self.p["ndims"] == 1:
            self.colvars_count[getIndices(coord_x, self.bins)] += 1

        if self.p["ndims"] == 2:
            self.colvars_count[d][getIndices(coord_x, self.bins)][getIndices(
                coord_y, self.bins)] += 1
예제 #4
0
    def _forceDistrRecord(self, coord_x, updated_Fsys, coord_y, d):

        if self.p["ndims"] == 1:
            self.colvars_force[getIndices(coord_x, self.bins)] += updated_Fsys

        if self.p["ndims"] == 2:
            self.colvars_force[d][getIndices(coord_x, self.bins)][getIndices(
                coord_y, self.bins)] += updated_Fsys
예제 #5
0
 def _accumulateColvarsHist(self):
     for n in range(self.p["nparticle"]):
         if self.p["ndims"] == 1:
             self.colvars_hist[getIndices(self.current_coord[n][0],
                                          self.bins)] += 1
         elif self.p["ndims"] == 2:
             self.colvars_hist[getIndices(self.current_coord[n][0],
                                          self.bins)][getIndices(
                                              self.current_coord[n][1],
                                              self.bins)] += 1
예제 #6
0
    def _calBiasingForce(self, coord_x, coord_y, d):

        if (self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"]
                == "no") or (self.p["abfCheckFlag"] == "yes"
                             and self.p["nnCheckFlag"] == "yes" and
                             self.p["init_frame"] <= self.p["earlyStopCheck"]):
            bsForce = copy.deepcopy(self.colvars_FreeE)

        elif (self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"]
              == "yes") and self.p["init_frame"] > self.p["earlyStopCheck"]:
            bsForce = copy.deepcopy(self.colvars_FreeE_NN)

        elif self.p["abfCheckFlag"] == "no" and self.p["nnCheckFlag"] == "no":
            return 0

        if self.p["ndims"] == 1:
            bsForce = np.diff(bsForce)
            bsForce = np.append(bsForce,
                                bsForce[-1])  # padding to the right legnth
            bsForce = (bsForce / self.binw)
            return bsForce[getIndices(coord_x, self.bins)]

        if self.p["ndims"] == 2:

            if d == 0:
                bsForce = np.diff(bsForce,
                                  axis=0)  # axis=0 for x; axis=1 for y
                bsForce = np.append(bsForce, [bsForce[-1, :]],
                                    axis=0)  # padding to the right length
                bsForce = (bsForce / self.binw)

            elif d == 1:
                bsForce = np.diff(bsForce, axis=1)
                bsForce = np.append(bsForce,
                                    bsForce[:, -1][:, np.newaxis],
                                    axis=1)  # padding to the right length
                bsForce = (bsForce / self.binw)

            return bsForce[getIndices(coord_x, self.bins)][getIndices(
                coord_y, self.bins)]
예제 #7
0
    def getCurrentForce(self, coord_x, d, vel, coord_y):

        if self.p["abfCheckFlag"] == "no" and self.p["nnCheckFlag"] == "no":
            Fabf = 0

        elif self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"] == "no":
            Fabf = self._calBiasingForce(coord_x, coord_y, d)

        elif self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"] == "yes":

            if self.p["init_frame"] <= self.p["trainingFreq"]:
                Fabf = self._calBiasingForce(coord_x, coord_y, d)

            else:  # ANN takes over here

                if self.p["ndims"] == 1:
                    Fabf = self.gradient[getIndices(coord_x, self.bins)]

                elif self.p["ndims"] == 2:
                    Fabf = self.gradient[d][getIndices(coord_x,
                                                       self.bins)][getIndices(
                                                           coord_y, self.bins)]

        return Fabf
예제 #8
0
    def _calBiasingForce(self, coord_x, coord_y, d):
        if self.p["ndims"] == 1:
            if self.colvars_count[getIndices(coord_x, self.bins)] == 0:
                return 0
            else:
                return -(
                    (self.colvars_force[getIndices(coord_x, self.bins)] /
                     self.colvars_count[getIndices(coord_x, self.bins)] +
                     self._entropicCorrection()) * self._inverseGradient())

        if self.p["ndims"] == 2:
            if self.colvars_count[d][getIndices(coord_x,
                                                self.bins)][getIndices(
                                                    coord_y, self.bins)] == 0:
                return 0
            else:
                return -((self.colvars_force[d][getIndices(coord_x, self.bins)][getIndices(coord_y, self.bins)] / self.colvars_count[d][getIndices(coord_x, self.bins)][getIndices(coord_y, self.bins)] +\
                        self._entropicCorrection()) * self._inverseGradient())
예제 #9
0
    def _biasingPotential(self, coord_x, coord_y=None):

        if self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"] == "yes":

            if self.p["ndims"] == 1:
                if self.p["init_frame"] <= self.p[
                        "earlyStopCheck"]:  # initial sweep
                    return 0
                else:
                    return self.biasingPotentialFromNN[getIndices(
                        coord_x, self.bins)]

            if self.p["ndims"] == 2:
                if self.p["init_frame"] <= self.p[
                        "earlyStopCheck"]:  # initial sweep
                    return 0
                else:
                    return self.biasingPotentialFromNN[getIndices(
                        coord_x, self.bins)][getIndices(coord_y, self.bins)]

        elif self.p["abfCheckFlag"] == "yes" and self.p["nnCheckFlag"] == "no":

            if self.p["ndims"] == 1:
                if self.p["init_frame"] <= self.p["earlyStopCheck"]:
                    return 0
                else:
                    return self.biasingPotentialConv[getIndices(
                        coord_x, self.bins)]

            if self.p["ndims"] == 2:
                if self.p["init_frame"] <= self.p["earlyStopCheck"]:
                    return 0
                else:
                    return self.biasingPotentialConv[getIndices(
                        coord_x, self.bins)][getIndices(coord_y, self.bins)]

        else:
            return 0