<commit_before># Copyright (c) 2009-2019 The Regents of the University of Michigan
# This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

# Maintainer: joaander / All Developers are free to add commands for new features

R""" Bond potentials.

Bonds add forces between specified pairs of particles and are typically used to
model chemical bonds between two particles.

By themselves, bonds that have been specified in an initial configuration do nothing. Only when you
specify an bond force (i.e. bond.harmonic), are forces actually calculated between the
listed particles.
"""

from hoomd import _hoomd
from hoomd.md import _md
from hoomd.md.force import _Force
from hoomd.md import force
from hoomd.typeparam import TypeParameter
from hoomd.parameterdicts import TypeParameterDict
import hoomd

import math


class _Bond(_Force):
    """Constructs the bond potential.

    A bond in hoomd reflects a PotentialBond in c++. It is responsible for all
    high-level management that happens behind the scenes for hoomd writers.
    1) The instance of the c++ bond force itself is tracked and added to the
    System
    2) methods are provided for disabling the force from being added to the net
    force on each particle
    """
    def attach(self, simulation):
        """Create the c++ mirror class."""
        if not simulation.device.cpp_exec_conf.isCUDAEnabled():
            cpp_cls = getattr(_md, self._cpp_class_name)
        else:
            cpp_cls = getattr(_md, self._cpp_class_name + "GPU")

        # TODO remove string argument
        self._cpp_obj = cpp_cls(simulation.state._cpp_sys_def, "")

        super().attach(simulation)


class Harmonic(_Bond):
    R""" Harmonic bond potential.

    Args:
        name (str): Name of the bond instance.

    :py:class:`Harmonic` specifies a harmonic potential energy between the two
    particles in each defined bond.

    .. math::

        V(r) = \frac{1}{2} k \left( r - r_0 \right)^2

    where :math:`\vec{r}` is the vector pointing from one particle to the other
    in the bond.

    Coefficients:

    - :math:`k` - force constant ``k`` (in units of energy/distance^2)
    - :math:`r_0` - bond rest length ``r0`` (in distance units)
    """
    _cpp_class_name = "PotentialBondHarmonic"
    def __init__(self):
        params = TypeParameter("params", "bond_types",
                               TypeParameterDict(k=float, r0=float, len_keys=1)
                               )
        self._add_typeparam(params)


class FENE(_Bond):
    R""" FENE bond potential.

    Args:
        name (str): Name of the bond instance.

    :py:class:`FENE` specifies a FENE potential energy between the two particles
    in each defined bond.

    .. math::

        V(r) = - \frac{1}{2} k r_0^2 \ln \left( 1 - \left( \frac{r -
               \Delta}{r_0} \right)^2 \right) + V_{\mathrm{WCA}}(r)

    where :math:`\vec{r}` is the vector pointing from one particle to the other
    in the bond, :math:`\Delta = (d_i + d_j)/2 - 1`, :math:`d_i` is the diameter
    of particle :math:`i`, and

    .. math::
        :nowrap:

        \begin{eqnarray*}
        V_{\mathrm{WCA}}(r)  = & 4 \varepsilon \left[ \left( \frac{\sigma}{r -
                                 \Delta} \right)^{12} - \left( \frac{\sigma}{r -
                                 \Delta} \right)^{6} \right]  + \varepsilon
                               & r-\Delta < 2^{\frac{1}{6}}\sigma\\
                             = & 0
                               & r-\Delta \ge 2^{\frac{1}{6}}\sigma
        \end{eqnarray*}

    Coefficients:

    - :math:`k` - attractive force strength ``k`` (in units of
        energy/distance^2)
    - :math:`r_0` - size parameter ``r0`` (in distance units)
    - :math:`\varepsilon` - repulsive force strength ``epsilon`` (in energy
        units)
    - :math:`\sigma` - repulsive force interaction distance ``sigma`` (in
        distance units)
    """
    _cpp_class_name = "PotentialBondFENE"

    def __init__(self):
        params = TypeParameter("params", "bond_types",
                               TypeParameterDict(k=float,
                                                 r0=float,
                                                 epsilon=float,
                                                 sigma=float,
                                                 len_keys=1)
                               )
        self._add_typeparam(params)


def _table_eval(r, rmin, rmax, V, F, width):
      dr = (rmax - rmin) / float(width-1);
      i = int(round((r - rmin)/dr))
      return (V[i], F[i])

class table(force._force):
    R""" Tabulated bond potential.

    Args:
        width (int): Number of points to use to interpolate V and F
        name (str): Name of the potential instance
<commit_msg>updated docstrings for bond forces (except table)<commit_after># Copyright (c) 2009-2019 The Regents of the University of Michigan
# This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.

# Maintainer: joaander / All Developers are free to add commands for new features

R""" Bond potentials.

Bonds add forces between specified pairs of particles and are typically used to
model chemical bonds between two particles.

By themselves, bonds that have been specified in an initial configuration do nothing. Only when you
specify an bond force (i.e. bond.harmonic), are forces actually calculated between the
listed particles.
"""

from hoomd import _hoomd
from hoomd.md import _md
from hoomd.md.force import _Force
from hoomd.md import force
from hoomd.typeparam import TypeParameter
from hoomd.parameterdicts import TypeParameterDict
import hoomd

import math


class _Bond(_Force):
    """Constructs the bond potential.

    A bond in hoomd reflects a PotentialBond in c++. It is responsible for all
    high-level management that happens behind the scenes for hoomd writers.
    1) The instance of the c++ bond force itself is tracked and added to the
    System
    2) methods are provided for disabling the force from being added to the net
    force on each particle
    """
    def attach(self, simulation):
        """Create the c++ mirror class."""
        if not simulation.device.cpp_exec_conf.isCUDAEnabled():
            cpp_cls = getattr(_md, self._cpp_class_name)
        else:
            cpp_cls = getattr(_md, self._cpp_class_name + "GPU")

        # TODO remove string argument
        self._cpp_obj = cpp_cls(simulation.state._cpp_sys_def, "")

        super().attach(simulation)


class Harmonic(_Bond):
    R""" Harmonic bond potential.

    :py:class:`Harmonic` specifies a harmonic potential energy between the two
    particles in each defined bond.

    .. math::

        V(r) = \frac{1}{2} k \left( r - r_0 \right)^2

    where :math:`\vec{r}` is the vector pointing from one particle to the other
    in the bond.

    Attributes:
        params (TypeParameter[``bond type``, dict]):
            The parameter of the harmonic bonds for each particle type. 
            The dictionary has the following keys: 

            * ``k`` (`float`, **required**) - potential constant 
              (in units of energy/distance^2)

            * ``r0`` (`float`, **required**) - rest length 
              (in units distance)

    Examples::

        harmonic = bond.Harmonic()
        harmonic.params['polymer'] = dict(k=3.0, r0=2.38)
        harmonic.params['backbone'] = dict(k=10.0, r0=1.0)
    """
    _cpp_class_name = "PotentialBondHarmonic"
    def __init__(self):
        params = TypeParameter("params", "bond_types",
                               TypeParameterDict(k=float, r0=float, len_keys=1)
                               )
        self._add_typeparam(params)


class FENE(_Bond):
    R""" FENE bond potential.

    :py:class:`FENE` specifies a FENE potential energy between the two particles
    in each defined bond.

    .. math::

        V(r) = - \frac{1}{2} k r_0^2 \ln \left( 1 - \left( \frac{r -
               \Delta}{r_0} \right)^2 \right) + V_{\mathrm{WCA}}(r)

    where :math:`\vec{r}` is the vector pointing from one particle to the other
    in the bond, :math:`\Delta = (d_i + d_j)/2 - 1`, :math:`d_i` is the diameter
    of particle :math:`i`, and

    .. math::
        :nowrap:

        \begin{eqnarray*}
        V_{\mathrm{WCA}}(r)  = & 4 \varepsilon \left[ \left( \frac{\sigma}{r -
                                 \Delta} \right)^{12} - \left( \frac{\sigma}{r -
                                 \Delta} \right)^{6} \right]  + \varepsilon
                               & r-\Delta < 2^{\frac{1}{6}}\sigma\\
                             = & 0
                               & r-\Delta \ge 2^{\frac{1}{6}}\sigma
        \end{eqnarray*}

    Attributes:
        params (TypeParameter[``bond type``, dict]):
            The parameter of the FENE potential bonds. 
            The dictionary has the following keys: 

            * ``k`` (`float`, **required**) - attractive force strength
              (in units of energy/distance^2)

            * ``r0`` (`float`, **required**) - size parameter
              (in units distance)

            * ``epsilon`` (`float`, **required**) - repulsive force strength
              (in units of energy)

            * ``sigma`` (`float`, **required**) - repulsive force interaction distance
              (in units of distance)

    Examples::

        bond_potential = bond.FENE()
        bond_potential.params['molecule'] = dict(k=3.0, r0=2.38, epsilon=1.0, sigma=1.0)
        bond_potential.params['backbone'] = dict(k=10.0, r0=1.0, epsilon=0.8, sigma=1.2)

    """
    _cpp_class_name = "PotentialBondFENE"

    def __init__(self):
        params = TypeParameter("params", "bond_types",
                               TypeParameterDict(k=float,
                                                 r0=float,
                                                 epsilon=float,
                                                 sigma=float,
                                                 len_keys=1)
                               )
        self._add_typeparam(params)


def _table_eval(r, rmin, rmax, V, F, width):
      dr = (rmax - rmin) / float(width-1);
      i = int(round((r - rmin)/dr))
      return (V[i], F[i])

class table(force._force):
    R""" Tabulated bond potential.

    Args:
        width (int): Number of points to use to interpolate V and F
        name (str): Name of the potential instance

{'fraction_non_alphanumeric': 0.11026944098187745, 'fraction_numerical': 0.011698149391120913, 'mean_word_length': 2.039044289044289, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '606425', 'n_tokens_mistral': 3077, 'n_tokens_neox': 2915, 'n_words': 994}