Esempio n. 1
0
    def run(self):
        self._start()

        print(" - Calculating energy difference of both lambda edges")

        clear_directory(self.path)

        c_lambdas = self.settings.c_lambdas
        s_lambdas = self.settings.lj_lambdas
        if (len(c_lambdas) < 1):
            c_lambdas = self.settings.lambdas
        if (len(s_lambdas) < 1):
            s_lambdas = self.settings.lambdas

        first_lambda_value = 0.
        last_lambda_value = 1.

        if (self.settings.splitted_lambdas):
            if (self.alchemicalTemplateCreator.explicit_is_final):
                first_lambda_value = min(s_lambdas)
                last_lambda_value = max(c_lambdas)
            else:
                first_lambda_value = min(c_lambdas)
                last_lambda_value = max(s_lambdas)

        first_lambda = Lambda.Lambda(first_lambda_value,
                                     lambda_type=Lambda.DUAL_LAMBDA)
        last_lambda = Lambda.Lambda(last_lambda_value,
                                    lambda_type=Lambda.DUAL_LAMBDA)

        initial_energy = self._run(first_lambda)
        final_energy = self._run(last_lambda)

        print(" - Relative Unbound Free Energy prediction " +
              "{:.2f} kcal/mol".format(final_energy - initial_energy))
Esempio n. 2
0
    def __init__(self, settings):
        self._settings = settings

        # PELE needs to be working in the general path in order to find the
        # the required Data and Document folders
        os.chdir(self.settings.general_path)
        self._pid = int(0)

        checkPoint = CheckPoint(settings.general_path +
                                co.CHECKPOINT_NAME,
                                settings)

        try:
            checkPoint.initialize()
        except RuntimeError as e:
            print("  - {} Warning: ".format(self.name) + str(e))

        self._checkPoint = checkPoint

        self._lambdasBuilder = Lambda.LambdasBuilder()

        self._alchemicalTemplateCreator = AlchemicalTemplateCreator(
            settings.initial_template,
            settings.final_template,
            settings.atom_links)

        smBuilder = SamplingMethodBuilder(settings)
        self._s_method = smBuilder.createSamplingMethod()

        self._ligand_template = \
            self._alchemicalTemplateCreator.explicit_template

        lambdasBuilder = Lambda.LambdasBuilder()
        self._lambdas = lambdasBuilder.buildFromSettings(self.settings)
Esempio n. 3
0
    def _getShiftedLambdas(self, lambda_):
        shifted_lambdas = []

        previous_lambda = lambda_.previous_lambda
        next_lambda = lambda_.next_lambda
        if ((previous_lambda is not None) and (next_lambda is not None)):
            pre_pre_lambda = previous_lambda.previous_lambda
            if (pre_pre_lambda is not None):
                shifted_value = float(lambda_.value -
                                      (lambda_.value - previous_lambda.value) /
                                      2.0)
            else:
                shifted_value = float(lambda_.value -
                                      (lambda_.value - previous_lambda.value))

            shifted_lambdas.append(Lambda.Lambda(shifted_value,
                                                 lambda_type=lambda_.type))

            next_next_lambda = next_lambda.next_lambda
            if (next_next_lambda is not None):
                shifted_value = float(lambda_.value +
                                      (next_lambda.value - lambda_.value) /
                                      2.0)
            else:
                shifted_value = float(lambda_.value +
                                      (next_lambda.value - lambda_.value))

            shifted_lambdas.append(Lambda.Lambda(shifted_value,
                                                 lambda_type=lambda_.type))

        return shifted_lambdas
Esempio n. 4
0
 def getConstantLambda(self, lmb):
     ctt_lmb = None
     if (lmb.index == 2):
         if (lmb.type == Lambda.COULOMBIC_LAMBDA):
             ctt_lmb = Lambda.Lambda(
                 1.0, lambda_type=Lambda.STERIC_LAMBDA)
         elif (lmb.type == Lambda.STERIC_LAMBDA):
             ctt_lmb = Lambda.Lambda(
                 1.0, lambda_type=Lambda.COULOMBIC_LAMBDA)
     return ctt_lmb
    def run(self):
        self._start()

        create_directory(self.path)

        atoms_to_minimize = self._getAtomIdsToMinimize()

        for lmb in self.lambdas:
            writeLambdaTitle(lmb)

            create_directory(self.path + str(self.PID) + '_' +
                             co.MODELS_FOLDER)

            print(" - Splitting PELE models")
            simulation = self._getSimulation(lmb)

            self._splitModels(simulation)

            ctt_lmb = None
            if (lmb.index == 2):
                if (lmb.type == Lambda.COULOMBIC_LAMBDA):
                    ctt_lmb = Lambda.Lambda(1.0,
                                            lambda_type=Lambda.STERIC_LAMBDA)
                elif (lmb.type == Lambda.STERIC_LAMBDA):
                    ctt_lmb = Lambda.Lambda(
                        1.0, lambda_type=Lambda.COULOMBIC_LAMBDA)

            self._createAlchemicalTemplate(lmb, ctt_lmb)

            self._calculateOriginalEnergies(simulation, lmb)

            for shf_lmb in self.sampling_method.getShiftedLambdas(lmb):
                print(" - Applying delta lambda " +
                      str(round(shf_lmb.value - lmb.value, 5)))

                self._createAlchemicalTemplate(shf_lmb, ctt_lmb, gap=' ')

                general_path = self._getGeneralPath(lmb, shf_lmb)
                clear_directory(general_path)

                self._minimize(simulation,
                               lmb.type,
                               general_path,
                               atoms_to_minimize,
                               gap=' ')

                self._dECalculation(simulation, lmb, general_path, gap=' ')

            remove_directory(self.path + str(self.PID) + '_' +
                             co.MODELS_FOLDER)

        self._finish()
Esempio n. 6
0
    def _getShiftedLambdas(self, lambda_):
        shifted_lambdas = []

        previous_lambda = lambda_.previous_lambda
        if (previous_lambda is not None):
            shifted_lambdas.append(
                Lambda.Lambda(float(lambda_.value -
                                    (lambda_.value - previous_lambda.value)),
                              lambda_type=lambda_.type))

        next_lambda = lambda_.next_lambda
        if (next_lambda is not None):
            shifted_lambdas.append(
                Lambda.Lambda(float(lambda_.value +
                                    (next_lambda.value - lambda_.value)),
                              lambda_type=lambda_.type))

        return shifted_lambdas
Esempio n. 7
0
    def _run_with_splitted_lambdas(self):
        output = []

        c_lambdas = self.settings.c_lambdas
        s_lambdas = self.settings.lj_lambdas
        if (len(c_lambdas) < 1):
            c_lambdas = self.settings.lambdas
        if (len(s_lambdas) < 1):
            s_lambdas = self.settings.lambdas

        if (self.alchemicalTemplateCreator.explicit_is_final):
            # Case where the final atomset contains the initial one.
            # Thus, there are atoms that will be created. The best
            # method is to set from a first beggining coulombic lambda
            # to zero to ensure that final atoms will have a null
            # partial charge. Until their Lennard Jones parameters
            # are not the final ones, charges will be zero. Then,
            # progressively, charges will be introduced.
            c_lambda = Lambda.Lambda(0, lambda_type=Lambda.COULOMBIC_LAMBDA)
            output += self._run(s_lambdas, Lambda.STERIC_LAMBDA, num=1,
                                constant_lambda=c_lambda)

            s_lambda = Lambda.Lambda(1, lambda_type=Lambda.STERIC_LAMBDA)
            output += self._run(c_lambdas, Lambda.COULOMBIC_LAMBDA, num=2,
                                constant_lambda=s_lambda)
        else:
            # Case where the initial atomset contains the final
            # atomset. So, there are atoms that will disappear.
            # In this way, we need to annihilate first coulombic
            # charges, then, we modify Lennard Jones parameters.
            s_lambda = Lambda.Lambda(0, lambda_type=Lambda.STERIC_LAMBDA)
            output += self._run(c_lambdas, Lambda.COULOMBIC_LAMBDA, num=1,
                                constant_lambda=s_lambda)

            c_lambda = Lambda.Lambda(1, lambda_type=Lambda.COULOMBIC_LAMBDA)
            output += self._run(s_lambdas, Lambda.STERIC_LAMBDA, num=2,
                                constant_lambda=c_lambda)

        return output