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

Add LayeredDihedral and LayeredImproper support #569

Open
wants to merge 41 commits into
base: old_main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6add25d
WIP- Add LayeredDihedral and LayeredImproper classes
umesh-timalsina Jul 13, 2021
57debcb
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Jul 13, 2021
e563d41
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Jul 16, 2021
461a509
WIP- Make existing API work after layered classes addition
umesh-timalsina Jul 16, 2021
8257f2f
Merge remote-tracking branch 'origin/561-layered-dihedrals' into 561-…
umesh-timalsina Jul 16, 2021
2cff78a
WIP- Add layered dihedral and layered improper attributes
umesh-timalsina Jul 16, 2021
6e9ad3c
WIP- fix negation in typed check predicates
umesh-timalsina Jul 16, 2021
2693f89
Add simple unit test for layered dihedrals
rsdefever Jul 16, 2021
60ec0d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 16, 2021
cfd9125
WIP- add is_layered check while updating
umesh-timalsina Jul 16, 2021
caff017
Merge remote-tracking branch 'origin/561-layered-dihedrals' into 561-…
umesh-timalsina Jul 16, 2021
39dacc3
WIP- Use indexedset for layered dihedral/improper potentials
umesh-timalsina Jul 20, 2021
baec981
WIP- Add test for layered impropers
umesh-timalsina Jul 20, 2021
5ed6b2b
Merge remote-tracking branch 'upstream/master' into 561-layered-dihed…
umesh-timalsina Jul 20, 2021
fa9eb17
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Jul 27, 2021
76fa76b
WIP- Add _get_types function in topology.py for dihedral/impropers
umesh-timalsina Jul 27, 2021
da62893
WIP- use _get_types function in is_fully_typed
umesh-timalsina Jul 27, 2021
fa751fa
WIP- Remove layered_dihedral property
umesh-timalsina Jul 27, 2021
8e987e6
WIP- Remove unused import
umesh-timalsina Jul 27, 2021
569e769
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Jul 27, 2021
5c117c1
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Jul 30, 2021
e28ba6e
WIP- fix issues with object construction; add tests
umesh-timalsina Aug 2, 2021
c5ead83
Merge remote-tracking branch 'origin/561-layered-dihedrals' into 561-…
umesh-timalsina Aug 2, 2021
9e2f7dc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 2, 2021
6cb0289
WIP- Add documentation, fix object creation errors
umesh-timalsina Aug 2, 2021
8f7106a
Merge branch 'master' into 561-layered-dihedrals
daico007 Aug 26, 2021
2dd6fee
WIP- Address PR review comments
umesh-timalsina Aug 31, 2021
2a76937
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Aug 31, 2021
21c6c73
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Sep 21, 2021
24d86c4
Merge branch 'master' into 561-layered-dihedrals
daico007 Sep 21, 2021
fc02615
WIP- Merge branch master
umesh-timalsina Sep 23, 2021
21970ac
Merge branch 'master' into 561-layered-dihedrals
daico007 Sep 27, 2021
c6c3242
Merge branch 'master' into 561-layered-dihedrals
daico007 Oct 5, 2021
802185d
Merge branch 'master' into 561-layered-dihedrals
justinGilmer Oct 8, 2021
a1338dd
Merge branch 'master' into 561-layered-dihedrals
daico007 Nov 24, 2021
99ebe68
Merge branch 'master' into 561-layered-dihedrals
umesh-timalsina Dec 10, 2021
afbd33a
Merge branch 'master' into 561-layered-dihedrals
daico007 Jan 4, 2022
580b7df
Update gmso/core/dihedral.py
umesh-timalsina Feb 24, 2022
8534186
Merge branch 'main' into 561-layered-dihedrals
daico007 May 9, 2022
6140f01
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 9, 2022
ca1afa1
Merge branch 'main' into 561-layered-dihedrals
daico007 May 10, 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
4 changes: 2 additions & 2 deletions gmso/core/dihedral.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Config:


class Dihedral(BaseDihedral):
__base_doc__ = """A 4-Partner connection between 2 sites with a single dihedral type association
__base_doc__ = """A 4-Partner connection between 4 sites with a **single** dihedral type association

Notes
-----
Expand Down Expand Up @@ -143,7 +143,7 @@ class Config:


class LayeredDihedral(BaseDihedral):
__base_doc__ = """A 4-Partner connection between 2 sites with a multiple dihedral type associations
__base_doc__ = """A 4-Partner connection between 4 sites with a **multiple** dihedral type associations
umesh-timalsina marked this conversation as resolved.
Show resolved Hide resolved

Notes
-----
Expand Down
4 changes: 2 additions & 2 deletions gmso/core/improper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class BaseImproper(Connection):
__base_doc__ = """sA 4-partner connection between sites.
__base_doc__ = """A 4-partner connection between sites.

This is a subclass of the gmso.Connection superclass.
This class has strictly 4 members in its connection_members.
Expand Down Expand Up @@ -159,7 +159,7 @@ def __setattr__(self, key, value):
super().__setattr__(key, value)

@validator("improper_types_", pre=True, always=True)
def validate_dihedral_types(cls, improper_types):
def validate_improper_types(cls, improper_types):
if not isinstance(improper_types, Iterable):
raise ValidationError("ImproperTypes should be iterable", cls)

Expand Down
22 changes: 6 additions & 16 deletions gmso/core/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,28 +600,18 @@ def update_connection_types(self):
c.connection_type = self._angle_types[connection_type]
if isinstance(connection_type, DihedralType):
if c.is_layered():
if c.connection_types is None:
c.connection_types = IndexedSet(
[self._dihedrals_types[connection_type]]
)
else:
c.connection_types.add(
self._dihedral_types[connection_type]
)
c.connection_types.add(
self._dihedral_types[connection_type]
)
else:
c.connection_type = self._dihedral_types[
connection_type
]
if isinstance(connection_type, ImproperType):
if c.is_layered():
if c.connection_types is None:
c.connection_types = IndexedSet(
[self._improper_types[connection_type]]
)
else:
c.connection_types.add(
self._improper_types[connection_type]
)
c.connection_types.add(
self._improper_types[connection_type]
)
else:
c.connection_type = self._improper_types[
connection_type
Expand Down
17 changes: 16 additions & 1 deletion gmso/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,20 @@ def pairpotentialtype_top(self):
top.add_pairpotentialtype(pptype12)
return top

@pytest.fixture(scope="session")
def residue_top(self):
top = Topology()
for i in range(1, 26):
atom = Atom(
name=f"atom_{i + 1}",
residue_number=i % 5,
residue_name="MY_RES_EVEN" if i % 2 == 0 else f"MY_RES_ODD",
)
top.add_site(atom, update_types=False)
top.update_topology()

return top

@pytest.fixture
def ld_top(self):
lib = PotentialTemplateLibrary()
Expand All @@ -512,7 +526,7 @@ def ld_top(self):
)

top = Topology(name="Topology")
atoms = [Atom(name=f"Atom{i+1}") for i in range(0, 100)]
atoms = [Atom(name=f"Atom{i + 1}") for i in range(0, 100)]
dihedrals_group = [
(atoms[i], atoms[i + 1], atoms[i + 2], atoms[i + 3])
for i in range(0, 100, 4)
Expand All @@ -530,4 +544,5 @@ def ld_top(self):
dh.connection_types = [rb_type, periodic_type]
top.add_connection(connection=dh)
top.update_topology()

return top
30 changes: 30 additions & 0 deletions gmso/tests/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,33 @@ def test_top_with_layered_dihedrals(self, ld_top):
assert isinstance(ld_top._dihedrals[j], Dihedral)
else:
assert isinstance(ld_top._dihedrals[j], LayeredDihedral)

def test_iter_sites(self, residue_top):
for site in residue_top.iter_sites("residue_name", "MY_RES_EVEN"):
assert site.residue_name == "MY_RES_EVEN"

for site in residue_top.iter_sites("residue_name", "MY_RES_ODD"):
assert site.residue_name == "MY_RES_ODD"

sites = list(residue_top.iter_sites("residue_number", 4))
assert len(sites) == 5

def test_iter_sites_non_iterable_attribute(self, residue_top):
with pytest.raises(ValueError):
for site in residue_top.iter_sites("atom_type", "abc"):
pass

def test_iter_sites_none(self, residue_top):
with pytest.raises(ValueError):
for site in residue_top.iter_sites("residue_name", None):
pass

def test_iter_sites_by_residue_name(self, pairpotentialtype_top):
assert (
len(list(pairpotentialtype_top.iter_sites_by_residue_name("AAA")))
== 0
)

def test_iter_sites_by_residue_number(self, residue_top):
sites = list(residue_top.iter_sites_by_residue_number(4))
assert len(sites) == 5