Beispiel #1
0
    def test_system_charge_reporting(self):
        """Test if the system_charge is correctly reported."""

        pdb = app.PDBxFile(
            get_test_data("glu_ala_his-solvated-minimized-renamed.cif",
                          "testsystems/tripeptides"))
        initial_charge = (
            0
        )  # Ion totals are 0, and the system starts in state 0 for both, GLU deprotonated, HIS protonated
        forcefield = app.ForceField("amber10-constph.xml", "ions_tip3p.xml",
                                    "tip3p.xml")

        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=app.PME,
            nonbondedCutoff=1.0 * unit.nanometers,
            constraints=app.HBonds,
            rigidWater=True,
            ewaldErrorTolerance=0.0005,
        )

        temperature = 300 * unit.kelvin
        integrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=False,
        )
        ncmcintegrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=True,
        )

        compound_integrator = mm.CompoundIntegrator()
        compound_integrator.addIntegrator(integrator)
        compound_integrator.addIntegrator(ncmcintegrator)
        pressure = 1.0 * unit.atmosphere

        system.addForce(mm.MonteCarloBarostat(pressure, temperature))
        driver = ForceFieldProtonDrive(
            temperature,
            pdb.topology,
            system,
            forcefield,
            ["amber10-constph.xml"],
            pressure=pressure,
            perturbations_per_trial=0,
        )

        # pools defined by their residue index for convenience later on
        driver.define_pools({"0": [0], "1": [1]})
        simulation = app.ConstantPHSimulation(
            pdb.topology,
            system,
            compound_integrator,
            driver,
            platform=self._default_platform,
        )
        simulation.context.setPositions(pdb.positions)
        simulation.context.setVelocitiesToTemperature(temperature)
        filename = uuid.uuid4().hex + ".nc"
        ncfile = netCDF4.Dataset(filename, "w")
        print("Temporary file: ", filename)
        newreporter = tr.TitrationReporter(ncfile, 2)
        simulation.update_reporters.append(newreporter)

        # Regular MD step
        simulation.step(1)
        # Update the titration states forcibly from a pregenerated series

        glu_states = np.asarray([
            1, 4, 4, 1, 0, 2, 0, 2, 4, 3, 2, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 2,
            1, 3, 1
        ])
        his_states = np.asarray([
            2, 1, 0, 1, 2, 2, 1, 2, 2, 1, 0, 2, 2, 1, 2, 2, 2, 2, 2, 2, 0, 2,
            2, 2, 1
        ])

        for i in range(len(glu_states)):

            simulation.drive.set_titration_state(0,
                                                 glu_states[i],
                                                 updateContextParameters=False)
            simulation.drive.set_titration_state(1,
                                                 his_states[i],
                                                 updateContextParameters=False)
            simulation.update_reporters[0].report(simulation)
            tot_charge = 0
            for resi, residue in enumerate(simulation.drive.titrationGroups):
                icharge = int(floor(0.5 + residue.total_charge))
                tot_charge += icharge
                assert (
                    ncfile["Protons/Titration/{}_charge".format(resi)][i] ==
                    icharge), "Residue charge is not recorded correctly."
            assert (
                ncfile["Protons/Titration/complex_charge"][i] == tot_charge
            ), "The recorded complex total charge does not match the actual charge."

        # close files to avoid segfaults, possibly
        ncfile.close()
Beispiel #2
0
    def test_atom_status_reporting(self):
        """Test if the atom_status is correctly reported."""

        pdb = app.PDBxFile(
            get_test_data("glu_ala_his-solvated-minimized-renamed.cif",
                          "testsystems/tripeptides"))
        forcefield = app.ForceField("amber10-constph.xml", "ions_tip3p.xml",
                                    "tip3p.xml")

        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=app.PME,
            nonbondedCutoff=1.0 * unit.nanometers,
            constraints=app.HBonds,
            rigidWater=True,
            ewaldErrorTolerance=0.0005,
        )

        temperature = 300 * unit.kelvin
        integrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=False,
        )
        ncmcintegrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=True,
        )

        compound_integrator = mm.CompoundIntegrator()
        compound_integrator.addIntegrator(integrator)
        compound_integrator.addIntegrator(ncmcintegrator)
        pressure = 1.0 * unit.atmosphere

        system.addForce(mm.MonteCarloBarostat(pressure, temperature))
        driver = ForceFieldProtonDrive(
            temperature,
            pdb.topology,
            system,
            forcefield,
            ["amber10-constph.xml"],
            pressure=pressure,
            perturbations_per_trial=0,
        )

        simulation = app.ConstantPHSimulation(
            pdb.topology,
            system,
            compound_integrator,
            driver,
            platform=self._default_platform,
        )
        simulation.context.setPositions(pdb.positions)
        simulation.context.setVelocitiesToTemperature(temperature)
        filename = uuid.uuid4().hex + ".nc"
        ncfile = netCDF4.Dataset(filename, "w")
        print("Temporary file: ", filename)
        newreporter = tr.TitrationReporter(ncfile, 2)
        simulation.update_reporters.append(newreporter)

        # Regular MD step
        simulation.step(1)
        # Update the titration states forcibly from a pregenerated series
        glu_states = np.asarray([
            1, 4, 4, 1, 0, 2, 0, 2, 4, 3, 2, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 2,
            1, 3, 1
        ])
        his_states = np.asarray([
            2, 1, 0, 1, 2, 2, 1, 2, 2, 1, 0, 2, 2, 1, 2, 2, 2, 2, 2, 2, 0, 2,
            2, 2, 1
        ])

        for i in range(len(glu_states)):
            simulation.drive.set_titration_state(0,
                                                 glu_states[i],
                                                 updateContextParameters=False)
            simulation.drive.set_titration_state(1,
                                                 his_states[i],
                                                 updateContextParameters=False)
            simulation.update_reporters[0].report(simulation)
            # check glu
            self._verify_atom_status(i, 0, ncfile, simulation)
            # check his
            self._verify_atom_status(i, 1, ncfile, simulation)

        ncfile.close()
Beispiel #3
0
    def test_reports(self):
        """Instantiate a simulation at 300K/1 atm for a small peptide with reporter."""

        pdb = app.PDBxFile(
            get_test_data(
                "glu_ala_his-solvated-minimized-renamed.cif", "testsystems/tripeptides"
            )
        )
        forcefield = app.ForceField(
            "amber10-constph.xml", "ions_tip3p.xml", "tip3p.xml"
        )

        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=app.PME,
            nonbondedCutoff=1.0 * unit.nanometers,
            constraints=app.HBonds,
            rigidWater=True,
            ewaldErrorTolerance=0.0005,
        )

        temperature = 300 * unit.kelvin
        integrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=False,
        )
        ncmcintegrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=True,
        )

        compound_integrator = mm.CompoundIntegrator()
        compound_integrator.addIntegrator(integrator)
        compound_integrator.addIntegrator(ncmcintegrator)
        pressure = 1.0 * unit.atmosphere

        system.addForce(mm.MonteCarloBarostat(pressure, temperature))
        driver = ForceFieldProtonDrive(
            temperature,
            pdb.topology,
            system,
            forcefield,
            ["amber10-constph.xml"],
            pressure=pressure,
            perturbations_per_trial=3,
        )

        # prep the driver for calibration
        driver.enable_calibration(
            SAMSApproach.ONESITE, group_index=1, update_rule=UpdateRule.BINARY
        )

        calibration = app.ConstantPHSimulation(
            pdb.topology,
            system,
            compound_integrator,
            driver,
            platform=self._default_platform,
        )
        calibration.context.setPositions(pdb.positions)
        calibration.context.setVelocitiesToTemperature(temperature)
        filename = uuid.uuid4().hex + ".nc"
        print("Temporary file: ", filename)
        newreporter = sr.SAMSReporter(filename, 2)
        calibration.calibration_reporters.append(newreporter)

        # Regular MD step
        for iteration in range(4):
            calibration.step(1)
            # Update the titration states using the uniform proposal
            calibration.update(1)
            # adapt sams weights
            calibration.adapt()

        # Basic checks for dimension
        assert (
            newreporter.ncfile["Protons/SAMS"].dimensions["adaptation"].size == 2
        ), "There should be 2 updates recorded."
        assert (
            newreporter.ncfile["Protons/SAMS"].dimensions["state"].size == 3
        ), "There should be 3 states reported."

        newreporter.ncfile.close()
Beispiel #4
0
    def test_reports(self):
        """Instantiate a ConstantPHSimulation at 300K/1 atm for a small peptide."""

        pdb = app.PDBxFile(
            get_test_data("glu_ala_his-solvated-minimized-renamed.cif",
                          "testsystems/tripeptides"))
        num_atoms = pdb.topology.getNumAtoms()
        forcefield = app.ForceField("amber10-constph.xml", "ions_tip3p.xml",
                                    "tip3p.xml")

        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=app.PME,
            nonbondedCutoff=1.0 * unit.nanometers,
            constraints=app.HBonds,
            rigidWater=True,
            ewaldErrorTolerance=0.0005,
        )

        temperature = 300 * unit.kelvin
        integrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=False,
        )
        ncmcintegrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=True,
        )

        compound_integrator = mm.CompoundIntegrator()
        compound_integrator.addIntegrator(integrator)
        compound_integrator.addIntegrator(ncmcintegrator)
        pressure = 1.0 * unit.atmosphere

        system.addForce(mm.MonteCarloBarostat(pressure, temperature))
        driver = ForceFieldProtonDrive(
            temperature,
            pdb.topology,
            system,
            forcefield,
            ["amber10-constph.xml"],
            pressure=pressure,
            perturbations_per_trial=0,
        )

        num_titratable = len(driver.titrationGroups)
        simulation = app.ConstantPHSimulation(
            pdb.topology,
            system,
            compound_integrator,
            driver,
            platform=self._default_platform,
        )
        simulation.context.setPositions(pdb.positions)
        simulation.context.setVelocitiesToTemperature(temperature)
        filename = uuid.uuid4().hex + ".nc"
        print("Temporary file: ", filename)
        newreporter = tr.TitrationReporter(filename, 2)
        simulation.update_reporters.append(newreporter)

        # Regular MD step
        simulation.step(1)
        # Update the titration states using the uniform proposal
        simulation.update(6)
        # Basic checks for dimension
        assert (newreporter.ncfile["Protons/Titration"].dimensions["update"].
                size == 3), "There should be 3 updates recorded."
        assert (
            newreporter.ncfile["Protons/Titration"].dimensions["residue"].size
            == num_titratable
        ), "There should be {} residues recorded.".format(num_titratable)
        assert (
            newreporter.ncfile["Protons/Titration"].dimensions["atom"].size ==
            num_atoms), "There should be {} atoms recorded.".format(num_atoms)
        newreporter.ncfile.close()
Beispiel #5
0
    def test_reports_every_perturbation_saltswap(self):
        """Instantiate a ConstantPHSimulation at 300K/1 atm for a small peptide, save every perturbation step, with saltswap."""

        pdb = app.PDBxFile(
            get_test_data("glu_ala_his-solvated-minimized-renamed.cif",
                          "testsystems/tripeptides"))
        forcefield = app.ForceField("amber10-constph.xml", "ions_tip3p.xml",
                                    "tip3p.xml")

        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=app.PME,
            nonbondedCutoff=1.0 * unit.nanometers,
            constraints=app.HBonds,
            rigidWater=True,
            ewaldErrorTolerance=0.0005,
        )

        temperature = 300 * unit.kelvin
        integrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=False,
        )
        ncmcintegrator = GBAOABIntegrator(
            temperature=temperature,
            collision_rate=1.0 / unit.picoseconds,
            timestep=2.0 * unit.femtoseconds,
            constraint_tolerance=1.0e-7,
            external_work=True,
        )

        compound_integrator = mm.CompoundIntegrator()
        compound_integrator.addIntegrator(integrator)
        compound_integrator.addIntegrator(ncmcintegrator)
        pressure = 1.0 * unit.atmosphere

        system.addForce(mm.MonteCarloBarostat(pressure, temperature))
        driver = ForceFieldProtonDrive(
            temperature,
            pdb.topology,
            system,
            forcefield,
            ["amber10-constph.xml"],
            pressure=pressure,
            perturbations_per_trial=3,
        )

        simulation = app.ConstantPHSimulation(
            pdb.topology,
            system,
            compound_integrator,
            driver,
            platform=self._default_platform,
        )
        simulation.context.setPositions(pdb.positions)
        simulation.context.setVelocitiesToTemperature(temperature)
        filename = uuid.uuid4().hex + ".nc"
        print("Temporary file: ", filename)
        # The salinator initializes the system salts
        salinator = Salinator(
            context=simulation.context,
            system=simulation.system,
            topology=simulation.topology,
            ncmc_integrator=simulation.integrator.getIntegrator(1),
            salt_concentration=0.2 * unit.molar,
            pressure=pressure,
            temperature=temperature,
        )
        salinator.neutralize()
        salinator.initialize_concentration()
        swapper = salinator.swapper
        driver.enable_neutralizing_ions(swapper)

        newreporter = ncr.NCMCReporter(filename, 1, cumulativeworkInterval=1)
        simulation.update_reporters.append(newreporter)

        # Regular MD step
        simulation.step(1)
        # Update the titration states using the uniform proposal
        simulation.update(4)
        # Basic checks for dimension
        assert (newreporter.ncfile["Protons/NCMC"].dimensions["update"].size ==
                4), "There should be 4 updates recorded."
        assert (newreporter.ncfile["Protons/NCMC"].dimensions["residue"].size
                == 2), "There should be 2 residues recorded."
        assert (newreporter.ncfile["Protons/NCMC"].dimensions["perturbation"].
                size == 3), "There should be max 3 perturbations recorded."
        assert (newreporter.ncfile["Protons/NCMC"].dimensions["ion_site"].size
                == 1269), "The system should have 1269 potential ion sites."

        # Ensure clean exit
        newreporter.ncfile.sync()
        newreporter.ncfile.close()