-
Notifications
You must be signed in to change notification settings - Fork 37
Bonds and Angles handle wildcards for bonds and sites. #928
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
Changes from 5 commits
99933ab
7128362
d8da81e
272fb39
e5bb131
0d62054
dcf82b3
6d80bba
63c09e9
d7df8de
3aef84c
1f5c393
b6ba7bd
ef08138
4e9836b
5c6f7bc
a41cbe6
956809c
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 |
|---|---|---|
|
|
@@ -2,11 +2,12 @@ | |
|
|
||
| from typing import Callable, ClassVar, Optional, Tuple | ||
|
|
||
| from pydantic import ConfigDict, Field | ||
| from pydantic import ConfigDict, Field, model_validator | ||
|
|
||
| from gmso.abc.abstract_connection import Connection | ||
| from gmso.core.angle_type import AngleType | ||
| from gmso.core.atom import Atom | ||
| from gmso.core.bond import Bond | ||
|
|
||
|
|
||
| class Angle(Connection): | ||
|
|
@@ -26,12 +27,24 @@ class Angle(Connection): | |
|
|
||
| __members_creator__: ClassVar[Callable] = Atom.model_validate | ||
|
|
||
| connectivity: ClassVar[Tuple[Tuple[int]]] = ((0, 1), (1, 2)) | ||
|
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. We should add a description here. 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, do we need an alias? 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. I specified connectivity as a ClassVar, so it's not modifiable across classes, and doesn't get treated the same way as other pydantic variables, which are defined under with pydantic Field. 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 also no alias here. |
||
|
|
||
| connection_members_: Tuple[Atom, Atom, Atom] = Field( | ||
| ..., | ||
| description="The 3 atoms involved in the angle.", | ||
| alias="connection_members", | ||
| ) | ||
|
|
||
| bonds_: Tuple[Bond, Bond] = Field( | ||
| default=None, | ||
| description=""" | ||
| List of connection bonds. | ||
| Ordered to align with connection_members, such that self.bonds_[0] is | ||
| the bond between (self.connection_members[0], self.connection_members[1]). | ||
| """, | ||
| alias="bonds", | ||
| ) | ||
|
|
||
| angle_type_: Optional[AngleType] = Field( | ||
| default=None, | ||
| description="AngleType of this angle.", | ||
|
|
@@ -48,6 +61,7 @@ class Angle(Connection): | |
| """, | ||
| alias="restraint", | ||
| ) | ||
|
|
||
| model_config = ConfigDict( | ||
| alias_to_fields=dict( | ||
| **Connection.model_config["alias_to_fields"], | ||
|
|
@@ -73,6 +87,24 @@ def restraint(self): | |
| """Return the restraint of this angle.""" | ||
| return self.__dict__.get("restraint_") | ||
|
|
||
| @property | ||
| def bonds(self): | ||
| """Return the bond_order symbol of this bond.""" | ||
CalCraven marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return self.__dict__.get("bonds_") | ||
|
|
||
| @bonds.setter | ||
| def bonds(self, bonds): | ||
| """Return the bonds that makeup this Improper. | ||
CalCraven marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Connectivity is ((0,1), (0,2), (0,3)) | ||
| """ | ||
| self._bonds = bonds | ||
|
|
||
| @property | ||
| def bonds_orders(self): | ||
| """Return the bond_order strings of this angle.""" | ||
| return "".join([str(b.bond_order) for b in self.bonds]) | ||
|
|
||
| def equivalent_members(self): | ||
| """Return a set of the equivalent connection member tuples. | ||
|
|
||
|
|
@@ -99,3 +131,14 @@ def __setattr__(self, key, value): | |
| super(Angle, self).__setattr__("angle_type", value) | ||
| else: | ||
| super(Angle, self).__setattr__(key, value) | ||
|
|
||
| @model_validator(mode="before") | ||
| @classmethod | ||
| def set_dependent_value_default(cls, data): | ||
CalCraven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if "bonds" not in data and "connection_members" in data: | ||
| atoms = data["connection_members"] | ||
| data["bonds"] = ( | ||
| Bond(connection_members=(atoms[0], atoms[1])), | ||
| Bond(connection_members=(atoms[1], atoms[2])), | ||
| ) | ||
| return data | ||
|
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. We should probably have a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ class Bond(Connection): | |
|
|
||
| __members_creator__: ClassVar[Callable] = Atom.model_validate | ||
|
|
||
| connectivity: ClassVar[Tuple[Tuple[int]]] = ((0, 1),) | ||
|
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. Same as 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. See above. |
||
|
|
||
| connection_members_: Tuple[Atom, Atom] = Field( | ||
| ..., | ||
| description="The 2 atoms involved in the bond.", | ||
|
|
@@ -46,12 +48,20 @@ class Bond(Connection): | |
| """, | ||
| alias="restraint", | ||
| ) | ||
|
|
||
| bond_order_: Optional[float] = Field( | ||
| default=None, | ||
| description="Bond order of this bond.", | ||
| alias="bond_order", | ||
| ) | ||
|
|
||
| model_config = ConfigDict( | ||
| alias_to_fields=dict( | ||
| **Connection.model_config["alias_to_fields"], | ||
| **{ | ||
| "bond_type": "bond_type_", | ||
| "restraint": "restraint_", | ||
| "bond_order": "bond_order_", | ||
| }, | ||
| ) | ||
| ) | ||
|
|
@@ -71,6 +81,11 @@ def restraint(self): | |
| """Return the restraint of this bond.""" | ||
| return self.__dict__.get("restraint_") | ||
|
|
||
| @property | ||
| def bond_order(self): | ||
| """Return the bond_order of this bond.""" | ||
| return self.__dict__.get("bond_order_") | ||
|
|
||
| def equivalent_members(self): | ||
| """Get a set of the equivalent connection member tuples. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.