예제 #1
0
파일: test_yank.py 프로젝트: lorybaby/yank
def test_topography_subset_regions():
    """Test that topography subset region selection works"""
    # This test relies on all other tests for topography passing
    host_guest_explicit = testsystems.HostGuestExplicit()
    topography = Topography(host_guest_explicit.topology, ligand_atoms='resname B2')
    ligand_list = list(range(126, 156))
    receptor_list = list(range(126))
    n_slice = 3  # Number of atoms to slice from front and back
    assert topography.ligand_atoms == ligand_list
    topography.add_region('lig_dsl', 'resname B2')
    topography.add_region('lig_list', ligand_list)
    topography.add_region('rec_list', receptor_list)
    topography.add_region('rec_lig_slice', receptor_list[-n_slice:] + ligand_list[:n_slice])
    # Selection list: selection, subset, sort_by, result
    selections = (
        # DSL select, same DSL subset, small to large
        ('resname B2', 'resname B2', 'index', ligand_list),
        # DSL select, region subset
        ('resname B2', 'lig_list', 'index', ligand_list),
        # region, dsl, small to large
        ('lig_list', 'resname B2', 'index', ligand_list),
        # region, region that is subset, small to large
        ('lig_list', 'rec_lig_slice', 'index', ligand_list[:n_slice]),
        # indices, region thats a subset, index. Remember, if given a subset: selection is RELATIVE
        (receptor_list, 'rec_lig_slice', 'index', topography.get_region('rec_lig_slice')),
        # region, region that is NOT part of selection, index
        ('lig_list', 'resname CB7', 'index', []),
        # compound Region, partial subset in bad order, order of region
        ('lig_list or rec_list', 'rec_lig_slice', 'region_order', ligand_list[:n_slice] + receptor_list[-n_slice:])
                )
    for selection, subset, sort_by, result in selections:
        selected = topography.select(selection, sort_by=sort_by, subset=subset, as_set=False)
        assert result == selected, "Failed to match {}, subset {}, by {} to {},\ngot {}".format(selection, subset,
                                                                                                sort_by, result,
                                                                                                selected)
예제 #2
0
def test_replace_reaction_field():
    """Check that replacing reaction-field electrostatics with Custom*Force
    yields minimal force differences with original system.

    Note that we cannot test for energy consistency or energy overlap because
    which atoms are within the cutoff will cause energy difference to vary wildly.

    """
    test_cases = [
        testsystems.AlanineDipeptideExplicit(
            nonbondedMethod=openmm.app.CutoffPeriodic),
        testsystems.HostGuestExplicit(
            nonbondedMethod=openmm.app.CutoffPeriodic)
    ]
    platform = openmm.Platform.getPlatformByName('Reference')
    for test_system in test_cases:
        test_name = test_system.__class__.__name__

        # Replace reaction field.
        modified_rf_system = replace_reaction_field(test_system.system,
                                                    switch_width=None)

        # Make sure positions are not at minimum.
        positions = generate_new_positions(test_system.system,
                                           test_system.positions)

        # Test forces.
        f = partial(compare_system_forces,
                    test_system.system,
                    modified_rf_system,
                    positions,
                    name=test_name,
                    platform=platform)
        f.description = "Testing replace_reaction_field on system {}".format(
            test_name)
        yield f

    for test_system in test_cases:
        test_name = test_system.__class__.__name__

        # Replace reaction field.
        modified_rf_system = replace_reaction_field(test_system.system,
                                                    switch_width=None,
                                                    shifted=True)

        # Make sure positions are not at minimum.
        positions = generate_new_positions(test_system.system,
                                           test_system.positions)

        # Test forces.
        f = partial(compare_system_forces,
                    test_system.system,
                    modified_rf_system,
                    positions,
                    name=test_name,
                    platform=platform)
        f.description = "Testing replace_reaction_field on system {} with shifted=True".format(
            test_name)
        yield f
예제 #3
0
    def setup_class(cls):
        """Shared test cases for the suite."""
        temperature = 300 * unit.kelvin

        # Default protocols for tests.
        cls.protocol = dict(lambda_electrostatics=[1.0, 0.5, 0.0, 0.0, 0.0],
                            lambda_sterics=[1.0, 1.0, 1.0, 0.5, 0.0])
        cls.restrained_protocol = dict(
            lambda_electrostatics=[1.0, 1.0, 0.0, 0.0],
            lambda_sterics=[1.0, 1.0, 1.0, 0.0],
            lambda_restraints=[0.0, 1.0, 1.0, 1.0])

        # Ligand-receptor in implicit solvent.
        test_system = testsystems.HostGuestImplicit()
        thermodynamic_state = states.ThermodynamicState(
            test_system.system, temperature=temperature)
        sampler_state = states.SamplerState(
            positions=test_system.positions,
            box_vectors=test_system.system.getDefaultPeriodicBoxVectors())
        topography = Topography(test_system.topology,
                                ligand_atoms='resname B2')
        cls.host_guest_implicit = ('Host-guest implicit', thermodynamic_state,
                                   sampler_state, topography)

        # Ligand-receptor in explicit solvent.
        test_system = testsystems.HostGuestExplicit()
        thermodynamic_state = states.ThermodynamicState(
            test_system.system, temperature=temperature)
        positions = test_system.positions
        box_vectors = test_system.system.getDefaultPeriodicBoxVectors()
        sampler_state = states.SamplerState(positions=positions,
                                            box_vectors=box_vectors)
        topography = Topography(test_system.topology,
                                ligand_atoms='resname B2')
        cls.host_guest_explicit = ('Host-guest explicit', thermodynamic_state,
                                   sampler_state, topography)

        # Peptide solvated in explicit solvent.
        test_system = testsystems.AlanineDipeptideExplicit()
        thermodynamic_state = states.ThermodynamicState(
            test_system.system, temperature=temperature)
        positions = test_system.positions
        box_vectors = test_system.system.getDefaultPeriodicBoxVectors()
        sampler_state = states.SamplerState(positions=positions,
                                            box_vectors=box_vectors)
        topography = Topography(test_system.topology)
        cls.alanine_explicit = ('Alanine dipeptide explicit',
                                thermodynamic_state, sampler_state, topography)

        # All test cases
        cls.all_test_cases = [
            cls.host_guest_implicit, cls.host_guest_explicit,
            cls.alanine_explicit
        ]
예제 #4
0
def get_HostGuestExplicit():
    testsystem_class = testsystems.HostGuestExplicit(
        constraints=None,
        hydrogenMass=4 * unit.amus,
    )

    #remove the CMMotionRemover
    num_forces = testsystem_class.system.getNumForces()
    testsystem_class.system.removeForce(
        num_forces -
        1)  # remove the CMMotionRemover force because it is unknown

    return testsystem_class
예제 #5
0
파일: test_yank.py 프로젝트: lorybaby/yank
def test_topography():
    """Test that topology components are isolated correctly by Topography."""
    toluene_vacuum = testsystems.TolueneVacuum()
    topography = Topography(toluene_vacuum.topology)
    assert len(topography.ligand_atoms) == 0
    assert len(topography.receptor_atoms) == 0
    assert topography.solute_atoms == list(range(toluene_vacuum.system.getNumParticles()))
    assert len(topography.solvent_atoms) == 0
    assert len(topography.ions_atoms) == 0

    host_guest_explicit = testsystems.HostGuestExplicit()
    topography = Topography(host_guest_explicit.topology, ligand_atoms='resname B2')
    assert topography.ligand_atoms == list(range(126, 156))
    assert topography.receptor_atoms == list(range(126))
    assert topography.solute_atoms == list(range(156))
    assert topography.solvent_atoms == list(range(156, host_guest_explicit.system.getNumParticles()))
    assert len(topography.ions_atoms) == 0
def test_restrain_atoms():
    """Check that the restrained molecule's centroid is in the origin."""
    host_guest = testsystems.HostGuestExplicit()
    topology = mdtraj.Topology.from_openmm(host_guest.topology)
    sampler_state = states.SamplerState(positions=host_guest.positions)
    thermodynamic_state = states.ThermodynamicState(
        host_guest.system,
        temperature=300 * unit.kelvin,
        pressure=1.0 * unit.atmosphere)

    # Restrain all the host carbon atoms.
    restrained_atoms = [
        atom.index for atom in topology.atoms
        if atom.element.symbol is 'C' and atom.index <= 125
    ]
    restrain_atoms(thermodynamic_state, sampler_state, restrained_atoms)

    # Compute host center_of_geometry.
    centroid = np.mean(sampler_state.positions[:126], axis=0)
    assert np.allclose(centroid, np.zeros(3))
예제 #7
0
        cls.protocol = dict(lambda_electrostatics=[1.0, 0.5, 0.0, 0.0, 0.0],
                            lambda_sterics=[1.0, 1.0, 1.0, 0.5, 0.0])
        cls.restrained_protocol = dict(lambda_electrostatics=[1.0, 1.0, 0.0, 0.0],
                                       lambda_sterics=[1.0, 1.0, 1.0, 0.0],
                                       lambda_restraints=[0.0, 1.0, 1.0, 1.0])

        # Ligand-receptor in implicit solvent.
        test_system = testsystems.HostGuestImplicit()
        thermodynamic_state = states.ThermodynamicState(test_system.system,
                                                        temperature=temperature)
        sampler_state = states.SamplerState(positions=test_system.positions, box_vectors=test_system.system.getDefaultPeriodicBoxVectors())
        topography = Topography(test_system.topology, ligand_atoms='resname B2')
        cls.host_guest_implicit = ('Host-guest implicit', thermodynamic_state, sampler_state, topography)

        # Ligand-receptor in explicit solvent.
        test_system = testsystems.HostGuestExplicit()
        thermodynamic_state = states.ThermodynamicState(test_system.system,
                                                        temperature=temperature)
        positions = test_system.positions
        box_vectors = test_system.system.getDefaultPeriodicBoxVectors()
        sampler_state = states.SamplerState(positions=positions, box_vectors=box_vectors)
        topography = Topography(test_system.topology, ligand_atoms='resname B2')
        cls.host_guest_explicit = ('Host-guest explicit', thermodynamic_state, sampler_state, topography)

        # Peptide solvated in explicit solvent.
        test_system = testsystems.AlanineDipeptideExplicit()
        thermodynamic_state = states.ThermodynamicState(test_system.system,
                                                        temperature=temperature)
        positions = test_system.positions
        box_vectors = test_system.system.getDefaultPeriodicBoxVectors()
        sampler_state = states.SamplerState(positions=positions, box_vectors=box_vectors)