Пример #1
0
 def test_calibration_class_multisite(self):
     """Test the multisite SAMS sampling approach."""
     old_log_level = log.getEffectiveLevel()
     pep = self.setup_peptide_implicit("yeah", createsim=True)
     pep.drive.enable_calibration(SAMSApproach.MULTISITE)
     sampler = SAMSCalibrationEngine(pep.drive)
     total_iterations = 1500
     for x in range(total_iterations):
         if x == total_iterations - 1:
             log.setLevel(logging.DEBUG)
         pep.simulation.step(1)
         pep.simulation.update(1)
         sampler.adapt_zetas(UpdateRule.BINARY, b=0.51, stage=Stage.NODECAY)
     log.setLevel(old_log_level)
     return
Пример #2
0
    def test_onesite_sams_sampling_global(self):
        """Test the one site sams sampling approach with global updates"""
        old_log_level = log.getEffectiveLevel()

        pep = self.setup_peptide_implicit("yeah")
        pep.drive.enable_calibration(SAMSApproach.ONESITE, group_index=1)
        sampler = SAMSCalibrationEngine(pep.drive)
        total_iterations = 1500
        for x in range(total_iterations):
            if x == total_iterations - 1:
                log.setLevel(logging.DEBUG)
            pep.simulation.step(1)
            pep.simulation.update(1)
            sampler.adapt_zetas(UpdateRule.GLOBAL, b=0.51, stage=Stage.NODECAY)
        log.setLevel(old_log_level)
Пример #3
0
    def test_onesite_sams_sampling_binary_all_stages(self):
        """Test the one site sams sampling approach with binary updates through all 4 stages of the algorithm"""
        old_log_level = log.getEffectiveLevel()
        log.setLevel(logging.INFO)
        pep = self.setup_peptide_implicit("yeah", createsim=False)
        pep.drive.enable_calibration(
            SAMSApproach.ONESITE,
            group_index=0,
            min_burn=200,
            min_fast=100,
            min_slow=100,
            flatness_criterion=0.15,
        )
        pep.simulation = app.ConstantPHSimulation(
            pep.topology,
            pep.system,
            pep.integrator,
            pep.drive,
            platform=TestSAMS.platform,
        )
        pep.simulation.context.setPositions(pep.positions)
        pep.context = pep.simulation.context
        pep.simulation.minimizeEnergy()

        total_iterations = 1000
        for x in range(total_iterations):
            if x == total_iterations - 1:
                log.setLevel(logging.DEBUG)
            pep.simulation.step(1)
            pep.simulation.update(1)
            pep.simulation.adapt()

        # log.info(pep.drive.calibration_state.observed_counts)
        log.setLevel(old_log_level)
Пример #4
0
    def test_onesite_sams_sampling_binary_all_stages_serialization(self):
        """Test the one site sams sampling approach with binary updates through all 4 stages of the algorithm
        and after serialization."""
        old_log_level = log.getEffectiveLevel()
        log.setLevel(logging.INFO)
        pep = self.setup_peptide_implicit("yeah", createsim=False)
        pep.drive.enable_calibration(
            SAMSApproach.ONESITE,
            group_index=0,
            min_burn=200,
            min_fast=200,
            min_slow=200,
            flatness_criterion=0.15,
        )
        pep.simulation = app.ConstantPHSimulation(
            pep.topology,
            pep.system,
            pep.integrator,
            pep.drive,
            platform=TestSAMS.platform,
        )
        pep.simulation.context.setPositions(pep.positions)
        pep.context = pep.simulation.context
        pep.simulation.minimizeEnergy()

        total_iterations = 1000
        for x in range(total_iterations):
            pep.simulation.step(1)
            pep.simulation.update(1)
            pep.simulation.adapt()

        pep.drive: NCMCProtonDrive
        drive_state = pep.drive.state_to_xml()
        new_drive = NCMCProtonDrive(
            pep.temperature,
            pep.topology,
            pep.system,
            pressure=None,
            perturbations_per_trial=pep.perturbations_per_trial,
            propagations_per_step=pep.propagations_per_step,
        )
        new_drive.state_from_xml_tree(etree.fromstring(drive_state))

        new_simulation = app.ConstantPHSimulation(
            pep.topology,
            pep.system,
            create_compound_gbaoab_integrator(pep),
            new_drive,
            platform=TestSAMS.platform,
        )
        old_state: app.State = pep.simulation.context.getState(
            getPositions=True, getVelocities=True
        )
        new_simulation.context.setPositions(old_state.getPositions())
        new_simulation.context.setVelocities(old_state.getVelocities())

        total_iterations = 1000
        for x in range(total_iterations):
            if x == total_iterations - 1:
                log.setLevel(logging.DEBUG)
            new_simulation.step(1)
            new_simulation.update(1)
            new_simulation.adapt()
            log.debug("Last deviation: %f", new_simulation.last_dev)
        log.info(
            "Observed counts: %s", str(pep.drive.calibration_state.observed_counts)
        )
        log.setLevel(old_log_level)
Пример #5
0
import numpy as np
from protons.app import AmberProtonDrive, ForceFieldProtonDrive, NCMCProtonDrive
from protons.app import ForceField
from protons.app import UniformProposal
from protons.app.calibration import SAMSCalibrationEngine
from protons.app.driver import SAMSApproach, Stage, UpdateRule
from protons.app import log
import logging

from protons.tests.utilities import (
    SystemSetup,
    create_compound_gbaoab_integrator,
    hasCUDA,
)

log.setLevel(logging.INFO)


class TestSAMS:
    """Test the functionality of the ``app.calibration.WeighsTable`` class."""

    if hasCUDA:
        default_platform_name = "CUDA"
    else:
        default_platform_name = "CPU"

    platform = mm.Platform.getPlatformByName(default_platform_name)

    @staticmethod
    def setup_peptide_implicit(name: str, minimize=True, createsim=True):
        """
Пример #6
0
from protons.app import ForceField
from protons.app import UniformProposal
from protons.app.template_patches import patch_cooh
from protons.app.proposals import UniformSwapProposal, COOHDummyMover
from protons.tests import get_test_data
from protons.tests.utilities import (
    SystemSetup,
    create_compound_gbaoab_integrator,
    hasCUDA,
)
import logging
from random import choice, uniform, sample
from protons.app import log
from math import exp

log.setLevel(logging.INFO)


class TestCarboxylicAcid:
    if hasCUDA:
        default_platform_name = "CUDA"
    else:
        default_platform_name = "CPU"

    platform = openmm.Platform.getPlatformByName(default_platform_name)

    @staticmethod
    def setup_viologen_vacuum():
        """
        Set up viologen in vacuum
        """