示例#1
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
示例#2
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
        ]
示例#3
0
def test_get_traj():
    nc_filename = tempfile.mkdtemp() + "/out.nc"

    T_min = 300.0 * unit.kelvin
    T_i = [T_min, T_min * 1.01, T_min * 1.1]
    n_replicas = len(T_i)

    ho = testsystems.AlanineDipeptideExplicit()

    system = ho.system
    positions = ho.positions

    states = [
        ThermodynamicState(system=system, temperature=T_i[i])
        for i in range(n_replicas)
    ]

    coordinates = [positions] * n_replicas

    mpicomm = dummympi.DummyMPIComm()
    parameters = {"number_of_iterations": 3}
    replica_exchange = ReplicaExchange.create(states,
                                              coordinates,
                                              nc_filename,
                                              mpicomm=mpicomm,
                                              parameters=parameters)
    replica_exchange.run()

    db = replica_exchange.database

    prmtop_filename = testsystems.get_data_filename(
        "data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop")
    crd_filename = testsystems.get_data_filename(
        "data/alanine-dipeptide-explicit/alanine-dipeptide.crd")
    trj0 = md.load_restrt(crd_filename, top=prmtop_filename)
    db.set_traj(trj0)

    trj1 = db.get_traj(state_index=0)
    trj2 = db.get_traj(replica_index=0)
示例#4
0
def load(sysname):
    cutoff = 0.9 * u.nanometers
    temperature = 300. * u.kelvin
    langevin_timestep = 0.5 * u.femtoseconds
    timestep = 2 * u.femtoseconds
    equil_steps = 40000
    groups = [(0, 1)]
    steps_per_hmc = 25

    if sysname == "chargedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            charge=0.15 * u.elementary_charge)

    if sysname == "chargedswitchedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers)

    if sysname == "chargedlongljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers, charge=0.15 * u.elementary_charge)

    if sysname == "chargedswitchedlongljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers,
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers)

    if sysname == "chargedswitchedaccuratelongljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers,
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers,
            ewaldErrorTolerance=5E-5)

    if sysname == "chargedswitchedaccurateljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            charge=0.15 * u.elementary_charge,
            switch_width=0.34 * u.nanometers,
            ewaldErrorTolerance=5E-5)

    if sysname == "ljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj()

    if sysname == "longljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=1.333 * u.nanometers)

    if sysname == "shortljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=0.90 * u.nanometers)

    if sysname == "shiftedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            shift=True)

    if sysname == "switchedljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            switch_width=0.34 * u.nanometers)

    if sysname == "switchedshortljbox":
        testsystem, system, positions, timestep, langevin_timestep = load_lj(
            cutoff=0.90 * u.nanometers, switch_width=0.34 * u.nanometers)

    if sysname == "cluster":
        testsystem = testsystems.LennardJonesCluster(nx=8, ny=8, nz=8)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 40 * u.femtoseconds

    if sysname == "shortbigcluster":
        testsystem = testsystems.LennardJonesCluster(nx=20,
                                                     ny=20,
                                                     nz=20,
                                                     cutoff=0.75 *
                                                     u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 10 * u.femtoseconds

    if sysname == "switchedshortbigcluster":
        testsystem = testsystems.LennardJonesCluster(
            nx=20,
            ny=20,
            nz=20,
            cutoff=0.75 * u.nanometers,
            switch_width=0.1 * u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 10 * u.femtoseconds

    if sysname == "bigcluster":
        testsystem = testsystems.LennardJonesCluster(nx=20,
                                                     ny=20,
                                                     nz=20,
                                                     cutoff=1.25 *
                                                     u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 10 * u.femtoseconds

    if sysname == "shortcluster":
        testsystem = testsystems.LennardJonesCluster(nx=8,
                                                     ny=8,
                                                     nz=8,
                                                     cutoff=0.75 *
                                                     u.nanometers)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0)
        groups = [(0, 1)]
        temperature = 25. * u.kelvin
        timestep = 40 * u.femtoseconds

    if sysname == "shortwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=0.9 * u.nanometers,
            switch_width=None)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "shortswitchedwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=0.9 * u.nanometers,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "water":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=None)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "switchedwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "switchedaccuratewater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(
            system, nonbonded=0, fft=1, others=0)  # We may want to try reduce

    if sysname == "switchedaccurateflexiblewater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5,
            constrained=False)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        # Using these groups for hyperopt-optimal RESPA integrators
        #hmc_integrators.guess_force_groups(system, nonbonded=0, others=1, fft=0)
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           others=1,
                                           fft=0)
        equil_steps = 100000
        langevin_timestep = 0.25 * u.femtoseconds

    if sysname == "switchedaccuratebigflexiblewater":
        testsystem = testsystems.WaterBox(
            box_edge=10.0 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5,
            constrained=False)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        # Using these groups for hyperopt-optimal RESPA integrators
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           others=0,
                                           fft=1)
        equil_steps = 100000
        langevin_timestep = 0.1 * u.femtoseconds

    if sysname == "switchedaccuratestiffflexiblewater":

        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5,
            constrained=False)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        # Using these groups for hyperopt-optimal RESPA integrators
        #hmc_integrators.guess_force_groups(system, nonbonded=0, others=1, fft=0)
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           others=1,
                                           fft=0)
        equil_steps = 100000
        langevin_timestep = 0.25 * u.femtoseconds

        FACTOR = 10.0
        # Make bonded terms stiffer to highlight RESPA advantage
        for force in system.getForces():
            if type(force) == mm.HarmonicBondForce:
                for i in range(force.getNumBonds()):
                    (a0, a1, length, strength) = force.getBondParameters(i)
                    force.setBondParameters(i, a0, a1, length,
                                            strength * FACTOR)

            elif type(force) == mm.HarmonicAngleForce:
                for i in range(force.getNumAngles()):
                    (a0, a1, a2, length,
                     strength) = force.getAngleParameters(i)
                    force.setAngleParameters(i, a0, a1, a2, length,
                                             strength * FACTOR)

    if sysname == "switchedaccuratenptwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            switch_width=3.0 * u.angstroms,
            ewaldErrorTolerance=5E-5)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions
        system.addForce(
            mm.MonteCarloBarostat(1.0 * u.atmospheres, temperature, 1))

    if sysname == "longswitchedwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.5 * u.nanometers,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "rfwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            nonbondedMethod=app.CutoffPeriodic,
            switch_width=None)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "switchedrfwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.1 * u.nanometers,
            nonbondedMethod=app.CutoffPeriodic,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "longswitchedrfwater":
        testsystem = testsystems.WaterBox(
            box_edge=3.18 * u.nanometers,
            cutoff=1.5 * u.nanometers,
            nonbondedMethod=app.CutoffPeriodic,
            switch_width=3.0 * u.angstroms)  # Around 1060 molecules of water
        system, positions = testsystem.system, testsystem.positions

    if sysname == "density":
        system, positions = load_lb(hydrogenMass=3.0 * u.amu)
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           fft=1,
                                           others=0)
        groups = [(0, 4), (1, 1)]
        timestep = 2.0 * u.femtoseconds

    if sysname == "dhfr":
        testsystem = testsystems.DHFRExplicit(nonbondedCutoff=1.1 *
                                              u.nanometers,
                                              nonbondedMethod=app.PME,
                                              switch_width=2.0 * u.angstroms,
                                              ewaldErrorTolerance=5E-5)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           fft=2,
                                           others=0)
        groups = [(0, 4), (1, 2), (2, 1)]
        timestep = 0.75 * u.femtoseconds
        equil_steps = 10000

    if sysname == "src":
        testsystem = testsystems.SrcExplicit(nonbondedCutoff=1.1 *
                                             u.nanometers,
                                             nonbondedMethod=app.PME,
                                             switch_width=2.0 * u.angstroms,
                                             ewaldErrorTolerance=5E-5)
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=1,
                                           fft=1,
                                           others=0)
        groups = [(0, 2), (1, 1)]
        timestep = 0.25 * u.femtoseconds
        equil_steps = 1000

    if sysname == "ho":
        K = 90.0 * u.kilocalories_per_mole / u.angstroms**2
        mass = 39.948 * u.amu
        timestep = np.sqrt(mass / K) * 0.4
        testsystem = testsystems.HarmonicOscillatorArray()
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 1)]

    if sysname == "customho":
        timestep = 1000.0 * u.femtoseconds
        testsystem = testsystems.CustomExternalForcesTestSystem()
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 1)]

    if sysname == "customsplitho":
        timestep = 1000.0 * u.femtoseconds
        energy_expressions = ("0.75 * (x^2 + y^2 + z^2)",
                              "0.25 * (x^2 + y^2 + z^2)")
        testsystem = testsystems.CustomExternalForcesTestSystem(
            energy_expressions=energy_expressions)
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 2), (1, 1)]

    if sysname == "alanine":
        testsystem = testsystems.AlanineDipeptideImplicit()
        system, positions = testsystem.system, testsystem.positions
        groups = [(0, 2), (1, 1)]
        timestep = 2.0 * u.femtoseconds
        hmc_integrators.guess_force_groups(system, nonbonded=1, others=0)
        #remove_cmm(system)  # Unrolled shouldn't need this
        equil_steps = 10000

    if sysname == "alanineexplicit":
        testsystem = testsystems.AlanineDipeptideExplicit(
            cutoff=1.1 * u.nanometers,
            switch_width=2 * u.angstrom,
            ewaldErrorTolerance=5E-5)
        system, positions = testsystem.system, testsystem.positions
        #groups = [(0, 2), (1, 1), (2, 1)]
        #groups = [(0, 2), (1, 1)]
        timestep = 1.0 * u.femtoseconds
        #hmc_integrators.guess_force_groups(system, nonbonded=1, others=0, fft=2)
        #hmc_integrators.guess_force_groups(system, nonbonded=0, others=0, fft=1)
        groups = [(0, 1), (1, 2)]
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=0,
                                           others=1,
                                           fft=0)

        #remove_cmm(system)  # Unrolled doesn't need this
        equil_steps = 4000

    # guess force groups

    if "ljbox" in sysname:
        timestep = 25 * u.femtoseconds
        temperature = 25. * u.kelvin
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system, nonbonded=0, fft=1)
        groups = [(0, 2), (1, 1)]
        equil_steps = 10000
        steps_per_hmc = 15

    if sysname == "amoeba":
        testsystem = testsystems.AMOEBAIonBox()
        system, positions = testsystem.system, testsystem.positions
        hmc_integrators.guess_force_groups(system,
                                           nonbonded=0,
                                           fft=1,
                                           others=0)

    return system, positions, groups, temperature, timestep, langevin_timestep, testsystem, equil_steps, steps_per_hmc
示例#5
0
#test_systems['TIP3P with PME, no switch, no dispersion correction'] = {
#    'test' : testsystems.WaterBox(dispersion_correction=False, switch=False, nonbondedMethod=app.PME),
#    'ligand_atoms' : range(0,3), 'receptor_atoms' : range(3,6) }
test_systems['alanine dipeptide in vacuum'] = {
    'test': testsystems.AlanineDipeptideVacuum(),
    'ligand_atoms': range(0, 22),
    'receptor_atoms': range(22, 22)
}
test_systems['alanine dipeptide in OBC GBSA'] = {
    'test': testsystems.AlanineDipeptideImplicit(),
    'ligand_atoms': range(0, 22),
    'receptor_atoms': range(22, 22)
}
test_systems['alanine dipeptide in TIP3P with reaction field'] = {
    'test':
    testsystems.AlanineDipeptideExplicit(nonbondedMethod=app.CutoffPeriodic),
    'ligand_atoms':
    range(0, 22),
    'receptor_atoms':
    range(22, 22)
}
test_systems['T4 lysozyme L99A with p-xylene in OBC GBSA'] = {
    'test': testsystems.LysozymeImplicit(),
    'ligand_atoms': range(2603, 2621),
    'receptor_atoms': range(0, 2603)
}
#test_systems['Src in OBC GBSA'] = {
#    'test' : testsystems.SrcImplicit(),
#    'ligand_atoms' : range(0,21), 'receptor_atoms' : range(21,4091) }
#test_systems['Src in TIP3P with reaction field'] = {
#    'test' : testsystems.SrcExplicit(nonbondedMethod=app.CutoffPeriodic),
示例#6
0
    def test_compute_standard_state_correction(self):
        """Test standard state correction works correctly in all ensembles."""
        toluene = testsystems.TolueneVacuum()
        alanine = testsystems.AlanineDipeptideExplicit()
        big_radius = 200.0 * unit.nanometers
        temperature = 300.0 * unit.kelvin

        # Limit the maximum volume to 1nm^3.
        distance_unit = unit.nanometers
        state_volume = 1.0 * distance_unit**3
        box_vectors = np.identity(3) * np.cbrt(
            state_volume / distance_unit**3) * distance_unit
        alanine.system.setDefaultPeriodicBoxVectors(*box_vectors)
        toluene.system.setDefaultPeriodicBoxVectors(*box_vectors)

        # Create systems in various ensembles (NVT, NPT and non-periodic).
        nvt_state = states.ThermodynamicState(alanine.system, temperature)
        npt_state = states.ThermodynamicState(alanine.system, temperature,
                                              1.0 * unit.atmosphere)
        nonperiodic_state = states.ThermodynamicState(toluene.system,
                                                      temperature)

        def assert_equal_ssc(expected_restraint_volume,
                             restraint,
                             thermodynamic_state,
                             square_well=False,
                             radius_cutoff=None,
                             energy_cutoff=None,
                             max_volume=None):
            expected_ssc = -math.log(
                STANDARD_STATE_VOLUME / expected_restraint_volume)
            ssc = restraint.compute_standard_state_correction(
                thermodynamic_state, square_well, radius_cutoff, energy_cutoff,
                max_volume)
            err_msg = '{} computed SSC != expected SSC'.format(
                restraint.__class__.__name__)
            nose.tools.assert_equal(ssc, expected_ssc, msg=err_msg)

        for restraint in self.restraints:
            # In NPT ensemble, an exception is thrown if max_volume is not provided.
            with nose.tools.assert_raises_regexp(
                    TypeError, "max_volume must be provided"):
                restraint.compute_standard_state_correction(npt_state)

            # With non-periodic systems and reweighting to square-well
            # potential, a cutoff must be given.
            with nose.tools.assert_raises_regexp(TypeError,
                                                 "One between radius_cutoff"):
                restraint.compute_standard_state_correction(nonperiodic_state,
                                                            square_well=True)
            # While there are no problems if we don't reweight to a square-well potential.
            restraint.compute_standard_state_correction(nonperiodic_state,
                                                        square_well=False)

            # SSC is limited by max_volume (in NVT and NPT).
            assert_equal_ssc(state_volume,
                             restraint,
                             nvt_state,
                             radius_cutoff=big_radius)
            assert_equal_ssc(state_volume,
                             restraint,
                             npt_state,
                             radius_cutoff=big_radius,
                             max_volume='system')

            # SSC is not limited by max_volume with non periodic systems.
            expected_ssc = -math.log(STANDARD_STATE_VOLUME / state_volume)
            ssc = restraint.compute_standard_state_correction(
                nonperiodic_state, radius_cutoff=big_radius)
            assert expected_ssc < ssc, (restraint, expected_ssc, ssc)

            # Check reweighting to square-well potential.
            expected_volume = _compute_sphere_volume(big_radius)
            assert_equal_ssc(expected_volume,
                             restraint,
                             nonperiodic_state,
                             square_well=True,
                             radius_cutoff=big_radius)

            energy_cutoff = 10 * nonperiodic_state.kT
            radius_cutoff = _compute_harmonic_radius(self.spring_constant,
                                                     energy_cutoff)
            if isinstance(restraint, FlatBottomRestraintForceMixIn):
                radius_cutoff += self.well_radius
            expected_volume = _compute_sphere_volume(radius_cutoff)
            assert_equal_ssc(expected_volume,
                             restraint,
                             nonperiodic_state,
                             square_well=True,
                             radius_cutoff=radius_cutoff)

            max_volume = 3.0 * unit.nanometers**3
            assert_equal_ssc(max_volume,
                             restraint,
                             nonperiodic_state,
                             square_well=True,
                             max_volume=max_volume)
示例#7
0
        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]

    @staticmethod
    @contextlib.contextmanager
    def temporary_storage_path():
        """Generate a storage path in a temporary folder and share it.