-
Notifications
You must be signed in to change notification settings - Fork 32
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
Dihedral class #146
Merged
Merged
Dihedral class #146
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7ceab4d
Added dihedral and dihedral_type classes. Modified topology to reflec…
uppittu11 57ac30d
Added tests for dihedrals
uppittu11 a02ab3b
fixed missing n_angle in topology.py
uppittu11 862c166
fixed dihedral test
uppittu11 d6473d9
Merge branch 'master' into dihedral_class
uppittu11 51851b2
pulled changes 5-28-19
uppittu11 03236cf
pulled and merged 5-28-2019
uppittu11 5a3d8c4
added hashing functionality to dihedral and dihedral_type class
uppittu11 550ae5b
Pulled from upstream/master
uppittu11 b748b33
updated dihedral_type.py to reflect new changes
uppittu11 4f5108a
updated dihedral.py to reflect new connection fmt
uppittu11 98c5ad3
updated topology.py for formatting consistency
uppittu11 b346aab
PEP8 -- string quotation marks
uppittu11 bb6b64f
PEP8 -- missin space
uppittu11 bb15a75
Added missing tests for dihedral class
uppittu11 6961e08
Updated init.py to include dihedral and dihedral_types
uppittu11 6a2c515
missing property decorator for subtops
uppittu11 bdca0f5
Remove commented code
mattwthompson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import warnings | ||
|
||
from topology.core.connection import Connection | ||
from topology.core.dihedral_type import DihedralType | ||
from topology.exceptions import TopologyError | ||
|
||
|
||
class Dihedral(Connection): | ||
"""A 4-partner connection between sites. | ||
|
||
Partners | ||
-------- | ||
connection_members: list of topology.Site | ||
Should be length 4 | ||
connection_type : topology.DihedralType | ||
name : name of the dihedral | ||
inherits the name attribute from Connection | ||
|
||
Notes | ||
----- | ||
Inherits some methods from Connection: | ||
__eq__, __repr__, _validate methods | ||
Addiitonal _validate methods are presented | ||
""" | ||
|
||
def __init__(self, connection_members=[], connection_type=None, name="Dihedral"): | ||
connection_members = _validate_four_partners(connection_members) | ||
connection_type = _validate_dihedraltype(connection_type) | ||
|
||
super(Dihedral, self).__init__(connection_members=connection_members, | ||
connection_type=connection_type, name=name) | ||
|
||
def __eq__(self, other): | ||
return hash(self) == hash(other) | ||
|
||
def __hash__(self): | ||
if self.connection_type: | ||
return hash( | ||
tuple( | ||
( | ||
self.name, | ||
self.connection_type, | ||
tuple(self.connection_members), | ||
) | ||
) | ||
) | ||
return hash(tuple(self.connection_members)) | ||
|
||
|
||
def _validate_four_partners(connection_members): | ||
"""Ensure 4 partners are involved in Dihedral""" | ||
if len(connection_members) != 4: | ||
raise TopologyError("Trying to create an Dihedral " | ||
"with {} connection members". format(len(connection_members))) | ||
|
||
return connection_members | ||
|
||
|
||
def _validate_dihedraltype(contype): | ||
"""Ensure connection_type is a DihedralType """ | ||
if contype is None: | ||
warnings.warn("Non-parametrized Dihedral detected") | ||
elif not isinstance(contype, DihedralType): | ||
raise TopologyError("Supplied non-DihedralType {}".format(contype)) | ||
return contype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import warnings | ||
import unyt as u | ||
|
||
from topology.core.potential import Potential | ||
from topology.exceptions import TopologyError | ||
|
||
|
||
class DihedralType(Potential): | ||
"""A Potential between 4-bonded partners. | ||
|
||
Parameters | ||
---------- | ||
name : str | ||
expression : str or sympy.Expression | ||
See `Potential` documentation for more information | ||
parameters : dict {str, unyt.unyt_quantity} | ||
See `Potential` documentation for more information | ||
independent vars : set of str | ||
See `Potential` documentation for more information | ||
member_types : list of topology.AtomType.name (str) | ||
|
||
Notes | ||
---- | ||
Inherits many functions from topology.Potential: | ||
__eq__, _validate functions | ||
""" | ||
|
||
def __init__(self, | ||
name='DihedralType', | ||
expression='k * (1 + cos(n * phi - phi_eq))**2', | ||
parameters={ | ||
'k': 1000 * u.Unit('kJ / (deg**2)'), | ||
'phi_eq': 180 * u.deg, | ||
'n': 1*u.dimensionless | ||
}, | ||
independent_variables={'phi'}, | ||
member_types=[]): | ||
|
||
super(DihedralType, self).__init__(name=name, expression=expression, | ||
parameters=parameters, independent_variables=independent_variables) | ||
|
||
self._member_types = _validate_four_member_type_names(member_types) | ||
|
||
@property | ||
def member_types(self): | ||
return self._member_types | ||
|
||
@member_types.setter | ||
def member_types(self, val): | ||
if self.member_types != val: | ||
warnings.warn("Changing an DihedralType's constituent " | ||
"member types: {} to {}".format(self.member_types, val)) | ||
self._member_types = _validate_four_member_type_names(val) | ||
|
||
def __repr__(self): | ||
return "<DihedralType {}, id {}>".format(self.name, id(self)) | ||
|
||
def _validate_four_member_type_names(types): | ||
"""Ensure 4 partners are involved in DihedralType""" | ||
if len(types) != 4 and len(types) != 0: | ||
raise TopologyError("Trying to create an DihedralType " | ||
"with {} constituent types". format(len(types))) | ||
if not all([isinstance(t, str) for t in types]): | ||
raise TopologyError("Types passed to DihedralType " | ||
"need to be strings corresponding to AtomType names") | ||
|
||
return types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is fine but a couple thoughts:
Connection
with the number of connections and the name of the subclass as arguments