Пример #1
0
    def setUp(self):
        prmtop = app.AmberPrmtopFile('systems/water-box-216.prmtop')

        system = prmtop.createSystem(nonbondedMethod=app.PME,
                                     nonbondedCutoff=0.9 * unit.nanometers,
                                     constraints=app.HBonds,
                                     rigidWater=True,
                                     ewaldErrorTolerance=0.0005)
        integrator = mm.LangevinIntegrator(300 * unit.kelvin,
                                           1.0 / unit.picoseconds,
                                           2.0 * unit.femtoseconds)
        self.simulation = app.Simulation(
            prmtop.topology, system, integrator,
            mm.Platform.getPlatformByName('Reference'))
Пример #2
0
def _configure_amber_implicit(
    pdb_file: PathLike,
    top_file: Optional[PathLike],
    dt_ps: float,
    temperature_kelvin: float,
    heat_bath_friction_coef: float,
    platform: "openmm.Platform",
    platform_properties: dict,
) -> Tuple["app.Simulation", Optional["app.PDBFile"]]:

    # Configure system
    if top_file is not None:
        pdb = None
        top = app.AmberPrmtopFile(str(top_file))
        system = top.createSystem(
            nonbondedMethod=app.CutoffNonPeriodic,
            nonbondedCutoff=1.0 * u.nanometer,
            constraints=app.HBonds,
            implicitSolvent=app.OBC1,
        )
    else:
        pdb = app.PDBFile(str(pdb_file))
        top = pdb.topology
        forcefield = app.ForceField("amber99sbildn.xml", "amber99_obc.xml")
        system = forcefield.createSystem(
            top,
            nonbondedMethod=app.CutoffNonPeriodic,
            nonbondedCutoff=1.0 * u.nanometer,
            constraints=app.HBonds,
        )

    # Configure integrator
    integrator = openmm.LangevinIntegrator(
        temperature_kelvin * u.kelvin,
        heat_bath_friction_coef / u.picosecond,
        dt_ps * u.picosecond,
    )
    integrator.setConstraintTolerance(0.00001)

    sim = app.Simulation(top, system, integrator, platform,
                         platform_properties)

    # Returning the pdb file object for later use to reduce I/O.
    # If a topology file is passed, the pdb variable is None.
    return sim, pdb
Пример #3
0
def _configure_amber_explicit(
    top_file: PathLike,
    dt_ps: float,
    temperature_kelvin: float,
    heat_bath_friction_coef: float,
    platform: "openmm.Platform",
    platform_properties: dict,
    explicit_barostat: str,
) -> "app.Simulation":

    top = app.AmberPrmtopFile(str(top_file))
    system = top.createSystem(
        nonbondedMethod=app.PME,
        nonbondedCutoff=1.0 * u.nanometer,
        constraints=app.HBonds,
    )

    # Congfigure integrator
    integrator = openmm.LangevinIntegrator(
        temperature_kelvin * u.kelvin,
        heat_bath_friction_coef / u.picosecond,
        dt_ps * u.picosecond,
    )

    if explicit_barostat == "MonteCarloBarostat":
        system.addForce(
            openmm.MonteCarloBarostat(1 * u.bar,
                                      temperature_kelvin * u.kelvin))
    elif explicit_barostat == "MonteCarloAnisotropicBarostat":
        system.addForce(
            openmm.MonteCarloAnisotropicBarostat(
                (1, 1, 1) * u.bar, temperature_kelvin * u.kelvin, False, False,
                True))
    else:
        raise ValueError(
            f"Invalid explicit_barostat option: {explicit_barostat}")

    sim = app.Simulation(top.topology, system, integrator, platform,
                         platform_properties)

    return sim
Пример #4
0
def create_openmm_system(sim_openmm,
                         model,
                         anchor,
                         frame=0,
                         load_state_file=None):
    """
    Create an openmm System() object.
    """
    building_directory = os.path.join(model.anchor_rootdir, anchor.directory,
                                      anchor.building_directory)
    box_vectors = None
    num_frames = 0
    positions_obj = None
    if anchor.__class__.__name__ in ["MMVT_toy_anchor", "Elber_toy_anchor"]:
        if load_state_file is not None:
            positions = None
            num_frames = 1
        elif anchor.starting_positions is not None:
            positions_frames = np.array(anchor.starting_positions) \
                * openmm.unit.nanometers
            positions = positions_frames[frame]
            num_frames = len(positions_frames)
        else:
            raise Exception(
                "No starting state or starting positions provided.")

    else:
        if anchor.amber_params is not None:
            prmtop_filename = os.path.join(building_directory,
                                           anchor.amber_params.prmtop_filename)
            prmtop = openmm_app.AmberPrmtopFile(prmtop_filename)
            #assert anchor.amber_params.pdb_coordinates_filename is not None
            if anchor.amber_params.pdb_coordinates_filename is None \
                    or anchor.amber_params.pdb_coordinates_filename == "":
                positions_obj = None
                positions = None
                sim_openmm.try_to_load_state = True
            else:
                pdb_coordinates_filename = os.path.join(
                    building_directory,
                    anchor.amber_params.pdb_coordinates_filename)
                positions_obj = openmm_app.PDBFile(pdb_coordinates_filename)

            #assert anchor.amber_params.box_vectors is not None
            box_vectors = anchor.amber_params.box_vectors
            topology = prmtop.topology

        elif anchor.forcefield_params is not None:
            forcefield_filenames = []
            for forcefield_filename in \
                    anchor.forcefield_params.built_in_forcefield_filenames:
                forcefield_filenames.append(forcefield_filename)
            for forcefield_filename in \
                    anchor.forcefield_params.custom_forcefield_filenames:
                forcefield_filenames.append(
                    os.path.join(building_directory, forcefield_filename))
            print("anchor.forcefield_params.pdb_filename:",
                  anchor.forcefield_params.pdb_coordinates_filename)
            pdb_filename = os.path.join(
                building_directory,
                anchor.forcefield_params.pdb_coordinates_filename)
            print("pdb_filename:", pdb_filename)
            pdb = openmm_app.PDBFile(pdb_filename)
            forcefield = openmm_app.ForceField(*forcefield_filenames)
            box_vectors = anchor.forcefield_params.box_vectors

            topology = pdb.topology
            positions_obj = pdb
            positions = None

        elif anchor.charmm_params is not None:
            raise Exception("Charmm systems not yet implemented")

        else:
            raise Exception("No Amber or Charmm input settings detected.")

    #assert box_vectors is not None, "No source of box vectors provided."
    nonbonded_method = model.openmm_settings.nonbonded_method.lower()
    if nonbonded_method == "pme":
        nonbondedMethod = openmm_app.PME

    elif nonbonded_method == "nocutoff":
        nonbondedMethod = openmm_app.NoCutoff

    elif nonbonded_method == "cutoffnonperiodic":
        nonbondedMethod = openmm_app.CutoffNonPeriodic

    elif nonbonded_method == "cutoffperiodic":
        nonbondedMethod = openmm_app.CutoffPeriodic

    elif nonbonded_method == "ewald":
        nonbondedMethod = openmm_app.Ewald

    else:
        raise Exception("nonbonded method not found: %s",
                        model.openmm_settings.nonbonded_method)

    if model.openmm_settings.constraints is None:
        constraints_str = None
    else:
        constraints_str = model.openmm_settings.constraints

    if constraints_str is None:
        constraints = None

    elif constraints_str.lower() == "none":
        constraints = None

    elif constraints_str.lower() == "hbonds":
        constraints = openmm_app.HBonds

    elif constraints_str.lower() == "allbonds":
        constraints = openmm_app.AllBonds

    elif constraints_str.lower() == "hangles":
        constraints = openmm_app.HAngles

    else:
        raise Exception("constraints not found: %s",
                        model.openmm_settings.constraints)

    if model.openmm_settings.hydrogenMass is not None:
        hydrogenMass = model.openmm_settings.hydrogenMass * openmm.unit.amu
    else:
        hydrogenMass = None

    rigidWater = model.openmm_settings.rigidWater

    if anchor.__class__.__name__ in ["MMVT_toy_anchor", "Elber_toy_anchor"]:
        system, topology = make_toy_system_object(model)
    else:
        if anchor.amber_params is not None:
            system = prmtop.createSystem(
                nonbondedMethod=nonbondedMethod,
                nonbondedCutoff=model.openmm_settings.nonbonded_cutoff,
                constraints=constraints,
                hydrogenMass=hydrogenMass,
                rigidWater=rigidWater)

        elif anchor.forcefield_params is not None:
            system = forcefield.createSystem(
                pdb.topology,
                nonbondedMethod=nonbondedMethod,
                nonbondedCutoff=model.openmm_settings.nonbonded_cutoff,
                constraints=constraints,
                hydrogenMass=hydrogenMass,
                rigidWater=rigidWater)

        elif anchor.charmm_params is not None:
            raise Exception("Charmm input settings not yet implemented")

        else:
            print("Settings for Amber or Charmm simulations not found")

    if positions_obj is not None:
        positions = positions_obj.getPositions(frame=frame)
        assert frame >= 0, "Cannot have negative frame index"
        assert frame < positions_obj.getNumFrames(), \
            "Frame index {} out of range.".format(frame)
        num_frames = positions_obj.getNumFrames()

    return system, topology, positions, box_vectors, num_frames
Пример #5
0
def runOneTest(testName, options):
    """Perform a single benchmarking simulation."""
    explicit = (testName not in ('gbsa', 'amoebagk'))
    amoeba = (testName in ('amoebagk', 'amoebapme'))
    apoa1 = testName.startswith('apoa1')
    amber = (testName.startswith('amber'))
    hydrogenMass = None
    print()
    if amoeba:
        print('Test: %s (epsilon=%g)' % (testName, options.epsilon))
    elif testName == 'pme':
        print('Test: pme (cutoff=%g)' % options.cutoff)
    else:
        print('Test: %s' % testName)
    print('Ensemble: %s' % options.ensemble)
    platform = mm.Platform.getPlatformByName(options.platform)

    # Create the System.

    temperature = 300 * unit.kelvin
    if explicit:
        friction = 1 * (1 / unit.picoseconds)
    else:
        friction = 91 * (1 / unit.picoseconds)
    if amoeba:
        constraints = None
        epsilon = float(options.epsilon)
        if explicit:
            ff = app.ForceField('amoeba2009.xml')
            pdb = app.PDBFile('5dfr_solv-cube_equil.pdb')
            cutoff = 0.7 * unit.nanometers
            vdwCutoff = 0.9 * unit.nanometers
            system = ff.createSystem(pdb.topology,
                                     nonbondedMethod=app.PME,
                                     nonbondedCutoff=cutoff,
                                     vdwCutoff=vdwCutoff,
                                     constraints=constraints,
                                     ewaldErrorTolerance=0.00075,
                                     mutualInducedTargetEpsilon=epsilon,
                                     polarization=options.polarization)
        else:
            ff = app.ForceField('amoeba2009.xml', 'amoeba2009_gk.xml')
            pdb = app.PDBFile('5dfr_minimized.pdb')
            cutoff = 2.0 * unit.nanometers
            vdwCutoff = 1.2 * unit.nanometers
            system = ff.createSystem(pdb.topology,
                                     nonbondedMethod=app.NoCutoff,
                                     constraints=constraints,
                                     mutualInducedTargetEpsilon=epsilon,
                                     polarization=options.polarization)
        for f in system.getForces():
            if isinstance(f, mm.AmoebaMultipoleForce) or isinstance(
                    f, mm.AmoebaVdwForce) or isinstance(
                        f, mm.AmoebaGeneralizedKirkwoodForce) or isinstance(
                            f, mm.AmoebaWcaDispersionForce):
                f.setForceGroup(1)
        dt = 0.002 * unit.picoseconds
        if options.ensemble == 'NVE':
            integ = mm.MTSIntegrator(dt, [(0, 2), (1, 1)])
        else:
            integ = mm.MTSLangevinIntegrator(temperature, friction, dt,
                                             [(0, 2), (1, 1)])
        positions = pdb.positions
    elif amber:
        dirname = downloadAmberSuite()
        names = {
            'amber20-dhfr': 'JAC',
            'amber20-factorix': 'FactorIX',
            'amber20-cellulose': 'Cellulose',
            'amber20-stmv': 'STMV'
        }
        fileName = names[testName]
        prmtop = app.AmberPrmtopFile(
            os.path.join(dirname, f'PME/Topologies/{fileName}.prmtop'))
        inpcrd = app.AmberInpcrdFile(
            os.path.join(dirname, f'PME/Coordinates/{fileName}.inpcrd'))
        topology = prmtop.topology
        positions = inpcrd.positions
        dt = 0.004 * unit.picoseconds
        method = app.PME
        cutoff = options.cutoff
        constraints = app.HBonds
        system = prmtop.createSystem(nonbondedMethod=method,
                                     nonbondedCutoff=cutoff,
                                     constraints=constraints)
        if options.ensemble == 'NVE':
            integ = mm.VerletIntegrator(dt)
        else:
            integ = mm.LangevinMiddleIntegrator(temperature, friction, dt)
    else:
        if apoa1:
            ff = app.ForceField('amber14/protein.ff14SB.xml',
                                'amber14/lipid17.xml', 'amber14/tip3p.xml')
            pdb = app.PDBFile('apoa1.pdb')
            if testName == 'apoa1pme':
                method = app.PME
                cutoff = options.cutoff
            elif testName == 'apoa1ljpme':
                method = app.LJPME
                cutoff = options.cutoff
            else:
                method = app.CutoffPeriodic
                cutoff = 1 * unit.nanometers
            hydrogenMass = 1.5 * unit.amu
        elif explicit:
            ff = app.ForceField('amber99sb.xml', 'tip3p.xml')
            pdb = app.PDBFile('5dfr_solv-cube_equil.pdb')
            if testName == 'pme':
                method = app.PME
                cutoff = options.cutoff
            else:
                method = app.CutoffPeriodic
                cutoff = 1 * unit.nanometers
        else:
            ff = app.ForceField('amber99sb.xml', 'amber99_obc.xml')
            pdb = app.PDBFile('5dfr_minimized.pdb')
            method = app.CutoffNonPeriodic
            cutoff = 2 * unit.nanometers
        if options.heavy:
            dt = 0.005 * unit.picoseconds
            constraints = app.AllBonds
            hydrogenMass = 4 * unit.amu
            if options.ensemble == 'NVE':
                integ = mm.VerletIntegrator(dt)
            else:
                integ = mm.LangevinIntegrator(temperature, friction, dt)
        else:
            dt = 0.004 * unit.picoseconds
            constraints = app.HBonds
            if options.ensemble == 'NVE':
                integ = mm.VerletIntegrator(dt)
            else:
                integ = mm.LangevinMiddleIntegrator(temperature, friction, dt)
        positions = pdb.positions
        system = ff.createSystem(pdb.topology,
                                 nonbondedMethod=method,
                                 nonbondedCutoff=cutoff,
                                 constraints=constraints,
                                 hydrogenMass=hydrogenMass)
    if options.ensemble == 'NPT':
        system.addForce(mm.MonteCarloBarostat(1 * unit.bar, temperature, 100))
    print('Step Size: %g fs' % dt.value_in_unit(unit.femtoseconds))
    properties = {}
    initialSteps = 5
    if options.device is not None and platform.getName() in ('CUDA', 'OpenCL'):
        properties['DeviceIndex'] = options.device
        if ',' in options.device or ' ' in options.device:
            initialSteps = 250
    if options.precision is not None and platform.getName() in ('CUDA',
                                                                'OpenCL'):
        properties['Precision'] = options.precision

    # Run the simulation.

    integ.setConstraintTolerance(1e-5)
    if len(properties) > 0:
        context = mm.Context(system, integ, platform, properties)
    else:
        context = mm.Context(system, integ, platform)
    context.setPositions(positions)
    if amber:
        if inpcrd.boxVectors is not None:
            context.setPeriodicBoxVectors(*inpcrd.boxVectors)
        mm.LocalEnergyMinimizer.minimize(
            context, 100 * unit.kilojoules_per_mole / unit.nanometer)
    context.setVelocitiesToTemperature(temperature)

    steps = 20
    while True:
        time = timeIntegration(context, steps, initialSteps)
        if time >= 0.5 * options.seconds:
            break
        if time < 0.5:
            steps = int(
                steps * 1.0 / time
            )  # Integrate enough steps to get a reasonable estimate for how many we'll need.
        else:
            steps = int(steps * options.seconds / time)
    print('Integrated %d steps in %g seconds' % (steps, time))
    print('%g ns/day' %
          (dt * steps * 86400 / time).value_in_unit(unit.nanoseconds))
Пример #6
0
def create_openmm_system(sim_openmm, model, anchor):
    """
    Create an openmm System() object.
    """
    building_directory = os.path.join(model.anchor_rootdir, anchor.directory,
                                      anchor.building_directory)
    box_vectors = None
    if anchor.amber_params is not None:
        prmtop_filename = os.path.join(building_directory,
                                       anchor.amber_params.prmtop_filename)
        prmtop = openmm_app.AmberPrmtopFile(prmtop_filename)
        assert anchor.amber_params.pdb_coordinates_filename is not None
        pdb_coordinates_filename = os.path.join(
            building_directory, anchor.amber_params.pdb_coordinates_filename)
        positions = openmm_app.PDBFile(pdb_coordinates_filename)
        #assert anchor.amber_params.box_vectors is not None
        box_vectors = anchor.amber_params.box_vectors
        topology = prmtop

    elif anchor.forcefield_params is not None:
        forcefield_filenames = []
        for forcefield_filename in \
                anchor.forcefield_params.built_in_forcefield_filenames:
            forcefield_filenames.append(forcefield_filename)
        for forcefield_filename in \
                anchor.forcefield_params.custom_forcefield_filenames:
            forcefield_filenames.append(
                os.path.join(building_directory, forcefield_filename))
        pdb_filename = os.path.join(building_directory,
                                    anchor.forcefield_params.pdb_filename)
        pdb = openmm_app.PDBFile(pdb_filename)
        forcefield = openmm_app.ForceField(*forcefield_filenames)
        box_vectors = anchor.forcefield_params.box_vectors

        topology = pdb
        positions = pdb

    elif anchor.charmm_params is not None:
        raise Exception("Charmm systems not yet implemented")

    else:
        raise Exception("No Amber or Charmm input settings detected.")

    #assert box_vectors is not None, "No source of box vectors provided."
    nonbonded_method = model.openmm_settings.nonbonded_method.lower()
    if nonbonded_method == "pme":
        nonbondedMethod = openmm_app.PME

    elif nonbonded_method == "nocutoff":
        nonbondedMethod = openmm_app.NoCutoff

    elif nonbonded_method == "cutoffnonperiodic":
        nonbondedMethod = openmm_app.CutoffNonPeriodic

    elif nonbonded_method == "cutoffperiodic":
        nonbondedMethod = openmm_app.CutoffPeriodic

    elif nonbonded_method == "ewald":
        nonbondedMethod = openmm_app.Ewald

    else:
        raise Exception("nonbonded method not found: %s",
                        model.openmm_settings.nonbonded_method)

    if model.openmm_settings.constraints is None:
        constraints_str = None
    else:
        constraints_str = model.openmm_settings.constraints

    if constraints_str is None:
        constraints = None

    elif constraints_str.lower() == "none":
        constraints = None

    elif constraints_str.lower() == "hbonds":
        constraints = openmm_app.HBonds

    elif constraints_str.lower() == "allbonds":
        constraints = openmm_app.AllBonds

    elif constraints_str.lower() == "hangles":
        constraints = openmm_app.HAngles

    else:
        raise Exception("constraints not found: %s",
                        model.openmm_settings.constraints)

    if model.openmm_settings.hydrogenMass:
        hydrogenMass = model.openmm_settings.hydrogenMass * openmm.unit.amu
    else:
        hydrogenMass = model.openmm_settings.hydrogenMass
    rigidWater = model.openmm_settings.rigidWater

    if anchor.amber_params is not None:
        system = prmtop.createSystem(
            nonbondedMethod=nonbondedMethod,
            nonbondedCutoff=model.openmm_settings.nonbonded_cutoff,
            constraints=constraints,
            hydrogenMass=hydrogenMass,
            rigidWater=rigidWater)

    elif anchor.forcefield_params is not None:
        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=nonbondedMethod,
            nonbondedCutoff=model.openmm_settings.nonbonded_cutoff,
            constraints=constraints,
            hydrogenMass=hydrogenMass,
            rigidWater=rigidWater)

    elif anchor.charmm_params is not None:
        raise Exception("Charmm input settings not yet implemented")

    else:
        print("Settings for Amber or Charmm simulations not found")

    return system, topology, positions, box_vectors