Ejemplo n.º 1
0
def test_ensemble_potential_nompi(spc_water_box):
    """Test ensemble potential without an ensemble.
    """
    tpr_filename = spc_water_box
    print("Testing plugin potential with input file {}".format(
        os.path.abspath(tpr_filename)))

    assert gmx.version.api_is_at_least(0, 0, 5)
    md = from_tpr([tpr_filename], append_output=False)

    # Create a WorkElement for the potential
    params = {
        'sites': [1, 4],
        'nbins': 10,
        'binWidth': 0.1,
        'min_dist': 0.,
        'max_dist': 10.,
        'experimental': [1.] * 10,
        'nsamples': 1,
        'sample_period': 0.001,
        'nwindows': 4,
        'k': 10000.,
        'sigma': 1.
    }
    potential = WorkElement(namespace="myplugin",
                            operation="ensemble_restraint",
                            params=params)
    # Note that we could flexibly capture accessor methods as workflow elements, too. Maybe we can
    # hide the extra Python bindings by letting myplugin.HarmonicRestraint automatically convert
    # to a WorkElement when add_dependency is called on it.
    potential.name = "ensemble_restraint"
    md.add_dependency(potential)

    context = Context(md)

    with context as session:
        session.run()
Ejemplo n.º 2
0
    def build_plugin(self):
        """Builds production phase plugin for BRER simulations.

        Returns
        -------
        WorkElement
            a gmxapi WorkElement to be added to the workflow graph

        Raises
        ------
        KeyError
            if required parameters for building the plugin are missing.
        """
        WorkElement = _get_workelement()
        if self.get_missing_keys():
            raise KeyError('Must define {}'.format(self.get_missing_keys()))
        if self.get('alpha') == 0.0:
            raise ValueError('Read a non-sensical alpha value: 0.0')
        potential = WorkElement(namespace="brer",
                                operation="linear_restraint",
                                depends=[],
                                params=self.get_as_dictionary())
        potential.name = '{}'.format(self.get('sites'))
        return potential
Ejemplo n.º 3
0
def test_binding_protocol(spc_water_box, mdrun_kwargs):
    """Test that gmxapi successfully attaches MD plugins."""
    import myplugin

    if _MPI is not None:
        _size = _MPI.COMM_WORLD.Get_size()
        _rank = _MPI.COMM_WORLD.Get_rank()
    else:
        _size = 1
        _rank = 0

    tpr_filename = spc_water_box
    logger.info("Testing plugin potential with input file {}".format(
        os.path.abspath(tpr_filename)))

    assert gmx.version.api_is_at_least(0, 2, 1)
    md = from_tpr([tpr_filename] * _size, append_output=False, **mdrun_kwargs)

    potential = WorkElement(namespace="myplugin",
                            operation="null_restraint",
                            params={'sites': [1, 4]})
    potential.name = "null restraint"
    md.add_dependency(potential)

    context = Context(md)

    with context as session:
        session.run()

    # See also #3038, #3145, #4079
    assert isinstance(context.potentials, list)
    assert len(context.potentials) > 0
    for restraint in context.potentials:
        if isinstance(restraint, myplugin.NullRestraint):
            assert gmx.version.api_is_at_least(0, 2, 1)
            assert restraint.count() > 1