예제 #1
0
def restraint_selection_template(topography_ligand_atoms=None,
                                 restrained_receptor_atoms=None,
                                 restrained_ligand_atoms=None,
                                 topography_regions=None):
    """The DSL atom selection works as expected."""
    test_system = testsystems.HostGuestVacuum()
    topography = Topography(test_system.topology, ligand_atoms=topography_ligand_atoms)
    if topography_regions is not None:
        for region, selection in topography_regions.items():
            topography.add_region(region, selection)
    sampler_state = states.SamplerState(positions=test_system.positions)
    thermodynamic_state = states.ThermodynamicState(test_system.system,
                                                    temperature=300.0 * unit.kelvin)

    # Initialize with DSL and without processing the string raises an error.
    restraint = yank.restraints.Harmonic(spring_constant=2.0 * unit.kilojoule_per_mole / unit.nanometer ** 2,
                                         restrained_receptor_atoms=restrained_receptor_atoms,
                                         restrained_ligand_atoms=restrained_ligand_atoms)
    with nose.tools.assert_raises(yank.restraints.RestraintParameterError):
        restraint.restrain_state(thermodynamic_state)

    # After parameter determination, the indices of the restrained atoms are correct.
    restraint.determine_missing_parameters(thermodynamic_state, sampler_state, topography)
    assert len(restraint.restrained_receptor_atoms) == 14
    assert len(restraint.restrained_ligand_atoms) == 30

    # The bond force is configured correctly.
    restraint.restrain_state(thermodynamic_state)
    system = thermodynamic_state.system
    for force in system.getForces():
        if isinstance(force, openmm.CustomCentroidBondForce):
            assert force.getBondParameters(0)[0] == (0, 1)
            assert len(force.getGroupParameters(0)[0]) == 14
            assert len(force.getGroupParameters(1)[0]) == 30
    assert isinstance(force, openmm.CustomCentroidBondForce)  # We have found a force.
예제 #2
0
def restraint_selection_template(topography_ligand_atoms=None,
                                 restrained_receptor_atoms=None,
                                 restrained_ligand_atoms=None,
                                 topography_regions=None):
    """The DSL atom selection works as expected."""
    test_system = testsystems.HostGuestVacuum()
    topography = Topography(test_system.topology, ligand_atoms=topography_ligand_atoms)
    if topography_regions is not None:
        for region, selection in topography_regions.items():
            topography.add_region(region, selection)
    sampler_state = states.SamplerState(positions=test_system.positions)
    thermodynamic_state = states.ThermodynamicState(test_system.system,
                                                    temperature=300.0 * unit.kelvin)

    # Initialize with DSL and without processing the string raises an error.
    restraint = yank.restraints.Harmonic(spring_constant=2.0 * unit.kilojoule_per_mole / unit.nanometer ** 2,
                                         restrained_receptor_atoms=restrained_receptor_atoms,
                                         restrained_ligand_atoms=restrained_ligand_atoms)
    with nose.tools.assert_raises(yank.restraints.RestraintParameterError):
        restraint.restrain_state(thermodynamic_state)

    # After parameter determination, the indices of the restrained atoms are correct.
    restraint.determine_missing_parameters(thermodynamic_state, sampler_state, topography)
    assert len(restraint.restrained_receptor_atoms) == 14
    assert len(restraint.restrained_ligand_atoms) == 30

    # The bond force is configured correctly.
    restraint.restrain_state(thermodynamic_state)
    system = thermodynamic_state.system
    for force in system.getForces():
        if isinstance(force, openmm.CustomCentroidBondForce):
            assert force.getBondParameters(0)[0] == (0, 1)
            assert len(force.getGroupParameters(0)[0]) == 14
            assert len(force.getGroupParameters(1)[0]) == 30
    assert isinstance(force, openmm.CustomCentroidBondForce)  # We have found a force.
예제 #3
0
def test_harmonic_standard_state():
    """
    Test that the expected harmonic standard state correction is close to our approximation

    Also ensures that PBC bonds are being computed and disabled correctly as expected
    """
    LJ_fluid = testsystems.LennardJonesFluid()

    # Create Harmonic restraint.
    restraint = yank.restraints.create_restraint('Harmonic',
                                                 restrained_receptor_atoms=1)

    # Determine other parameters.
    ligand_atoms = [3, 4, 5]
    topography = Topography(LJ_fluid.topology, ligand_atoms=ligand_atoms)
    sampler_state = states.SamplerState(positions=LJ_fluid.positions)
    thermodynamic_state = states.ThermodynamicState(system=LJ_fluid.system,
                                                    temperature=300.0 *
                                                    unit.kelvin)
    restraint.determine_missing_parameters(thermodynamic_state, sampler_state,
                                           topography)
    spring_constant = restraint.spring_constant

    # Compute standard-state volume for a single molecule in a box of size (1 L) / (avogadros number)
    liter = 1000.0 * unit.centimeters**3  # one liter
    box_volume = liter / (unit.AVOGADRO_CONSTANT_NA * unit.mole
                          )  # standard state volume
    analytical_shell_volume = (
        2 * math.pi / (spring_constant * thermodynamic_state.beta))**(3.0 / 2)
    analytical_standard_state_G = -math.log(
        box_volume / analytical_shell_volume)
    restraint_standard_state_G = restraint.get_standard_state_correction(
        thermodynamic_state)
    np.testing.assert_allclose(analytical_standard_state_G,
                               restraint_standard_state_G)
예제 #4
0
 def setup_class(cls):
     lysozyme = testsystems.LysozymeImplicit()
     system, positions = lysozyme.system, lysozyme.positions
     thermodynamic_state = states.ThermodynamicState(system, 300*unit.kelvin)
     sampler_state = states.SamplerState(positions)
     topography = Topography(lysozyme.topology, ligand_atoms='resname TMP')
     cls.lysozyme_test_case = (thermodynamic_state, sampler_state, topography)
예제 #5
0
def test_BoreschLike_standard_state_analytical():
    """
    Perform some analytical tests of the Boresch standard state correction.
    Also ensures that PBC is being handled correctly
    """
    LJ_fluid = testsystems.LennardJonesFluid()

    # Define receptor and ligand atoms
    receptor_atoms = [0, 1, 2]
    ligand_atoms = [3, 4, 5]

    # Create restraint
    K_r = 1.0 * unit.kilocalories_per_mole / unit.angstrom**2
    r_0 = 0.0 * unit.angstrom
    K_theta = 0.0 * unit.kilocalories_per_mole / unit.degrees**2
    theta_0 = 30.0 * unit.degrees

    topography = Topography(LJ_fluid.topology, ligand_atoms=ligand_atoms)
    sampler_state = states.SamplerState(positions=LJ_fluid.positions)
    thermodynamic_state = states.ThermodynamicState(system=LJ_fluid.system,
                                                    temperature=300.0 *
                                                    unit.kelvin)

    for restraint_name in ['Boresch', 'PeriodicTorsionBoresch']:
        restraint = yank.restraints.create_restraint(
            'Boresch',
            restrained_receptor_atoms=receptor_atoms,
            restrained_ligand_atoms=ligand_atoms,
            K_r=K_r,
            r_aA0=r_0,
            K_thetaA=K_theta,
            theta_A0=theta_0,
            K_thetaB=K_theta,
            theta_B0=theta_0,
            K_phiA=K_theta,
            phi_A0=theta_0,
            K_phiB=K_theta,
            phi_B0=theta_0,
            K_phiC=K_theta,
            phi_C0=theta_0)

        # Determine other parameters
        restraint.determine_missing_parameters(thermodynamic_state,
                                               sampler_state, topography)

        # Compute standard-state volume for a single molecule in a box of size (1 L) / (avogadros number)
        liter = 1000.0 * unit.centimeters**3  # one liter
        box_volume = liter / (unit.AVOGADRO_CONSTANT_NA * unit.mole
                              )  # standard state volume
        analytical_shell_volume = (2 * math.pi /
                                   (K_r * thermodynamic_state.beta))**(3.0 / 2)
        analytical_standard_state_G = -math.log(
            box_volume / analytical_shell_volume)
        restraint_standard_state_G = restraint.get_standard_state_correction(
            thermodynamic_state)
        msg = 'Failed test for restraint {}'.format(restraint_name)
        np.testing.assert_allclose(analytical_standard_state_G,
                                   restraint_standard_state_G,
                                   err_msg=msg)
예제 #6
0
def test_partial_parametrization():
    """The automatic restraint parametrization doesn't overwrite user values."""
    # Create states and identify ligand/receptor.
    test_system = testsystems.HostGuestVacuum()
    topography = Topography(test_system.topology, ligand_atoms='resname B2')
    sampler_state = states.SamplerState(positions=test_system.positions)
    thermodynamic_state = states.ThermodynamicState(test_system.system,
                                                    temperature=300.0*unit.kelvin)

    # Test case: (restraint_type, constructor_kwargs)
    boresch = dict(restrained_ligand_atoms=[130, 131, 136], K_r=1.0*unit.kilojoule_per_mole/unit.angstroms**2)
    test_cases = [
        ('Harmonic', dict(spring_constant=2.0*unit.kilojoule_per_mole/unit.nanometer**2,
                          restrained_receptor_atoms=[5])),
        ('FlatBottom', dict(well_radius=1.0*unit.angstrom, restrained_ligand_atoms=[130])),
        ('Boresch', boresch),
        ('PeriodicTorsionBoresch', boresch),
    ]
    if OpenMM73.dev_validate:
        test_cases.append(('RMSD', dict(restrained_ligand_atoms=[130, 131, 136],
                           K_RMSD=1.0 * unit.kilojoule_per_mole / unit.angstroms ** 2)))

    for restraint_type, kwargs in test_cases:
        state = copy.deepcopy(thermodynamic_state)
        restraint = yank.restraints.create_restraint(restraint_type, **kwargs)

        # Test-precondition: The restraint has undefined parameters.
        with nose.tools.assert_raises(yank.restraints.RestraintParameterError):
            restraint.restrain_state(state)

        # The automatic parametrization maintains user values.
        restraint.determine_missing_parameters(state, sampler_state, topography)
        for parameter_name, parameter_value in kwargs.items():
            assert getattr(restraint, parameter_name) == parameter_value

        # The rest of the parameters has been determined.
        restraint.get_standard_state_correction(state)

        # The force has been configured correctly.
        restraint.restrain_state(state)
        system = state.system
        for force in system.getForces():
            # RadiallySymmetricRestraint between two single atoms.
            if isinstance(force, openmm.CustomBondForce):
                particle1, particle2, _ = force.getBondParameters(0)
                assert particle1 == restraint.restrained_receptor_atoms[0]
                assert particle2 == restraint.restrained_ligand_atoms[0]
            # Boresch restraint.
            elif isinstance(force, openmm.CustomCompoundBondForce):
                particles, _ = force.getBondParameters(0)
                assert particles == tuple(restraint.restrained_receptor_atoms + restraint.restrained_ligand_atoms)
            # RMSD restraint.
            elif OpenMM73.dev_validate and isinstance(force, openmm.CustomCVForce):
                rmsd_cv = force.getCollectiveVariable(0)
                particles = rmsd_cv.getParticles()
                assert particles == tuple(restraint.restrained_receptor_atoms + restraint.restrained_ligand_atoms)
예제 #7
0
    def build_test_case():
        """Create a new ThermodynamicState, SamplerState and Topography."""
        # Create a test system
        t = HostGuestNoninteracting()

        # Create states and topography encoding the info to determine the parameters.
        topography = Topography(t.topology, ligand_atoms='resname B2')
        sampler_state = states.SamplerState(positions=t.positions)
        thermodynamic_state = states.ThermodynamicState(system=t.system, temperature=300.0*unit.kelvin)
        return thermodynamic_state, sampler_state, topography