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

Expanded search for improper_types #665

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions gmso/core/forcefield.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for working with GMSO forcefields."""
import itertools
import warnings
from collections import ChainMap
from typing import Iterable
Expand Down Expand Up @@ -409,14 +410,18 @@ def _get_improper_type(self, atom_types, warn=False):
)

forward = FF_TOKENS_SEPARATOR.join(atom_types)
reverse = FF_TOKENS_SEPARATOR.join(
[atom_types[0], atom_types[2], atom_types[1], atom_types[3]]
)
equivalent = [
FF_TOKENS_SEPARATOR.join(
[atom_types[0], atom_types[i], atom_types[j], atom_types[k]]
)
for (i, j, k) in itertools.permutations((1, 2, 3), 3)
]

if forward in self.improper_types:
return self.improper_types[forward]
if reverse in self.improper_types:
return self.improper_types[reverse]
for eq in equivalent:
if eq in self.improper_types:
return self.improper_types[eq]

match = None
for i in range(1, 5):
Expand Down
17 changes: 17 additions & 0 deletions gmso/tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sympy import sympify

from gmso.core.forcefield import ForceField
from gmso.core.improper_type import ImproperType
from gmso.exceptions import (
ForceFieldParseError,
MissingAtomTypesError,
Expand Down Expand Up @@ -596,3 +597,19 @@ def test_non_element_types(self, non_element_ff, opls_ethane_foyer):
).definition
== "[_CH2;X2]([_CH3,_CH2])[_CH3,_CH2]"
)

def test_forcefield_get_impropers_combinations(self):
ff_with_impropers = ForceField()
ff_with_impropers.name = "imp_ff"
ff_with_impropers.improper_types = {
"CT~CT~HC~HC": ImproperType(name="imp1"),
"CT~HC~HC~HC": ImproperType(name="imp2"),
}
imp1 = ff_with_impropers.get_potential(
"improper_type", ["CT", "HC", "HC", "CT"]
)
imp2 = ff_with_impropers.get_potential(
"improper_type", ["CT", "HC", "CT", "HC"]
)
assert imp1.name == imp2.name
assert imp1 is imp2