Skip to content
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

Create RestCapableHybridTopologyFactory #848

Merged
merged 106 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
7f35cb3
add initial version
zhang-ivy Aug 20, 2021
d690bba
address dominic's comments and fix rest scale bug
zhang-ivy Aug 25, 2021
f7aa0fb
set alpha to 0 for NoCutofF
zhang-ivy Aug 26, 2021
b92ab02
map CBs
zhang-ivy Aug 30, 2021
ac75cb0
update with scaled water rest changes
zhang-ivy Oct 26, 2021
6a5eb7a
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Oct 26, 2021
1356d6d
change continue to pass
zhang-ivy Oct 26, 2021
c8d1ce9
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Oct 26, 2021
0c92881
fix r_cutoff
zhang-ivy Oct 26, 2021
cc984eb
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers
zhang-ivy Oct 26, 2021
3eac6df
fix bugs
zhang-ivy Oct 27, 2021
3c815e3
temp changes to allow small molecule pipeline
zhang-ivy Oct 28, 2021
b64d6be
Merge branch 'master' into rest-over-protocol
zhang-ivy Oct 28, 2021
5cce173
add more comments and fix valence problems
zhang-ivy Oct 29, 2021
9a35406
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Oct 29, 2021
917a432
fix torsions
zhang-ivy Nov 1, 2021
cd79304
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 1, 2021
aed807c
fix K_old/new
zhang-ivy Nov 1, 2021
d375f75
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 1, 2021
66bc728
don't add torsions twice
zhang-ivy Nov 1, 2021
311a46d
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 1, 2021
332fd52
fix keys and add print statements:
zhang-ivy Nov 1, 2021
23d5253
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 1, 2021
e29b254
fix keys again
zhang-ivy Nov 1, 2021
d07dbc9
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 1, 2021
2dfb005
fix torsions
zhang-ivy Nov 1, 2021
30129b3
add core/env torsions twice
zhang-ivy Nov 2, 2021
ec24d7b
fix nonbondeds
zhang-ivy Nov 2, 2021
6d507a1
speed up nonbondeds
zhang-ivy Nov 3, 2021
23f4a5e
fixes to enable speed up and simplify some other stuff
zhang-ivy Nov 3, 2021
e40187d
resolve comments from johns first reviewg
zhang-ivy Nov 3, 2021
22b2bf7
remove PME in name of class
zhang-ivy Nov 4, 2021
c35f865
change Rest to REST in class name
zhang-ivy Nov 4, 2021
01829bb
add first attempt at lambda protocol and alchemical state
zhang-ivy Nov 4, 2021
7245c08
allow lambda protocol input
zhang-ivy Nov 4, 2021
8b33645
change no_alchemy to no-alchemy
zhang-ivy Nov 4, 2021
a7c4f35
fix set parameters alch lambdas for rest at endstates
zhang-ivy Nov 8, 2021
411a9e3
fix endstate param
zhang-ivy Nov 8, 2021
3f1c875
add reciprocal space lambda
zhang-ivy Nov 9, 2021
24bed24
forgot to add reciprocal space lambda to state
zhang-ivy Nov 9, 2021
778a045
allow specificatoin of rest radius
zhang-ivy Nov 9, 2021
1415b62
fix merge conflicts
zhang-ivy Nov 9, 2021
a9c0dc4
remove need to pass residue id through top proposal
zhang-ivy Nov 9, 2021
975de12
add import
zhang-ivy Nov 9, 2021
31b11a8
fix small molecule api bug
zhang-ivy Nov 9, 2021
f3f744b
fix another small molecule api bug
zhang-ivy Nov 9, 2021
7495b82
remove small molecule api changes
zhang-ivy Nov 9, 2021
315cc1d
speed up co copy exceptions and do not set sigma to 0
zhang-ivy Nov 10, 2021
7d967c4
fix sterics expression
zhang-ivy Nov 10, 2021
d58ee36
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 10, 2021
150d0a1
change min to max
zhang-ivy Nov 10, 2021
e4b6b66
fix custom expression logic for electrostatics and exceptions
zhang-ivy Nov 10, 2021
93e38d8
add max() to exceptions sigma expression
zhang-ivy Nov 10, 2021
c7e47f9
remove remaining sigmas that are zeroed in copy_*
zhang-ivy Nov 10, 2021
a0214e0
remove zeros from _copy() functions again
zhang-ivy Nov 10, 2021
638a67b
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Nov 10, 2021
b3a643f
fix units
zhang-ivy Nov 11, 2021
5473fd1
undo typo
zhang-ivy Nov 11, 2021
266bfde
remove checks for nb params old*new != 0
zhang-ivy Nov 11, 2021
a6f0e14
remove lifting from exceptions
zhang-ivy Nov 12, 2021
48ffefd
clean up code
zhang-ivy Nov 12, 2021
a519847
take average mass for mapped atoms
zhang-ivy Nov 12, 2021
6ec66b7
fix bug 0.5 -> 0.05
zhang-ivy Nov 12, 2021
da6c5e9
remove checks
zhang-ivy Nov 15, 2021
aa24a6b
Merge branch 'master' into rest-over-protocol
zhang-ivy Nov 15, 2021
8356b55
set name of forces with duplicate names
zhang-ivy Nov 17, 2021
821dd4c
fix flags for test
zhang-ivy Nov 22, 2021
3416899
allow vanilla and rest htf generation at same time
zhang-ivy Nov 24, 2021
45ad88e
fix test_rest
zhang-ivy Nov 24, 2021
a17c102
fix test rest pt 2
zhang-ivy Nov 24, 2021
9cc7f73
add tests
zhang-ivy Nov 24, 2021
856f5a1
add minimization to all test cases
zhang-ivy Nov 24, 2021
2cb8110
remove os.chdir()
zhang-ivy Nov 25, 2021
f82c35a
load htf before md test and fix formatting
zhang-ivy Nov 25, 2021
3add6a2
Merge branch 'master' into rest-over-protocol
mikemhenry Dec 6, 2021
6ffd0a1
rework tests
zhang-ivy Dec 23, 2021
d3be4cd
first attempt at fixing endstate validation cases
zhang-ivy Jan 3, 2022
120d317
add endstate validation for each type of htf
zhang-ivy Jan 3, 2022
3a04f72
fix variable name in test
zhang-ivy Jan 3, 2022
199ba42
add step to set epsilon to 0 if negative
zhang-ivy Jan 11, 2022
84264e6
add step to set epsilon to 0 if negative
zhang-ivy Jan 11, 2022
773ccc7
finish fixes for endstate validation
zhang-ivy Jan 19, 2022
860c061
add copy import
zhang-ivy Jan 19, 2022
85cd8ca
fix bugs in endstate validation code
zhang-ivy Jan 19, 2022
e31b6e8
move nonscale interactions to NonbondedForce and update tests
zhang-ivy Jan 21, 2022
56e749f
use reference platform for generate_dipeptide_top_pos_sys
zhang-ivy Jan 21, 2022
f7539f5
use compute values feature
zhang-ivy Jan 28, 2022
05a6256
select full residues when defining rest region
zhang-ivy Mar 6, 2022
3bed2b5
add class attributes to docstring
zhang-ivy Mar 7, 2022
1bab485
fixed lifting term lambdas
zhang-ivy Mar 7, 2022
fa31ffe
update lambda protocol docstrings
zhang-ivy Mar 7, 2022
8c02029
update docstrings
zhang-ivy Mar 7, 2022
9cda693
Merge branch 'main' into rest-over-protocol
mikemhenry Mar 7, 2022
0fb1317
run slower tets only on the GPU
mikemhenry Mar 7, 2022
c19ae83
fix bug in test
zhang-ivy Mar 16, 2022
5105a5c
only use computed values if CustomNonbondedForce hasattr
zhang-ivy Mar 21, 2022
bb48999
Merge branch 'main' into rest-over-protocol
mikemhenry Mar 22, 2022
cc658d8
added import I forgot to add
mikemhenry Mar 22, 2022
e3519df
turn LRC off for scaled sterics force
zhang-ivy Mar 29, 2022
8408e55
Merge branch 'rest-over-protocol' of ssh://github.com/choderalab/pers…
zhang-ivy Mar 29, 2022
6dc6094
Merge branch 'main' into rest-over-protocol
mikemhenry Mar 29, 2022
c1ab43f
Update perses/tests/test_relative_point_mutation_setup.py
zhang-ivy Apr 12, 2022
abdaf1b
Update perses/tests/test_topology_proposal.py
zhang-ivy Apr 12, 2022
ae2a0ed
Update perses/tests/test_topology_proposal.py
zhang-ivy Apr 12, 2022
85f115f
turn LRC on for scaled sterics force to make tests pass for now
zhang-ivy Apr 12, 2022
7cae422
Merge branch 'main' into rest-over-protocol
ijpulidos Apr 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 180 additions & 1 deletion perses/annihilation/lambda_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def plot_functions(self,n=50):
plt.show()

class RESTProtocol(object):
"""
Lambda protocol to be used with perses.annihilation.rest.RESTTopologyFactory (which enables rest at the endstates only, not over the alchemical protocol)
"""
default_functions = {'solute_scale': lambda beta0, beta : beta / beta0,
'inter_scale' : lambda beta0, beta : np.sqrt(beta / beta0),
'steric_scale' : lambda beta0, beta : beta / beta0 - 1,
Expand All @@ -219,6 +222,74 @@ class RESTProtocol(object):
def __init__(self):
self.functions = RESTProtocol.default_functions

class RESTCapableLambdaProtocol(object):
"""
Lambda protocols to be used with perses.annihilation.relative.RESTCapableHybridTopologyFactory (which enables rest during the alchemical protocol).

`default_functions` - default protocol to be used for running with alchemical and rest scaling at the same time. Scales the old energies linearly from 1 to 0, the new energies linearly from 0 to 1, and the rest region linearly such that sqrt(beta / beta0) is reached half way through the protocol.

`no_alchemy_functions` - default protocol to be used for running with rest scaling at one of the endstates (no alchemy). Scales the rest region linearly such that sqrt(beta / beta0) is reached half way through the protocol. lambda_alchemical_* should be set to either 0 or 1 (see RESTCapableRelativeAlchemicalState.set_alchemical_parameters()).

"""
default_functions = {'lambda_rest_bonds': lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_rest_angles': lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_rest_torsions':lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_rest_electrostatics': lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_rest_electrostatics_exceptions': lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_rest_sterics':lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_rest_sterics_exceptions': lambda x, beta0, beta : -2 * (1 - np.sqrt(beta / beta0)) * x + 1 if x < 0.5 else 2 * (1 - np.sqrt(beta / beta0)) * x - 1 + 2 * np.sqrt(beta / beta0),
'lambda_alchemical_bonds_old': lambda x: 1 - x,
'lambda_alchemical_bonds_new': lambda x: x,
'lambda_alchemical_angles_old': lambda x: 1 - x,
'lambda_alchemical_angles_new': lambda x: x,
'lambda_alchemical_torsions_old': lambda x: 1 - x,
'lambda_alchemical_torsions_new': lambda x: x,
'lambda_alchemical_electrostatics_old': lambda x: 1 - x,
'lambda_alchemical_electrostatics_new': lambda x: x,
'lambda_alchemical_electrostatics_exceptions_old': lambda x: 1 - x,
'lambda_alchemical_electrostatics_exceptions_new': lambda x: x,
'lambda_alchemical_electrostatics_reciprocal': lambda x: x,
'lambda_alchemical_sterics_old': lambda x: 1 - x,
'lambda_alchemical_sterics_new': lambda x: x,
'lambda_alchemical_sterics_exceptions_old': lambda x: 1 - x,
'lambda_alchemical_sterics_exceptions_new': lambda x: x
}

no_alchemy_functions = {'lambda_rest_bonds': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_rest_angles': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_rest_torsions': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_rest_electrostatics': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_rest_electrostatics_exceptions': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_rest_sterics': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_rest_sterics_exceptions': lambda x, beta0, beta : (np.sqrt(beta / beta0) - 1) * x + 1,
'lambda_alchemical_bonds_old': lambda x: 1 - x,
'lambda_alchemical_bonds_new': lambda x: x,
'lambda_alchemical_angles_old': lambda x: 1 - x,
'lambda_alchemical_angles_new': lambda x: x,
'lambda_alchemical_torsions_old': lambda x: 1 - x,
'lambda_alchemical_torsions_new': lambda x: x,
'lambda_alchemical_electrostatics_old': lambda x: 1 - x,
'lambda_alchemical_electrostatics_new': lambda x: x,
'lambda_alchemical_electrostatics_exceptions_old': lambda x: 1 - x,
'lambda_alchemical_electrostatics_exceptions_new': lambda x: x,
'lambda_alchemical_electrostatics_reciprocal': lambda x: x,
'lambda_alchemical_sterics_old': lambda x: 1 - x,
'lambda_alchemical_sterics_new': lambda x: x,
'lambda_alchemical_sterics_exceptions_old': lambda x: 1 - x,
'lambda_alchemical_sterics_exceptions_new': lambda x: x
}

def __init__(self, functions='default'):
if functions == 'default':
self.functions = RESTCapableLambdaProtocol.default_functions
elif functions == 'no-alchemy':
self.functions = RESTCapableLambdaProtocol.no_alchemy_functions
else:
raise Exception("User defined lambda protocols are not yet supported")

# TODO: Do I want to subclass LambdaProtocol to get its methods?



class RelativeAlchemicalState(AlchemicalState):
"""
Expand Down Expand Up @@ -266,12 +337,15 @@ def set_alchemical_parameters(self, global_lambda,

class RESTState(AlchemicalState):
"""
REST State to handle all lambda parameters required for REST2 implementation.
AlchemicalState to handle all lambda parameters required for running REST at the endstates with
perses.annihilation.rest.RESTTopologyFactory.

Attributes
----------
solute_scale : solute scaling parameter
inter_scale : inter-region scaling parameter
electrostatic_scale : electrostatics scaling parameter
steric_scale : steric scaling parameter
"""

class _LambdaParameter(AlchemicalState._LambdaParameter):
Expand Down Expand Up @@ -302,3 +376,108 @@ def set_alchemical_parameters(self,
for parameter_name in lambda_protocol.functions:
lambda_value = lambda_protocol.functions[parameter_name](beta0, beta)
setattr(self, parameter_name, lambda_value)

class RESTCapableRelativeAlchemicalState(AlchemicalState):
zhang-ivy marked this conversation as resolved.
Show resolved Hide resolved
"""
AlchemicalState to handle all lambda parameters required for running REST during the alchemical transformation with
perses.annihilation.relative.RESTCapableHybridTopologyFactory.

Attributes
----------
lambda_rest_bonds
controls scaling of the rest region's bond energy
lambda_rest_angles
controls scaling of the rest region's angle energy
lambda_rest_torsions
controls scaling of the rest region's torsion energy
lambda_rest_electrostatics
controls scaling of the rest region's electrostatics energy
lambda_rest_electrostatics_exceptions
controls scaling of the rest region's electrostatics exceptions energy
lambda_rest_sterics
controls scaling of the rest region's sterics energy
lambda_rest_sterics_exceptions
controls scaling of the rest region's sterics exceptions energy
lambda_alchemical_bonds_old
controls alchemical scaling of the old bond energy
lambda_alchemical_bonds_new
controls alchemical scaling of the the new bond energy
lambda_alchemical_angles_old
controls alchemical scaling of the old angle energy
lambda_alchemical_angles_new
controls alchemical scaling of the new angle energy
lambda_alchemical_torsions_old
controls alchemical scaling of the old torsion energy
lambda_alchemical_torsions_new
controls alchemical scaling of the new torsion energy
lambda_alchemical_electrostatics_old
controls alchemical scaling of the old electrostatics energy
lambda_alchemical_electrostatics_new
controls alchemical scaling of the new electrostatics energy
lambda_alchemical_electrostatics_exceptions_old
controls alchemical scaling of the old electrostatics exceptions energy
lambda_alchemical_electrostatics_exceptions_new
controls alchemical scaling of the new electrostatics exceptions energy
lambda_alchemical_electrostatics_reciprocal
controls alchemical scaling of the reciprocal space energy
lambda_alchemical_sterics_old
controls alchemical scaling of the old sterics energy
lambda_alchemical_sterics_new
controls alchemical scaling of the new sterics energy
lambda_alchemical_sterics_exceptions_old
controls alchemical scaling of the old sterics exceptions energy
lambda_alchemical_sterics_exceptions_new
controls alchemical scaling of the new sterics exceptions energy
"""

class _LambdaParameter(AlchemicalState._LambdaParameter):
@staticmethod
def lambda_validator(self, instance, parameter_value):
if parameter_value is None:
return parameter_value
return float(parameter_value)

lambda_rest_bonds = _LambdaParameter('lambda_rest_bonds')
lambda_rest_angles = _LambdaParameter('lambda_rest_angles')
lambda_rest_torsions = _LambdaParameter('lambda_rest_torsions')
lambda_rest_electrostatics = _LambdaParameter('lambda_rest_electrostatics')
lambda_rest_electrostatics_exceptions = _LambdaParameter('lambda_rest_electrostatics_exceptions')
lambda_rest_sterics = _LambdaParameter('lambda_rest_sterics')
lambda_rest_sterics_exceptions = _LambdaParameter('lambda_rest_sterics_exceptions')
lambda_alchemical_bonds_old = _LambdaParameter('lambda_alchemical_bonds_old')
lambda_alchemical_bonds_new = _LambdaParameter('lambda_alchemical_bonds_new')
lambda_alchemical_angles_old = _LambdaParameter('lambda_alchemical_angles_old')
lambda_alchemical_angles_new = _LambdaParameter('lambda_alchemical_angles_new')
lambda_alchemical_torsions_old = _LambdaParameter('lambda_alchemical_torsions_old')
lambda_alchemical_torsions_new = _LambdaParameter('lambda_alchemical_torsions_new')
lambda_alchemical_electrostatics_old = _LambdaParameter('lambda_alchemical_electrostatics_old')
lambda_alchemical_electrostatics_new = _LambdaParameter('lambda_alchemical_electrostatics_new')
lambda_alchemical_electrostatics_exceptions_old = _LambdaParameter('lambda_alchemical_electrostatics_exceptions_old')
lambda_alchemical_electrostatics_exceptions_new = _LambdaParameter('lambda_alchemical_electrostatics_exceptions_new')
lambda_alchemical_electrostatics_reciprocal = _LambdaParameter('lambda_alchemical_electrostatics_reciprocal')
lambda_alchemical_sterics_old = _LambdaParameter('lambda_alchemical_sterics_old')
lambda_alchemical_sterics_new = _LambdaParameter('lambda_alchemical_sterics_new')
lambda_alchemical_sterics_exceptions_old = _LambdaParameter('lambda_alchemical_sterics_exceptions_old')
lambda_alchemical_sterics_exceptions_new = _LambdaParameter('lambda_alchemical_sterics_exceptions_new')

def set_alchemical_parameters(self, global_lambda, beta0, beta, lambda_protocol=RESTCapableLambdaProtocol(), endstate=None):
"""Set each lambda value according to the lambda_functions protocol.
The undefined parameters (i.e. those being set to None) remain
undefined.

Parameters
----------
lambda_value : float
The new value for all defined parameters.
"""
self.global_lambda = global_lambda
for parameter_name in lambda_protocol.functions:
if 'rest' in parameter_name:
lambda_value = lambda_protocol.functions[parameter_name](global_lambda, beta0, beta)
else:
if endstate is None:
lambda_value = lambda_protocol.functions[parameter_name](global_lambda)
else:
assert endstate in [0, 1], f"`endstate` should be 0 or 1, but was {endstate}"
lambda_value = lambda_protocol.functions[parameter_name](endstate)
setattr(self, parameter_name, lambda_value)
Loading