-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GlobalParameterState and changes for multi-restraint calculations #363
Changes from 14 commits
41a3145
e68add2
37fd7da
a440ea2
2377556
d20d7b3
84b3d85
e7c825c
1c575a0
004bbb9
694f66d
32ed63a
b0f219e
1046305
8ed7277
e803f50
05f1bdc
fdc41d5
8726101
e36b593
66d86c6
3c7ba04
7686d1f
77c6ac8
24841a0
aa3d00f
f8d6ed8
b96e28f
5c6a0aa
c548fbf
b64c7c5
e0afad7
bf6e799
8e14077
f28b16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,14 +254,22 @@ class RadiallySymmetricRestraintForce(utils.RestorableOpenMMObject): | |
The indices of the first group of atoms to restrain. | ||
restrained_atom_indices2 : iterable of int | ||
The indices of the second group of atoms to restrain. | ||
controlling_parameter_name : str | ||
The name of the global parameter controlling the energy function. | ||
*args, **kwargs | ||
Parameters to pass to the super constructor. | ||
|
||
Attributes | ||
---------- | ||
controlling_parameter_name | ||
|
||
""" | ||
|
||
def __init__(self, restraint_parameters, restrained_atom_indices1, | ||
restrained_atom_indices2, *args, **kwargs): | ||
restrained_atom_indices2, controlling_parameter_name, | ||
*args, **kwargs): | ||
super(RadiallySymmetricRestraintForce, self).__init__(*args, **kwargs) | ||
self._controlling_parameter_name = controlling_parameter_name | ||
|
||
# Unzip bond parameters names and values from dict. | ||
assert len(restraint_parameters) == 1 or isinstance(restraint_parameters, collections.OrderedDict) | ||
|
@@ -271,7 +279,7 @@ def __init__(self, restraint_parameters, restrained_atom_indices1, | |
self._create_bond(parameter_values, restrained_atom_indices1, restrained_atom_indices2) | ||
|
||
# Add parameters. | ||
self.addGlobalParameter('lambda_restraints', 1.0) | ||
self.addGlobalParameter(self._controlling_parameter_name, 1.0) | ||
for parameter in parameter_names: | ||
self.addPerBondParameter(parameter) | ||
|
||
|
@@ -318,6 +326,11 @@ def restraint_parameters(self): | |
for parameter_idx, parameter_value in enumerate(parameter_values)] | ||
return collections.OrderedDict(restraint_parameters) | ||
|
||
@property | ||
def controlling_parameter_name(self): | ||
"""str: The name of the global parameter controlling the energy function (read-only).""" | ||
return self._controlling_parameter_name | ||
|
||
def distance_at_energy(self, potential_energy): | ||
"""Compute the distance at which the potential energy is ``potential_energy``. | ||
|
||
|
@@ -650,16 +663,17 @@ class RadiallySymmetricCentroidRestraintForce(RadiallySymmetricRestraintForce, | |
|
||
The restraint is applied between the centers of mass of two groups | ||
of atoms. The restraint strength is controlled by a global context | ||
parameter called 'lambda_restraints'. | ||
parameter whose name is passed on construction through the optional | ||
argument ``controlling_parameter_name``. | ||
|
||
With OpenCL, only on 64bit platforms are supported. | ||
|
||
Parameters | ||
---------- | ||
energy_function : str | ||
The energy function to pass to ``CustomCentroidBondForce``. The | ||
global parameter 'lambda_restraint' will be prepended to this | ||
expression. | ||
name of the controlling global parameter will be prepended to | ||
this expression. | ||
restraint_parameters : OrderedDict | ||
An ordered dictionary containing the bond parameters in the form | ||
parameter_name: parameter_value. The order is important to make | ||
|
@@ -669,23 +683,28 @@ class RadiallySymmetricCentroidRestraintForce(RadiallySymmetricRestraintForce, | |
The indices of the first group of atoms to restrain. | ||
restrained_atom_indices2 : iterable of int | ||
The indices of the second group of atoms to restrain. | ||
controlling_parameter_name : str, optional | ||
The name of the global parameter controlling the energy function. | ||
The default value is 'lambda_restraints'. | ||
|
||
Attributes | ||
---------- | ||
restraint_parameters | ||
restrained_atom_indices1 | ||
restrained_atom_indices2 | ||
controlling_parameter_name | ||
|
||
""" | ||
|
||
def __init__(self, energy_function, restraint_parameters, | ||
restrained_atom_indices1, restrained_atom_indices2): | ||
restrained_atom_indices1, restrained_atom_indices2, | ||
controlling_parameter_name='lambda_restraints'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, see, here in this subclass, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sounds good! I'll move the default to the base class and use kwargs here. I'll have to keep it buried in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah... I forgot about that. Might be best to leave it then and it can be removed in 0.17 when we drop Py2 officially There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I just rememberd why I did this. It's because I need to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also a good point |
||
# Initialize CustomCentroidBondForce. | ||
energy_function = 'lambda_restraints * ' + energy_function | ||
energy_function = controlling_parameter_name + ' * ' + energy_function | ||
custom_centroid_bond_force_args = [2, energy_function] | ||
super(RadiallySymmetricCentroidRestraintForce, self).__init__( | ||
restraint_parameters, restrained_atom_indices1, restrained_atom_indices2, | ||
*custom_centroid_bond_force_args) | ||
controlling_parameter_name, *custom_centroid_bond_force_args) | ||
|
||
@property | ||
def restrained_atom_indices1(self): | ||
|
@@ -726,12 +745,14 @@ class RadiallySymmetricBondRestraintForce(RadiallySymmetricRestraintForce, | |
""" | ||
|
||
def __init__(self, energy_function, restraint_parameters, | ||
restrained_atom_index1, restrained_atom_index2): | ||
restrained_atom_index1, restrained_atom_index2, | ||
controlling_parameter_name='lambda_restraints'): | ||
# Initialize CustomBondForce. | ||
energy_function = energy_function.replace('distance(g1,g2)', 'r') | ||
energy_function = 'lambda_restraints * ' + energy_function | ||
super(RadiallySymmetricBondRestraintForce, self).__init__(restraint_parameters, | ||
[restrained_atom_index1], [restrained_atom_index2], energy_function) | ||
energy_function = controlling_parameter_name + ' * ' + energy_function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I just noticed a potential bug here. If the user passes in an e.g. >>> energy_function = '(K/2)*r^2 + 5*r'
>>> controlling_parameter_name = 'X`
>>> controlling_parameter_name + ' * ' + energy_function
X * (K/2)*r^2 + 5*r the Easy fix is just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Will change it. |
||
super(RadiallySymmetricBondRestraintForce, self).__init__( | ||
restraint_parameters, [restrained_atom_index1], [restrained_atom_index2], | ||
controlling_parameter_name, energy_function) | ||
|
||
# ------------------------------------------------------------------------- | ||
# Public properties. | ||
|
@@ -832,12 +853,11 @@ class HarmonicRestraintForce(HarmonicRestraintForceMixIn, | |
|
||
The energy expression of the restraint is given by | ||
|
||
``E = lambda_restraints * (K/2)*r^2`` | ||
``E = controlling_parameter * (K/2)*r^2`` | ||
|
||
where `K` is the spring constant, `r` is the distance between the | ||
two group centroids, and `lambda_restraints` is a scale factor that | ||
can be used to control the strength of the restraint. You can control | ||
``lambda_restraints`` through :class:`RestraintState` class. | ||
two group centroids, and `controlling_parameter` is a scale factor that | ||
can be used to control the strength of the restraint. | ||
|
||
With OpenCL, only on 64bit platforms are supported. | ||
|
||
|
@@ -850,13 +870,17 @@ class HarmonicRestraintForce(HarmonicRestraintForceMixIn, | |
The indices of the first group of atoms to restrain. | ||
restrained_atom_indices2 : iterable of int | ||
The indices of the second group of atoms to restrain. | ||
controlling_parameter_name : str, optional | ||
The name of the global parameter controlling the energy function. | ||
The default value is 'lambda_restraints'. | ||
|
||
Attributes | ||
---------- | ||
spring_constant | ||
restrained_atom_indices1 | ||
restrained_atom_indices2 | ||
restraint_parameters | ||
controlling_parameter_name | ||
|
||
""" | ||
# All the methods are provided by the mix-ins. | ||
|
@@ -879,13 +903,17 @@ class HarmonicRestraintBondForce(HarmonicRestraintForceMixIn, | |
The index of the first atom to restrain. | ||
restrained_atom_index2 : int | ||
The index of the second atom to restrain. | ||
controlling_parameter_name : str, optional | ||
The name of the global parameter controlling the energy function. | ||
The default value is 'lambda_restraints'. | ||
|
||
Attributes | ||
---------- | ||
spring_constant | ||
restrained_atom_indices1 | ||
restrained_atom_indices2 | ||
restraint_parameters | ||
controlling_parameter_name | ||
|
||
""" | ||
# All the methods are provided by the mix-ins. | ||
|
@@ -986,14 +1014,13 @@ class FlatBottomRestraintForce(FlatBottomRestraintForceMixIn, | |
|
||
More precisely, the energy expression of the restraint is given by | ||
|
||
``E = lambda_restraints * step(r-r0) * (K/2)*(r-r0)^2`` | ||
``E = controlling_parameter * step(r-r0) * (K/2)*(r-r0)^2`` | ||
|
||
where ``K`` is the spring constant, ``r`` is the distance between the | ||
restrained atoms, ``r0`` is another parameter defining the distance | ||
at which the restraint is imposed, and ``lambda_restraints`` | ||
at which the restraint is imposed, and ``controlling_parameter`` | ||
is a scale factor that can be used to control the strength of the | ||
restraint. You can control ``lambda_restraints`` through the class | ||
:class:`RestraintState`. | ||
restraint. | ||
|
||
With OpenCL, only on 64bit platforms are supported. | ||
|
||
|
@@ -1009,6 +1036,9 @@ class FlatBottomRestraintForce(FlatBottomRestraintForceMixIn, | |
The indices of the first group of atoms to restrain. | ||
restrained_atom_indices2 : iterable of int | ||
The indices of the second group of atoms to restrain. | ||
controlling_parameter_name : str, optional | ||
The name of the global parameter controlling the energy function. | ||
The default value is 'lambda_restraints'. | ||
|
||
Attributes | ||
---------- | ||
|
@@ -1017,6 +1047,7 @@ class FlatBottomRestraintForce(FlatBottomRestraintForceMixIn, | |
restrained_atom_indices1 | ||
restrained_atom_indices2 | ||
restraint_parameters | ||
controlling_parameter_name | ||
|
||
""" | ||
# All the methods are provided by the mix-ins. | ||
|
@@ -1042,6 +1073,9 @@ class FlatBottomRestraintBondForce(FlatBottomRestraintForceMixIn, | |
The index of the first group of atoms to restrain. | ||
restrained_atom_index2 : int | ||
The index of the second group of atoms to restrain. | ||
controlling_parameter_name : str, optional | ||
The name of the global parameter controlling the energy function. | ||
The default value is 'lambda_restraints'. | ||
|
||
Attributes | ||
---------- | ||
|
@@ -1050,6 +1084,7 @@ class FlatBottomRestraintBondForce(FlatBottomRestraintForceMixIn, | |
restrained_atom_indices1 | ||
restrained_atom_indices2 | ||
restraint_parameters | ||
controlling_parameter_name | ||
|
||
""" | ||
# All the methods are provided by the mix-ins. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make
controlling_parameter_name
have a default? E.g.controlling_parameter_name = 'lambda_restraints'
? Or would we instead just wantcontrolling_parameter_name = 'restraints'
and thelambda_
prefix is assumed prepended?