Skip to content

Commit

Permalink
Merge branch 'main' into centroid-function-with-named-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlles Abreu committed Dec 8, 2023
2 parents 7223d49 + 139763d commit c64161f
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 220 deletions.
60 changes: 31 additions & 29 deletions cvpack/atomic_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,44 @@ class AtomicFunction(openmm.CustomCompoundBondForce, AbstractCollectiveVariable)
{\\bf r}_{i,1}, {\\bf r}_{i,2}, \\dots, {\\bf r}_{i,n}
\\right)
where :math:`F` is a user-defined function and :math:`{\\bf r}_{i,j}` is the position of the
:math:`j`-th atom of the :math:`i`-th group.
where :math:`F` is a user-defined function and :math:`{\\bf r}_{i,j}` is the
position of the :math:`j`-th atom of the :math:`i`-th group.
The function :math:`F` is defined as a string and can be any expression supported by
:OpenMM:`CustomCompoundBondForce`. If it contains named parameters, they must be passed as
keyword arguments to the :class:`AtomicFunction` constructor. The parameters can be scalars
or arrays of length :math:`m`. In the latter case, each value will be assigned to the
corresponding group of atoms.
:OpenMM:`CustomCompoundBondForce`. If it contains named parameters, they must be
passed as keyword arguments to the :class:`AtomicFunction` constructor. The
parameters can be scalars or arrays of length :math:`m`. In the latter case, each
value will be assigned to the corresponding group of atoms.
Parameters
----------
atomsPerGroup
The number of atoms in each group
function
The function to be evaluated. It must be a valid :OpenMM:`CustomCompoundBondForce`
expression
The function to be evaluated. It must be a valid
:OpenMM:`CustomCompoundBondForce` expression
atoms
The indices of the atoms in each group, passed as a 2D array-like object of shape
`(m, n)`, where `m` is the number of groups and `n` is the number of atoms per group,
or as a 1D array-like object of length `m*n`, where the first `n` elements are the
indices of the atoms in the first group, the next `n` elements are the indices of the
atoms in the second group, and so on.
The indices of the atoms in each group, passed as a 2D array-like object of
shape `(m, n)`, where `m` is the number of groups and `n` is the number of
atoms per group, or as a 1D array-like object of length `m*n`, where the
first `n` elements are the indices of the atoms in the first group, the next
`n` elements are the indices of the atoms in the second group, and so on.
unit
The unit of measurement of the collective variable. It must be compatible with the
MD unit system (mass in `daltons`, distance in `nanometers`, time in `picoseconds`,
temperature in `kelvin`, energy in `kilojoules_per_mol`, angle in `radians`). If the
collective variables does not have a unit, use `unit.dimensionless`
The unit of measurement of the collective variable. It must be compatible
with the MD unit system (mass in `daltons`, distance in `nanometers`, time
in `picoseconds`, temperature in `kelvin`, energy in `kilojoules_per_mol`,
angle in `radians`). If the collective variables does not have a unit, use
`unit.dimensionless`
pbc
Whether to use periodic boundary conditions
Keyword Args
------------
**parameters
The named parameters of the function. Each parameter can be specified as single
value for all groups of atoms, or as a sequence of values, one for each group.
In the latter case, the length of the sequence must be equal to `m` (see the
`atoms` argument description). If the specified values have units, they will be
converted to the MD unit system.
The named parameters of the function. Each parameter can be a scalar
quantity or a 1D array-like object of length `m`, where `m` is the number of
groups. In the latter case, each entry of the array is used for the
corresponding group of atoms.
Raises
------
Expand Down Expand Up @@ -198,9 +198,10 @@ def _fromCustomForce(
if isinstance(force, openmm.CustomCompoundBondForce):
indices, per_item_parameters = force.getBondParameters(i)
else:
*indices, per_item_parameters = getattr(force, f"get{item}Parameters")(
i
)
*indices, per_item_parameters = getattr(
force,
f"get{item}Parameters",
)(i)
atoms.append(indices)
for name, value in zip(per_item_parameter_names, per_item_parameters):
parameters[name].append(value)
Expand Down Expand Up @@ -285,10 +286,11 @@ def fromOpenMMForce(
force
The force to be converted
unit
The unit of measurement of the collective variable. It must be compatible with the
MD unit system (mass in `daltons`, distance in `nanometers`, time in `picoseconds`,
temperature in `kelvin`, energy in `kilojoules_per_mol`, angle in `radians`). If
the collective variables does not have a unit, use `unit.dimensionless`
The unit of measurement of the collective variable. It must be
compatible with the MD unit system (mass in `daltons`, distance in
`nanometers`, time in `picoseconds`, temperature in `kelvin`, energy in
`kilojoules_per_mol`, angle in `radians`). If the collective variables
does not have a unit, use `unit.dimensionless`
pbc
Whether to use periodic boundary conditions
Expand Down
62 changes: 34 additions & 28 deletions cvpack/attraction_strength.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,54 @@ class AttractionStrength(openmm.CustomNonbondedForce, AbstractCollectiveVariable
.. math::
S_{\\rm attr}({\\bf r}) =
&-\\sum_{i \\in {\\bf g}_1} \\sum_{\\substack{j \\in {\\bf g}_2 \\\\ j \\neq i}}
\\epsilon_{ij} u_{\\rm disp}\\left(
\\frac{\\|{\\bf r}_i - {\\bf r}_j\\|}{\\sigma_{ij}}
\\right) \\\\
&-\\sum_{i \\in {\\bf g}_1} \\sum_{\\substack{j \\in {\\bf g}_2 \\\\ q_jq_i < 0}}
\\frac{q_i q_j}{4 \\pi \\varepsilon_0 r_{\\rm c}} u_{\\rm elec}\\left(
\\frac{\\|{\\bf r}_i - {\\bf r}_j\\|}{r_{\\rm c}}
\\right)
where :math:`{\\bf g}_1` and :math:`{\\bf g}_2` are the two atom groups, :math:`r_{\\rm c}`
is the cutoff distance, :math:`\\varepsilon_0` is the permittivity of empty space, and
:math:`q_i` is the charge of atom :math:`i`. The Lennard-Jones parameters are given by the
Lorentz-Berthelot mixing rule, i.e. :math:`\\epsilon_{ij} = \\sqrt{\\epsilon_i \\epsilon_j}`,
and :math:`\\sigma_{ij} = (\\sigma_i + \\sigma_j)/2`.
The function :math:`u_{\\rm disp}(x)` is a Lennard-Jones-like reduced potential with a
highly softened repulsion part, defined as
&-\\sum_{i \\in {\\bf g}_1}
\\sum_{\\substack{j \\in {\\bf g}_2 \\\\ j \\neq i}}
\\epsilon_{ij} u_{\\rm disp}\\left(
\\frac{\\|{\\bf r}_i - {\\bf r}_j\\|}{\\sigma_{ij}}
\\right) \\\\
&-\\sum_{i \\in {\\bf g}_1}
\\sum_{\\substack{j \\in {\\bf g}_2 \\\\ q_jq_i < 0}}
\\frac{q_i q_j}{4 \\pi \\varepsilon_0 r_{\\rm c}} u_{\\rm elec}\\left(
\\frac{\\|{\\bf r}_i - {\\bf r}_j\\|}{r_{\\rm c}}
\\right)
where :math:`{\\bf g}_1` and :math:`{\\bf g}_2` are the two atom groups,
:math:`r_{\\rm c}` is the cutoff distance, :math:`\\varepsilon_0` is the
permittivity of empty space, and :math:`q_i` is the charge of atom :math:`i`. The
Lennard-Jones parameters are given by the Lorentz-Berthelot mixing rule, i.e.
:math:`\\epsilon_{ij} = \\sqrt{\\epsilon_i \\epsilon_j}`, and
:math:`\\sigma_{ij} = (\\sigma_i + \\sigma_j)/2`.
The function :math:`u_{\\rm disp}(x)` is a Lennard-Jones-like reduced potential with
a highly softened repulsion part, defined as
.. math::
u_{\\rm disp}(x) = 4\\left(\\frac{1}{y^2} - \\frac{1}{y}\\right),
\\quad \\text{where} \\quad
y = |x^6 - 2| + 2
The function :math:`u_{\\rm elec}(x)` provides a Coulomb-like decay with reaction-field
screening, defined as
The function :math:`u_{\\rm elec}(x)` provides a Coulomb-like decay with
reaction-field screening, defined as
.. math::
u_{\\rm elec}(x) = \\frac{1}{x} + \\frac{x^2 - 3}{2}
The screening considers a perfect conductor as the surrounding medium :cite:`Correa_2022`.
The screening considers a perfect conductor as the surrounding medium
:cite:`Correa_2022`.
.. note::
Only attractive electrostatic interactions are considered (:math:`q_i q_i < 0`). This makes
:math:`S_{\\rm attr}({\\bf r})` exclusively non-negative. Its upper bound depends on the
system and the chosen groups of atoms.
Only attractive electrostatic interactions are considered (:math:`q_i q_i < 0`).
This makes :math:`S_{\\rm attr}({\\bf r})` exclusively non-negative. Its upper
bound depends on the system and the chosen groups of atoms.
The Lennard-Jones parameters, atomic charges, cutoff distance, boundary conditions, as well as
whether to use a switching function and its corresponding switching distance, are taken from
:openmm:`NonbondedForce` object. Any non-exclusion exceptions involving atoms in
:math:`{\\bf g}_1` and :math:`{\\bf g}_2` are turned into exclusions.
The Lennard-Jones parameters, atomic charges, cutoff distance, boundary conditions,
as well as whether to use a switching function and its corresponding switching
distance, are taken from :openmm:`NonbondedForce` object. Any non-exclusion
exceptions involving atoms in :math:`{\\bf g}_1` and :math:`{\\bf g}_2` are turned
into exclusions.
Parameters
----------
Expand All @@ -83,7 +88,8 @@ class AttractionStrength(openmm.CustomNonbondedForce, AbstractCollectiveVariable
group2
The second atom group.
nonbondedForce
The :openmm:`NonbondedForce` object from which to collect the necessary parameters.
The :openmm:`NonbondedForce` object from which to collect the necessary
parameters.
Examples
--------
Expand Down
34 changes: 18 additions & 16 deletions cvpack/centroid_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,42 @@ class CentroidFunction(openmm.CustomCentroidBondForce, AbstractCollectiveVariabl
f({\\bf r}) = F({\\bf R}_1, {\\bf R}_2, \\dots, {\\bf R}_n)
where :math:`F` is a user-defined function and :math:`{\\bf R}_i` is the centroid of the
:math:`i`-th group of atoms. The function :math:`F` is defined as a string and can be any valid
:OpenMM:`CustomCentroidBondForce` expression.
where :math:`F` is a user-defined function and :math:`{\\bf R}_i` is the centroid of
the :math:`i`-th group of atoms. The function :math:`F` is defined as a string and
can be any valid :OpenMM:`CustomCentroidBondForce` expression.
The centroid of a group of atoms is defined as:
.. math::
{\\bf R}_i({\\bf r}) = \\frac{1}{n_i} \\sum_{j=1}^{n_i} {\\bf r}_{j, i}
where :math:`n_i` is the number of atoms in group :math:`i` and :math:`{\\bf r}_{j, i}` is the
position of the :math:`j`-th atom in group :math:`i`. Optionally, the centroid can be weighted
by the mass of each atom in the group. In this case, it is defined as:
where :math:`n_i` is the number of atoms in group :math:`i` and
:math:`{\\bf r}_{j, i}` is the position of the :math:`j`-th atom in group :math:`i`.
Optionally, the centroid can be weighted by the mass of each atom in the group. In
this case, it is defined as:
.. math::
{\\bf R}_i({\\bf r}) = \\frac{1}{M_i} \\sum_{j=1}^{n_i} m_{j, i} {\\bf r}_{j, i}
where :math:`M_i` is the total mass of group :math:`i` and :math:`m_{j, i}` is the mass of the
:math:`j`-th atom in group :math:`i`.
where :math:`M_i` is the total mass of group :math:`i` and :math:`m_{j, i}` is the
mass of the :math:`j`-th atom in group :math:`i`.
Parameters
----------
function
The function to be evaluated. It must be a valid :OpenMM:`CustomCentroidBondForce`
expression
The function to be evaluated. It must be a valid
:OpenMM:`CustomCentroidBondForce` expression
groups
The groups of atoms to be used in the function. Each group must be a list of atom
indices
The groups of atoms to be used in the function. Each group must be a list of
atom indices
unit
The unit of measurement of the collective variable. It must be compatible with the
MD unit system (mass in `daltons`, distance in `nanometers`, time in `picoseconds`,
temperature in `kelvin`, energy in `kilojoules_per_mol`, angle in `radians`). If
the collective variables does not have a unit, use `dimensionless`
The unit of measurement of the collective variable. It must be compatible
with the MD unit system (mass in `daltons`, distance in `nanometers`, time
in `picoseconds`, temperature in `kelvin`, energy in `kilojoules_per_mol`,
angle in `radians`). If the collective variables does not have a unit, use
`dimensionless`
pbc
Whether to use periodic boundary conditions
weighByMass
Expand Down
Loading

0 comments on commit c64161f

Please sign in to comment.