Skip to content

Commit

Permalink
Expanded search for impropertypes
Browse files Browse the repository at this point in the history
  • Loading branch information
umesh-timalsina committed Jun 9, 2022
1 parent 02bdcd3 commit ae5b1de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
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

0 comments on commit ae5b1de

Please sign in to comment.